:root {
  --bg: #f6f3ec;
  --text: #22201c;
  --muted: #7a756b;
  --paper: #fffdf8;
  --line: #cfc8b8;
  --guide: #e6dfd0;
  --accent: #2f5d8a;
  --right: #2e7d4f;
  --wrong: #b5483c;
  --model: #e0261b;
  /* KanjiVG stroke numbers are small: keep diagrams at 300px where the screen allows. */
  /* --n is the number of answer kanji, so their boxes fit on one row. */
  --box: min(calc((100vw - 32px - (var(--n, 1) - 1) * 8px) / var(--n, 1)), 300px);
  /* Switching to BIZ UDPGothic is a change to this line and the <link> in index.html. */
  --sentence: "BIZ UDPMincho", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1c1a;
    --text: #ece8df;
    --muted: #9c968a;
    --line: #55504a;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "BIZ UDPGothic", "Hiragino Sans", "Yu Gothic", sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

h1 {
  margin: 0;
  font-size: 1.2rem;
}

#progress { color: var(--muted); }

.instruction {
  color: var(--muted);
  margin: 24px 0 4px;
}

#question {
  font-family: var(--sentence);
  font-size: 1.8rem;
  line-height: 1.6;
  margin: 0 0 20px;
}

.target {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
}

.columns {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
}

.boxes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* The writing paper stays light in both themes; the cross is the usual practice-sheet guide. */
.box {
  display: block;
  width: var(--box);
  height: var(--box);
  border: 2px solid var(--line);
  border-radius: 6px;
  background:
    linear-gradient(var(--guide), var(--guide)) center / 100% 1px no-repeat,
    linear-gradient(var(--guide), var(--guide)) center / 1px 100% no-repeat,
    var(--paper);
}

canvas.box {
  touch-action: none;
  cursor: crosshair;
}

.cell { position: relative; }

/* Model answer drawn over the handwriting after reveal. */
.overlay {
  position: absolute;
  inset: 2px;
  pointer-events: none;
}

[data-view="mine"] .overlay { display: none; }

.overlay svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* Red only when laid over the handwriting; alone, the diagram keeps its own colours. */
[data-view="both"] .overlay { opacity: 0.8; }
[data-view="both"] .overlay [id^="kvg:StrokePaths"] { stroke: var(--model) !important; }
[data-view="both"] .overlay [id^="kvg:StrokeNumbers"] { fill: var(--model) !important; }

.view-buttons {
  display: flex;
  margin-top: 12px;
}

.view-buttons button {
  font-size: 0.95rem;
  padding: 8px 16px;
  border-radius: 0;
  margin-left: -2px;
}

.view-buttons button:first-child {
  border-radius: 8px 0 0 8px;
  margin-left: 0;
}

.view-buttons button:last-child { border-radius: 0 8px 8px 0; }

.view-buttons button[aria-pressed="true"] {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

button {
  font: inherit;
  font-size: 1.05rem;
  padding: 12px 20px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}

button.primary,
button.right,
button.wrong {
  color: #fff;
  border-color: transparent;
}

button.primary { background: var(--accent); }
button.right { background: var(--right); }
button.wrong { background: var(--wrong); }

/* On a phone the view switch covers the comparison, so the separate diagram
   would only push the buttons off screen. */
@media (max-width: 660px) {
  #answer-col { display: none; }
}

#score {
  font-size: 1.8rem;
  margin: 48px 0 8px;
}

footer {
  margin-top: 48px;
  font-size: 0.85rem;
}

footer a,
.document a {
  color: var(--muted);
}

h1 a {
  color: inherit;
  text-decoration: none;
}

/* Text pages such as 出典・ライセンス. */
.document {
  -webkit-user-select: text;
  user-select: text;
  line-height: 1.8;
}

.document h2 {
  font-size: 1.4rem;
  margin: 32px 0 8px;
}

.document h3 {
  font-size: 1.05rem;
  margin: 28px 0 4px;
}

.document p,
.document ul {
  margin: 4px 0 8px;
}

.document ul { padding-left: 1.4em; }
