:root {
  color-scheme: light dark;
  --bg: #f7f9f4;
  --surface: #ffffff;
  --surface-soft: #f0f4ec;
  --text: #1c2922;
  --muted: #68756d;
  --border: #dfe7dc;
  --primary: #4c9b5f;
  --primary-deep: #307c47;
  --primary-soft: #e2f4e6;
  --accent: #f2bd4c;
  --danger: #d95454;
  --danger-soft: #fde8e8;
  --success: #27864c;
  --shadow: 0 12px 34px rgb(40 70 50 / 10%);
  --shadow-small: 0 6px 18px rgb(40 70 50 / 9%);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --safe-bottom: max(16px, env(safe-area-inset-bottom));
  --app-height: 100dvh;
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #111814;
  --surface: #1b251f;
  --surface-soft: #232f28;
  --text: #eef6f0;
  --muted: #a8b6ad;
  --border: #334239;
  --primary: #66c47b;
  --primary-deep: #49a861;
  --primary-soft: #203f2a;
  --accent: #e5b957;
  --danger: #f07878;
  --danger-soft: #4b292c;
  --success: #74d791;
  --shadow: 0 14px 38px rgb(0 0 0 / 25%);
  --shadow-small: 0 6px 20px rgb(0 0 0 / 20%);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111814;
    --surface: #1b251f;
    --surface-soft: #232f28;
    --text: #eef6f0;
    --muted: #a8b6ad;
    --border: #334239;
    --primary: #66c47b;
    --primary-deep: #49a861;
    --primary-soft: #203f2a;
    --accent: #e5b957;
    --danger: #f07878;
    --danger-soft: #4b292c;
    --success: #74d791;
    --shadow: 0 14px 38px rgb(0 0 0 / 25%);
    --shadow-small: 0 6px 20px rgb(0 0 0 / 20%);
  }
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100svh;
  background:
    radial-gradient(circle at 5% -5%, rgb(103 194 123 / 12%), transparent 34rem),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent);
  outline-offset: 3px;
}

.app-shell {
  width: min(100%, 1080px);
  margin: 0 auto;
  min-height: var(--app-height);
  padding: env(safe-area-inset-top) 18px var(--safe-bottom);
}

.app-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 0;
  cursor: pointer;
  text-align: left;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(145deg, var(--primary), var(--primary-deep));
  box-shadow: 0 6px 0 color-mix(in srgb, var(--primary-deep) 75%, #153e22);
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 0.98rem; letter-spacing: -0.01em; }
.brand small { color: var(--muted); margin-top: 2px; font-size: 0.72rem; }

.icon-button {
  border: 1px solid var(--border);
  background: var(--surface);
  width: 44px;
  height: 44px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1.25rem;
  box-shadow: var(--shadow-small);
}

.view { display: none; }
.view.is-active { display: block; }
.card {
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.hero-card {
  padding: 28px 24px;
  background:
    radial-gradient(circle at 100% 0, rgb(242 189 76 / 22%), transparent 15rem),
    var(--surface);
  overflow: hidden;
}

.eyebrow {
  color: var(--primary-deep);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
.hero-card h1 { margin: 9px 0 10px; font-size: clamp(1.8rem, 7vw, 3.35rem); line-height: 1.08; letter-spacing: -0.045em; }
.hero-card > p { color: var(--muted); line-height: 1.7; max-width: 42rem; margin-bottom: 20px; }
.hero-stats { display: flex; gap: 10px; flex-wrap: wrap; }
.mini-stat { padding: 9px 13px; border-radius: 999px; background: var(--surface-soft); font-size: 0.78rem; color: var(--muted); }
.mini-stat strong { color: var(--text); margin-right: 4px; }
.history-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary-deep);
  font-weight: 800;
  cursor: pointer;
}

.resume-card {
  margin-top: 18px;
  padding: 20px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: start;
  border-color: color-mix(in srgb, var(--primary) 38%, var(--border));
  background:
    linear-gradient(140deg, color-mix(in srgb, var(--primary-soft) 42%, var(--surface)), var(--surface) 58%);
}
.resume-card-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 17px;
  color: var(--primary-deep);
  background: var(--primary-soft);
  font-size: 1.45rem;
  font-weight: 850;
}
.resume-card-copy { min-width: 0; }
.resume-card-copy h2 { margin: 5px 0 4px; font-size: 1.25rem; }
.resume-card-copy > p { margin-bottom: 10px; color: var(--text); font-weight: 720; overflow-wrap: anywhere; }
.resume-card-meta { display: flex; flex-wrap: wrap; gap: 7px 14px; color: var(--muted); font-size: 0.8rem; }
.resume-card-actions { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quiet-danger-button {
  grid-column: 1 / -1;
  width: fit-content;
  justify-self: center;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 7px 12px;
  font-size: 0.78rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.quiet-danger-button:hover, .quiet-danger-button:focus-visible { color: var(--danger); }

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin: 34px 2px 16px;
}
.section-heading h1, .section-heading h2 { margin: 5px 0 0; font-size: 1.5rem; letter-spacing: -0.03em; }
.text-button { border: 0; background: transparent; color: var(--primary-deep); font-weight: 750; cursor: pointer; padding: 8px; }
.danger-text { color: var(--danger); }

.unit-grid { display: grid; gap: 14px; }
.unit-card { padding: 20px; display: grid; gap: 18px; }
.unit-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-width: 72px;
  padding: 7px 12px;
  background: var(--primary-soft);
  color: var(--primary-deep);
  border-radius: 999px;
  font-weight: 850;
  font-size: 0.8rem;
}
.unit-card h3 { margin: 0 0 7px; font-size: 1.23rem; }
.unit-card p { color: var(--muted); margin: 0; line-height: 1.55; font-size: 0.9rem; }
.unit-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.word-count { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }

.button {
  border: 0;
  border-radius: 17px;
  min-height: 52px;
  padding: 0 20px;
  font-weight: 820;
  cursor: pointer;
  transition: transform 110ms ease, filter 160ms ease, opacity 160ms ease;
}
.button:active, .icon-button:active { transform: scale(0.97); }
.button:disabled { opacity: 0.55; cursor: not-allowed; }
.primary-button { background: var(--primary); color: #fff; box-shadow: 0 5px 0 var(--primary-deep); }
.secondary-button { background: var(--surface); color: var(--danger); border: 1px solid var(--border); box-shadow: 0 5px 0 var(--border); }
.ghost-button { background: var(--surface-soft); color: var(--text); }
.danger-button { background: var(--danger); color: #fff; }

.notice { border: 1px solid color-mix(in srgb, var(--accent) 60%, var(--border)); background: color-mix(in srgb, var(--accent) 14%, var(--surface)); border-radius: var(--radius-md); padding: 12px 15px; margin-bottom: 14px; line-height: 1.5; font-size: 0.88rem; }
.is-hidden { display: none !important; }
.loading-card { padding: 24px; color: var(--muted); }

.dictation-topbar { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 12px; margin: 4px 0 14px; }
.dictation-title { min-width: 0; }
.dictation-title strong, .dictation-title span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dictation-title span, .question-count { color: var(--muted); font-size: 0.78rem; margin-top: 3px; }
.progress-track { height: 12px; background: var(--surface-soft); border-radius: 99px; overflow: hidden; }
.progress-track span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--primary), #82ce72); transition: width 280ms ease; }

.dictation-stage { min-height: calc(var(--app-height) - 272px); display: grid; place-items: center; padding: 22px 0 104px; }
.prompt-card { width: min(100%, 680px); padding: clamp(24px, 7vw, 52px); text-align: center; }
.round-badge { display: inline-flex; padding: 7px 12px; background: var(--primary-soft); color: var(--primary-deep); border-radius: 999px; font-size: 0.75rem; font-weight: 850; }
.prompt-label { color: var(--muted); margin: 24px 0 8px; font-size: 0.88rem; }
.chinese-prompt { margin: 0 auto 28px; font-size: clamp(2rem, 9vw, 4.5rem); letter-spacing: -0.05em; line-height: 1.12; overflow-wrap: anywhere; }
.answer-input { width: 100%; height: 62px; border: 2px solid var(--border); border-radius: 18px; background: var(--bg); color: var(--text); text-align: center; font-size: 1.25rem; padding: 0 16px; appearance: none; }
.answer-input:focus { border-color: var(--primary); }
.feedback { min-height: 52px; padding-top: 14px; font-weight: 750; line-height: 1.5; }
.feedback.success { color: var(--success); }
.feedback.error { color: var(--danger); }
.feedback small { display: block; color: var(--muted); font-weight: 550; }

.action-dock {
  position: fixed;
  z-index: 10;
  left: max(18px, env(safe-area-inset-left));
  right: max(18px, env(safe-area-inset-right));
  bottom: var(--safe-bottom);
  margin: auto;
  width: min(calc(100% - 36px), 700px);
  display: grid;
  grid-template-columns: minmax(110px, 0.7fr) minmax(150px, 1.3fr);
  gap: 12px;
  padding: 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
  border-radius: 24px;
  backdrop-filter: blur(16px);
}

.report-hero { padding: 28px 22px; text-align: center; overflow: hidden; position: relative; }
.score-ring { width: 150px; height: 150px; border-radius: 50%; margin: 8px auto 18px; display: grid; place-items: center; background: conic-gradient(var(--primary) var(--score-angle, 0deg), var(--surface-soft) 0); position: relative; }
.score-ring::after { content: ""; position: absolute; inset: 13px; border-radius: 50%; background: var(--surface); }
.score-value { position: relative; z-index: 1; font-size: 3rem; font-weight: 900; letter-spacing: -0.06em; }
.report-hero h1 { margin-bottom: 8px; }
.report-hero p { color: var(--muted); }
.metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 20px; }
.metric { background: var(--surface-soft); border-radius: var(--radius-md); padding: 14px 10px; }
.metric strong, .metric span { display: block; }
.metric strong { font-size: 1.3rem; }
.metric span { color: var(--muted); font-size: 0.75rem; margin-top: 4px; }
.report-section { margin-top: 22px; }
.report-section h2 { font-size: 1.2rem; margin: 0 0 12px 4px; }
.record-list { display: grid; gap: 10px; }
.record-card { padding: 16px; display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: start; }
.record-word strong, .record-word span { display: block; }
.record-word strong { font-size: 1.06rem; }
.record-word span { color: var(--muted); font-size: 0.84rem; margin-top: 4px; }
.result-pill { border-radius: 999px; padding: 5px 9px; font-size: 0.7rem; font-weight: 850; }
.result-pill.correct { background: var(--primary-soft); color: var(--primary-deep); }
.result-pill.wrong { background: var(--danger-soft); color: var(--danger); }
.record-meta { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 0.78rem; color: var(--muted); }
.record-meta span { background: var(--surface-soft); border-radius: 11px; padding: 9px 10px; overflow-wrap: anywhere; }
.report-actions { display: grid; gap: 10px; margin: 22px 0 8px; }

