:root {
  --green-950: #052e16;
  --green-900: #14532d;
  --green-800: #166534;
  --green-700: #15803d;
  --green-100: #dcfce7;
  --green-50: #f0fdf4;
  --ink: #17221b;
  --muted: #647067;
  --line: #dce5df;
  --paper: #fffef9;
  --cream: #f8f7ef;
  --orange: #c2410c;
  --red: #b42318;
  --shadow: 0 18px 55px rgba(20, 83, 45, .10);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  color: var(--ink);
  background: var(--cream);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at 85% 3%, rgba(187, 247, 208, .8), transparent 23rem),
    linear-gradient(180deg, #fbfdf8 0, var(--cream) 38rem);
  line-height: 1.75;
}

button,
input { font: inherit; }

button { cursor: pointer; }

a { color: inherit; }

[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 8px 12px;
  color: #fff;
  background: var(--green-900);
  transform: translateY(-150%);
}

.skip-link:focus { transform: none; }

.site-header {
  border-bottom: 1px solid rgba(20, 83, 45, .12);
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(10px);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1100px, calc(100% - 40px));
  min-height: 68px;
  margin: 0 auto;
}

.brand {
  color: var(--green-900);
  font-family: Georgia, "Yu Mincho", serif;
  font-size: 21px;
  font-weight: 700;
  text-decoration: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

.language-control {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

#language-select {
  min-height: 38px;
  padding: 5px 30px 5px 10px;
  border: 1px solid #b7c7bc;
  border-radius: 8px;
  color: var(--green-900);
  background: #fff;
  font-weight: 800;
}

#language-select:focus {
  border-color: var(--green-700);
  outline: 3px solid rgba(21, 128, 61, .14);
}

.back-link {
  color: var(--green-800);
  font-size: 13px;
  font-weight: 700;
  text-underline-offset: 4px;
}

.hero { padding: 76px 20px 48px; }

.hero__inner {
  width: min(900px, 100%);
  margin: 0 auto;
  text-align: center;
}

.eyebrow,
.step-label {
  margin: 0 0 6px;
  color: var(--green-700);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(40px, 7vw, 72px);
  font-weight: 700;
  letter-spacing: .03em;
  line-height: 1.2;
}

.hero h1 span { color: var(--green-800); }

.hero__lead {
  max-width: 660px;
  margin: 24px auto 0;
  color: #526058;
  font-size: 16px;
}

.hero__cover {
  display: block;
  width: min(760px, 100%);
  height: auto;
  margin: 30px auto 0;
  border: 1px solid rgba(20, 83, 45, .16);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.kanji-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  max-width: 700px;
  max-height: 155px;
  margin: 26px auto 0;
  padding: 2px;
  overflow-y: auto;
}

.kanji-list span {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid #b9d6c1;
  border-radius: 7px;
  background: rgba(255, 255, 255, .72);
  font-family: "Yu Mincho", serif;
  font-size: 18px;
  font-weight: 700;
}

.app-message {
  width: min(1100px, calc(100% - 40px));
  margin: 0 auto 20px;
  padding: 12px 16px;
  border: 1px solid #fed7aa;
  border-radius: 10px;
  color: #7c2d12;
  background: #fff7ed;
  font-weight: 700;
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(280px, .8fr);
  gap: 22px;
  width: min(1100px, calc(100% - 40px));
  margin: 0 auto;
  align-items: start;
}

.panel {
  border: 1px solid rgba(20, 83, 45, .13);
  border-radius: 20px;
  background: rgba(255, 255, 255, .92);
  box-shadow: var(--shadow);
}

.setup-panel { padding: clamp(24px, 4vw, 42px); }
.progress-panel { padding: 30px; }

.panel__heading h2,
.about-panel h2,
.result-summary h2 {
  margin: 0;
  font-family: "Yu Mincho", serif;
  font-size: clamp(24px, 3vw, 32px);
  line-height: 1.45;
}

.form-group {
  min-width: 0;
  margin: 30px 0 0;
  padding: 0;
  border: 0;
}

.form-group legend {
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 800;
}

.select-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

#unit-select,
#grade-select {
  width: 100%;
  min-height: 52px;
  padding: 10px 42px 10px 14px;
  border: 2px solid #b7c7bc;
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
  font-weight: 800;
}

#grade-select { margin-bottom: 16px; }

#unit-select:focus,
#grade-select:focus {
  border-color: var(--green-700);
  outline: 3px solid rgba(21, 128, 61, .14);
}

.unit-summary {
  margin: 7px 0 0;
  color: var(--green-800);
  font-size: 12px;
  font-weight: 800;
}

.choice-grid {
  display: grid;
  gap: 10px;
}

