:root {
  --ink: #263656;
  --muted: #61718f;
  --blue: #4169d1;
  --blue-deep: #3157ba;
  --blue-soft: #eaf0ff;
  --line: #e2e8f4;
  --paper: #ffffff;
  --warm: #f3b653;
  color: var(--ink);
  background: #fff;
}

body {
  background: radial-gradient(circle at 88% 0, #edf2ff 0, transparent 34%), #f7f9ff;
}

.brand-logo {
  display: block;
  width: 48px;
  height: 48px;
  flex: none;
  filter: drop-shadow(0 5px 7px #3659aa1b);
}

.topbar {
  background: #fff;
  border-color: var(--line);
  padding-top: env(safe-area-inset-top);
  height: calc(82px + env(safe-area-inset-top));
}
.layout { min-height: calc(100vh - 82px - env(safe-area-inset-top)); }

.brand strong { color: #263a67; }
.brand small { color: var(--muted); }
.topbar-side { color: var(--muted); }
.text-button { color: var(--blue); }
.nav { border-color: var(--line); }
.nav-item { color: #657694; }
.nav-item:hover { background: #f0f4ff; }
.nav-item.active { background: var(--blue-soft); color: var(--blue-deep); }
.nav-foot { border-color: var(--line); color: var(--muted); }

.eyebrow { color: var(--blue); }
.page-heading h1 { color: #25395f; }
.page-heading p { color: var(--muted); }

.content-card,
.review-card {
  border-color: var(--line);
  background: var(--paper);
  box-shadow: 0 16px 40px #3451940b;
}

.stat-card { border-color: #e1e8fb; background: #eef3ff; }
.stat-card:nth-child(2) { border-color: #ddede9; background: #eef8f5; }
.stat-card:nth-child(3) { border-color: #f6e9d4; background: #fff7eb; }
.stat-card span { color: #576988; }
.stat-card strong { color: var(--blue-deep); }
.stat-card:nth-child(2) strong { color: #267c72; }
.stat-card:nth-child(3) strong { color: #bd7830; }

.chip { background: var(--blue-soft); color: var(--blue-deep); }
.muted { color: var(--muted); }
.prompt-label { color: #62779f; }
.answer-grid label { color: #53688d; }
.pronunciation { color: var(--muted); }
.answer-panel,
.lookup-head,
.term-item,
.setting-row { border-color: var(--line); }
.answer-panel h3 { color: #637695; }
.answer-panel { scroll-margin-top: 20px; }
.feedback { color: #b8614e; }
.feedback.ok { color: #267a70; }
.result-status { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; border-radius: 13px; padding: 13px 16px; margin-bottom: 16px; font-size: 14px; }
.result-status strong { font-size: 17px; }
.result-status.correct { background: #edf8f4; color: #246e65; }
.result-status.incorrect { background: #fff0eb; color: #a4543e; }
.answer-checks { display: flex; gap: 9px; flex-wrap: wrap; margin-bottom: 18px; }
.answer-check { display: grid; gap: 4px; min-width: min(180px, 100%); border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; }
.answer-check span { font-size: 12px; font-weight: 700; }
.answer-check strong { font-size: 15px; word-break: break-word; }
.answer-check.correct { border-color: #cfe8df; color: #246e65; }
.answer-check.incorrect { border-color: #f0d2c7; color: #a4543e; }
.check-note { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.spelling-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-top: 14px; color: var(--muted); font-size: 12px; }
.spelling-tools .small-button { font-size: 13px; font-weight: 700; }
.choice-field { padding: 0; margin: 20px 0 0; border: 0; }
.choice-field legend { padding: 0 0 10px; color: #53688d; font-size: 14px; font-weight: 700; }
.chinese-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.chinese-choice { display: flex; align-items: center; gap: 11px; min-height: 54px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; line-height: 1.35; }
.chinese-choice:has(input:checked) { border-color: #7293ea; background: #edf2ff; box-shadow: 0 0 0 2px #4169d122; }
.chinese-choice:has(input:disabled) { cursor: default; }
.chinese-choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chinese-choice:has(input:focus-visible) { outline: 3px solid #4169d166; outline-offset: 2px; }
.choice-letter { display: grid; place-items: center; width: 27px; height: 27px; flex: none; border-radius: 8px; background: #edf2ff; color: var(--blue-deep); font-size: 12px; font-weight: 800; }
.chinese-choice:has(input:checked) .choice-letter { background: var(--blue); color: #fff; }
.spelling-keyboard { max-width: 650px; margin-top: 12px; padding: 12px; border: 1px solid #dce5f8; border-radius: 16px; background: #f2f6ff; }
.key-row { display: flex; justify-content: center; gap: 5px; margin-top: 6px; }
.key-row:first-child { margin-top: 0; }
.letter-key { flex: 1; min-width: 0; max-width: 55px; min-height: 44px; border: 1px solid #cad8f2; border-radius: 9px; background: #fff; box-shadow: 0 2px 0 #c7d5ee; color: var(--ink); font-size: 15px; font-weight: 750; touch-action: manipulation; }
.letter-key:active { background: #dce7ff; transform: translateY(1px); box-shadow: 0 1px 0 #c7d5ee; }
.key-controls .letter-key { max-width: 90px; font-size: 13px; }
.key-controls .space-key { max-width: 230px; flex: 2; }
#answer-english[readonly] { background: #f8faff; caret-color: var(--blue); }

input,
textarea,
.voice-controls select {
  border-color: #d9e2f2;
  color: var(--ink);
}
input:focus,
textarea:focus,
.voice-controls select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px #4169d126;
  outline: none;
}
.sense input { accent-color: var(--blue); }
.sense { border-color: var(--line); }
.sense:has(input:checked) { border-color: #8aa4ed; background: #f2f5ff; }

.button.primary { background: var(--blue); }
.button.primary:hover { background: var(--blue-deep); }
.button.secondary { background: var(--blue-soft); color: var(--blue-deep); }
.button.secondary:hover { background: #dce6ff; }
.button.ghost { border-color: #cad7f2; color: var(--blue-deep); }
.button.ghost:hover { background: #f4f7ff; }
.button.warn { background: #fff0eb; color: #ae6046; }
.small-button { background: #eef3ff; color: var(--blue-deep); }

.empty-state { color: var(--muted); }
.empty-icon { background: #eaf0ff; color: var(--blue); }
.empty-state h2 { color: var(--ink); }
.field-label { color: #344b74; }
.help-text { color: var(--muted); }
.lookup-head span,
.term-main small { color: var(--muted); }
.lookup-result h3 { color: #576e97; }
.notice { background: #f0f4ff; color: #5e7197; }
.notice.error { background: #fff1eb; color: #a5533c; }
.term-main p { color: #647590; }
.setting-row p { color: var(--muted); }
.setting-row input { color: var(--blue-deep); }
.toast { background: #2d416f; }
.schedule-note { margin: 2px 0 20px; padding: 13px 16px; border-radius: 12px; background: #eef3ff; color: #52678e; font-size: 13px; line-height: 1.65; }

.calendar-card { margin-top: 22px; padding: 23px 26px 20px; border: 1px solid var(--line); border-radius: 20px; background: var(--paper); box-shadow: 0 16px 40px #3451940b; }
.calendar-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.calendar-heading h2 { margin: 3px 0 0; font-size: 20px; color: var(--ink); }
.calendar-nav { display: flex; align-items: center; gap: 11px; color: var(--ink); white-space: nowrap; }
.calendar-nav strong { min-width: 88px; text-align: center; font-size: 14px; }
.calendar-nav button { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 9px; background: #f7f9ff; color: var(--blue-deep); font: inherit; font-size: 21px; line-height: 1; cursor: pointer; }
.calendar-weekdays,.calendar-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 7px; text-align: center; }
.calendar-weekdays { margin-bottom: 8px; color: var(--muted); font-size: 12px; font-weight: 700; }
.calendar-day { position: relative; display: grid; place-items: center; height: 39px; border-radius: 10px; color: #8390a9; font-size: 13px; }
.calendar-day.complete { background: #e9f7f2; color: #267c72; font-weight: 800; }
.calendar-day.complete.just-completed { z-index: 1; animation: calendar-check-pop 900ms ease-out both; }
.calendar-day.complete.just-completed::after { content: ""; position: absolute; inset: -5px; border: 2px solid #62bda3; border-radius: 15px; pointer-events: none; animation: calendar-check-ring 1.4s ease-out both; }
.stat-card.just-completed strong { animation: completed-count-pop 900ms ease-out both; }
.calendar-day.missed { background: #fff2eb; color: #ae715b; }
.calendar-day.today { outline: 2px solid #9fb6f5; outline-offset: -2px; color: var(--blue-deep); font-weight: 800; }
.calendar-day b { position: absolute; right: 4px; bottom: 0; font-size: 10px; }
.calendar-legend { display: flex; gap: 18px; margin-top: 16px; color: var(--muted); font-size: 12px; }
.calendar-legend span { display: flex; align-items: center; gap: 6px; }
.calendar-legend i { width: 11px; height: 11px; border-radius: 4px; }
.legend-done { background: #c7eadd; }.legend-missed { background: #f5d9ca; }.legend-today { border: 2px solid #9fb6f5; }

.celebration { position: relative; overflow: hidden; }
.celebration .empty-icon { background: #e8f7ef; color: #31856f; animation: celebrate-pop 700ms both; }
.celebration-sparks { position: absolute; left: 50%; top: 35%; width: 1px; height: 1px; pointer-events: none; }
.celebration-sparks i { position: absolute; width: 6px; height: 6px; border-radius: 2px; background: #f3b653; transform: rotate(calc(var(--i) * 30deg)) translateY(-68px); animation: celebrate-spark 1.3s ease-out both; animation-delay: calc(var(--i) * 25ms); }
.celebration-sparks i:nth-child(3n) { background: #7aa6eb; }.celebration-sparks i:nth-child(3n + 1) { background: #69baa6; }
.completion-stamp { display: table; margin: 6px auto 18px; padding: 6px 14px; border: 1px solid #82cbb4; border-radius: 100px; background: #eaf8f2; color: #287c68; font-size: 13px; font-weight: 800; animation: completion-stamp-in 850ms 350ms both; }
@keyframes celebrate-pop { from { transform: scale(.55); opacity: .3; } 60% { transform: scale(1.12); } to { transform: scale(1); opacity: 1; } }
@keyframes celebrate-spark { from { opacity: 0; transform: rotate(calc(var(--i) * 30deg)) translateY(-15px) scale(.5); } 35% { opacity: 1; } to { opacity: 0; transform: rotate(calc(var(--i) * 30deg)) translateY(-90px) scale(1); } }
@keyframes calendar-check-pop { 0% { transform: scale(.6); } 55% { transform: scale(1.26); box-shadow: 0 0 0 9px #80d0b743; } 100% { transform: scale(1); box-shadow: none; } }
@keyframes calendar-check-ring { from { opacity: .9; transform: scale(.65); } to { opacity: 0; transform: scale(1.45); } }
@keyframes completed-count-pop { 0% { transform: scale(.75); opacity: .6; } 60% { transform: scale(1.18); } 100% { transform: scale(1); opacity: 1; } }
@keyframes completion-stamp-in { from { opacity: 0; transform: translateY(12px) scale(.78) rotate(-9deg); } 65% { transform: translateY(-3px) scale(1.08) rotate(3deg); } to { opacity: 1; transform: translateY(0) scale(1) rotate(0); } }

.login-screen {
  background: radial-gradient(circle at 20% 10%, #eaf0ff, transparent 42%), #f7f9ff;
}
.login-card { border-color: var(--line); box-shadow: 0 18px 60px #34519414; }
.login-card .brand-logo { width: 64px; height: 64px; }
.login-card p { color: var(--muted); }
.review-top { justify-content: flex-start; flex-wrap: wrap; }
.review-top .muted { margin-left: auto; }
.waiting-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.setting-number { display: flex; align-items: center; gap: 8px; color: var(--muted); white-space: nowrap; }
.setting-number input { width: 94px; }

.badge-summary { display: flex; align-items: center; gap: 20px; padding: 22px 27px; margin-bottom: 20px; border: 1px solid #dfe6f8; border-radius: 20px; background: linear-gradient(115deg, #eef3ff, #fffaf0); }
.badge-summary > strong { color: var(--blue-deep); font-size: 39px; line-height: 1; white-space: nowrap; }
.badge-summary > strong span { color: #9aa8bf; font-size: 23px; }
.badge-summary b { color: var(--ink); font-size: 16px; }
.badge-summary p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.badge-groups { display: grid; gap: 20px; }
.badge-group { --badge-color: #d58250; --badge-light: #fff1de; --badge-ribbon: #e9ab76; padding: 24px; border: 1px solid var(--line); border-radius: 20px; background: #fff; box-shadow: 0 12px 36px #34519408; }
.badge-checkins { --badge-color: #318b82; --badge-light: #e4f7f1; --badge-ribbon: #76c4ad; }
.badge-words { --badge-color: #486bc7; --badge-light: #eaf0ff; --badge-ribbon: #94aae9; }
.badge-perfect { --badge-color: #8d65ba; --badge-light: #f3eaff; --badge-ribbon: #b89bda; }
.badge-group-heading { display: flex; align-items: end; justify-content: space-between; gap: 14px; margin-bottom: 22px; }
.badge-group-heading .eyebrow { color: var(--badge-color); }
.badge-group-heading h2 { margin: 6px 0 0; font-size: 19px; color: var(--ink); }
.badge-group-heading h2 strong { color: var(--badge-color); font-size: 23px; }
.badge-group-heading > span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.badge-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.badge-card { min-width: 0; padding: 14px 10px 16px; border: 1px solid var(--line); border-radius: 16px; background: #fbfcff; text-align: center; }
.badge-card.earned { border-color: var(--badge-ribbon); background: linear-gradient(#fff, var(--badge-light)); }
.medal { position: relative; display: grid; place-items: end center; width: 108px; height: 113px; margin: 0 auto 10px; color: var(--badge-color); }
.medal::before,.medal::after { content: ""; position: absolute; top: 0; width: 20px; height: 52px; background: var(--badge-ribbon); }
.medal::before { left: 30px; transform: rotate(-15deg); }
.medal::after { right: 30px; transform: rotate(15deg); }
.medal-face { position: relative; z-index: 1; display: grid; align-content: center; justify-items: center; width: 92px; height: 92px; border: 5px solid var(--badge-color); border-radius: 50%; background: var(--badge-light); box-shadow: inset 0 0 0 3px #fff9, 0 5px 12px #273d6517; }
.medal-face svg { width: 34px; height: 34px; }
.medal-face strong { font-size: 19px; line-height: 1; margin-top: 3px; }
.medal-face small { font-size: 10px; margin-left: 2px; }
.badge-card.locked .medal { opacity: .42; }
.badge-card h3 { margin: 5px 0 2px; font-size: 15px; color: var(--ink); }
.badge-card p { margin: 0; color: var(--muted); font-size: 12px; }
.badge-state { display: inline-block; margin-top: 9px; padding: 5px 9px; border-radius: 100px; background: #edf1f7; color: var(--muted); font-size: 11px; font-weight: 700; }
.badge-card.earned .badge-state { background: var(--badge-light); color: var(--badge-color); }
.badge-card.newly-earned { animation: badge-library-glow 1.5s ease-out both; }
.badge-card.newly-earned .medal { animation: badge-library-bounce 850ms ease-out both; }

.badge-reward-backdrop { position: fixed; z-index: 30; inset: 0; display: grid; place-items: center; padding: 20px; background: #1b2d55a8; backdrop-filter: blur(5px); }
.badge-reward-card { --badge-color: #d58250; --badge-light: #fff1de; --badge-ribbon: #e9ab76; position: relative; width: min(420px, 100%); overflow: hidden; padding: 29px 25px 26px; border: 1px solid #fff9; border-radius: 25px; background: radial-gradient(circle at 50% 10%, var(--badge-light), #fff 62%); box-shadow: 0 25px 70px #12244555; text-align: center; animation: badge-reward-enter 650ms cubic-bezier(.2,.9,.2,1.2) both; }
.reward-checkins .badge-reward-card { --badge-color: #318b82; --badge-light: #e4f7f1; --badge-ribbon: #76c4ad; }
.reward-words .badge-reward-card { --badge-color: #486bc7; --badge-light: #eaf0ff; --badge-ribbon: #94aae9; }
.reward-perfect .badge-reward-card { --badge-color: #8d65ba; --badge-light: #f3eaff; --badge-ribbon: #b89bda; }
.reward-eyebrow { position: relative; z-index: 1; display: inline-block; padding: 6px 13px; border-radius: 100px; background: var(--badge-light); color: var(--badge-color); font-size: 13px; font-weight: 800; letter-spacing: .08em; }
.badge-reward-card .medal { z-index: 1; transform: scale(1.32); margin: 24px auto 25px; animation: badge-reward-medal 850ms 120ms both; }
.badge-reward-card h2 { position: relative; z-index: 1; margin: 0; color: var(--ink); font-size: 27px; }
.badge-reward-card p { position: relative; z-index: 1; margin: 7px 0 22px; color: var(--muted); }
.reward-actions { position: relative; z-index: 1; display: flex; justify-content: center; gap: 10px; }
.reward-actions .button { flex: 1; }
.reward-particles { position: absolute; left: 50%; top: 42%; pointer-events: none; }
.reward-particles i { position: absolute; width: 7px; height: 7px; border-radius: 2px; background: var(--badge-color); animation: reward-particle 1.5s ease-out both; animation-delay: calc(var(--i) * 35ms); }
.reward-particles i:nth-child(3n) { background: #f2bd58; }.reward-particles i:nth-child(3n + 1) { background: #6bbca8; }
@keyframes badge-reward-enter { from { opacity: 0; transform: translateY(35px) scale(.86); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes badge-reward-medal { from { opacity: 0; transform: rotate(-25deg) scale(.45); } 65% { transform: rotate(8deg) scale(1.46); } to { opacity: 1; transform: rotate(0) scale(1.32); } }
@keyframes reward-particle { from { opacity: 0; transform: rotate(calc(var(--i) * 22.5deg)) translateY(-15px) scale(.35); } 28% { opacity: 1; } to { opacity: 0; transform: rotate(calc(var(--i) * 22.5deg)) translateY(-150px) scale(1); } }
@keyframes badge-library-glow { from { box-shadow: 0 0 0 8px #f3bd6255; } to { box-shadow: 0 0 0 0 transparent; } }
@keyframes badge-library-bounce { 0% { transform: scale(.75) rotate(-10deg); } 65% { transform: scale(1.12) rotate(4deg); } to { transform: scale(1) rotate(0); } }

@media (max-width: 800px) {
  .nav { grid-template-columns: repeat(5, minmax(0, 1fr)); border-color: var(--line); background: #fff; box-shadow: 0 -5px 22px #3451940d; }
  .topbar { height: calc(70px + env(safe-area-inset-top)); }
  .layout { min-height: calc(100vh - 70px - env(safe-area-inset-top)); }
  .topbar .brand-logo { width: 43px; height: 43px; }
}

@media (min-width: 700px) and (min-height: 600px) and (any-pointer: coarse) {
  .topbar { height: calc(94px + env(safe-area-inset-top)); }
  .layout { min-height: calc(100vh - 94px - env(safe-area-inset-top)); }
  .topbar .brand { gap: 14px; }
  .topbar .brand-logo { width: 60px; height: 60px; }
  .topbar .brand strong { font-size: 24px; letter-spacing: 1.2px; }
  .topbar .brand small { font-size: 13px; letter-spacing: 1.5px; margin-top: 3px; }
}

@media (max-width: 620px) {
  .badge-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .badge-group { padding: 18px 12px; }
  .badge-group-heading { align-items: start; flex-direction: column; gap: 4px; }
  .badge-summary { padding: 18px; }
}

@media (max-width: 520px) {
  .chinese-choices { grid-template-columns: 1fr; gap: 8px; }
  .calendar-card { padding: 18px 15px; }
  .calendar-weekdays,.calendar-days { gap: 4px; }
  .calendar-day { height: 36px; }
  .spelling-keyboard { padding: 8px; }
  .key-row { gap: 3px; }
  .letter-key { min-height: 39px; border-radius: 7px; font-size: 13px; }
  .key-controls .letter-key { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) { .celebration .empty-icon,.celebration-sparks i,.completion-stamp,.calendar-day.complete.just-completed,.calendar-day.complete.just-completed::after,.stat-card.just-completed strong,.badge-card.newly-earned,.badge-card.newly-earned .medal,.badge-reward-card,.badge-reward-card .medal,.reward-particles i { animation: none; } .celebration-sparks,.reward-particles { display: none; } }
