:root {
  color-scheme: light;
  --background: #eff1f8;
  --paper: #fff;
  --ink: #202842;
  --muted: #505b75;
  --line: #cfd5e7;
  --line-strong: #8493b9;
  --surface: #f8f9fd;
  --action: #2e4189;
  --action-dark: #25346f;
  --action-light: #e6ebfa;
  --mark: #9c3455;
  --mark-light: #fbf0f4;
  --mark-line: #cfa2b3;
  --focus: #355ab7;
  --heading-font: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "BIZ UDPMincho", serif;
  --body-font: "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  --kanji-font: "YuKyokasho", "Yu Kyokasho", "Klee", "Hiragino Mincho ProN", "Yu Mincho", serif;
  font: 100%/1.55 var(--body-font);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--background); color: var(--ink); }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
h2 { font-size: 1.125rem; line-height: 1.35; }
button, input { font: inherit; }
button:enabled { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
a { color: var(--action); text-underline-offset: 0.2em; }

.sr-only, .option-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.container { width: min(100% - 64px, 1184px); margin-inline: auto; }
.site-header { background: var(--paper); border-bottom: 1px solid var(--line); }
.header-inner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; min-height: 72px; padding-block: 12px; }
.brand { display: flex; align-items: center; gap: 12px; font: 700 1.13rem/1.2 var(--heading-font); white-space: nowrap; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: linear-gradient(#fff3, #fff3) center / 68% 1px no-repeat,
    linear-gradient(#fff3, #fff3) center / 1px 68% no-repeat, var(--action);
  color: white;
  font: bold 1.55rem/1 var(--kanji-font);
}
.brand small { display: block; margin-top: 4px; color: var(--muted); font: 500 0.68rem/1.2 var(--body-font); letter-spacing: 0.06em; }
.header-actions { display: flex; flex-wrap: wrap; justify-content: end; align-items: center; gap: 8px; margin-inline-start: auto; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  white-space: nowrap;
}
.button-outline { color: var(--action-dark); background: var(--paper); border-color: var(--line-strong); }
.button-outline:hover:enabled { background: var(--action-light); }
.button-primary { background: var(--action); color: white; }
.button-primary:hover:enabled { background: var(--action-dark); }
.button:disabled { background: var(--background); color: var(--muted); }

.icon { position: relative; display: inline-block; flex: none; width: 15px; height: 15px; }
.icon-download, .icon-upload { border: 1.4px solid currentColor; border-top: 0; border-radius: 0 0 3px 3px; height: 6px; margin-top: 8px; }
.icon-download::before, .icon-upload::before { content: ""; position: absolute; left: 5.5px; top: -8px; width: 1.4px; height: 9px; background: currentColor; }
.icon-download::after, .icon-upload::after { content: ""; position: absolute; left: 3.3px; top: -4px; width: 6px; height: 6px; border-right: 1.4px solid currentColor; border-bottom: 1.4px solid currentColor; transform: rotate(45deg); }
.icon-upload::after { top: -8px; transform: rotate(225deg); }
.icon-print { height: 10px; margin-block: 2px; border: 1.4px solid currentColor; border-radius: 2px; }
.icon-print::before, .icon-print::after { content: ""; position: absolute; inset-inline: 2px; height: 4px; border: 1.4px solid currentColor; }
.icon-print::before { top: -5px; border-bottom: 0; }
.icon-print::after { bottom: -4px; height: 6px; background: var(--action); }
.button-primary:hover:enabled .icon-print::after { background: var(--action-dark); }
.button:disabled .icon-print::after { background: var(--background); }

.intro { padding-block: 32px 24px; }
.intro h1 { font: 700 clamp(1.65rem, 4vw, 2.55rem)/1.3 var(--heading-font); letter-spacing: 0.045em; }
.intro p { margin-top: 9px; color: var(--muted); }
.panel { border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.selections { display: flex; flex-wrap: wrap; gap: 18px 36px; align-items: start; padding: 17px 22px 20px; margin-bottom: 20px; }
fieldset { min-width: 0; padding: 0; margin: 0; border: 0; }
legend { padding: 0; font-size: 0.875rem; font-weight: 740; }
.option-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.option-row label { position: relative; cursor: pointer; }
.option-row span {
  display: grid;
  place-items: center;
  min-height: 39px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 630;
  white-space: nowrap;
}
.grade-options span { min-width: 64px; }
.option-row label:hover span { border-color: var(--line-strong); }
.option-row input:checked + span { border-color: var(--action); color: white; background: var(--action); }
.option-row input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 304px; gap: 20px; align-items: start; }
.sidebar { grid-column: 2; grid-row: 1; display: grid; gap: 16px; }
.kanji-panel { grid-column: 1; grid-row: 1; padding: 22px; border-top: 3px solid var(--action); }
.kanji-header { display: flex; justify-content: space-between; align-items: start; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.kanji-title { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.kanji-title h2 { font-size: 1.27rem; }
.scope-label { padding: 3px 9px; border-radius: 5px; background: var(--action-light); color: var(--action-dark); font-size: 0.82rem; font-weight: 700; }
.kanji-header p { color: var(--muted); margin-top: 5px; font-size: 0.91rem; }
.filters .option-row { gap: 2px; margin: 0; padding: 3px; background: var(--background); border-radius: 9px; }
.filters .option-row span { min-height: 34px; padding: 5px 9px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--muted); }
.filters .option-row label:hover span { color: var(--action-dark); }
.filters .option-row input:checked + span { background: var(--paper); border-color: var(--line-strong); color: var(--action-dark); }

.kanji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(67px, 1fr)); gap: 8px; }
.kanji-card {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  place-items: center;
  gap: 5px;
  min-height: 74px;
  padding: 8px 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}
.kanji-card:hover { border-color: var(--line-strong); }
.kanji-card:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.kanji-card:has(input:checked) { background: var(--mark-light); border-color: var(--mark-line); }
.kanji-character { position: relative; font: 500 1.85rem/1.1 var(--kanji-font); }
.kanji-card:has(input:checked) .kanji-character::after {
  content: "";
  position: absolute;
  inset: -3px -5px;
  border: 1.5px solid var(--mark);
  border-radius: 53% 47% 50% 45% / 47% 50% 53% 49%;
  transform: rotate(-12deg);
  pointer-events: none;
}
.kanji-card input { width: 15px; height: 15px; margin: 0; cursor: pointer; accent-color: var(--mark); }
.catalog-note { margin-top: 16px; font-size: 0.82rem; color: var(--muted); }
.empty { background: var(--surface); border-radius: 9px; padding: 24px 12px; text-align: center; color: var(--muted); }

.progress-panel { padding: 19px 19px 16px; }
.progress-numbers { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 7px 0 3px; }
.learned-total { color: var(--muted); font-size: 0.93rem; white-space: nowrap; }
.learned-total strong { color: var(--ink); font-size: 2.2rem; font-weight: 760; line-height: 1.3; font-variant-numeric: tabular-nums; }
.percent { color: var(--mark); font-weight: 750; font-size: 0.92rem; }
progress { display: block; width: 100%; height: 8px; overflow: hidden; border: 0; border-radius: 10px; background: var(--action-light); color: var(--mark); accent-color: var(--mark); }
progress::-webkit-progress-bar { background: var(--action-light); }
progress::-webkit-progress-value { background: var(--mark); border-radius: 10px; }
progress::-moz-progress-bar { background: var(--mark); border-radius: 10px; }
.progress-labels { display: flex; flex-wrap: wrap; gap: 8px 15px; margin-top: 13px; color: var(--muted); font-size: 0.83rem; }
.progress-labels span { white-space: nowrap; }
.progress-labels b { color: var(--ink); }
.dot { display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 50%; background: var(--line-strong); }
.dot-learned { background: var(--mark); }

.print-panel { overflow: hidden; }
.paper-demo {
  display: grid;
  justify-items: center;
  align-items: end;
  height: 124px;
  overflow: hidden;
  background: repeating-linear-gradient(0deg, #0000 0 19px, #fff8 19px 20px),
    repeating-linear-gradient(90deg, #0000 0 19px, #fff8 19px 20px), var(--action-light);
  padding-top: 13px;
}
.demo-sheet {
  width: 192px;
  height: 115px;
  padding: 13px 14px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px 4px 0 0;
  background: var(--paper);
  box-shadow: 0 4px 9px #23345426;
  color: var(--ink);
  font: 600 0.7rem/1.45 var(--kanji-font);
  transform: rotate(-4deg) translateY(6px);
}
.demo-title { border-bottom: 1px solid var(--line-strong); padding-bottom: 3px; font-size: 0.91rem; }
.demo-sentence { padding-block: 9px 5px; white-space: nowrap; }
.demo-blank { position: relative; display: inline-block; width: 13px; height: 11px; border: 1px solid var(--line-strong); vertical-align: middle; }
.demo-blank small { position: absolute; top: -7px; left: 0; width: 100%; background: var(--paper); text-align: center; font-size: 0.39rem; line-height: 1; }
.demo-boxes { display: flex; justify-content: end; }
.demo-boxes span { width: 13px; height: 13px; border: 1px solid var(--line-strong); }
.demo-boxes span + span { border-left: 0; }
.print-panel-content { padding: 18px 19px 16px; }
.print-panel-content p { margin: 7px 0 13px; color: var(--muted); font-size: 0.89rem; }
.print-panel-content .button { width: 100%; min-height: 44px; }
.print-panel-content .print-meta { margin: 8px 0 0; min-height: 1.4em; text-align: center; font-size: 0.81rem; }

.notice { margin-bottom: 14px; border: 1px solid var(--line-strong); border-radius: 9px; padding: 9px 14px; background: var(--action-light); color: var(--action-dark); font-size: 0.91rem; }
.notice-error { border-color: #dcafa2; background: #fff2ec; color: #862c21; }
.site-footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; padding-block: 18px 24px; color: var(--muted); font-size: 0.83rem; }

dialog {
  width: min(100% - 28px, 870px);
  max-height: min(90vh, 900px);
  max-height: min(90dvh, 900px);
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 12px 50px #1d284d45;
}
dialog::backdrop { background: #1d284d9e; }
.dialog-header, .dialog-footer { position: sticky; z-index: 1; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; background: var(--paper); }
.dialog-header { top: 0; border-bottom: 1px solid var(--line); }
.dialog-header p { margin-top: 3px; color: var(--muted); font-size: 0.86rem; }
.preview-summary { display: flex; flex-wrap: wrap; gap: 0 0.65em; }
.preview-summary span { white-space: nowrap; }
.dialog-footer { bottom: 0; justify-content: end; border-top: 1px solid var(--line); }
.preview-body { padding: 16px; background: var(--background); }
#preview-sheet, .answer-key { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: clamp(12px, 4vw, 27px); }
.answer-key { margin-top: 14px; }
.answer-key summary { cursor: pointer; font-size: 0.9rem; font-weight: 700; }
.answer-key ol { display: grid; grid-template-columns: repeat(auto-fill, minmax(55px, 1fr)); gap: 4px 14px; padding-left: 28px; margin: 10px 0 0; font-family: var(--kanji-font); }
#import-dialog { width: min(100% - 28px, 430px); }
#help-dialog { width: min(100% - 28px, 760px); }
#help-dialog .dialog-header { padding-inline: clamp(16px, 4vw, 24px); }
#help-title { font-size: 1.25rem; }
.help-steps {
  counter-reset: help-step;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 0;
  padding: clamp(12px, 4vw, 24px);
  list-style: none;
  background: var(--surface);
}
.help-steps li {
  counter-increment: help-step;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  padding: 12px 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
}
.help-steps p { padding-inline: 3px; }
.help-steps strong { white-space: nowrap; }
.help-scene {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  position: relative;
  min-height: clamp(82px, 13vw, 104px);
  border-radius: 8px;
  background: var(--action-light);
  color: var(--action-dark);
}
.help-scene::before {
  content: counter(help-step);
  position: absolute;
  inset: 8px auto auto 8px;
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 700;
}
.help-tiles { display: flex; gap: 6px; }
.help-tile {
  display: grid;
  justify-items: center;
  gap: 4px;
  width: 41px;
  padding: 5px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  font: 1.3rem/1.15 var(--kanji-font);
}
.help-tile::after {
  content: "";
  display: grid;
  place-items: center;
  width: 12px;
  height: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  font: 700 10px/1 sans-serif;
}
.help-tile-checked { position: relative; border-color: var(--mark-line); background: var(--mark-light); }
.help-tile-checked::before {
  content: "";
  position: absolute;
  top: 4px;
  width: 26px;
  height: 25px;
  border: 1px solid var(--mark);
  border-radius: 53% 47% 50% 45%;
  transform: rotate(-12deg);
}
.help-tile-checked::after { content: "✓"; border-color: var(--mark); background: var(--mark); color: white; }
.help-sheet {
  display: grid;
  gap: 7px;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  font: 700 0.79rem/1.4 var(--kanji-font);
  transform: rotate(-5deg);
}
.help-sheet > span { border-bottom: 1px solid var(--line-strong); padding-bottom: 3px; }
.help-sheet .demo-boxes span { width: 12px; height: 12px; }
.help-file {
  display: grid;
  align-items: end;
  justify-items: center;
  width: 50px;
  height: 60px;
  padding-bottom: 9px;
  border: 1px solid var(--line-strong);
  border-radius: 5px 14px 5px 5px;
  background: linear-gradient(var(--line), var(--line)) top 13px center / 22px 2px no-repeat,
    linear-gradient(var(--line), var(--line)) top 19px center / 22px 2px no-repeat, var(--paper);
  font: 700 0.72rem/1 sans-serif;
}
.help-transfer {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--paper);
}
.confirm-dialog { padding: 21px; }
.confirm-dialog p { margin-block: 8px 16px; color: var(--muted); }
.confirm-actions { display: flex; justify-content: end; flex-wrap: wrap; gap: 8px; }

#print-output { display: none; }
.worksheet { color: #181818; font-family: var(--kanji-font); }
.sheet-header { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 9px 16px; align-items: end; border-bottom: 1px solid; padding-bottom: 8px; }
.sheet-header h2 { font-size: clamp(1.15rem, 4vw, 1.6rem); }
.sheet-scope { font-size: 0.8rem; }
.sheet-fields { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.8rem; }
.sheet-fields span { min-width: 105px; border-bottom: 1px solid; white-space: nowrap; }
.sheet-instructions { padding-block: 8px; font-size: 0.87rem; }
.sheet-questions { padding: 0; margin: 0; list-style: none; }
.question { padding: 5px 0 7px; border-bottom: 1px solid #b0b0b0; }
.question-sentence { font-size: 1rem; line-height: 2.05; }
.question-number { display: inline-block; min-width: 2.3em; font-weight: 700; font-variant-numeric: tabular-nums; }
.answer-blank { margin-inline: 0.14em; white-space: nowrap; }
.answer-blank > span { display: inline-block; width: 1.5em; height: 1.5em; border: 1px solid #181818; vertical-align: -0.26em; }
.answer-blank rt { font-size: 0.57em; line-height: 1.1; }
.practice { display: flex; justify-content: end; align-items: center; gap: 8px; padding-top: 2px; font-size: 0.72rem; }
.practice-cells { display: flex; }
.practice-cells span { position: relative; width: 23px; height: 23px; border: 1px solid #555; }
.practice-cells span + span { border-left: 0; }
.practice-cells span::before, .practice-cells span::after { content: ""; position: absolute; }
.practice-cells span::before { top: 50%; left: 0; width: 100%; border-top: 1px dotted #b0b0b0; }
.practice-cells span::after { top: 0; left: 50%; height: 100%; border-left: 1px dotted #b0b0b0; }
.sheet-footer { margin-top: 9px; text-align: right; font-size: 0.74rem; }

@media (max-width: 900px) {
  .container { width: min(100% - 36px, 1184px); }
  .workspace { grid-template-columns: minmax(0, 1fr) 250px; gap: 14px; }
  .kanji-panel { padding: 17px; }
}
@media (max-width: 660px) {
  .help-steps { grid-template-columns: 1fr; gap: 12px; }
  .header-inner { min-height: 62px; gap: 8px; }
  .brand { gap: 8px; font-size: 1rem; }
  .brand-mark { width: 34px; height: 34px; border-radius: 9px; font-size: 1.28rem; }
  .brand small { display: none; }
  .header-actions { gap: 5px; }
  .header-actions .button { padding-inline: 7px; }
  .header-actions .icon { display: none; }
  .intro { padding-block: 23px 17px; }
  .intro p { font-size: 0.93rem; }
  .selections { padding: 13px; gap: 12px; margin-bottom: 14px; }
  .selections fieldset { width: 100%; }
  .grade-options { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .grade-options span { min-width: 0; padding-inline: 3px; }
  .option-row span { min-height: 44px; }
  .workspace { display: flex; flex-direction: column; }
  .workspace > * { width: 100%; }
  .sidebar { gap: 8px; }
  .progress-panel, .print-panel-content { padding: 12px 15px; }
  .progress-numbers { margin-top: 2px; }
  .learned-total strong { font-size: 1.75rem; }
  .progress-labels { margin-top: 8px; }
  .paper-demo, .print-panel-content h2, .print-panel-content > p:not(.print-meta) { display: none; }
  .kanji-panel { padding: 13px; }
  .kanji-grid { grid-template-columns: repeat(auto-fill, minmax(49px, 1fr)); gap: 6px; }
  .kanji-card { min-height: 67px; }
  .filters .option-row span { min-height: 40px; }
  .site-footer { padding-top: 12px; }
}
@media (max-width: 365px) {
  .container { width: calc(100% - 24px); }
  .brand { font-size: 0.95rem; }
  .header-actions .button { font-size: 0.8rem; }
  .grade-options span { padding-inline: 2px; font-size: 0.8rem; }
  .term-options span { padding-inline: 8px; }
}

@page { size: A4 portrait; margin: 12mm 14mm; }
@media print {
  body { background: white; }
  #screen, dialog { display: none !important; }
  #print-output { display: block; }
  .worksheet { display: flex; flex-direction: column; min-height: 268mm; }
  .worksheet + .worksheet { break-before: page; }
  .sheet-header { padding-bottom: 3mm; }
  .sheet-header h2 { font-size: 21pt; }
  .sheet-scope, .sheet-fields { font-size: 10pt; }
  .sheet-fields { gap: 5mm; }
  .sheet-fields span { min-width: 40mm; }
  .sheet-instructions { padding-block: 3mm; font-size: 11pt; }
  .question { padding-block: 0.7mm 1mm; break-inside: avoid; }
  .question-sentence { font-size: 15pt; line-height: 2.08; }
  .answer-blank > span { width: 10mm; height: 10mm; }
  .practice { gap: 2mm; font-size: 9pt; }
  .practice-cells span { width: 10mm; height: 10mm; }
  .sheet-footer { margin-top: auto; padding-top: 3mm; font-size: 9pt; }
}