.choice-grid--three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.choice-grid--two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.choice-grid--four { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.choice-card,
.number-choice {
  position: relative;
  display: block;
}

.choice-card input,
.number-choice input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.choice-card span,
.number-choice span {
  display: flex;
  min-height: 90px;
  padding: 15px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  transition: border-color .2s, background .2s, box-shadow .2s;
}

.choice-card span {
  flex-direction: column;
  justify-content: center;
}

.choice-card strong { font-size: 17px; }

.choice-card small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.choice-card--input span { min-height: 76px; }

.number-choice span {
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 10px;
  font-weight: 800;
}

.choice-card input:checked + span,
.number-choice input:checked + span {
  border-color: var(--green-700);
  background: var(--green-50);
  box-shadow: 0 0 0 3px rgba(21, 128, 61, .11);
}

.choice-card input:focus-visible + span,
.number-choice input:focus-visible + span {
  outline: 3px solid #f59e0b;
  outline-offset: 2px;
}

.check-row {
  display: flex;
  gap: 12px;
  margin: 26px 0 0;
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcfa;
}

.check-row input {
  width: 20px;
  height: 20px;
  margin-top: 3px;
  accent-color: var(--green-700);
}

.check-row span { display: flex; flex-direction: column; }
.check-row small { color: var(--muted); font-size: 11px; }

.primary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 30px;
}

.button {
  min-height: 50px;
  padding: 12px 20px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 800;
}

.button:focus-visible,
.text-button:focus-visible,
.back-link:focus-visible,
.brand:focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: 3px;
}

.button--primary {
  color: #fff;
  background: var(--green-700);
  box-shadow: 0 8px 18px rgba(21, 128, 61, .2);
}

.button--primary:hover { background: var(--green-900); }

.button--secondary {
  color: var(--green-800);
  border-color: #9fbea7;
  background: #fff;
}

.button--secondary:hover { background: var(--green-50); }

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 24px 0 0;
}

.stats-grid div {
  padding: 14px;
  border-radius: 12px;
  background: var(--green-50);
}

.stats-grid dt { color: var(--muted); font-size: 11px; font-weight: 700; }
.stats-grid dd { margin: 1px 0 0; color: var(--green-900); font-size: 26px; font-weight: 800; line-height: 1.3; }
.stats-grid dd span { margin-left: 2px; color: var(--muted); font-size: 12px; }

.storage-note {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.record-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 18px;
}

.text-button {
  min-height: 38px;
  padding: 4px 0;
  border: 0;
  color: var(--green-800);
  background: transparent;
  font-size: 12px;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.text-button--label { display: inline-flex; align-items: center; cursor: pointer; }
.text-button--danger { color: var(--red); }

.quiz-view,
.result-view {
  width: min(860px, calc(100% - 40px));
  margin: 0 auto;
}

.quiz-topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}

.quiz-progress-label { margin: 0; font-size: 20px; font-weight: 800; }

.progress-track {
  overflow: hidden;
  height: 8px;
  margin: 12px 0 18px;
  border-radius: 99px;
  background: #dce8df;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--green-700);
  transition: width .25s ease;
}

.question-card {
  min-height: 620px;
  padding: clamp(28px, 6vw, 60px);
  border: 1px solid rgba(20, 83, 45, .13);
  border-radius: 22px;
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--shadow);
}

.question-kicker { margin: 0; color: var(--muted); font-size: 14px; font-weight: 700; }

.question-stage {
  display: flex;
  overflow-x: auto;
  justify-content: center;
  width: 100%;
  min-height: 330px;
  margin: 24px 0 14px;
  padding: 18px 12px;
  border: 1px solid #d9e4dc;
  border-radius: 14px;
  background:
    linear-gradient(90deg, transparent calc(100% - 1px), rgba(20, 83, 45, .07) 0) 0 0 / 44px 100%,
    #fffefa;
}

.question-sentence {
  height: 292px;
  margin: 0;
  font-family: "Yu Mincho", serif;
  font-size: clamp(23px, 4.5vw, 34px);
  font-weight: 700;
  letter-spacing: .08em;
  line-height: 1.85;
  text-align: start;
  text-orientation: upright;
  writing-mode: vertical-rl;
}

.question-sentence mark {
  padding: 0 .12em;
  color: var(--green-950);
  background: transparent;
  text-decoration: underline;
  text-decoration-color: #65a873;
  text-decoration-thickness: .18em;
  text-underline-offset: .14em;
}

.question-meaning {
  min-height: 26px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.question-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  min-height: 38px;
}

.romaji-display {
  padding: 4px 10px;
  border: 1px solid #b9d6c1;
  border-radius: 999px;
  color: var(--green-900);
  background: var(--green-50);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .03em;
}

.answer-form { margin-top: 34px; }
.answer-form label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 800; }

.answer-row {
  display: flex;
  align-items: end;
  gap: 14px;
}

