:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #eef3fb;
  --ink: #172238;
  --muted: #647087;
  --line: #d7dfec;
  --blue: #2458a7;
  --blue-2: #3675d3;
  --teal: #087d75;
  --amber: #bf7412;
  --rose: #a43c62;
  --purple: #6b4ed3;
  --good: #167847;
  --danger: #b63232;
  --shadow: 0 18px 48px rgba(31, 54, 93, .11);
  --radius: 24px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; color: var(--ink); background: radial-gradient(circle at 70% -10%, #e4ecff 0, transparent 34rem), var(--bg); min-height: 100vh; }
button, input, select { font: inherit; }
button { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--blue); }
:focus-visible { outline: 3px solid rgba(54, 117, 211, .38); outline-offset: 3px; }
[hidden] { display: none !important; }

.skip-link { position: fixed; z-index: 100; left: 12px; top: -60px; padding: 10px 14px; background: var(--ink); color: #fff; border-radius: 10px; }
.skip-link:focus { top: 12px; }
.offline-banner { position: sticky; top: 0; z-index: 70; padding: 8px 16px; text-align: center; background: #fff1cc; color: #6f4700; font-size: 13px; }

.topbar { position: sticky; top: 0; z-index: 60; height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; border-bottom: 1px solid rgba(215, 223, 236, .86); background: rgba(255, 255, 255, .88); backdrop-filter: blur(16px); }
.brand, .profile-button { border: 0; background: transparent; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; padding: 6px; border-radius: 14px; }
.brand-mark, .avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 13px; background: linear-gradient(135deg, var(--blue-2), var(--purple)); color: white; font-weight: 900; box-shadow: 0 7px 18px rgba(36, 88, 167, .25); }
.brand strong { display: block; font-size: 18px; line-height: 1.05; text-align: left; }
.brand small { color: var(--muted); display: block; margin-top: 3px; font-size: 11px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; font-size: 13px; box-shadow: none; }
.topbar-actions { display: flex; align-items: center; gap: 7px; }
.profile-button { font-weight: 700; background: var(--surface-2); padding-right: 11px; }
.icon-button, .ghost-button { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; min-width: 40px; min-height: 40px; padding: 8px 12px; cursor: pointer; }
.ghost-button { color: var(--blue); font-weight: 700; }

.app-layout { display: grid; grid-template-columns: 92px 1fr; min-height: calc(100vh - 72px); }
.side-nav { position: sticky; top: 72px; align-self: start; height: calc(100vh - 72px); display: flex; flex-direction: column; gap: 7px; padding: 18px 10px; border-right: 1px solid var(--line); background: rgba(247, 249, 253, .76); }
.nav-item { border: 0; background: transparent; text-decoration: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 4px; border-radius: 16px; padding: 10px 5px; font-size: 12px; cursor: pointer; }
.nav-item span { font-weight: 800; font-size: 17px; }
.nav-item.active { color: var(--blue); background: #e3edff; font-weight: 800; }
.pdf-link { margin-top: auto; }
.pdf-link span { font-size: 11px; border: 1px solid currentColor; border-radius: 5px; padding: 2px; }
.bottom-nav { display: none; }

main { min-width: 0; }
.view-shell { width: min(1180px, calc(100vw - 132px)); margin: 0 auto; padding: 34px 20px 70px; }
.view-header { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.view-header h1 { font-size: clamp(28px, 4vw, 44px); margin: 2px 0 4px; letter-spacing: -.04em; }
.view-header p { color: var(--muted); margin: 0; max-width: 680px; line-height: 1.65; }
.eyebrow { display: block; color: var(--teal); font-size: 12px; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }

.loading-card { max-width: 560px; margin: 14vh auto; text-align: center; background: var(--surface); padding: 50px; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.loading-orbit { width: 54px; height: 54px; margin: 0 auto 22px; border: 5px solid #dce8ff; border-top-color: var(--blue); border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.hero-grid, .dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .8fr); gap: 20px; }
.hero-card { position: relative; overflow: hidden; min-height: 292px; border-radius: 30px; padding: clamp(25px, 4vw, 46px); background: linear-gradient(135deg, #1f4f9e 0%, #466ec5 55%, #6c4fcf 100%); color: white; box-shadow: 0 25px 60px rgba(42, 76, 146, .24); }
.hero-card::after { content: "声  形  义  景  用"; position: absolute; right: -10px; bottom: -20px; color: rgba(255,255,255,.08); font-size: clamp(40px, 7vw, 90px); font-weight: 950; white-space: nowrap; transform: rotate(-7deg); }
.hero-card h2 { font-size: clamp(26px, 3vw, 40px); margin: 14px 0 8px; max-width: 720px; }
.hero-card p { color: rgba(255, 255, 255, .82); line-height: 1.7; max-width: 620px; }
.hero-card .eyebrow { color: #9de8dc; }
.hero-actions, .button-row { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.primary-button, .secondary-button, .danger-button, .rating-button { border: 0; border-radius: 14px; padding: 12px 18px; font-weight: 850; cursor: pointer; min-height: 46px; }
.primary-button { background: var(--blue); color: white; box-shadow: 0 9px 23px rgba(36, 88, 167, .24); }
.hero-card .primary-button { background: white; color: var(--blue); box-shadow: none; }
.secondary-button { background: #edf3ff; color: var(--blue); border: 1px solid #d7e3fa; }
.hero-card .secondary-button { color: white; background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.24); }
.danger-button { background: #fff0f0; color: var(--danger); }
.full-width { width: 100%; }

.card, .metric-card, .control-panel, .learning-stage, .quiz-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(31, 54, 93, .06); }
.card { padding: 22px; }
.card h2, .card h3 { margin: 0 0 9px; }
.card p { color: var(--muted); line-height: 1.6; }
.card-header { display: flex; justify-content: space-between; align-items: start; gap: 14px; margin-bottom: 15px; }
.card-header p { margin: 4px 0 0; }
.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 13px; margin: 20px 0; }
.metric-card { padding: 18px; }
.metric-card strong { display: block; font-size: clamp(24px, 3vw, 38px); margin-top: 9px; }
.metric-card span { color: var(--muted); font-size: 13px; }
.metric-card small { color: var(--teal); font-weight: 750; }
.stack { display: grid; gap: 15px; }

.progress-ring { --value: 0; width: 118px; height: 118px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(#8de1d7 calc(var(--value) * 1%), rgba(255,255,255,.18) 0); }
.progress-ring::before { content: ""; width: 86px; height: 86px; border-radius: 50%; background: rgba(25, 61, 126, .94); }
.progress-ring span { position: absolute; font-size: 22px; font-weight: 900; }
.progress-line { height: 10px; border-radius: 999px; background: #e5eaf2; overflow: hidden; }
.progress-line > span { display: block; height: 100%; width: var(--value, 0%); border-radius: inherit; background: linear-gradient(90deg, var(--blue-2), var(--teal)); transition: width .5s ease; }
.progress-label { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 13px; margin: 8px 0 5px; }

.quick-list { display: grid; gap: 10px; }
.quick-row { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 13px; border-radius: 16px; background: var(--surface-2); }
.quick-row .number { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; background: white; color: var(--blue); font-weight: 900; }
.quick-row strong { display: block; }
.quick-row small { color: var(--muted); }
.status-pill, .mode-pill { display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px; border-radius: 999px; background: #e9f6f3; color: var(--teal); font-size: 12px; font-weight: 800; }
.status-pill.warn { background: #fff1dc; color: #9a5c06; }
.status-pill.rose { background: #fde9f0; color: var(--rose); }

.control-panel { padding: 18px; display: flex; flex-wrap: wrap; gap: 13px; align-items: end; margin-bottom: 18px; }
.field { display: grid; gap: 7px; min-width: 150px; flex: 1; }
.field > span { font-size: 12px; font-weight: 850; color: var(--muted); }
.field input, .field select, .answer-input, .search-input { width: 100%; min-height: 45px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); padding: 10px 12px; }
.field-wide { grid-column: 1 / -1; }

.learning-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.learning-stage { min-height: 610px; padding: clamp(22px, 4vw, 42px); position: relative; overflow: hidden; }
.learning-stage::before { content: ""; position: absolute; width: 260px; height: 260px; right: -100px; top: -100px; background: radial-gradient(circle, #e8f0ff, transparent 68%); }
.stage-top { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.stage-count { color: var(--muted); font-weight: 800; font-size: 13px; }
.stage-word { text-align: center; margin: 44px auto 26px; position: relative; z-index: 1; }
.stage-word h1 { font-family: ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif; font-size: clamp(44px, 10vw, 86px); letter-spacing: -.04em; margin: 0; color: var(--blue); overflow-wrap: anywhere; }
.stage-word .ipa { color: var(--muted); font-size: clamp(18px, 3vw, 28px); margin-top: 8px; }
.speaker-button { width: 58px; height: 58px; border-radius: 50%; border: 0; background: linear-gradient(135deg, var(--teal), #2ba79b); color: white; font-size: 25px; cursor: pointer; box-shadow: 0 12px 26px rgba(8, 125, 117, .22); }
.speaker-button.speaking { animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); box-shadow: 0 0 0 12px rgba(8,125,117,.12); } }

.layer-track { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin: 18px 0 30px; }
.layer-step { position: relative; border: 0; background: transparent; color: var(--muted); display: grid; justify-items: center; gap: 6px; font-size: 12px; cursor: pointer; }
.layer-step::before { content: attr(data-index); width: 31px; height: 31px; display: grid; place-items: center; border-radius: 50%; background: #edf1f7; font-weight: 900; }
.layer-step.done::before { content: "✓"; background: #dff4ef; color: var(--teal); }
.layer-step.active { color: var(--blue); font-weight: 850; }
.layer-step.active::before { background: var(--blue); color: #fff; box-shadow: 0 0 0 6px #e2ebfb; }
.layer-panel { position: relative; min-height: 205px; border-radius: 22px; background: linear-gradient(145deg, #f6f9ff, #edf3fc); border: 1px solid #dbe5f4; padding: clamp(20px, 4vw, 34px); display: grid; place-items: center; text-align: center; }
.layer-panel h2 { font-size: clamp(24px, 5vw, 42px); margin: 0 0 8px; }
.layer-panel p { color: var(--muted); line-height: 1.7; max-width: 700px; margin: 7px auto; }
.chunk-row { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin: 15px 0; }
.chunk { display: inline-block; padding: 10px 15px; border-radius: 13px; background: white; color: var(--purple); font-size: clamp(24px, 5vw, 44px); font-weight: 900; box-shadow: 0 8px 22px rgba(52, 74, 118, .1); animation: chunk-in .5s both; animation-delay: calc(var(--i) * 100ms); }
@keyframes chunk-in { from { opacity: 0; transform: translateY(20px) scale(.88); } }
.assembled .chunk { animation: assemble .7s both; margin-inline: -5px; border-radius: 4px; box-shadow: none; background: transparent; }
@keyframes assemble { to { transform: translateX(0); color: var(--blue); } }
.meaning-large { font-size: clamp(30px, 6vw, 58px); font-weight: 900; color: var(--rose); }
.scene-box { text-align: left; width: min(700px, 100%); padding: 20px; border-radius: 18px; background: #fff9e9; border: 1px solid #f4db9f; }
.scene-box strong { color: var(--amber); }
.usage-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; text-align: left; }
.usage-card { padding: 18px; border-radius: 16px; background: white; border: 1px solid var(--line); }
.usage-card span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.usage-card strong { font-size: 18px; line-height: 1.5; }
.stage-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 22px; }

.session-sidebar { display: grid; gap: 13px; }
.session-list { max-height: 430px; overflow: auto; display: grid; gap: 7px; }
.session-word { width: 100%; border: 1px solid transparent; border-radius: 13px; background: var(--surface-2); padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; cursor: pointer; text-align: left; }
.session-word.active { border-color: var(--blue-2); background: #e5efff; color: var(--blue); }
.session-word.done::after { content: "✓"; color: var(--good); font-weight: 900; }
.session-word small { display: block; color: var(--muted); margin-top: 2px; }

.mode-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 13px; }
.mode-card { border: 1px solid var(--line); background: var(--surface); padding: 20px; border-radius: 20px; cursor: pointer; text-align: left; transition: transform .2s ease, border-color .2s ease; }
.mode-card:hover { transform: translateY(-3px); border-color: #a7bde2; }
.mode-icon { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 14px; background: #e8f0ff; color: var(--blue); font-weight: 900; margin-bottom: 13px; }
.mode-card h3 { margin: 0 0 6px; }
.mode-card p { color: var(--muted); margin: 0; font-size: 13px; line-height: 1.55; }

.quiz-wrap { max-width: 820px; margin: 0 auto; }
.quiz-card { padding: clamp(24px, 5vw, 48px); text-align: center; }
.quiz-card h2 { font-size: clamp(32px, 7vw, 60px); margin: 18px 0; color: var(--blue); overflow-wrap: anywhere; }
.quiz-card .meaning-prompt { color: var(--rose); }
.quiz-meta { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 13px; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 24px; }
.choice-button { min-height: 62px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); padding: 12px; cursor: pointer; font-weight: 750; }
.choice-button:hover { border-color: var(--blue-2); background: #f1f6ff; }
.choice-button.correct { background: #e5f6ed; border-color: #55af7e; color: var(--good); }
.choice-button.wrong { background: #fff0f0; border-color: #dd7777; color: var(--danger); }
.answer-input { max-width: 480px; margin: 18px auto 0; text-align: center; font-size: 24px; font-weight: 800; min-height: 60px; }
.feedback { margin-top: 18px; padding: 14px 18px; border-radius: 15px; background: #e9f6f3; color: var(--good); font-weight: 800; }
.feedback.wrong { background: #fff0f0; color: var(--danger); }
.rating-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 18px; }
.rating-button.again { background: #fff0f0; color: var(--danger); }
.rating-button.hard { background: #fff4df; color: #98600e; }
.rating-button.good { background: #e5f6ed; color: var(--good); }

.filter-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.filter-button { border: 1px solid var(--line); border-radius: 999px; background: var(--surface); padding: 8px 12px; cursor: pointer; }
.filter-button.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.word-table { width: 100%; border-collapse: collapse; }
.word-table th, .word-table td { padding: 12px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.word-table th { color: var(--muted); font-size: 12px; }
.word-table td strong { display: block; }
.word-table td small { color: var(--muted); }
.word-table tbody tr { cursor: pointer; }
.word-table tbody tr:hover { background: #f6f9ff; }
.word-table-wrap { overflow-x: auto; }

.day-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.day-progress { border: 1px solid var(--line); border-radius: 16px; padding: 15px; }
.day-progress h3 { margin: 0 0 4px; font-size: 15px; }
.day-progress p { margin: 0 0 12px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mastery-bars { display: grid; gap: 12px; }
.mastery-row { display: grid; grid-template-columns: 58px 1fr 42px; gap: 10px; align-items: center; font-size: 13px; }

.app-dialog { border: 0; padding: 0; background: transparent; width: min(560px, calc(100vw - 28px)); max-height: 88vh; }
.app-dialog::backdrop { background: rgba(14, 24, 42, .56); backdrop-filter: blur(4px); }
.dialog-card { background: var(--surface); border-radius: 24px; padding: 24px; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow); }
.dialog-title { display: flex; justify-content: space-between; align-items: start; gap: 15px; margin-bottom: 20px; }
.dialog-title h2 { margin: 3px 0 0; }
.profile-list { display: grid; gap: 8px; margin: 12px 0 18px; }
.profile-option { border: 1px solid var(--line); background: var(--surface); border-radius: 15px; padding: 12px; display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.profile-option.active { border-color: var(--blue); background: #edf4ff; }
.dialog-note { color: var(--muted); font-size: 12px; line-height: 1.6; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; }
.toggle-row { display: flex; align-items: center; gap: 9px; min-height: 42px; }
.toggle-row input { width: 19px; height: 19px; }
.file-drop { display: grid; place-items: center; border: 2px dashed #bdcbe0; border-radius: 17px; min-height: 120px; color: var(--muted); margin-bottom: 15px; text-align: center; padding: 18px; }
.file-drop input { max-width: 100%; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translate(-50%, 30px); opacity: 0; pointer-events: none; background: #172238; color: white; border-radius: 13px; padding: 11px 16px; box-shadow: var(--shadow); transition: .25s ease; max-width: min(520px, calc(100vw - 30px)); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.empty-state { text-align: center; padding: 55px 20px; }
.empty-state .empty-icon { font-size: 50px; }
.empty-state p { max-width: 520px; margin: 8px auto 20px; color: var(--muted); line-height: 1.7; }

body.high-contrast { --ink: #05070b; --muted: #384052; --line: #aab5c7; --blue: #063b99; --bg: #fff; }
body.high-contrast .card, body.high-contrast .learning-stage { box-shadow: none; }
body.reduce-motion * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .001ms !important; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .001ms !important; }
}

@media (max-width: 920px) {
  .app-layout { grid-template-columns: 1fr; }
  .side-nav { display: none; }
  .view-shell { width: 100%; padding: 24px 18px calc(92px + var(--safe-bottom)); }
  .bottom-nav { position: fixed; z-index: 55; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); padding: 7px 7px calc(7px + var(--safe-bottom)); border-top: 1px solid var(--line); background: rgba(255,255,255,.94); backdrop-filter: blur(16px); }
  .bottom-nav .nav-item { padding: 5px; font-size: 10px; }
  .bottom-nav .nav-item span { font-size: 16px; }
  .hero-grid, .dashboard-grid, .learning-layout { grid-template-columns: 1fr; }
  .learning-layout { display: flex; flex-direction: column; }
  .learning-stage { min-height: 600px; width: 100%; }
  .session-sidebar { width: 100%; }
  .mode-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 620px) {
  .topbar { height: 64px; padding: 0 12px; }
  .brand small, #profile-name, #install-button { display: none; }
  .brand-mark { width: 34px; height: 34px; }
  .view-shell { padding: 20px 13px calc(88px + var(--safe-bottom)); }
  .view-header { align-items: start; flex-direction: column; }
  .hero-card { min-height: 330px; border-radius: 24px; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .mode-grid, .day-grid, .choice-grid { grid-template-columns: 1fr; }
  .control-panel { display: grid; grid-template-columns: 1fr 1fr; }
  .control-panel .field:first-child { grid-column: 1 / -1; }
  .learning-stage { min-height: 620px; padding: 18px; border-radius: 20px; }
  .layer-panel { min-height: 250px; }
  .layer-track { gap: 1px; }
  .layer-step { font-size: 10px; }
  .layer-step::before { width: 28px; height: 28px; }
  .usage-grid { grid-template-columns: 1fr; }
  .stage-actions { flex-direction: column-reverse; }
  .stage-actions button { width: 100%; }
  .rating-row { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .word-table th:nth-child(4), .word-table td:nth-child(4) { display: none; }
  .dialog-card { padding: 20px; }
}
