/* Boxes — drafting-table palette: warm paper, graphite ink, red-pencil corrections */

:root {
  --bg: #f3f0e9;
  --surface: #faf8f2;
  --ink: #2a2721;
  --muted: #8b8574;
  --line: #e0dbcc;
  --accent: #c0432c;      /* red pencil */
  --ok: #3f9e4d;
  --warn: #d99a1f;
  --bad: #cf3f3f;
  --f1: #3a6ea5;          /* family markers */
  --f2: #8a5aa8;
  --f3: #2e8a8a;
  --grid: rgba(42, 39, 33, 0.055);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1c18;
    --surface: #26241f;
    --ink: #e9e4d6;
    --muted: #9b9481;
    --line: #3b382e;
    --accent: #e06a50;
    --ok: #57b968;
    --warn: #e0b040;
    --bad: #e05f5f;
    --f1: #6f9fd0;
    --f2: #b08cd0;
    --f3: #5cb3b3;
    --grid: rgba(233, 228, 214, 0.05);
  }
}

:root[data-theme='light'] {
  --bg: #f3f0e9; --surface: #faf8f2; --ink: #2a2721; --muted: #8b8574;
  --line: #e0dbcc; --accent: #c0432c; --ok: #3f9e4d; --warn: #d99a1f;
  --bad: #cf3f3f; --f1: #3a6ea5; --f2: #8a5aa8; --f3: #2e8a8a;
  --grid: rgba(42, 39, 33, 0.055);
}

:root[data-theme='dark'] {
  --bg: #1d1c18; --surface: #26241f; --ink: #e9e4d6; --muted: #9b9481;
  --line: #3b382e; --accent: #e06a50; --ok: #57b968; --warn: #e0b040;
  --bad: #e05f5f; --f1: #6f9fd0; --f2: #b08cd0; --f3: #5cb3b3;
  --grid: rgba(233, 228, 214, 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ---------- header ---------- */

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex-wrap: wrap;
}

.brand {
  font-family: 'Avenir Next', Futura, -apple-system, sans-serif;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.brand .tagline {
  margin-left: 8px;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--muted);
  font-size: 13px;
}

#prompt {
  flex: 1;
  min-width: 200px;
  text-align: center;
  font-size: 13.5px;
  font-style: italic;
  color: var(--muted);
}

#counter {
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.actions { display: flex; gap: 8px; }

.modes {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.modes button {
  border: none;
  border-radius: 0;
  padding: 7px 10px;
  font-size: 12px;
  color: var(--muted);
  background: transparent;
}

.modes button + button { border-left: 1px solid var(--line); }

.modes button.active {
  background: var(--ink);
  color: var(--bg);
}

button {
  font: 600 13px/1 -apple-system, BlinkMacSystemFont, sans-serif;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

button:hover { border-color: var(--muted); }

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

button.primary:hover { opacity: 0.88; }

/* ---------- layout ---------- */

main {
  flex: 1;
  display: flex;
  min-height: 0;
}

#canvasWrap {
  position: relative;
  flex: 1;
  min-width: 0;
  background-image: radial-gradient(var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
}

#c {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#hint {
  position: absolute;
  top: 46%;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
  transition: opacity 0.3s;
}

#hint.hidden { opacity: 0; }

/* ---------- results panel ---------- */

aside {
  width: 320px;
  flex-shrink: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

aside h2 {
  margin: 0;
  font-family: 'Avenir Next', Futura, -apple-system, sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.steps {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13.5px;
}

.fine { font-size: 12.5px; color: var(--muted); margin: 0; }

.scorehead {
  display: flex;
  align-items: center;
  gap: 14px;
}

.scoreline {
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.muted { color: var(--muted); }

.fam {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.famlabel { flex: 1; }
.famcount { color: var(--muted); font-size: 12px; }

.famspread {
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 12.5px;
}

.grade {
  font-family: ui-monospace, 'SF Mono', monospace;
  font-weight: 700;
  font-size: 13px;
  width: 22px;
  text-align: center;
}

.grade-big { font-size: 34px; width: auto; }
.history { display: flex; gap: 4px; flex-wrap: wrap; }

#recap {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: var(--bg);
  overflow: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.recap-head { display: flex; align-items: center; gap: 12px; }
.recap-head button { margin-left: auto; }

.recap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}

.recap-cell {
  margin: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 6px;
  padding: 6px;
}

.recap-cell canvas { width: 100%; height: 130px; display: block; }

.recap-cell figcaption {
  font-size: 12px;
  color: var(--muted);
  padding-top: 4px;
}

.grade-A { color: var(--ok); }
.grade-B { color: var(--ok); }
.grade-C { color: var(--warn); }
.grade-D { color: var(--warn); }
.grade-F { color: var(--bad); }

.diagnosis {
  font-size: 13.5px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.diagnosis::before {
  content: 'correction notes';
  font-family: 'Avenir Next', Futura, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.diagnosis p { margin: 0; }

#morphRow {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

#morphRow[hidden] { display: none; }

#morph { flex: 1; accent-color: var(--accent); }

#nextBtn { width: 100%; }

/* ---------- narrow screens ---------- */

@media (max-width: 760px) {
  main { flex-direction: column; }
  aside {
    width: 100%;
    max-height: 42%;
    border-left: none;
    border-top: 1px solid var(--line);
  }
  #prompt { order: 3; flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  #hint { transition: none; }
}
