:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-soft: #f0f2f8;
  --text: #202235;
  --muted: #70758a;
  --line: #e3e6f0;
  --accent: #6557e8;
  --accent-dark: #5143cf;
  --accent-soft: #eeecff;
  --success: #1d9a6c;
  --danger: #d75f70;
  --shadow: 0 18px 48px rgba(48, 42, 108, .08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151622;
  --surface: #202132;
  --surface-soft: #2a2b3e;
  --text: #f5f5fb;
  --muted: #a3a6bb;
  --line: #37394e;
  --accent: #9187ff;
  --accent-dark: #a9a1ff;
  --accent-soft: #302d57;
  --success: #56d7a5;
  --danger: #ff8997;
  --shadow: 0 18px 48px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  transition: background .2s ease, color .2s ease;
}

button, input { font: inherit; }
button { cursor: pointer; }

.kana-app {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 18px max(28px, env(safe-area-inset-bottom));
}

.topbar, .brand, .top-actions, .welcome-row, .setup-heading, .round-label, .progress-head { display: flex; align-items: center; }
.topbar, .welcome-row, .setup-heading, .round-label, .progress-head { justify-content: space-between; }
.topbar { min-height: 56px; gap: 12px; }
.brand { gap: 10px; min-width: 0; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 13px; background: var(--accent); color: #fff; font-size: 17px; font-weight: 800; }
.brand h1 { margin: 1px 0 0; font-size: 18px; letter-spacing: -.02em; }
.eyebrow { margin: 0; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: .13em; }
.top-actions { gap: 7px; }
.icon-button, .login-button, .user-button, .modal-close { border: 0; color: var(--text); background: transparent; }
.icon-button { width: 38px; height: 38px; border-radius: 12px; background: var(--surface); box-shadow: 0 2px 8px rgba(40, 35, 95, .05); font-size: 19px; }
.login-button, .user-button { min-height: 38px; padding: 0 13px; border-radius: 12px; color: var(--accent); background: var(--accent-soft); font-size: 13px; font-weight: 700; }
.user-button { max-width: 125px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

.welcome-row { align-items: flex-end; gap: 16px; padding: 30px 2px 22px; }
.welcome-row h2 { margin: 7px 0 5px; font-size: clamp(24px, 7vw, 34px); line-height: 1.13; letter-spacing: -.045em; }
.muted { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.status-pill { flex: 0 0 auto; padding: 8px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.status-dot { display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; background: #afb3c2; vertical-align: 1px; }
.status-pill.logged-in { color: var(--success); border-color: color-mix(in srgb, var(--success) 35%, var(--line)); }
.status-pill.logged-in .status-dot { background: var(--success); }

.setup-card, .question-card, .summary-card { border: 1px solid var(--line); border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); }
.setup-card { padding: 21px; }
.setup-heading { gap: 10px; }
.setup-heading h3 { margin: 6px 0 0; font-size: 18px; }
.setting-note { color: var(--muted); font-size: 11px; white-space: nowrap; }
.script-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin: 20px 0 23px; padding: 4px; border-radius: 14px; background: var(--surface-soft); }
.script-option { min-height: 43px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 700; transition: all .2s ease; }
.script-option.active { background: var(--surface); color: var(--accent); box-shadow: 0 3px 10px rgba(40, 35, 95, .1); }
.round-label { font-size: 13px; color: var(--muted); }
.round-label strong { color: var(--text); font-size: 14px; }
.round-setting input { display: block; width: 100%; margin: 12px 0 4px; accent-color: var(--accent); }
.range-hints { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
.primary-button, .secondary-button { width: 100%; min-height: 48px; border-radius: 14px; font-weight: 800; transition: transform .15s ease, background .2s ease; }
.primary-button { border: 0; background: var(--accent); color: #fff; box-shadow: 0 8px 18px color-mix(in srgb, var(--accent) 27%, transparent); }
.primary-button:hover { background: var(--accent-dark); }
.primary-button:active, .secondary-button:active, .option-button:active, .pair-card:active { transform: scale(.98); }
.start-button { margin-top: 20px; font-size: 15px; }
.start-button span, .primary-button span { margin-left: 7px; font-size: 18px; }
.secondary-button { border: 1px solid var(--line); background: var(--surface); color: var(--accent); }

.quiz-section { margin-top: 24px; }
.progress-head { margin-bottom: 9px; color: var(--muted); font-size: 12px; font-weight: 700; }
.progress-track { height: 6px; overflow: hidden; border-radius: 99px; background: var(--surface-soft); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .3s ease; }
.question-card { min-height: 430px; margin-top: 16px; padding: clamp(20px, 5vw, 32px); }
.question-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 11px; }
.question-type { padding: 5px 9px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.question-prompt { display: flex; min-height: 152px; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; }
.prompt-main { max-width: 100%; overflow-wrap: anywhere; font-size: clamp(46px, 14vw, 82px); font-weight: 850; letter-spacing: .025em; line-height: 1.13; }
.prompt-sub { max-width: 100%; color: var(--muted); font-size: 15px; overflow-wrap: anywhere; }
.prompt-romaji { color: var(--accent); font-size: clamp(27px, 8vw, 43px); font-weight: 800; letter-spacing: .02em; }
.kana-word { display: inline-flex; flex-wrap: wrap; align-items: baseline; justify-content: center; gap: 8px; }
.kanji { color: var(--muted); font-size: .35em; font-weight: 600; letter-spacing: 0; }
.audio-button { display: inline-flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 15px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); color: var(--accent); font-size: 13px; font-weight: 800; }
.audio-button.speaking { background: var(--accent-soft); }
.option-button.speaking, .pair-card.speaking { border-color: var(--accent); background: var(--accent-soft); }
.answer-area { display: grid; gap: 10px; }
.option-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.option-button, .pair-card { min-width: 0; min-height: 55px; overflow-wrap: anywhere; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text); font-size: 16px; font-weight: 700; transition: all .15s ease; }
.option-button:hover, .pair-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.option-button.correct, .pair-card.correct { border-color: var(--success); background: color-mix(in srgb, var(--success) 12%, var(--surface)); color: var(--success); }
.option-button.wrong, .pair-card.wrong { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface)); color: var(--danger); }
.answer-form { display: flex; gap: 8px; }
.answer-input { min-width: 0; flex: 1; height: 50px; padding: 0 14px; border: 1px solid var(--line); border-radius: 14px; outline: none; background: var(--surface); color: var(--text); }
.answer-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.answer-form .primary-button { width: auto; padding: 0 18px; }
.feedback { min-height: 22px; color: var(--muted); font-size: 13px; line-height: 1.45; text-align: center; }
.feedback.correct { color: var(--success); }
.feedback.wrong { color: var(--danger); }
.question-actions { display: flex; justify-content: center; gap: 10px; margin-top: 15px; }
.text-button { border: 0; background: none; color: var(--muted); font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }
.next-button { min-height: 42px; padding: 0 20px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-size: 13px; font-weight: 800; }
.pair-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.pair-column { display: grid; gap: 9px; align-content: start; }
.pair-card { min-height: 49px; padding: 7px; font-size: 14px; }
.pair-card.selected { border: 2px solid var(--accent); background: var(--accent-soft); color: var(--accent); }
.pair-card.matched { opacity: .45; border-color: var(--line); background: var(--surface-soft); color: var(--muted); filter: saturate(.45); pointer-events: none; }

.summary-card { margin-top: 24px; padding: 34px 22px 24px; text-align: center; }
.summary-icon { display: grid; place-items: center; width: 53px; height: 53px; margin: 0 auto 17px; border-radius: 18px; background: #def8ed; color: var(--success); font-size: 26px; font-weight: 900; }
[data-theme="dark"] .summary-icon { background: #21483b; }
.summary-card h2 { margin: 8px 0 7px; font-size: 28px; letter-spacing: -.04em; }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 26px 0; }
.summary-grid div { padding: 13px 4px; border-radius: 15px; background: var(--surface-soft); }
.summary-grid strong, .summary-grid span { display: block; }
.summary-grid strong { font-size: 22px; }
.summary-grid span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.summary-actions { display: grid; gap: 9px; }
.footer-note { margin: 20px 2px 0; color: var(--muted); font-size: 11px; text-align: center; }

.modal-backdrop { position: fixed; z-index: 10; inset: 0; display: grid; place-items: center; padding: 18px; background: rgba(20, 20, 35, .48); backdrop-filter: blur(5px); }
.login-modal { position: relative; width: min(100%, 390px); padding: 27px 22px 22px; border: 1px solid var(--line); border-radius: 23px; background: var(--surface); box-shadow: var(--shadow); }
.modal-close { position: absolute; top: 12px; right: 14px; width: 34px; height: 34px; border-radius: 10px; color: var(--muted); font-size: 24px; line-height: 1; }
.login-modal h2 { margin: 9px 0 5px; font-size: 23px; }
.login-modal form { display: grid; gap: 13px; margin-top: 22px; }
.login-modal label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.login-modal input { height: 48px; padding: 0 13px; border: 1px solid var(--line); border-radius: 13px; outline: none; background: var(--surface); color: var(--text); }
.login-modal input:focus { border-color: var(--accent); }
.form-error { margin: 0; color: var(--danger); font-size: 12px; }
.toast { position: fixed; z-index: 20; right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); left: 18px; width: fit-content; max-width: calc(100% - 36px); margin: auto; padding: 11px 15px; border-radius: 12px; background: var(--text); color: var(--surface); font-size: 12px; text-align: center; box-shadow: var(--shadow); }

@media (min-width: 600px) {
  .kana-app { padding-right: 28px; padding-left: 28px; }
  .question-card { min-height: 470px; }
  .summary-actions { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 410px) {
  .kana-app { padding-right: 13px; padding-left: 13px; }
  .welcome-row { align-items: flex-start; flex-direction: column; }
  .status-pill { align-self: flex-start; }
  .setup-card, .question-card, .summary-card { border-radius: 20px; }
  .setup-card { padding: 17px 15px; }
  .setting-note { font-size: 10px; }
}