.history-heading { margin-top: 10px; }
.history-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 0 2px 16px; }
.history-toolbar p { margin: 0; color: var(--muted); font-size: 0.84rem; line-height: 1.5; }
.history-list { display: grid; gap: 11px; }
.history-item {
  width: 100%;
  padding: 17px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-small);
}
.history-item:hover { border-color: color-mix(in srgb, var(--primary) 42%, var(--border)); }
.history-item-main { min-width: 0; }
.history-item-main strong, .history-item-main span { display: block; }
.history-item-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item-main span { margin-top: 5px; color: var(--muted); font-size: 0.78rem; }
.history-score { align-self: center; color: var(--primary-deep); font-size: 1.55rem; font-weight: 900; letter-spacing: -0.04em; }
.history-score small { font-size: 0.72rem; margin-left: 2px; }
.history-result { grid-column: 1 / -1; color: var(--muted); font-size: 0.8rem; }
.empty-state { padding: 38px 24px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; margin-bottom: 8px; color: var(--text); font-size: 1.1rem; }

.settings-heading { margin-top: 10px; }
.settings-grid { display: grid; gap: 14px; }
.settings-card { padding: 22px; }
.settings-card h2 { font-size: 1.15rem; margin-bottom: 8px; }
.settings-card p { color: var(--muted); line-height: 1.6; font-size: 0.88rem; }
.segmented-control { display: grid; grid-template-columns: repeat(3, 1fr); padding: 4px; background: var(--surface-soft); border-radius: 15px; }
.segmented-control button { min-height: 42px; border: 0; border-radius: 12px; background: transparent; cursor: pointer; font-size: 0.8rem; font-weight: 750; }
.segmented-control button.is-selected { background: var(--surface); color: var(--primary-deep); box-shadow: var(--shadow-small); }
.settings-actions { display: grid; gap: 10px; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 28%, var(--border)); }

.resume-dialog { width: min(calc(100% - 36px), 440px); border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--surface); color: var(--text); padding: 28px; text-align: center; box-shadow: 0 25px 80px rgb(0 0 0 / 30%); }
.resume-dialog::backdrop { background: rgb(10 18 13 / 58%); backdrop-filter: blur(5px); }
.dialog-icon { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 19px; background: var(--primary-soft); color: var(--primary-deep); font-size: 1.8rem; margin: 0 auto 16px; }
.resume-dialog h2 { margin-bottom: 8px; }
.resume-dialog p { color: var(--muted); line-height: 1.55; }
.dialog-actions { display: grid; gap: 10px; margin-top: 20px; }

.toast-region { position: fixed; z-index: 30; top: max(18px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(calc(100% - 36px), 500px); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); border-radius: 15px; padding: 13px 16px; box-shadow: var(--shadow); text-align: center; font-size: 0.86rem; }
.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.confetti { position: absolute; top: -20px; width: 9px; height: 16px; border-radius: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (min-width: 680px) {
  .app-shell { padding-left: 28px; padding-right: 28px; }
  .app-header { min-height: 92px; }
  .hero-card { padding: 44px; }
  .resume-card { grid-template-columns: auto 1fr auto; align-items: center; padding: 24px; }
  .resume-card-actions { grid-column: auto; min-width: 210px; }
  .unit-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .unit-card { padding: 24px; }
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .record-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .report-actions { grid-template-columns: repeat(3, 1fr); }
  .report-actions.historical-actions { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-grid .danger-zone { grid-row: span 2; }
  .history-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 940px) {
  .unit-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .report-hero { padding: 38px; }
}

@media (max-height: 620px) {
  .app-header { min-height: 58px; }
  .dictation-stage { min-height: auto; padding: 18px 0 102px; }
  .prompt-card { padding-top: 20px; padding-bottom: 20px; }
  .prompt-label { margin-top: 14px; }
  .chinese-prompt { margin-bottom: 18px; font-size: clamp(1.8rem, 8vw, 3rem); }
}
