:root {
    --bg-main: #1a3a5c;
    --bg-accent: #2d6a4f;
    --gold: #f4c430;
    --danger: #e63946;
    --success: #52b788;
    --panel: rgba(255,255,255,.1);
    --panel-border: rgba(255,255,255,.2);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
    background: linear-gradient(135deg, #1a3a5c 0%, #2d6a4f 50%, #40916c 100%);
    min-height: 100vh;
    color: #fff;
    overflow-x: hidden;
}

.screen { display: none; min-height: 100vh; padding: 16px; }
.screen.active { display: block; animation: fadeIn .35s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.container { max-width: 960px; margin: 0 auto; }

/* ===== Top bar ===== */
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px;
}
.topbar h1 { font-size: 1.4rem; text-shadow: 0 2px 8px rgba(0,0,0,.3); }
.icon-btn {
    background: var(--panel); border: 1px solid var(--panel-border);
    color: #fff; border-radius: 50%; width: 44px; height: 44px;
    font-size: 1.2rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: transform .15s, background .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.25); transform: scale(1.08); }
.icon-btn:active { transform: scale(.94); }

/* ===== Home menu ===== */
.hero { text-align: center; margin-bottom: 32px; }
.hero h2 { font-size: 2rem; margin-bottom: 6px; text-shadow: 0 2px 10px rgba(0,0,0,.35); }
.hero p { opacity: .85; }

.menu-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 24px;
}
@media (max-width: 720px) { .menu-grid { grid-template-columns: 1fr; } }

.game-card {
    background: var(--panel); border: 1px solid var(--panel-border); border-radius: 16px;
    padding: 24px 18px; text-align: center; cursor: pointer;
    transition: transform .18s ease, background .18s ease; backdrop-filter: blur(6px);
    position: relative; overflow: hidden;
}
.game-card:hover { transform: translateY(-4px); background: rgba(255,255,255,.18); }
.game-card .emoji { font-size: 2.6rem; display: block; margin-bottom: 10px; }
.game-card h3 { font-size: 1.15rem; margin-bottom: 6px; }
.game-card p { font-size: .85rem; opacity: .8; line-height: 1.5; }
.game-card .progress-tag {
    position: absolute; top: 10px; right: 10px; background: var(--gold); color: #333;
    font-size: .7rem; padding: 3px 8px; border-radius: 10px; font-weight: bold;
}

.cert-banner {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    background: linear-gradient(90deg, rgba(244,196,48,.25), rgba(244,196,48,.05));
    border: 1px solid rgba(244,196,48,.5); border-radius: 14px; padding: 16px 20px; margin-bottom: 20px;
    flex-wrap: wrap;
}
.cert-banner.locked { opacity: .55; }
.btn {
    background: var(--gold); color: #2b2200; border: none; border-radius: 999px;
    padding: 10px 22px; font-weight: bold; font-size: .95rem; cursor: pointer;
    transition: transform .15s, box-shadow .15s;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,.25); }