.answer-row textarea {
  width: 88px;
  height: 220px;
  min-width: 88px;
  padding: 14px 18px;
  border: 2px solid #b7c7bc;
  border-radius: 10px;
  resize: none;
  color: var(--ink);
  background: #fff;
  font-family: "Yu Mincho", serif;
  font-size: 26px;
  letter-spacing: .12em;
  line-height: 1.7;
  text-orientation: upright;
  writing-mode: vertical-rl;
}

.answer-row textarea:focus {
  border-color: var(--green-700);
  outline: 3px solid rgba(21, 128, 61, .14);
}

.answer-row textarea.answer-input--romaji {
  width: min(100%, 420px);
  height: 58px;
  min-width: 0;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 21px;
  letter-spacing: .03em;
  line-height: 1.5;
  text-orientation: mixed;
  writing-mode: horizontal-tb;
}

.answer-row .button { min-width: 150px; }

.handwriting-panel { margin-top: 32px; }

.choice-panel { margin-top: 30px; }

.choice-panel h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.choice-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.choice-option {
  min-height: 62px;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: #fff;
  font-family: "Yu Mincho", serif;
  font-size: 18px;
  font-weight: 800;
}

.choice-option:hover:not(:disabled),
.choice-option:focus-visible {
  border-color: var(--green-700);
  background: var(--green-50);
}

.choice-option:focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: 2px;
}

.choice-option--correct {
  border-color: var(--green-700);
  color: var(--green-900);
  background: var(--green-100);
}

.choice-option--wrong {
  border-color: #fdba74;
  color: #9a3412;
  background: #fff7ed;
}

.handwriting-panel__heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.handwriting-panel__heading h3 { margin: 0; font-size: 15px; }
.handwriting-panel__heading p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }

.handwriting-tools { display: flex; gap: 14px; }

.handwriting-canvas-wrap {
  position: relative;
  overflow: hidden;
  width: min(100%, 520px);
  height: 300px;
  border: 2px solid #9db2a3;
  border-radius: 12px;
  background:
    linear-gradient(90deg, rgba(20, 83, 45, .14) 1px, transparent 1px) 0 0 / 86px 100%,
    repeating-linear-gradient(0deg, transparent 0, transparent 74px, rgba(20, 83, 45, .09) 75px),
    #fffefa;
  box-shadow: inset 0 0 0 5px #f5f8f5;
}

.handwriting-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.handwriting-privacy { margin: 7px 0 12px; color: var(--muted); font-size: 10px; }

.handwriting-assessment p { margin: 0 0 10px; font-size: 13px; font-weight: 700; }
.handwriting-assessment .button { margin: 0 7px 7px 0; }

.feedback {
  margin-top: 26px;
  padding: 20px;
  border-radius: 14px;
  background: var(--green-50);
}

