:root {
  color-scheme: light;
  --paper: #ffffff;
  --surface: #ffffff;
  --surface-soft: #f4f8e9;
  --ink: #29321e;
  --muted: #66705b;
  --line: #e1e8d5;
  --accent: #617c1f;
  --accent-dark: #4b6218;
  --accent-soft: #edf4dc;
  --green: #557434;
  --shadow: 0 10px 30px rgba(70, 92, 30, 0.07);
  font-family: "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: linear-gradient(180deg, #f7faef 0, #ffffff 220px);
}

button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid rgba(140, 174, 43, 0.38);
  outline-offset: 3px;
}

.site-shell { width: min(1240px, calc(100% - 56px)); margin: 0 auto; }
h2, h3, p { margin-top: 0; }
main { padding-top: 24px; }

.workbench { display: grid; grid-template-columns: minmax(280px, 0.78fr) minmax(0, 1.55fr); align-items: start; gap: 22px; }
.control-panel, .practice-panel { border: 1px solid var(--line); border-radius: 13px; background: rgba(255, 255, 255, 0.98); box-shadow: var(--shadow); }
.control-panel { padding: 25px 24px 22px; }
.practice-panel { padding: 25px 28px 20px; }
.panel-kicker { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: 0.1em; }
.kicker-line { height: 1px; flex: 1; background: #e5ecd8; }
.control-panel h2, .practice-panel h2 { margin: 17px 0 6px; font-family: "Noto Serif JP", serif; font-size: 23px; font-weight: 500; letter-spacing: 0.035em; }
.panel-description, .practice-subtitle { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.page-options { display: grid; gap: 9px; margin-top: 20px; }
.page-option { width: 100%; min-height: 76px; display: flex; align-items: center; gap: 14px; border: 1px solid var(--line); border-radius: 9px; background: #fff; padding: 12px 14px; text-align: left; cursor: pointer; transition: 160ms ease; }
.page-option:hover { border-color: #b5ca7b; background: #fbfdf6; transform: translateY(-1px); }
.page-option[aria-pressed="true"] { border-color: var(--accent); background: #f4f8e9; box-shadow: inset 3px 0 0 var(--accent); }
.page-number { display: grid; place-items: center; width: 36px; height: 36px; flex: 0 0 auto; border-radius: 7px; background: #f0f4e7; color: #727c5e; font-family: "Noto Serif JP", serif; font-size: 13px; }
.page-option[aria-pressed="true"] .page-number { background: var(--accent-dark); color: white; }
.page-option-copy { display: grid; gap: 5px; min-width: 0; }
.page-option-title { font-family: "Noto Serif JP", serif; font-size: 15px; font-weight: 600; }
.page-option-meta { color: #758064; font-size: 10px; }
.page-option-arrow { margin-left: auto; color: #a9b68f; font-size: 18px; }
.panel-divider { height: 1px; margin: 22px 0 18px; background: #e7eddc; }
.field-label { margin-bottom: 9px; color: #5f6b4f; font-size: 11px; font-weight: 600; }
.mode-options { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 4px; border: 1px solid #e2e9d7; border-radius: 9px; background: #f2f6e9; }
.mode-button { min-height: 39px; border: 0; border-radius: 6px; background: transparent; color: #647052; font-size: 11px; cursor: pointer; transition: 150ms ease; }
.mode-button span { padding: 0 3px; color: #9cac7b; }
.mode-button.is-active { background: #fff; color: var(--accent-dark); box-shadow: 0 1px 5px rgba(48, 64, 25, 0.12); font-weight: 700; }
.option-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 0 10px; color: #5f6b4f; font-size: 11px; }
.option-row select { max-width: 145px; border: 1px solid #e1e8d4; border-radius: 6px; background: #fff; padding: 8px 23px 8px 10px; color: #3f4a31; font-size: 11px; }
.stage-button { flex: 0 0 auto; border: 1px solid #dce6c7; border-radius: 8px; background: #f8fbed; padding: 9px 12px; color: #4e641d; font-size: 11px; cursor: pointer; transition: 160ms ease; }
.stage-button:hover { border-color: #a9c15e; background: #f0f6df; }
.stage-button span { margin-right: 5px; color: var(--accent-dark); }
.toggle-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 9px 0 2px; cursor: pointer; }
.toggle-row span { display: grid; gap: 3px; }
.toggle-row strong { color: #5f6b4f; font-size: 11px; font-weight: 600; }
.toggle-row small { color: #8b957b; font-size: 10px; }
.toggle-row input { accent-color: var(--accent); width: 16px; height: 16px; }
.keyboard-hint { display: flex; align-items: center; gap: 8px; margin-top: 19px; padding-top: 15px; border-top: 1px solid #e9eedf; color: #7e8970; font-size: 10px; }
.hint-icon { color: var(--accent); font-size: 14px; }

.practice-titlebar { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-top: 7px; }
.practice-summary { display: flex; align-items: center; gap: 15px; flex: 0 0 auto; }
.practice-panel h2 { margin: 13px 0 5px; }
.card-count { display: flex; align-items: baseline; gap: 5px; flex: 0 0 auto; color: var(--accent); font-family: "Noto Serif JP", serif; font-size: 30px; font-weight: 500; }
.count-slash, .card-count span:last-child { color: #899476; font-size: 13px; }
.progress-track { height: 4px; overflow: hidden; margin: 18px 0 16px; border-radius: 999px; background: #eaf0df; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #83a72b, #bad64e); transition: width 220ms ease; }
.flashcard { min-height: 385px; display: flex; flex-direction: column; border: 1px solid #e3ead7; border-radius: 11px; background: linear-gradient(140deg, #ffffff 0%, #ffffff 70%, #f7faef 100%); padding: 19px 22px 17px; box-shadow: 0 3px 12px rgba(64, 86, 29, 0.045); }
.card-meta { display: flex; align-items: center; justify-content: space-between; min-height: 18px; color: #87917a; font-size: 9px; letter-spacing: 0.14em; }
.card-context { color: var(--accent-dark); font-weight: 700; }
.card-state { color: var(--green); font-size: 10px; letter-spacing: 0.03em; }
.card-content { width: 100%; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 15px 0 23px; text-align: center; }
.answer-label { margin: 0 0 13px; color: #758064; font-size: 10px; letter-spacing: 0.12em; }
.prompt-text { max-width: 100%; color: #29321e; font-family: "Noto Serif JP", "Yu Mincho", serif; font-size: clamp(46px, 6vw, 76px); font-weight: 500; letter-spacing: 0.06em; line-height: 1.25; overflow-wrap: anywhere; }
.prompt-text.is-reading { font-family: "Noto Serif JP", serif; font-size: clamp(34px, 5vw, 60px); letter-spacing: 0.02em; }
.answer-area { width: 100%; margin-top: 10px; animation: answer-in 220ms ease both; }
.answer-divider { width: 40px; height: 1px; margin: 0 auto 14px; background: #dce6c9; }
.answer-label { margin-bottom: 4px; color: var(--accent); }
.answer-text { margin: 0; color: var(--accent-dark); font-family: "Noto Serif JP", serif; font-size: clamp(24px, 3.5vw, 36px); font-weight: 500; letter-spacing: 0.04em; }
.meaning-text { margin: 7px 0 0; color: #66705b; font-size: 12px; }
.meaning-text:empty { display: none; }
.card-actions { display: flex; justify-content: center; gap: 9px; }
.primary-button, .secondary-button { min-width: 158px; min-height: 43px; border-radius: 7px; padding: 10px 16px; font-size: 12px; font-weight: 600; cursor: pointer; transition: 160ms ease; }
.primary-button { border: 1px solid var(--accent-dark); background: var(--accent-dark); color: white; box-shadow: 0 3px 7px rgba(77, 101, 25, 0.16); }
.primary-button:hover { border-color: var(--accent-dark); background: var(--accent-dark); transform: translateY(-1px); }
.primary-button span { margin-left: 12px; font-size: 16px; }
.secondary-button { min-width: auto; border: 1px solid #dfe7d2; background: #fff; color: #59664a; }
.secondary-button:hover { border-color: #a9c15e; color: var(--accent-dark); }
.rating-actions { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 12px; animation: answer-in 220ms ease both; }
.rating-label { margin-right: 2px; color: #7f8973; font-size: 10px; }
.rating-button { border: 1px solid #dfe7d2; border-radius: 6px; background: #fff; padding: 7px 12px; color: #5b674d; font-size: 10px; cursor: pointer; }
.rating-button[aria-pressed="true"] { border-color: #b6cc79; background: #f1f6e3; color: var(--accent-dark); }
.rating-known[aria-pressed="true"] { border-color: #9eb66a; background: #edf4df; color: #456323; }
.navigation-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; margin-top: 14px; }
.nav-button { min-height: 38px; display: inline-flex; align-items: center; gap: 7px; border: 1px solid #e1e8d5; border-radius: 7px; background: #fff; padding: 8px 12px; color: #4e5c3f; font-size: 11px; cursor: pointer; transition: 150ms ease; }
.nav-button:last-child { justify-self: end; }
.nav-button:hover:not(:disabled) { border-color: #a9c15e; color: var(--accent-dark); }
.nav-button:disabled { opacity: 0.42; cursor: not-allowed; }
.nav-counter { color: #7a866d; font-size: 10px; font-variant-numeric: tabular-nums; }
.utility-row { display: flex; justify-content: space-between; gap: 12px; margin-top: 9px; padding-top: 10px; border-top: 1px solid #e9eedf; }
.text-button { border: 0; background: transparent; padding: 5px 2px; color: #657251; font-size: 10px; cursor: pointer; }
.text-button:hover { color: var(--accent-dark); }
.vocabulary-section { margin-top: 15px; padding-top: 17px; border-top: 1px solid #e4ebd8; }
.vocabulary-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.vocabulary-heading h3 { margin: 0; font-family: "Noto Serif JP", serif; font-size: 16px; font-weight: 500; }
.search-box { display: flex; align-items: center; gap: 5px; width: min(220px, 48%); border: 1px solid #e1e8d5; border-radius: 7px; background: white; padding: 7px 9px; color: #81906b; }
.search-box input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 10px; }
.search-box input:focus-visible { outline: 0; }
.vocabulary-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.vocab-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; border: 1px solid #e8eddf; border-radius: 7px; background: #fff; padding: 9px 10px; text-align: left; cursor: pointer; }
.vocab-item:hover { border-color: #b5ca7b; background: #f9fbf2; }
.vocab-word { overflow: hidden; color: #39432c; font-family: "Noto Serif JP", serif; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.vocab-reading { color: var(--accent-dark); font-size: 10px; white-space: nowrap; }
.empty-search { margin: 13px 0 0; color: var(--muted); font-size: 11px; }
.footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 23px 2px 30px; color: #7d8871; font-size: 10px; }
.footer > span { display: flex; align-items: center; gap: 7px; }
.saved-dot { width: 6px; height: 6px; border-radius: 50%; background: #8cae2b; }
.footer button { border: 0; background: transparent; padding: 4px; color: #7d8871; font-size: 10px; cursor: pointer; }
.footer button:hover { color: var(--accent-dark); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.stage-toolbar { position: fixed; z-index: 4; top: 18px; left: 24px; right: 24px; align-items: center; justify-content: space-between; color: #73805e; font-size: 10px; letter-spacing: 0.16em; }
.stage-toolbar:not([hidden]) { display: flex; }
.stage-toolbar button { border: 1px solid #dfe7d2; border-radius: 6px; background: var(--surface); padding: 8px 11px; color: #566348; font-size: 10px; cursor: pointer; }
.stage-toolbar button span { margin-left: 5px; color: var(--accent); }
.toast { position: fixed; z-index: 10; right: 22px; bottom: 20px; max-width: calc(100% - 44px); border-radius: 7px; background: #36432a; padding: 10px 14px; color: white; font-size: 11px; opacity: 0; pointer-events: none; transform: translateY(8px); transition: 180ms ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }

@keyframes answer-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

body.stage-mode { overflow: hidden; background: #ffffff; }
body.stage-mode .site-shell { width: 100%; max-width: none; height: 100vh; padding: 0 clamp(24px, 8vw, 150px); }
body.stage-mode .control-panel, body.stage-mode .footer { display: none; }
body.stage-mode main { height: 100%; display: flex; align-items: center; }
body.stage-mode .workbench { width: 100%; display: block; }
body.stage-mode .practice-panel { max-width: 1100px; margin: 0 auto; border: 0; background: transparent; box-shadow: none; padding: clamp(44px, 7vh, 85px) 0 28px; }
body.stage-mode .panel-kicker, body.stage-mode .practice-titlebar, body.stage-mode .progress-track, body.stage-mode .navigation-row, body.stage-mode .utility-row, body.stage-mode .vocabulary-section { max-width: 980px; margin-left: auto; margin-right: auto; }
body.stage-mode .practice-panel h2 { font-size: clamp(23px, 3vw, 33px); }
body.stage-mode .practice-subtitle { font-size: 14px; }
body.stage-mode .card-count { font-size: 40px; }
body.stage-mode .progress-track { margin-top: 16px; margin-bottom: 20px; }
body.stage-mode .flashcard { min-height: min(57vh, 560px); max-width: 980px; margin: 0 auto; padding: clamp(20px, 4vh, 42px) clamp(22px, 5vw, 55px); }
body.stage-mode .prompt-text { font-size: clamp(64px, 10vw, 120px); }
body.stage-mode .prompt-text.is-reading { font-size: clamp(46px, 7vw, 82px); }
body.stage-mode .answer-text { font-size: clamp(32px, 5vw, 54px); }
body.stage-mode .meaning-text { font-size: 15px; }
body.stage-mode .primary-button, body.stage-mode .secondary-button { min-height: 50px; font-size: 14px; }
body.stage-mode .stage-button { visibility: hidden; }

@media (max-width: 820px) {
  .site-shell { width: min(100% - 32px, 680px); }
  main { padding-top: 16px; }
  .workbench { grid-template-columns: 1fr; gap: 14px; }
  .control-panel { padding: 21px 20px; }
  .practice-panel { padding: 21px 20px 17px; }
  .page-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-option { min-height: 84px; padding: 10px; gap: 8px; }
  .page-option-arrow { display: none; }
  .flashcard { min-height: 360px; }
  body.stage-mode .site-shell { padding: 0 20px; }
  body.stage-mode .practice-panel { padding-top: 58px; }
  body.stage-mode .flashcard { min-height: 52vh; }
}

@media (max-width: 480px) {
  .site-shell { width: calc(100% - 24px); }
  main { padding-top: 12px; }
  .control-panel, .practice-panel { border-radius: 10px; }
  .control-panel { padding: 18px 15px; }
  .practice-panel { padding: 18px 14px 14px; }
  .control-panel h2, .practice-panel h2 { font-size: 20px; }
  .page-options { gap: 7px; }
  .page-option { min-height: 75px; }
  .page-number { width: 31px; height: 31px; font-size: 11px; }
  .page-option-title { font-size: 12px; }
  .page-option-meta { font-size: 9px; }
  .practice-titlebar { align-items: flex-start; flex-wrap: wrap; }
  .practice-summary { gap: 8px; }
  .stage-button { padding: 7px 9px; font-size: 10px; }
  .practice-panel h2 { font-size: 18px; }
  .practice-subtitle { font-size: 10px; }
  .card-count { font-size: 25px; }
  .flashcard { min-height: 330px; padding: 15px 13px 13px; }
  .prompt-text { font-size: clamp(42px, 12vw, 58px); }
  .prompt-text.is-reading { font-size: clamp(30px, 9vw, 43px); }
  .primary-button, .secondary-button { min-width: 0; padding: 9px 12px; font-size: 11px; }
  .primary-button { flex: 1; }
  .rating-actions { gap: 5px; }
  .rating-label { display: none; }
  .rating-button { padding: 7px 9px; }
  .navigation-row { gap: 6px; }
  .nav-button { min-height: 35px; gap: 4px; padding: 7px 9px; font-size: 10px; }
  .utility-row { align-items: flex-start; }
  .text-button { max-width: 50%; text-align: left; font-size: 9px; line-height: 1.5; }
  .vocabulary-heading { align-items: flex-start; flex-direction: column; }
  .search-box { width: 100%; }
  .vocabulary-list { grid-template-columns: 1fr; }
  .footer { padding-top: 17px; font-size: 9px; }
  .footer button { font-size: 9px; }
  .stage-toolbar { top: 10px; left: 12px; right: 12px; }
  body.stage-mode .site-shell { padding: 0 12px; }
  body.stage-mode .practice-panel { padding-top: 57px; }
  body.stage-mode .flashcard { min-height: 56vh; padding: 18px 12px; }
  body.stage-mode .prompt-text { font-size: clamp(50px, 15vw, 75px); }
  body.stage-mode .prompt-text.is-reading { font-size: clamp(34px, 10vw, 52px); }
}

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