:root {
  color-scheme: light;
  --navy: #123d68;
  --navy-2: #0b2e52;
  --blue-soft: #e8f1f8;
  --teal: #178b78;
  --teal-soft: #e4f5f1;
  --orange: #e58d28;
  --orange-soft: #fff2df;
  --red: #c94d4d;
  --red-soft: #fff0ee;
  --ink: #172b3d;
  --muted: #67798a;
  --line: #dce5eb;
  --paper: #ffffff;
  --canvas: #f3f7fa;
  --shadow: 0 16px 45px rgba(25, 58, 86, .09);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: radial-gradient(circle at 92% 4%, rgba(23,139,120,.09), transparent 25rem), var(--canvas); }
button { font: inherit; }
button, .option { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

.topbar {
  height: 82px; padding: max(12px, env(safe-area-inset-top)) max(28px, env(safe-area-inset-right)) 12px max(28px, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,.88);
  border-bottom: 1px solid rgba(204,219,228,.8); backdrop-filter: blur(18px); position: sticky; top: 0; z-index: 10;
}
.brand { border: 0; background: transparent; display: flex; align-items: center; gap: 12px; text-align: left; color: var(--ink); cursor: pointer; padding: 4px; }
.brand-mark { width: 42px; height: 42px; border-radius: 12px; background: var(--navy); color: white; display: grid; place-items: center; font-size: 20px; font-weight: 800; box-shadow: inset 0 -3px 0 rgba(0,0,0,.12); }
.brand strong { display: block; font-size: 18px; line-height: 1.15; }
.brand small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.today-summary { display: flex; gap: 9px; align-items: center; color: var(--muted); font-size: 14px; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 9px 15px; }
.today-summary strong { color: var(--ink); }
.today-summary i { width: 1px; height: 18px; background: var(--line); margin: 0 3px; }

main { max-width: 1360px; margin: 0 auto; padding: 42px max(30px, env(safe-area-inset-right)) max(45px, env(safe-area-inset-bottom)) max(30px, env(safe-area-inset-left)); }
.welcome-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; }
.eyebrow { text-transform: none; letter-spacing: .08em; color: var(--teal); font-weight: 800; font-size: 13px; margin: 0 0 8px; }
h1 { margin: 0; font-size: clamp(30px, 4vw, 48px); line-height: 1.18; letter-spacing: -.03em; }
h2, h3, p { margin-top: 0; }
.review-pill { border: 1px solid #d5e8e4; background: var(--teal-soft); color: var(--ink); border-radius: 17px; padding: 12px 17px; display: flex; gap: 12px; align-items: center; cursor: pointer; min-width: 156px; }
.review-icon { background: var(--teal); color: white; border-radius: 50%; width: 34px; height: 34px; display: grid; place-items: center; font-size: 20px; }
.review-pill small, .review-pill strong { display: block; text-align: left; }
.review-pill small { color: #54746e; font-size: 12px; }
.review-pill strong { font-size: 17px; margin-top: 2px; }

.exam-switch { display: inline-flex; padding: 5px; background: #e3ebf1; border-radius: 14px; margin-bottom: 24px; }
.exam-tab { border: 0; background: transparent; color: #617485; border-radius: 10px; padding: 11px 25px; font-weight: 750; cursor: pointer; min-width: 170px; }
.exam-tab.active { background: white; color: var(--navy); box-shadow: 0 4px 12px rgba(30,60,82,.09); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, .75fr); gap: 24px; }
.subject-panel, .practice-card, .question-card, .lesson-panel, .complete-card { background: var(--paper); border: 1px solid rgba(216,228,235,.95); border-radius: 24px; box-shadow: var(--shadow); }
.subject-panel { padding: 27px; }
.panel-title-row { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; }
.panel-title-row h2 { margin: 0; font-size: 24px; }
.demo-tag { background: var(--orange-soft); color: #9a5a10; padding: 7px 11px; border-radius: 999px; font-size: 12px; font-weight: 750; }
.subject-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 13px; }
.subject-button { min-height: 98px; border: 1.5px solid var(--line); border-radius: 17px; padding: 14px; background: white; text-align: left; cursor: pointer; display: flex; flex-direction: column; justify-content: space-between; transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease; }
.subject-button:hover { transform: translateY(-2px); border-color: #9db7ca; }
.subject-button.active { border-color: var(--navy); background: #f5f9fc; box-shadow: inset 0 0 0 1px var(--navy); }
.subject-icon { width: 33px; height: 33px; display: grid; place-items: center; border-radius: 10px; color: var(--navy); background: var(--blue-soft); font-size: 14px; font-weight: 850; }
.subject-button:nth-child(3n+2) .subject-icon { background: var(--teal-soft); color: #126e60; }
.subject-button:nth-child(3n+3) .subject-icon { background: var(--orange-soft); color: #9a5a10; }
.subject-button strong { font-size: 16px; }
.subject-button small { color: var(--muted); font-size: 12px; margin-top: 5px; }

.practice-card { padding: 27px; align-self: start; position: sticky; top: 106px; }
.practice-card-top { display: flex; align-items: center; gap: 14px; padding-bottom: 23px; border-bottom: 1px solid var(--line); }
.practice-subject-icon { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 16px; color: white; background: var(--navy); font-size: 20px; font-weight: 850; }
.practice-card-top h2 { margin: 0; font-size: 23px; }
.practice-setting { padding: 16px 0; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.practice-setting > span { color: var(--muted); font-size: 14px; }
.practice-setting strong { font-size: 15px; text-align: right; }
.count-picker, .year-picker { background: #edf3f6; border-radius: 10px; display: flex; padding: 3px; }
.count-picker button, .year-picker button { padding: 7px 9px; border: 0; background: transparent; border-radius: 7px; cursor: pointer; color: #667988; white-space: nowrap; }
.count-picker button { width: 40px; padding-inline: 0; }
.count-picker button.active, .year-picker button.active { background: white; color: var(--navy); font-weight: 800; box-shadow: 0 2px 7px rgba(30,55,75,.1); }
.year-setting { align-items: flex-start; flex-direction: column; }
.year-picker { width: 100%; }
.year-picker button { flex: 1; }
.english-year-picker button { min-width: 0; padding-inline: 6px; }
.english-shortcuts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.secondary-button { min-height: 44px; border: 1px solid var(--line); border-radius: 12px; background: white; color: var(--navy); font-weight: 750; cursor: pointer; }
.secondary-button span { color: var(--muted); font-weight: 600; }
.primary-button, .confirm-button, .next-button { width: 100%; border: 0; border-radius: 14px; min-height: 52px; background: var(--navy); color: white; font-weight: 800; cursor: pointer; margin-top: 23px; display: flex; align-items: center; justify-content: center; gap: 12px; }
.primary-button span, .confirm-button span { font-size: 20px; }
.card-note { color: var(--muted); font-size: 12px; text-align: center; margin: 11px 0 0; }

.insight-panel { margin-top: 24px; background: var(--paper); border: 1px solid rgba(216,228,235,.95); border-radius: 24px; box-shadow: var(--shadow); padding: 25px 27px; }
.insight-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.insight-heading h2 { margin: 0; font-size: 24px; }
.overall-score { display: flex; align-items: baseline; gap: 8px; }
.overall-score strong { color: var(--navy); font-size: 30px; }
.overall-score span { color: var(--muted); font-size: 13px; }
.insight-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.insight-empty { grid-column: 1 / -1; color: var(--muted); background: #f5f8fa; border-radius: 14px; padding: 20px; text-align: center; }
.ai-tutor-panel { border-top: 4px solid var(--teal); }
.ai-local-badge { color: #126e60; background: var(--teal-soft); border-radius: 999px; padding: 8px 12px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.ai-tutor-note { color: var(--muted); font-size: 13px; line-height: 1.6; }
.ai-tutor-diagnosis, .ai-tutor-teaching, .ai-tutor-run { background: #f5f8fa; border: 1px solid var(--line); border-radius: 15px; padding: 17px; margin-top: 12px; }
.ai-tutor-diagnosis h3, .ai-tutor-teaching h3 { margin: 0 0 9px; font-size: 18px; }
.ai-tutor-diagnosis p, .ai-tutor-teaching p, .ai-tutor-teaching small { margin: 6px 0; line-height: 1.65; }
.ai-tutor-teaching small { color: var(--muted); display: block; }
.grammar-lesson { border: 1px solid var(--line); border-radius: 15px; padding: 18px; margin: 14px 0; background: #f5f8fa; }
.grammar-lesson h3 { margin: 4px 0 14px; color: var(--navy); }
.grammar-lesson h4 { margin: 16px 0 5px; color: var(--navy); font-size: 15px; }
.grammar-lesson p, .grammar-lesson li { line-height: 1.65; }
.grammar-lesson small { color: var(--muted); }
.grammar-example { padding: 10px 12px; border-left: 3px solid var(--teal); background: #fff; font-weight: 600; }
.grammar-weakness-card { border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 14px; margin: 10px 0; }
.grammar-weakness-card h3 { margin: 0 0 6px; font-size: 17px; }
.grammar-weakness-card p { margin: 5px 0 10px; color: var(--muted); }
.grammar-weakness-card .followup-button { margin: 4px 8px 4px 0; }
.ai-common-mistake { border-left: 3px solid var(--orange); padding-left: 10px; }
.ai-provider-error, .ai-run-feedback.bad { color: var(--red); }
.ai-mastery-state, .ai-run-feedback.good { color: var(--teal); font-weight: 800; }
.ai-run-progress { color: var(--teal); font-weight: 800; }
.ai-run-stem { font-size: 20px; line-height: 1.45; }
.ai-run-options { display: grid; gap: 9px; }
.ai-run-option { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; text-align: left; background: white; color: var(--ink); cursor: pointer; }
.ai-run-option.selected { border-color: var(--navy); box-shadow: inset 0 0 0 1px var(--navy); background: var(--blue-soft); }
.ai-run-option:disabled { cursor: default; }
.ai-run-explanation { line-height: 1.6; }
.ai-review-row { color: var(--muted); margin-bottom: 7px; }
.weak-card { border: 1px solid var(--line); border-radius: 15px; padding: 15px; display: grid; grid-template-columns: 1fr auto; gap: 8px 14px; align-items: center; }
.weak-card small { color: var(--muted); font-size: 12px; }
.weak-card strong { font-size: 16px; }
.weak-card b { grid-row: 1 / 3; grid-column: 2; color: var(--orange); font-size: 20px; }
.source-note { display: flex; align-items: center; gap: 11px; border-top: 1px solid var(--line); padding-top: 17px; margin-top: 18px; }
.source-check { width: 29px; height: 29px; flex: 0 0 29px; border-radius: 50%; display: grid; place-items: center; background: var(--teal-soft); color: var(--teal); font-weight: 900; }
.source-note > span:nth-child(2) { margin-right: auto; }
.source-note strong, .source-note small { display: block; }
.source-note strong { font-size: 14px; }
.source-note small { color: var(--muted); margin-top: 3px; font-size: 12px; }
.source-note a { color: var(--navy); font-size: 13px; font-weight: 750; text-decoration: none; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; white-space: nowrap; }

.quiz-view { margin-top: -14px; }
.quiz-header { display: grid; grid-template-columns: auto 1fr auto; gap: 15px; align-items: center; margin-bottom: 20px; }
.back-button { width: 48px; height: 48px; border: 1px solid var(--line); border-radius: 14px; background: white; color: var(--navy); font-size: 34px; line-height: 1; cursor: pointer; }
.quiz-heading p { margin: 0 0 3px; color: var(--muted); font-size: 13px; }
.quiz-heading strong { font-size: 20px; }
.progress-wrap { min-width: 240px; }
.progress-wrap > span { font-size: 13px; color: var(--muted); display: block; text-align: right; margin-bottom: 7px; }
.progress-track { width: 100%; height: 7px; background: #dfe8ed; border-radius: 999px; overflow: hidden; }
.progress-track > div { height: 100%; background: var(--teal); border-radius: inherit; transition: width .3s ease; }
.quiz-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(350px, .75fr); gap: 22px; align-items: start; }
.question-card { padding: 32px; min-height: 590px; display: flex; flex-direction: column; }
.question-topline { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.question-number { width: 45px; height: 45px; border-radius: 13px; background: var(--navy); color: white; font-weight: 850; display: grid; place-items: center; }
.question-kind { color: var(--muted); font-size: 13px; background: #eef3f6; padding: 7px 10px; border-radius: 999px; }
.official-source { margin-left: auto; color: var(--navy); background: var(--blue-soft); border: 1px solid #c5dbe9; border-radius: 999px; padding: 7px 10px; font-size: 12px; font-weight: 800; text-decoration: none; }
.question-context { margin: -6px 0 22px; border: 1px solid #d5e1e8; border-radius: 14px; background: #f7fafb; overflow: hidden; }
.question-context summary { cursor: pointer; padding: 12px 15px; color: var(--navy); font-weight: 800; font-size: 14px; }
.question-context p { margin: 0; padding: 0 15px 15px; color: #405361; font-size: 15px; line-height: 1.75; white-space: pre-line; }
.question-image { display: block; width: 100%; max-height: 420px; object-fit: contain; margin: 16px 0; border-radius: 12px; background: #f7fafb; }
.question-card h2 { font-size: clamp(20px, 2.5vw, 27px); line-height: 1.6; font-weight: 700; margin-bottom: 26px; }
.options { display: grid; gap: 12px; }
.options.long-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.option { width: 100%; min-height: 62px; border: 1.5px solid var(--line); background: white; border-radius: 15px; padding: 12px 16px; display: flex; align-items: center; gap: 14px; text-align: left; color: var(--ink); cursor: pointer; font-size: 17px; }
.option-letter { width: 34px; height: 34px; flex: 0 0 34px; border-radius: 50%; border: 1.5px solid #c5d2dc; display: grid; place-items: center; font-weight: 800; color: #607482; }
.option.selected { border-color: var(--navy); background: #f1f7fb; box-shadow: inset 0 0 0 1px var(--navy); }
.option.selected .option-letter { background: var(--navy); color: white; border-color: var(--navy); }
.option.correct { border-color: var(--teal); background: var(--teal-soft); }
.option.correct .option-letter { background: var(--teal); color: white; border-color: var(--teal); }
.option.wrong { border-color: var(--red); background: var(--red-soft); }
.option.wrong .option-letter { background: var(--red); color: white; border-color: var(--red); }
.option.image-option { align-items: flex-start; }
.option-image { display: block; width: min(100%, 360px); max-height: 220px; object-fit: contain; }
.option-asset-error { color: var(--red); font-weight: 700; }
.confirm-button { margin-top: auto; }
.confirm-button:disabled { background: #cbd6dd; cursor: default; }

.lesson-panel { min-height: 590px; padding: 25px; position: sticky; top: 103px; }
.lesson-empty { min-height: 535px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; }
.lesson-orbit { width: 80px; height: 80px; border-radius: 50%; border: 1px solid #bcded7; display: grid; place-items: center; position: relative; margin-bottom: 22px; }
.lesson-orbit::before { content: ""; width: 103px; height: 43px; border: 1px solid #d5e8e3; border-radius: 50%; position: absolute; transform: rotate(-25deg); }
.lesson-orbit span { width: 55px; height: 55px; border-radius: 50%; background: var(--teal); color: white; display: grid; place-items: center; font-weight: 850; font-size: 18px; z-index: 1; }
.lesson-empty h3 { font-size: 19px; max-width: 250px; margin-bottom: 9px; line-height: 1.45; }
.lesson-empty p { color: var(--muted); line-height: 1.55; max-width: 250px; font-size: 14px; }
.result-banner { border-radius: 14px; padding: 13px 15px; font-weight: 800; margin-bottom: 15px; }
.result-banner.good { color: #126e60; background: var(--teal-soft); }
.result-banner.bad { color: #a63b3b; background: var(--red-soft); }
.answer-compare { display: grid; grid-template-columns: 1fr auto 1fr; gap: 13px; align-items: center; background: #f4f7f9; padding: 13px; border-radius: 14px; margin-bottom: 22px; }
.answer-source { display: block; color: var(--navy); font-size: 12px; font-weight: 750; text-align: center; text-decoration: none; margin: -10px 0 20px; }
.answer-compare div { text-align: center; }
.answer-compare small { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.answer-compare strong { font-size: 20px; }
.lesson-content h3 { font-size: 17px; margin-bottom: 12px; }
.prompt-chips { display: grid; gap: 9px; }
.prompt-chip, .followup-button { border: 1px solid #cbd9e2; color: var(--navy); background: white; min-height: 43px; border-radius: 12px; padding: 9px 12px; text-align: left; cursor: pointer; font-weight: 700; font-size: 14px; }
.prompt-chip:hover, .prompt-chip.active { border-color: var(--navy); background: var(--blue-soft); }
.ai-response { margin-top: 17px; padding: 16px; border-radius: 15px; background: var(--blue-soft); border-left: 4px solid var(--navy); }
.ai-label { color: var(--navy); font-size: 13px; font-weight: 850; margin-bottom: 9px; }
.ai-label span { background: var(--navy); color: white; border-radius: 6px; padding: 3px 5px; margin-right: 5px; }
.ai-response p { margin: 0; line-height: 1.65; font-size: 15px; }
.followup-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 13px; }
.followup-button { min-height: 36px; font-size: 12px; padding: 7px 9px; }
.next-button { background: var(--teal); margin-top: 18px; }

.complete-view { display: grid; place-items: center; min-height: calc(100vh - 170px); }
.complete-card { width: min(620px, 100%); padding: 40px; text-align: center; }
.complete-mark { width: 62px; height: 62px; border-radius: 50%; background: var(--teal-soft); color: var(--teal); display: grid; place-items: center; font-size: 32px; font-weight: 800; margin: 0 auto 20px; }
.complete-card h1 { font-size: 35px; }
.score-ring { width: 150px; height: 150px; border-radius: 50%; margin: 28px auto; display: grid; place-items: center; align-content: center; background: conic-gradient(var(--teal) 0deg, var(--teal) var(--score-angle, 0deg), #e8eef2 var(--score-angle, 0deg)); position: relative; }
.score-ring::before { content: ""; position: absolute; width: 119px; height: 119px; border-radius: 50%; background: white; }
.score-ring strong, .score-ring span { position: relative; z-index: 1; }
.score-ring strong { font-size: 31px; }
.score-ring span { font-size: 12px; color: var(--muted); margin-top: 2px; }
.complete-stats { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.complete-stats div { padding: 18px 10px; }
.complete-stats div + div { border-left: 1px solid var(--line); }
.complete-stats strong, .complete-stats span { display: block; }
.complete-stats strong { font-size: 24px; }
.complete-stats span { color: var(--muted); font-size: 13px; margin-top: 4px; }

@media (max-width: 900px) {
  main { padding: 28px 20px 40px; }
  .dashboard-grid, .quiz-layout { grid-template-columns: 1fr; }
  .practice-card, .lesson-panel { position: static; }
  .quiz-layout { gap: 16px; }
  .options.long-options { grid-template-columns: 1fr; }
  .question-card, .lesson-panel { min-height: auto; }
  .lesson-empty { min-height: 260px; }
  .subject-grid { grid-template-columns: repeat(2, 1fr); }
  .insight-grid { grid-template-columns: 1fr; }
  .source-note { align-items: flex-start; flex-wrap: wrap; }
  .source-note > span:nth-child(2) { width: calc(100% - 44px); }
}

@media (max-width: 600px) {
  .topbar { padding: 10px 16px; height: 72px; }
  .today-summary span, .today-summary i { display: none; }
  .today-summary { min-width: 0; padding: 8px 12px; }
  .brand small { display: none; }
  main { padding: 23px 14px 34px; }
  .welcome-row { align-items: flex-end; }
  .welcome-row h1 { font-size: 29px; }
  .review-pill { min-width: 0; padding: 9px; }
  .review-pill small { display: none; }
  .exam-switch { display: flex; }
  .exam-tab { min-width: 0; flex: 1; padding: 10px; }
  .subject-panel, .practice-card, .question-card, .lesson-panel, .complete-card { border-radius: 19px; padding: 20px; }
  .subject-grid { grid-template-columns: repeat(2, 1fr); }
  .subject-button { min-height: 88px; }
  .insight-panel { border-radius: 19px; padding: 20px; }
  .source-note a { flex: 1; text-align: center; }
  .quiz-header { grid-template-columns: auto 1fr; }
  .progress-wrap { grid-column: 1 / -1; min-width: 0; }
  .progress-wrap > span { text-align: left; }
  .question-card h2 { font-size: 20px; }
  .question-topline { flex-wrap: wrap; }
  .official-source { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