.feedback--wrong { background: #fff7ed; }
.feedback__result { margin: 0; color: var(--green-800); font-size: 22px; font-weight: 800; }
.feedback--wrong .feedback__result { color: var(--orange); }
.feedback__answer { margin: 7px 0 0; font-size: 17px; font-weight: 800; }
.feedback__note { margin: 4px 0 14px; color: var(--muted); font-size: 13px; }

.result-view { display: grid; gap: 22px; }
.result-summary { padding: clamp(28px, 6vw, 52px); text-align: center; }
.result-summary .primary-actions { justify-content: center; }

.result-score { margin: 20px 0 0; color: var(--green-900); }
.result-score strong { font-size: clamp(56px, 10vw, 90px); line-height: 1; }
.result-score span { margin-left: 8px; color: var(--muted); font-size: 18px; font-weight: 800; }
.result-message { margin: 15px 0 0; color: var(--muted); }

.result-details { padding: 28px; }
.result-details h3 { margin: 0 0 16px; font-size: 20px; }
.result-list { display: grid; gap: 8px; margin: 0; padding-left: 2rem; }

.result-list li {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.result-list li::marker { color: var(--green-700); font-weight: 800; }
.result-list__status { margin-left: 8px; color: var(--green-700); font-weight: 800; }
.result-list__status--wrong { color: var(--red); }
.result-list__answer { display: block; color: var(--muted); font-size: 12px; }

.about-panel {
  width: min(820px, calc(100% - 40px));
  margin: 70px auto;
  padding: 32px;
  border-top: 1px solid #cad8ce;
  text-align: center;
}

.about-panel p { max-width: 660px; margin: 14px auto 0; color: var(--muted); }
.about-panel__answer-sheets a { color: var(--green-800); font-weight: 800; text-underline-offset: 4px; }
.about-panel__note { font-size: 11px; }

.site-footer {
  padding: 28px 20px;
  color: #d7e9dc;
  background: var(--green-950);
  text-align: center;
  font-size: 12px;
}

.print-sheet { display: none; }

@media (max-width: 820px) {
  .app-layout { grid-template-columns: 1fr; }
  .progress-panel { order: 2; }
}

@media (max-width: 580px) {
  .site-header__inner { width: min(100% - 28px, 1100px); min-height: 60px; gap: 10px; }
  .header-actions { gap: 8px; }
  .language-control span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  #language-select { min-height: 36px; padding-left: 8px; font-size: 12px; }
  .back-link { font-size: 11px; }
  .hero { padding: 48px 16px 34px; }
  .hero__lead { font-size: 14px; }
  .kanji-list span { width: 30px; height: 30px; font-size: 16px; }
  .app-layout,
  .quiz-view,
  .result-view { width: min(100% - 24px, 1100px); }
  .setup-panel,
  .progress-panel,
  .question-card,
  .result-summary,
  .result-details { border-radius: 15px; }
  .setup-panel { padding: 22px 16px; }
  .choice-grid--three { grid-template-columns: 1fr; }
  .choice-grid--two { grid-template-columns: 1fr 1fr; }
  .choice-grid--four { grid-template-columns: 1fr 1fr; }
  .choice-card span { min-height: 68px; }
  .choice-card small { font-size: 10px; }
  .form-group:nth-of-type(2) .choice-grid--three { grid-template-columns: repeat(3, 1fr); }
  .number-choice span { min-height: 48px; }
  .primary-actions { flex-direction: column; }
  .primary-actions .button { width: 100%; }
  .question-card { min-height: 650px; padding: 24px 16px; }
  .question-stage { min-height: 350px; padding: 14px 8px; }
  .question-sentence { height: 320px; font-size: 23px; line-height: 1.7; }
  .answer-row { align-items: stretch; }
  .answer-row textarea { width: 82px; min-width: 82px; height: 210px; padding: 12px 16px; font-size: 24px; }
  .answer-row textarea.answer-input--romaji { width: 100%; height: 58px; min-width: 0; padding: 10px 12px; font-size: 19px; }
  .answer-row .button { min-width: 0; flex: 1; }
  .handwriting-panel__heading { align-items: start; flex-direction: column; }
  .handwriting-canvas-wrap { height: 330px; }
  .choice-options { grid-template-columns: 1fr; }
  .quiz-topbar { align-items: center; }
  .about-panel { width: calc(100% - 24px); padding: 26px 12px; }
}

@media print {
  @page { size: A4 portrait; margin: 11mm 12mm; }

  :root,
  body { color: #000; background: #fff; }

  body > :not(.print-sheet) { display: none !important; }

  .print-sheet {
    display: block !important;
    font-family: "Yu Gothic", Meiryo, sans-serif;
    font-size: 10pt;
    line-height: 1.45;
  }

  .print-page {
    min-height: 272mm;
    break-after: page;
    page-break-after: always;
  }

  .print-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .print-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 8mm;
    padding-bottom: 3mm;
    border-bottom: 1.5pt solid #000;
  }

  .print-header h1 { margin: 0; font-family: "Yu Mincho", serif; font-size: 17pt; }
  .print-header p { margin: 0; font-size: 9pt; }
  .print-fields { display: flex; gap: 5mm; margin: 4mm 0; }
  .print-fields span { min-width: 42mm; padding-bottom: 1mm; border-bottom: .8pt solid #000; }

  .print-instruction { margin: 2mm 0 4mm; font-weight: 700; }

  .print-questions {
    display: grid;
    grid-template-rows: 225mm;
    grid-template-columns: repeat(10, 1fr);
    gap: 1.5mm;
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: print-question var(--print-start, 0);
  }

  .print-questions li {
    position: relative;
    display: flex;
    min-width: 0;
    height: 225mm;
    padding: 4mm 2mm 2mm;
    border-left: .5pt solid #bbb;
    break-inside: avoid;
    counter-increment: print-question;
    text-orientation: upright;
    writing-mode: vertical-rl;
  }

  .print-questions li::before {
    position: absolute;
    top: 0;
    right: 1mm;
    content: counter(print-question) ".";
    font-weight: 800;
    writing-mode: horizontal-tb;
  }

  .print-prompt { display: block; font-family: "Yu Mincho", serif; font-size: 10.5pt; letter-spacing: .04em; }
  .print-target { font-weight: 800; text-decoration: underline; text-decoration-thickness: 1.5pt; text-underline-offset: 2pt; }
  .print-answer-line {
    display: block;
    width: 9mm;
    height: 58mm;
    margin-right: 2mm;
    border-right: .7pt solid #000;
    background: repeating-linear-gradient(0deg, transparent 0, transparent 11mm, #ddd 11.2mm);
  }

  .print-key {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2mm 8mm;
    margin: 5mm 0 0;
    padding-left: 7mm;
  }

  .print-key li { padding: 1.5mm 0; border-bottom: .5pt solid #bbb; }
  .print-footer-note { margin-top: 8mm; font-size: 8pt; }
}
