:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --paper: #f3f4f6;
  --card: #ffffff;
  --line: #d4d9e2;
  --teal: #356ae6;
  --teal-dark: #2857c8;
  --teal-soft: #eaf0ff;
  --coral: #e44730;
  --gold: #f0a000;
  --sidebar: #17243b;
  --shadow: 0 8px 24px rgba(23, 32, 51, 0.04);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body { margin: 0; color: var(--ink); background: var(--paper); }
button, input, select { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(53, 106, 230, 0.3);
  outline-offset: 2px;
}

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 236px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 30px 18px; background: var(--sidebar); color: #f7f9fc; z-index: 10; }
.brand { display: block; margin: 2px 10px 46px; color: inherit; text-decoration: none; }
.brand strong { font-size: 24px; letter-spacing: -0.7px; }
.nav { display: grid; gap: 10px; }
.nav-item { width: 100%; min-height: 58px; border: 0; border-radius: 10px; padding: 0 16px; display: flex; align-items: center; gap: 14px; background: transparent; color: #c8d1e0; cursor: pointer; text-align: left; font-weight: 700; }
.nav-item img { width: 22px; height: 22px; opacity: 0.82; }
.nav-item:hover,
.nav-item.is-active { color: #fff; background: rgba(117, 148, 202, 0.2); }
.nav-item.is-active img { opacity: 1; }

.main { min-width: 0; padding: 0 clamp(30px, 3.4vw, 52px) 64px; }
.topbar { min-height: 138px; display: flex; align-items: center; gap: 24px; }
.topbar h1 { margin: 0; font-size: clamp(28px, 2.5vw, 36px); letter-spacing: -1px; }
.wordset-control { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.wordset-control label { color: var(--muted); font-size: 12px; }
.wordset-control select { min-width: 190px; border: 1px solid var(--line); border-radius: 9px; padding: 13px 38px 13px 14px; background: var(--card); color: var(--ink); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.loading-card { max-width: 520px; margin: 100px auto; padding: 28px; border-radius: 14px; display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--muted); background: var(--card); }
.spinner { width: 18px; height: 18px; border: 2px solid #cbd8d5; border-top-color: var(--teal); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.qa-banner { margin-bottom: 16px; padding: 12px 16px; display: flex; align-items: center; gap: 16px; border: 1px solid #e6c798; border-radius: 10px; background: #fff6e7; color: #66481c; font-size: 12px; }
.qa-banner strong { flex: 0 0 auto; }
.qa-banner span { color: #7b5a28; }

.dashboard-card { overflow: hidden; }
.study-command-row { padding: 34px 30px; display: grid; grid-template-columns: minmax(270px, 0.9fr) minmax(0, 2.1fr); gap: 28px; border-bottom: 1px solid var(--line); }
.study-start-button { min-height: 132px; border: 0; border-radius: 10px; padding: 20px 24px; display: flex; align-items: center; justify-content: center; gap: 16px; color: #fff; background: var(--teal); cursor: pointer; font-size: 24px; font-weight: 800; }
.study-start-button:hover { background: var(--teal-dark); }
.study-start-button img { width: 42px; height: 42px; }
.dashboard-data-row { padding: 34px 30px 36px; display: grid; grid-template-columns: minmax(330px, 0.92fr) minmax(470px, 1.35fr); gap: 34px; }
.overall-data { min-width: 0; padding-left: 34px; border-left: 1px solid var(--line); }
.mastery-card,
.calendar-card,
.word-browser { padding: 26px; }
.card-heading,
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.card-heading h2,
.section-heading h2 { margin: 0; font-size: 19px; letter-spacing: -0.3px; }
.card-heading > span,
.section-heading > span,
.total-label { color: var(--muted); font-size: 12px; }

.primary-button,
.secondary-button { min-height: 44px; border: 0; border-radius: 9px; padding: 10px 17px; cursor: pointer; font-weight: 700; }
.primary-button { color: white; background: var(--teal); }
.primary-button:hover { background: var(--teal-dark); }
.secondary-button { background: #e9eeeb; }
.danger-button { min-height: 44px; border: 1px solid #cc3825; border-radius: 9px; padding: 10px 17px; color: #fff; background: #cc3825; cursor: pointer; font-weight: 700; }
.danger-button:hover { border-color: #a92c1e; background: #a92c1e; }

.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.metric { min-width: 0; padding-right: 12px; border-right: 1px solid var(--line); }
.metric:last-child { padding-right: 0; border-right: 0; }
.metric span,
.metric strong,
.metric small { display: block; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { margin-top: 14px; font-size: clamp(34px, 3.4vw, 48px); line-height: 1; }
.metric small { margin-top: 6px; color: var(--muted); font-size: 11px; }

.mastery-row { margin: 0 0 14px; display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 8px 16px; }
.mastery-row span { color: var(--muted); font-size: 12px; }
.mastery-row strong { grid-column: 1; font-size: 38px; }
.mastery-row .total-label { display: none; }
.status-track { height: 10px; display: flex; overflow: hidden; border-radius: 999px; background: #e3e7e3; }
.status-track span { display: block; min-width: 0; height: 100%; }
.stats-grid { margin-top: 18px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat { display: grid; grid-template-columns: 10px 1fr; align-items: center; column-gap: 8px; }
.stat small { color: var(--muted); font-size: 11px; }
.stat strong { grid-column: 2; margin-top: 3px; font-size: 19px; }
.dot { width: 9px; height: 9px; border-radius: 50%; }
.unseen { background: #aab3c2 !important; }
.learning { background: var(--gold) !important; }
.due { background: var(--coral) !important; }
.mastered { background: var(--teal) !important; }

.section-heading { margin-bottom: 18px; }
.mode-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mode-option { min-width: 0; min-height: 118px; border: 1px solid var(--line); border-radius: 10px; padding: 18px; background: #fff; cursor: pointer; text-align: left; }
.mode-option:hover { border-color: var(--teal); background: #f8faff; }
.mode-option > span { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mode-option b,
.mode-option small { display: inline; }
.mode-option b { line-height: 1.4; white-space: nowrap; }
.mode-option small { color: var(--muted); font-size: 12px; white-space: nowrap; }
.mastery-card { margin-top: 22px; padding: 28px 30px 32px; }
.mastery-heading { margin-bottom: 28px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.mastery-heading h2 { margin: 0; font-size: 20px; }
.mastery-tabs { width: min(100%, 400px); display: grid; grid-template-columns: 1fr 1fr 1.25fr; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; }
.mastery-tabs button { min-height: 42px; border: 0; border-right: 1px solid var(--line); padding: 8px 14px; background: #fff; color: var(--ink); cursor: pointer; font-size: 12px; font-weight: 700; }
.mastery-tabs button:last-child { border-right: 0; }
.mastery-tabs button:hover { background: #f5f7fb; }
.mastery-tabs button.is-active { color: #fff; background: var(--teal); }
.mastery-progress { display: grid; gap: 24px; }
.mastery-line header { margin-bottom: 7px; display: flex; justify-content: space-between; font-size: 12px; }
.mastery-line header span { color: var(--muted); }
.mastery-track { height: 7px; overflow: hidden; border-radius: 999px; background: #e1e5ec; }
.mastery-track i { display: block; height: 100%; border-radius: inherit; background: var(--teal); }

.mode-picker { max-width: 820px; margin: 24px auto; padding: 30px; }
.picker-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.picker-option { min-height: 130px; border: 1px solid var(--line); border-radius: 12px; padding: 22px; background: white; cursor: pointer; text-align: left; }
.picker-option:hover { border-color: var(--teal); background: #f8faff; }
.picker-option b,
.picker-option small { display: block; }
.picker-option b { font-size: 17px; line-height: 1.5; }
.picker-option small { margin-top: 18px; color: var(--muted); }

.quiz { max-width: 900px; margin: 0 auto; }
.quiz-head { margin: 8px 0 18px; display: grid; grid-template-columns: 80px 1fr 64px; align-items: center; gap: 16px; }
.text-button { min-height: 40px; border: 0; background: none; color: var(--muted); cursor: pointer; text-align: left; }
.quiz-progress { height: 5px; overflow: hidden; border-radius: 99px; background: #dfe4df; }
.quiz-progress span { display: block; width: 0; height: 100%; background: var(--teal); transition: width 0.2s ease; }
.quiz-head > span { color: var(--muted); text-align: right; }
.question-card { min-height: 500px; padding: clamp(28px, 4vw, 48px); display: flex; flex-direction: column; }
.question-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; font-weight: 700; }
.question-prompt-block { min-height: 160px; margin: 20px 0 30px; display: grid; place-items: center; align-content: center; gap: 12px; }
.question-prompt-block h2 { margin: 0; text-align: center; font-size: clamp(30px, 4vw, 46px); line-height: 1.35; }
.audio-button { min-height: 38px; border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; color: var(--muted); background: #fff; cursor: pointer; font-size: 12px; font-weight: 700; }
.audio-button:hover { border-color: var(--teal); color: var(--teal); }
.audio-button.is-playing { border-color: var(--teal); color: #fff; background: var(--teal); }
.audio-button img { width: 17px; height: 17px; }
.audio-button.is-playing img { filter: brightness(0) invert(1); }
.audio-button.compact { min-height: 32px; margin-top: 10px; padding: 5px 11px; }
.choice-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice { min-height: 68px; border: 1px solid var(--line); border-radius: 11px; padding: 13px 16px; display: flex; align-items: center; gap: 12px; background: #fff; cursor: pointer; text-align: left; }
.choice:hover { border-color: var(--teal); }
.choice-key { flex: 0 0 auto; width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; background: #eef1f6; color: var(--muted); font-size: 12px; }
.choice.is-correct { border-color: var(--teal); background: #edf3ff; }
.choice.is-wrong { border-color: var(--coral); background: #fbece8; }
.choice:disabled { cursor: default; color: inherit; }
.choice-unknown { grid-column: 1 / -1; min-height: 52px; justify-content: center; color: var(--muted); background: #f7f8fa; font-weight: 700; text-align: center; }
.choice-unknown:hover { color: var(--ink); background: #f1f3f7; }
.spelling-form { width: min(100%, 580px); margin: 0 auto; }
.spelling-form label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; }
.spelling-form > div { display: flex; gap: 8px; }
.spelling-form input { min-width: 0; flex: 1; border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; font-size: 20px; }
.spelling-form input.is-wrong { border-color: var(--coral); background: #fff5f2; }
.feedback { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.feedback strong { color: var(--teal); font-size: 17px; }
.feedback.is-wrong strong { color: var(--coral); }
.feedback p { margin: 5px 0 0; }
.feedback-copy { min-width: 0; }
.auto-next-label { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 700; }
.shortcut-hint { margin: 12px 0 0; color: var(--muted); font-size: 11px; text-align: right; }
kbd { padding: 2px 5px; border: 1px solid var(--line); border-radius: 4px; background: #fff; font: inherit; }

.session-result { max-width: 560px; margin: 28px auto; padding: 42px; text-align: center; }
.session-result h2 { margin: 0 0 22px; font-size: 20px; }
.session-result > strong { font-size: 50px; }
.session-result > p { margin: 10px 0 0; }
.session-result > div { margin-top: 28px; display: flex; justify-content: center; gap: 10px; }
.muted { color: var(--muted); }

.calendar-card { max-width: 980px; margin: 0 auto; }
.calendar-toolbar { display: grid; grid-template-columns: 90px 1fr 90px; align-items: center; gap: 12px; }
.calendar-toolbar h2 { margin: 0; text-align: center; font-size: 20px; }
.calendar-summary { margin: 24px 0; display: grid; grid-template-columns: repeat(3, 1fr); overflow: hidden; border: 1px solid var(--line); border-radius: 12px; }
.calendar-metric { min-width: 0; padding: 18px 20px; border-right: 1px solid var(--line); }
.calendar-metric:last-child { border-right: 0; }
.calendar-metric span,
.calendar-metric strong,
.calendar-metric small { display: block; }
.calendar-metric span { color: var(--muted); font-size: 12px; }
.calendar-metric strong { margin-top: 7px; font-size: 28px; line-height: 1; }
.calendar-metric small { margin-top: 5px; color: var(--muted); font-size: 11px; }
.calendar-weekdays,
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.calendar-weekdays { margin-bottom: 6px; color: var(--muted); text-align: center; font-size: 11px; }
.calendar-day { min-height: 92px; border: 1px solid var(--line); border-radius: 9px; padding: 10px; display: flex; flex-direction: column; gap: 5px; background: #fff; }
.calendar-day.is-blank { border-color: transparent; background: transparent; }
.calendar-day.has-data { border-color: #b8c9ee; background: #f1f5ff; }
.calendar-day.is-today { box-shadow: inset 0 0 0 2px var(--teal); }
.calendar-date { color: var(--muted); font-size: 12px; }
.calendar-day strong { margin-top: auto; font-size: 18px; }
.calendar-day small { color: var(--muted); font-size: 11px; }

.word-browser { margin: 0 auto; }
.word-tools input { width: min(340px, 45%); border: 1px solid var(--line); border-radius: 9px; padding: 10px 13px; background: #fff; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; }
.filter-chip { min-height: 38px; border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px; background: white; cursor: pointer; font-size: 12px; }
.filter-chip.is-active { border-color: var(--teal); color: white; background: var(--teal); }
#word-count-label { margin: 22px 0 8px; font-size: 12px; }
.word-list-head,
.word-row { display: grid; grid-template-columns: 74px minmax(130px, 1fr) minmax(220px, 1.5fr) 90px 80px; align-items: center; gap: 12px; }
.word-list-head { padding: 10px 5px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.word-list-head span:nth-last-child(-n + 2) { text-align: right; }
.word-row { padding: 12px 5px; border-bottom: 1px solid #e7e9e4; font-size: 13px; }
.word-row b,
.word-row .japanese { min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.word-row .number,
.word-row .meta { color: var(--muted); font-size: 11px; }
.word-row .meta { text-align: right; }
.word-status { justify-self: end; min-width: 58px; border-radius: 999px; padding: 4px 8px; color: white; font-size: 10px; text-align: center; }
.word-status.unseen { color: #43514e; }

.settings-stack { max-width: 760px; display: grid; gap: 16px; }
.settings-card { padding: 28px 30px; display: flex; align-items: center; justify-content: space-between; gap: 30px; }
.settings-copy h2 { margin: 0; font-size: 19px; }
.settings-copy p { margin: 9px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.settings-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; }
.toggle-control { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; }
.toggle-control input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-control span { width: 44px; height: 24px; border-radius: 999px; padding: 2px; display: block; background: #c9d0da; transition: background 0.2s ease; }
.toggle-control span::after { content: ""; width: 20px; height: 20px; border-radius: 50%; display: block; background: #fff; box-shadow: 0 1px 4px rgba(23, 32, 51, 0.25); transition: transform 0.2s ease; }
.toggle-control input:checked + span { background: var(--teal); }
.toggle-control input:checked + span::after { transform: translateX(20px); }
.toggle-control input:focus-visible + span { outline: 3px solid rgba(53, 106, 230, 0.3); outline-offset: 2px; }
.confirm-dialog { width: min(520px, calc(100% - 32px)); border: 1px solid var(--line); border-radius: 12px; padding: 0; color: var(--ink); background: var(--card); box-shadow: 0 24px 80px rgba(23, 32, 51, 0.28); }
.confirm-dialog::backdrop { background: rgba(13, 22, 38, 0.56); }
.confirm-dialog form { padding: 28px; }
.confirm-dialog h2 { margin: 0; font-size: 21px; }
.confirm-dialog p { margin: 14px 0 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.confirm-dialog p strong { color: var(--ink); }
.dialog-actions { margin-top: 28px; display: flex; justify-content: flex-end; gap: 10px; }

.toast { position: fixed; right: 22px; bottom: 22px; max-width: 380px; padding: 12px 16px; border-radius: 9px; background: var(--sidebar); color: white; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(8px); transition: 0.2s; z-index: 20; }
.toast.is-visible { opacity: 1; transform: none; }

@media (max-width: 1060px) {
  .app-shell { grid-template-columns: 190px minmax(0, 1fr); }
  .sidebar { padding-inline: 14px; }
  .study-command-row,
  .dashboard-data-row { grid-template-columns: 1fr; }
  .study-start-button { min-height: 90px; }
  .overall-data { padding: 30px 0 0; border-top: 1px solid var(--line); border-left: 0; }
  .mode-list { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: auto 0 0; width: 100%; height: calc(68px + env(safe-area-inset-bottom)); padding: 8px max(12px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); border-top: 1px solid rgba(255, 255, 255, 0.12); }
  .brand { display: none; }
  .nav { height: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .nav-item { min-height: 50px; padding: 0 4px; flex-direction: column; justify-content: center; gap: 3px; text-align: center; font-size: 10px; }
  .nav-item img { width: 19px; height: 19px; }
  .main { padding: 0 max(16px, env(safe-area-inset-right)) calc(94px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .topbar { min-height: calc(88px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); gap: 12px; }
  .topbar h1 { font-size: 23px; }
  .wordset-control label { display: none; }
  .wordset-control select { width: 145px; min-width: 0; padding: 9px 24px 9px 10px; font-size: 13px; }
  .qa-banner { align-items: flex-start; flex-direction: column; gap: 4px; }
  .dashboard-card,
  .mastery-card,
  .calendar-card,
  .word-browser { padding: 20px; }
  .dashboard-card { padding: 0; }
  .study-command-row,
  .dashboard-data-row { padding: 18px; gap: 18px; }
  .study-start-button { min-height: 72px; font-size: 20px; }
  .study-start-button img { width: 34px; height: 34px; }
  .mode-list,
  .picker-grid { grid-template-columns: 1fr; }
  .mode-option { min-height: 64px; }
  .picker-option { min-height: 72px; }
  .mastery-heading { align-items: stretch; flex-direction: column; }
  .mastery-tabs { width: 100%; }
  .picker-option small { margin-top: 8px; }
  .choice-list { grid-template-columns: 1fr; }
  .question-card { min-height: 0; padding: 24px; }
  .question-prompt-block { min-height: 140px; margin: 16px 0 24px; }
  .question-prompt-block h2 { font-size: clamp(28px, 9vw, 38px); }
  .shortcut-hint { display: none; }
  .feedback { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); margin: 20px -8px -8px; padding: 16px 8px 8px; background: var(--card); }
  .calendar-day { min-height: 68px; padding: 7px; gap: 3px; }
  .calendar-day strong { font-size: 14px; }
  .calendar-day small { font-size: 10px; }
  .word-tools { align-items: stretch; flex-direction: column; }
  .word-tools input { width: 100%; }
  .word-list-head { display: none; }
  .word-row { grid-template-columns: 54px minmax(0, 1fr) 72px; gap: 8px; }
  .word-browser,
  .word-list { min-width: 0; overflow: hidden; }
  .word-row .japanese { grid-column: 2 / 4; color: var(--muted); }
  .word-row .meta { display: none; }
  .word-status { grid-column: 3; grid-row: 1; }
  .settings-card { padding: 20px; align-items: stretch; flex-direction: column; gap: 20px; }
  .settings-card .danger-button { align-self: flex-start; }
  .settings-actions { width: 100%; }
  .settings-actions button { flex: 1; }
  .toast { right: max(12px, env(safe-area-inset-right)); bottom: calc(82px + env(safe-area-inset-bottom)); left: max(12px, env(safe-area-inset-left)); max-width: none; }
}

@media (max-width: 440px) {
  .metric strong { font-size: 28px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .spelling-form > div,
  .feedback,
  .session-result > div { align-items: stretch; flex-direction: column; }
  .session-result { padding: 30px 20px; }
  .calendar-card { padding: 16px; }
  .calendar-toolbar { grid-template-columns: 68px 1fr 68px; gap: 8px; }
  .calendar-toolbar .secondary-button { min-height: 38px; padding: 7px 9px; font-size: 12px; }
  .calendar-toolbar h2 { font-size: 17px; }
  .calendar-summary { margin: 18px 0; }
  .calendar-metric { padding: 13px 9px; }
  .calendar-metric strong { font-size: 22px; }
  .calendar-weekdays,
  .calendar-grid { gap: 3px; }
  .calendar-day { min-height: 57px; border-radius: 7px; padding: 5px; }
  .calendar-date { font-size: 10px; }
  .calendar-day strong { font-size: 12px; }
  .calendar-day small { display: none; }
}

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