:root {
    --ink: #1d2433;
    --muted: #5c6780;
    --paper: #fffdf6;
    --page: #eef3fb;
    --line: #eadfbf;
    --highlight: #fff18a;
    --spoken: #ffe8a3;
    --active-word: #ff8a3d;
    --card: #ffffff;
    --shadow: 0 8px 24px rgba(28, 45, 80, .08);
    --radius: 16px;
    --blue: #2b6cff;
    --teal: #0f9d8a;
    --orange: #e67a00;
    --red: #d64545;
    --green: #2a9d5c;
    --gray: #667085;
    --purple: #6d4aff;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    color: var(--ink);
    background: var(--page);
    font-family: "Segoe UI", "PingFang HK", "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
}

.wrapper {
    max-width: 1180px;
    margin: 0 auto;
    padding: 18px 18px 40px;
}

.topbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.topbar a {
    display: inline-block;
    padding: 10px 14px;
    border-radius: 999px;
    text-decoration: none;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
}

.topbar a.active {
    box-shadow: 0 0 0 3px rgba(43, 108, 255, .22);
}

.nav-home { background: #334155; }
.nav-study { background: var(--blue); }
.nav-practice { background: var(--gray); }
.nav-point { background: var(--teal); }
.nav-dict { background: var(--orange); }
.nav-game { background: #db2777; }
.nav-listen { background: #0284c7; }
.nav-unseen { background: #0f172a; }
.nav-manage { background: var(--purple); }

h1 {
    margin: 0 0 8px;
    font-size: 30px;
    letter-spacing: .01em;
}

h2 {
    margin: 0 0 12px;
    font-size: 22px;
}

.note {
    margin: 0 0 18px;
    color: var(--muted);
    font-size: 16px;
    line-height: 1.55;
}

.set-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    background: var(--card);
    padding: 12px 14px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.set-bar label {
    font-weight: 700;
}

.set-bar select,
.select,
.speed-select,
input[type="text"],
input[type="number"],
textarea {
    font: inherit;
    padding: 10px 12px;
    border-radius: 12px;
    border: 2px solid #d7deea;
    background: #fff;
    min-width: 180px;
}

textarea {
    width: 100%;
    min-height: 120px;
    resize: vertical;
    line-height: 1.5;
}

.toolbar,
.controls,
.settings {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin: 12px 0;
}

.btn,
.control-btn {
    border: none;
    border-radius: 14px;
    padding: 12px 16px;
    font: inherit;
    font-weight: 800;
    color: #fff;
    cursor: pointer;
    background: var(--blue);
    transition: transform .12s ease, filter .12s ease;
}

.btn:hover, .control-btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn:active, .control-btn:active { transform: translateY(0); }
.btn:disabled, .control-btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn.green, .control-btn.green { background: var(--green); }
.btn.orange, .control-btn.orange, .control-btn.random { background: var(--orange); }
.btn.red, .control-btn.red, .control-btn.secondary { background: var(--red); }
.btn.gray, .control-btn.gray { background: var(--gray); }
.btn.teal { background: var(--teal); }
.btn.purple { background: var(--purple); }
.btn.big {
    font-size: 20px;
    padding: 16px 22px;
    border-radius: 18px;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0 16px;
}

.chip {
    border: none;
    background: #e8eefc;
    color: #1e3a8a;
    font-weight: 800;
    border-radius: 999px;
    padding: 8px 12px;
    cursor: pointer;
}

.chip.on, .chip.current {
    background: var(--teal);
    color: #fff;
}

.book {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 6px 22px 22px 6px;
    padding: 26px 28px 26px 56px;
    box-shadow: 10px 12px 0 rgba(90, 70, 20, .06), var(--shadow);
    min-height: 220px;
    position: relative;
}

.book::after {
    content: "";
    position: absolute;
    left: 22px;
    top: 16px;
    bottom: 16px;
    width: 3px;
    background: #e9c9c9;
    border-radius: 2px;
}

.sentence {
    position: relative;
    font-size: 26px;
    line-height: 1.7;
    margin: 0 0 16px;
    padding: 8px 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: background .15s ease, box-shadow .15s ease;
}

.sentence:hover { background: rgba(255, 241, 138, .35); }

.sentence.current {
    background: var(--highlight);
    box-shadow: 0 0 0 3px #f0c84a;
}

.sentence.current::before {
    content: "☝️";
    position: absolute;
    left: -48px;
    top: 6px;
    font-size: 30px;
    animation: point 0.7s ease-in-out infinite alternate;
}

.sentence.done { color: #667085; }
.sentence.hidden-text { filter: blur(0); }

.word {
    display: inline-block;
    padding: 0 2px;
    border-radius: 6px;
    transition: background .12s ease, color .12s ease, transform .12s ease;
}

.word.spoken { background: var(--spoken); }
.word.active {
    background: var(--active-word);
    color: #fff;
    transform: translateY(-1px) scale(1.04);
}

.dict-stage {
    background: #1b2436;
    color: #fff;
    border-radius: 24px;
    padding: 28px 22px;
    text-align: center;
    box-shadow: var(--shadow);
    min-height: 280px;
}

.dict-kicker {
    opacity: .75;
    letter-spacing: .12em;
    font-size: 14px;
    font-weight: 700;
}

.dict-num {
    font-size: 64px;
    font-weight: 900;
    margin: 8px 0 4px;
    line-height: 1;
}

.dict-status {
    font-size: 24px;
    font-weight: 800;
    margin: 8px 0 18px;
    min-height: 36px;
}

.dict-timer {
    display: inline-block;
    background: rgba(255,255,255,.1);
    border-radius: 999px;
    padding: 10px 18px;
    font-size: 28px;
    font-weight: 900;
    margin-bottom: 8px;
}

.pulse {
    width: 86px;
    height: 86px;
    margin: 8px auto 16px;
    border-radius: 50%;
    background: #ff8a3d;
    display: grid;
    place-items: center;
    font-size: 36px;
}

.pulse.talking {
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,138,61,.55); }
    100% { transform: scale(1.08); box-shadow: 0 0 0 18px rgba(255,138,61,0); }
}

@keyframes point {
    from { transform: translateY(0); }
    to { transform: translateY(7px); }
}

.progress-wrap {
    height: 10px;
    background: #d7deea;
    border-radius: 99px;
    overflow: hidden;
    margin: 12px 0 6px;
}

.progress-wrap.dark { background: rgba(255,255,255,.15); }

.progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #2b6cff, #0f9d8a);
}

.status-box {
    margin-top: 16px;
    padding: 14px 16px;
    background: var(--card);
    border-radius: 14px;
    font-size: 18px;
    font-weight: 800;
    box-shadow: var(--shadow);
    min-height: 54px;
}

.carby-face {
    margin-top: 8px;
    font-size: 64px;
    text-align: center;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

.home-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin-top: 8px;
}

.home-card {
    display: block;
    background: var(--card);
    border-radius: 22px;
    padding: 22px 20px;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow);
    min-height: 170px;
}

.home-card .emoji { font-size: 40px; display: block; margin-bottom: 8px; }
.home-card h2 { margin: 0 0 6px; font-size: 22px; }
.home-card p { margin: 0; color: var(--muted); line-height: 1.45; }
.home-card.point { border-top: 6px solid var(--teal); }
.home-card.dict { border-top: 6px solid var(--orange); }
.home-card.study { border-top: 6px solid var(--blue); }
.home-card.practice { border-top: 6px solid var(--gray); }
.home-card.manage { border-top: 6px solid var(--purple); }
.home-card.game { border-top: 6px solid #db2777; }

.study-btn, .practice-btn {
    border: none;
    border-radius: 16px;
    cursor: pointer;
    font: inherit;
}

.study-btn {
    background: #fff;
    color: var(--ink);
    min-height: 180px;
    padding: 16px 12px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 6px;
}

.study-btn .icon { font-size: 42px; }
.study-btn .num { font-size: 14px; color: var(--muted); font-weight: 800; }
.study-btn .label-en { font-size: 20px; font-weight: 800; line-height: 1.3; }
.study-btn .label-zh { font-size: 15px; color: var(--muted); }
.study-btn .pos { font-size: 12px; color: #8a94a6; }

.practice-btn {
    background: var(--blue);
    color: #fff;
    min-height: 100px;
    font-size: 30px;
    font-weight: 900;
    box-shadow: 0 4px 14px rgba(43,108,255,.25);
}

.practice-btn:hover { filter: brightness(1.05); }

.card {
    background: var(--card);
    border-radius: 18px;
    padding: 18px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.setting-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
}

.setting {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-weight: 700;
    font-size: 14px;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
}

.manage-table {
    width: 100%;
    border-collapse: collapse;
}

.manage-table th,
.manage-table td {
    text-align: left;
    padding: 8px 6px;
    vertical-align: top;
    border-bottom: 1px solid #edf1f7;
}

.manage-table input[type="text"] {
    min-width: 0;
    width: 100%;
}

.flash {
    padding: 12px 14px;
    border-radius: 12px;
    font-weight: 700;
    margin-bottom: 12px;
}

.flash.ok { background: #d1f3e0; color: #146c3c; }
.flash.err { background: #fde2e2; color: #9b1c1c; }

.answer-box {
    display: none;
    margin-top: 14px;
    background: #fff;
    color: var(--ink);
    border-radius: 14px;
    padding: 16px;
    font-size: 20px;
    line-height: 1.6;
    text-align: left;
}

.home-card.unseen { border-top: 6px solid #0f172a; }
.home-card.listen { border-top: 6px solid #0284c7; }

.choice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin: 14px 0;
}

.choice-card {
    border: 3px solid #d7deea;
    background: #fff;
    border-radius: 18px;
    padding: 16px 14px;
    cursor: pointer;
    text-align: left;
    font: inherit;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.choice-card:hover { border-color: #0284c7; transform: translateY(-2px); }
.choice-card.correct { border-color: #2a9d5c; background: #d1f3e0; }
.choice-card.wrong { border-color: #d64545; background: #fde2e2; }
.choice-card:disabled { cursor: default; transform: none; }

.choice-key {
    font-size: 14px;
    font-weight: 800;
    color: #0284c7;
}

.choice-text {
    font-size: 22px;
    font-weight: 800;
    line-height: 1.35;
}

.choice-zh {
    color: var(--muted);
    font-weight: 700;
}

.mini-speak {
    align-self: flex-start;
    border: none;
    background: #e0f2fe;
    color: #075985;
    font-weight: 800;
    border-radius: 999px;
    padding: 8px 12px;
    cursor: pointer;
}

.target-play {
    display: flex;
    justify-content: center;
    margin: 8px 0 4px;
}

.mode-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.mode-tabs a {
    display: inline-block;
    padding: 10px 14px;
    border-radius: 999px;
    text-decoration: none;
    font-weight: 800;
    background: #e8eefc;
    color: #1e3a8a;
}

.mode-tabs a.on {
    background: #db2777;
    color: #fff;
}

.mode-tabs a.dark.on {
    background: #0f172a;
}

.prompt {
    font-size: 28px;
    line-height: 1.85;
    margin: 10px 0 8px;
    word-break: break-word;
}

.letter-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 46px;
    margin: 2px;
    border: 2px solid #cfd8e3;
    border-radius: 10px;
    background: #fff;
    vertical-align: middle;
}

.letter-slot input {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    text-align: center;
    font-size: 24px;
    font-weight: 800;
    text-transform: lowercase;
    background: transparent;
}

.letter-slot.correct {
    background: #d1e7dd;
    border-color: #75b798;
}

.letter-slot.wrong {
    background: #f8d7da;
    border-color: #dc3545;
}

.fixed-char {
    display: inline-block;
    padding: 0 2px;
    font-weight: 800;
}

.hint-zh {
    color: var(--muted);
    font-size: 18px;
    font-weight: 700;
    min-height: 28px;
}

.pick-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
    gap: 8px;
}

.pick-btn {
    border: none;
    background: #eef3ff;
    color: #123;
    border-radius: 12px;
    padding: 12px 8px;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
}

.pick-btn:hover, .pick-btn.on { background: #dbe7ff; }
.pick-btn.on { box-shadow: 0 0 0 2px #2b6cff; }

.caby-panel {
    text-align: center;
    margin: 8px 0 4px;
}

.caby-wrap {
    display: inline-block;
    position: relative;
    width: 160px;
    height: 150px;
}

.caby-head {
    position: absolute;
    left: 28px;
    top: 38px;
    width: 104px;
    height: 72px;
    background: #c9844a;
    border-radius: 46px 46px 36px 36px;
    z-index: 2;
}

.caby-ear {
    position: absolute;
    top: 28px;
    width: 22px;
    height: 20px;
    background: #b06c38;
    border-radius: 10px 10px 6px 6px;
    z-index: 1;
}
.caby-ear.left { left: 40px; }
.caby-ear.right { right: 40px; }

.caby-eye {
    position: absolute;
    top: 28px;
    width: 10px;
    height: 12px;
    background: #2b1b12;
    border-radius: 50%;
}
.caby-eye.left { left: 30px; }
.caby-eye.right { right: 30px; }

.caby-snout {
    position: absolute;
    left: 34px;
    top: 42px;
    width: 36px;
    height: 22px;
    background: #a96a3a;
    border-radius: 12px;
}
.caby-snout::before,
.caby-snout::after {
    content: "";
    position: absolute;
    top: 8px;
    width: 6px;
    height: 6px;
    background: #3b2416;
    border-radius: 50%;
}
.caby-snout::before { left: 8px; }
.caby-snout::after { right: 8px; }

.caby-body {
    position: absolute;
    left: 18px;
    top: 86px;
    width: 124px;
    height: 52px;
    background: #d39255;
    border-radius: 40px;
    z-index: 1;
}

.caby-scarf {
    display: none;
    position: absolute;
    left: 24px;
    top: 22px;
    width: 112px;
    height: 34px;
    background: #e23d3d;
    border-radius: 18px 18px 8px 8px;
    z-index: 3;
    box-shadow: inset 0 -8px 0 #c81e1e;
}
.caby-scarf::after {
    content: "";
    position: absolute;
    right: 8px;
    top: 28px;
    width: 18px;
    height: 34px;
    background: #e23d3d;
    border-radius: 4px;
    transform: rotate(18deg);
}

.caby-wrap.happy .caby-head { animation: caby-bounce 0.45s ease-in-out infinite alternate; }
.caby-wrap.happy .caby-eye { height: 4px; top: 32px; border-radius: 4px; }
.caby-wrap.encourage .caby-scarf { display: block; }
.caby-wrap.encourage .caby-head { animation: caby-nod 1.1s ease-in-out infinite; }

.caby-msg {
    font-size: 20px;
    font-weight: 800;
    min-height: 32px;
    margin-top: 6px;
}
.caby-wrap.happy + .caby-msg { color: #146c3c; }
.caby-wrap.encourage + .caby-msg { color: #9a3412; }

.unseen-banner {
    background: #0f172a;
    color: #fff;
    border-radius: 16px;
    padding: 12px 16px;
    font-weight: 800;
    margin-bottom: 14px;
}

@keyframes caby-bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-7px); }
}
@keyframes caby-nod {
    0%, 100% { transform: rotate(-2deg); }
    50% { transform: rotate(3deg); }
}

@media (max-width: 720px) {
    h1 { font-size: 24px; }
    .sentence { font-size: 20px; padding-top: 28px; }
    .sentence.current::before {
        left: 8px;
        top: -6px;
        font-size: 24px;
    }
    .book { padding: 18px 14px 18px 16px; }
    .book::after { display: none; }
    .dict-num { font-size: 46px; }
    .set-bar select, .select { width: 100%; min-width: 0; }
    .prompt { font-size: 22px; }
    .letter-slot { width: 32px; height: 40px; }
    .letter-slot input { font-size: 20px; }
}
