/* Design tokens. Each theme block is checked by scripts/check_contrast.py. */
:root {
  --bg: #f5f3ee; --panel: #fffdf9; --sunken: #eeebe3;
  --text: #1f2328; --muted: #595f68; --line: #dcd7cc; --control-line: #858075;
  --accent: #14655a; --on-accent: #ffffff;
  --right: #176b38; --wrong: #a8231c; --threat: #8f4a00;
  --tile: #fffaf0; --tile-text: #1f2328;


  --text-xs: .75rem; --text-s: .875rem; --text-m: 1rem; --text-l: 1.25rem; --text-xl: 1.5rem;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --radius-s: 6px; --radius-m: 10px;
  --fade: 160ms ease-out;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a; --panel: #1e2125; --sunken: #272b30;
    --text: #e9e7e2; --muted: #a6abb3; --line: #373c43; --control-line: #737b85;
    --accent: #55bda9; --on-accent: #0d1f1c;
    --right: #66d193; --wrong: #ff9189; --threat: #f0ac62;
    --tile: #ece6d8; --tile-text: #1f2328;
  }
}
@media (prefers-reduced-motion: reduce) {
  :root { --fade: 0ms; }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.7;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
:lang(ja) { font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  line-break: strict; }
header, main, footer { max-width: 760px; margin: 0 auto; padding: 0 var(--space-4); }
header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }
nav { display: flex; gap: var(--space-2); }
h1 { font-size: var(--text-l); } h2 { font-size: var(--text-l); margin: 0 0 var(--space-2); } h3 { font-size: var(--text-m); margin: var(--space-5) 0 var(--space-2); }
h2 small { font-size: var(--text-s); color: var(--muted); font-weight: 400; }
button { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--control-line); border-radius: var(--radius-s);
  min-height: 44px; padding: var(--space-1) var(--space-4); cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.small, .help, footer { font-size: var(--text-s); }
.help, footer { color: var(--muted); }
footer { margin-block: var(--space-6); font-size: var(--text-xs); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.warning { color: var(--wrong); }
.accent { color: var(--accent); font-weight: 600; font-size: var(--text-s); margin: 0; }
.figures { font-weight: 600; font-variant-numeric: tabular-nums; }
.actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-3) 0; }

.chapters { list-style: none; padding: 0; }
.chapters li { border-top: 1px solid var(--line); padding: var(--space-4) 0; }
progress { width: 100%; height: 6px; accent-color: var(--accent); }

.strip { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0; }
.strip > div { display: flex; align-items: center; gap: var(--space-2); background: var(--sunken); border-radius: var(--radius-s); padding: var(--space-1) var(--space-3); }
.strip dt { font-size: var(--text-xs); color: var(--muted); } .strip dd { margin: 0; font-weight: 700; display: flex; }
.ask { font-size: var(--text-m); font-weight: 600; margin: var(--space-4) 0 var(--space-2); }

.tile { position: relative; display: inline-block; flex: none; width: 30px; aspect-ratio: 3 / 4; vertical-align: middle;
  background: url("tiles/Front.svg") center / 100% 100% no-repeat; }
.tile img { position: absolute; inset: 6%; width: 88%; height: 88%; }
.tile small { position: absolute; right: 1px; bottom: 0; color: var(--tile-text); background: var(--tile); font-size: .55rem; font-weight: 700; line-height: 1.1; }
@media (prefers-color-scheme: dark) { .tile { filter: brightness(.9); } }

/* A hand always stays on one row, so its shape reads at a glance: tiles shrink to fit. */
.hand { display: flex; }
.pick { display: flex; flex-direction: column; align-items: center; background: none; border: 2px solid transparent; padding: 2px 1px; min-height: 0; flex: 0 1 46px; min-width: 0; }
.pick.gap { margin-left: 6px; }
.pick .tile { width: 100%; max-width: 40px; }
@media (hover: hover) { .pick:not(:disabled):hover { border-color: var(--control-line); } }
.pick.selected { border-color: var(--accent); background: var(--sunken); }
.pick.chosen { border-color: var(--text); }
.pick:disabled { color: inherit; }
.mark { font-size: var(--text-s); font-weight: 700; line-height: 1.2; min-height: 1.2em; }
.mark-correct .mark { color: var(--right); } .mark-ng .mark { color: var(--wrong); } .mark-alt .mark { color: var(--threat); }
.melds, .follow, .yours { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.melds { margin-top: var(--space-2); gap: var(--space-4); }
.follow { margin: var(--space-3) 0; }
.tiles { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 2px; }

.verdict { font-size: var(--text-xl); font-weight: 700; margin: var(--space-3) 0 0; animation: fade var(--fade); }
.verdict.correct { color: var(--right); } .verdict.ng { color: var(--wrong); } .verdict.alt { color: var(--threat); } .verdict.none { color: var(--muted); }
@keyframes fade { from { opacity: 0; } }
.yours { margin: var(--space-2) 0; }
.lines { list-style: none; padding: 0; margin: 0; }
.lines li { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); border-top: 1px solid var(--line); padding: var(--space-2) 0; }
.lines .label { min-width: 10em; font-weight: 600; }
.line-correct .label { color: var(--right); } .line-ng .label { color: var(--wrong); }
/* The book's pages are black on white; keep them so in dark mode, a little dimmed. */
.page { display: block; width: 100%; max-width: 560px; height: auto; margin: 0 auto var(--space-4); background: #fff; border: 1px solid var(--line); border-radius: var(--radius-s); }
@media (prefers-color-scheme: dark) { .page { filter: brightness(.88); } }

.pager { justify-content: space-between; border-top: 1px solid var(--line); padding-top: var(--space-3); }
.list summary { cursor: pointer; min-height: 44px; font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: var(--space-2); margin-bottom: var(--space-4); }
.grid button { padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.2; }
.grid button[aria-current] { border: 2px solid var(--accent); }

@media (max-width: 480px) {
  header, main, footer { padding: 0 var(--space-2); }
  /* Every pixel goes to the fourteen tiles: they reach nearly to the screen's edges,
     and outlines replace borders. Taller buttons make up for the narrow ones. */
  .hand { margin: 0 -4px; }
  .pick { flex: 1 1 0; max-width: 46px; border: 0; padding: var(--space-2) .5px 0; }
  .pick.gap { margin-left: 3px; }
  .pick.selected, .pick.chosen { outline: 2px solid var(--accent); }
  .pick.chosen { outline-color: var(--text); }
  .keys { display: none; }
}

.saved { border-top: 1px solid var(--line); padding-top: var(--space-3); margin-top: var(--space-5); }
.saved h2 { font-size: var(--text-m); }
/* Opened from the Home Screen the page reaches under the notch and the home bar. */
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