.btn:disabled { background: #666; color: #aaa; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.secondary { background: rgba(255,255,255,.15); color: #fff; border: 1px solid var(--panel-border); }
.btn.danger { background: var(--danger); color: #fff; }

/* ===== Quiz modal ===== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.6);
    display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal-box {
    background: #16324a; border: 1px solid var(--panel-border); border-radius: 16px;
    padding: 28px; max-width: 480px; width: 100%; text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-box h3 { margin-bottom: 16px; font-size: 1.1rem; line-height: 1.6; }
.quiz-options { display: grid; gap: 10px; margin-top: 16px; }
.quiz-option {
    background: rgba(255,255,255,.1); border: 1px solid var(--panel-border); color: #fff;
    padding: 12px; border-radius: 10px; cursor: pointer; font-size: .95rem; text-align: left;
    transition: background .15s;
}
.quiz-option:hover { background: rgba(255,255,255,.22); }
.quiz-option.correct { background: var(--success); border-color: var(--success); }
.quiz-option.wrong { background: var(--danger); border-color: var(--danger); }

/* ===== Battle screen (Knight) ===== */
.stage-header { text-align: center; margin-bottom: 16px; }
.stage-header h2 { font-size: 1.3rem; }
.battle-field {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin: 20px 0; flex-wrap: wrap;
}
.combatant { flex: 1; min-width: 130px; text-align: center; }
.combatant .avatar {
    font-size: 3.4rem; margin-bottom: 6px; display: block;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,.4));
    transition: transform .25s;
}
.combatant.hit .avatar { animation: shake .35s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.hp-bar-wrap { background: rgba(0,0,0,.4); border-radius: 999px; height: 16px; overflow: hidden; border: 1px solid rgba(255,255,255,.25); }
.hp-bar { height: 100%; background: linear-gradient(90deg, #52b788, #95d5b2); transition: width .4s ease; }
.hp-bar.boss { background: linear-gradient(90deg, #e63946, #ff8fa3); }
.hp-label { font-size: .8rem; margin-top: 4px; opacity: .85; }
.vs { font-size: 1.4rem; font-weight: bold; color: var(--gold); }

.timer-bar-wrap { background: rgba(0,0,0,.35); border-radius: 999px; height: 10px; margin: 12px 0 20px; overflow: hidden; }
.timer-bar { height: 100%; background: var(--gold); transition: width linear; }

.question-panel { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px; padding: 20px; }
.question-panel h3 { margin-bottom: 16px; font-size: 1.05rem; line-height: 1.6; }
.options-grid { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
@media (max-width: 600px) { .options-grid { grid-template-columns: 1fr; } }

.floating-dmg {
    position: absolute; font-weight: bold; font-size: 1.1rem; color: var(--danger);
    animation: floatUp 1s ease forwards; pointer-events: none;
}
@keyframes floatUp { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-40px); } }

/* ===== Year-end journal entry ===== */
.chapter-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 16px; }
.chapter-tab {
    flex: 0 0 auto; background: var(--panel); border: 1px solid var(--panel-border); color: #fff;
    padding: 8px 14px; border-radius: 999px; font-size: .85rem; cursor: pointer; white-space: nowrap;
}
.chapter-tab.active { background: var(--gold); color: #2b2200; font-weight: bold; }
.chapter-tab.done::after { content: " ✓"; }

.journal-panel { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px; padding: 20px; }
.journal-q { margin-bottom: 18px; font-size: 1.02rem; line-height: 1.7; }
.journal-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .journal-cols { grid-template-columns: 1fr; } }
.journal-col h4 { margin-bottom: 8px; font-size: .95rem; color: var(--gold); }
.journal-row { display: flex; gap: 6px; margin-bottom: 8px; }
.journal-row select, .journal-row input {
    flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--panel-border);
    background: rgba(255,255,255,.08); color: #fff; font-size: .85rem; min-width: 0;
}
.journal-row select option { color: #000; }
.journal-row input::placeholder { color: rgba(255,255,255,.5); }
.journal-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-end; flex-wrap: wrap; }

.answer-feedback { margin-top: 14px; padding: 12px; border-radius: 10px; font-size: .9rem; line-height: 1.7; }
.answer-feedback.correct { background: rgba(82,183,136,.2); border: 1px solid var(--success); }
.answer-feedback.wrong { background: rgba(230,57,70,.2); border: 1px solid var(--danger); }

.stars-row { display: flex; gap: 4px; margin-top: 8px; }
.star { font-size: 1rem; opacity: .3; }
.star.on { opacity: 1; color: var(--gold); }

/* ===== Certificate ===== */
.cert-page { display: flex; align-items: center; justify-content: center; min-height: 80vh; }
.certificate {
    background: linear-gradient(160deg, #fff8e1, #fdecc8);
    color: #4a3200; border: 10px double #c99a2e; border-radius: 10px;
    padding: 48px 32px; max-width: 560px; width: 100%; text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.certificate h2 { font-size: 1.8rem; margin-bottom: 20px; letter-spacing: 4px; }
.certificate .name-line { font-size: 1.3rem; margin: 20px 0; font-weight: bold; border-bottom: 2px solid #c99a2e; display: inline-block; padding: 0 20px 6px; }
.certificate p { line-height: 2; }
.certificate .stamp { font-size: 3rem; margin-top: 16px; }

/* ===== Login form ===== */
.login-form { display: grid; gap: 12px; max-width: 360px; margin: 40px auto; }
.login-form input {
    padding: 12px; border-radius: 8px; border: 1px solid var(--panel-border);
    background: rgba(255,255,255,.1); color: #fff; font-size: 1rem;
}
.login-form input::placeholder { color: rgba(255,255,255,.6); }

/* ===== Toast ===== */
#toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,.85); color: #fff; padding: 12px 22px; border-radius: 999px;
    font-size: .9rem; z-index: 200; opacity: 0; transition: opacity .3s; pointer-events: none;
}
#toast.show { opacity: 1; }

footer.site-footer { text-align: center; opacity: .55; font-size: .8rem; margin-top: 30px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.1); }
