:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --text: #1f1d1a;
  --muted: #6a645b;
  --line: #ddd6ca;
  --accent: #b2361f;
  --accent-text: #ffffff;
  --ok: #1f7a46;
  --bad: #b3261e;
  --warn: #b26a00;
  --pin: #c2410c;
  --pin-identified: #2b6cb0;
  --paper: #f1e9d6;
  --paper-edge: #d9ccb0;
  --focus: #2b6cb0;
  --radius: 10px;
  --gutter: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513;
    --surface: #211f1c;
    --text: #ece7de;
    --muted: #a59d90;
    --line: #3a3631;
    --accent: #e0664c;
    --accent-text: #161513;
    --ok: #4fbf7f;
    --bad: #f07167;
    --warn: #e5a443;
    --pin: #e8590c;
    --pin-identified: #3b82c4;
    --paper: #e9dfc6;
    --paper-edge: #8a7f69;
    --focus: #7fb2e8;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #161513;
  --surface: #211f1c;
  --text: #ece7de;
  --muted: #a59d90;
  --line: #3a3631;
  --accent: #e0664c;
  --accent-text: #161513;
  --ok: #4fbf7f;
  --bad: #f07167;
  --warn: #e5a443;
  --pin: #e8590c;
  --pin-identified: #3b82c4;
  --paper: #e9dfc6;
  --paper-edge: #8a7f69;
  --focus: #7fb2e8;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}

a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

h1 { font: 600 1.5rem/1.25 Georgia, "Times New Roman", serif; margin: 0 0 4px; text-wrap: balance; }
h2 { font: 600 1.2rem/1.3 Georgia, "Times New Roman", serif; margin: 0 0 8px; }
h3 { font-size: 1rem; margin: 0; }
.muted { color: var(--muted); }

.top, main, .foot { max-width: 1240px; margin: 0 auto; padding-left: var(--gutter); padding-right: var(--gutter); }

.top {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  padding-top: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--line);
}
.brand { font: 700 1.15rem Georgia, "Times New Roman", serif; color: var(--text); text-decoration: none; }
.tagline { color: var(--muted); font-size: .9rem; }

main { padding-top: 18px; padding-bottom: 24px; }
.status { color: var(--muted); }
.status.error { color: var(--bad); }
.lede { color: var(--muted); max-width: 62ch; margin: 4px 0 18px; }

/* Plate picker */
.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
}
.card {
  display: flex; flex-direction: column; height: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: inherit; text-decoration: none; overflow: hidden;
}
.card:hover { border-color: var(--accent); }
.card .thumb { aspect-ratio: 4 / 3; display: flex; align-items: center; justify-content: center; padding: 8px; }
.card .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.card .meta { color: var(--muted); font-size: .85rem; margin: 0; }
.card .best { font-size: .85rem; margin: 0; color: var(--ok); font-weight: 600; }

/* Paper backing, the same in both themes */
.paper { background: var(--paper); border: 1px solid var(--paper-edge); border-radius: 6px; }

/* Plate view */
.crumbs { margin-bottom: 8px; font-size: .95rem; }
.src { color: var(--muted); margin: 0 0 12px; font-size: .9rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface); }
.seg button {
  font: inherit; font-size: .95rem; border: 0; background: transparent; color: var(--text);
  padding: 8px 16px; min-height: 40px; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.lang button { padding: 8px 12px; }

.quizbar {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 12px; display: grid; gap: 6px;
}
.quizbar .ask { font-size: 1.15rem; margin: 0; }
.quizbar .ask b { font-family: Georgia, "Times New Roman", serif; }
.quizbar .hint { color: var(--muted); margin: 0; font-size: .9rem; }
.quizbar .row { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.quizbar .progress { color: var(--muted); font-size: .9rem; }
.quizbar .feedback { margin: 0; font-weight: 600; min-height: 1.5em; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }
.feedback.warn { color: var(--warn); }

.btn {
  font: inherit; font-size: .95rem; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 14px; min-height: 36px; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

.stage { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 960px) {
  .stage { grid-template-columns: minmax(0, 1fr) 340px; }
  .panel { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; }
}

.plate-figure { margin: 0; padding: 6px; }
.plate-figure svg {
  display: block; width: 100%; height: auto; max-height: 78vh;
  touch-action: manipulation; cursor: crosshair; user-select: none; -webkit-user-select: none;
}

/* SVG layers */
.covers { display: none; }
.quiz .covers { display: inline; }
.cover { transition: opacity .4s; }
.cover.open { opacity: 0; }
.poly { fill: transparent; stroke: var(--pin); stroke-opacity: .0; }
.poly:hover, .poly.sel { fill: color-mix(in srgb, var(--pin) 18%, transparent); stroke-opacity: .9; }
.pin { cursor: pointer; }
.pin .halo { fill: transparent; }
.pin .dot { fill: var(--pin); stroke: #fff; stroke-width: 2; }
.pin.identified .dot { fill: var(--pin-identified); stroke-dasharray: 3 2; }
.pin.sel .dot { fill: #fff; stroke: var(--pin); stroke-width: 4; }
.pin.sel.identified .dot { stroke: var(--pin-identified); }
.quiz .pin .dot { fill: #fff; stroke: #333; stroke-width: 2; stroke-dasharray: none; opacity: .85; }
.quiz .pin.done-ok .dot { fill: var(--ok); stroke: #fff; opacity: 1; }
.quiz .pin.done-miss .dot { fill: var(--warn); stroke: #fff; opacity: 1; }
.quiz .pin.reveal .dot { fill: var(--warn); stroke: #fff; stroke-width: 3; opacity: 1; animation: pulse 1s ease-in-out infinite; }
.quiz .pin.right .dot { fill: var(--ok); stroke: #fff; stroke-width: 3; opacity: 1; }
.mark { stroke: var(--bad); stroke-width: 3; fill: none; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .quiz .pin.reveal .dot { animation: none; } .cover { transition: none; } }

/* Info panel */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  min-width: 0; overflow-wrap: anywhere;
}
.panel h2 { margin-bottom: 2px; }
.panel .names { margin: 0 0 10px; }
.panel .names div { margin: 0; }
.panel .latin { font-style: italic; }
.panel .label-printed { color: var(--muted); font-size: .85rem; margin: 0 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; padding: 0; list-style: none; }
.chips li { font-size: .8rem; border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; color: var(--muted); }
.panel p { margin: 0 0 10px; }
.panel .area-note { border-left: 3px solid var(--accent); padding-left: 10px; }
.panel .conf { font-size: .85rem; color: var(--warn); }
.panel dl { margin: 0; display: grid; gap: 6px; }
.panel dt { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.panel dd { margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.link {
  font: inherit; font-size: .9rem; background: none; border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 8px; color: var(--accent); cursor: pointer; text-align: left;
}
.link:hover { border-color: var(--accent); }
.link .where { color: var(--muted); font-size: .8rem; }
.list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.list button { width: 100%; }

/* About and footer */
.about { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--line); max-width: 72ch; }
.about p { margin: 0 0 10px; }
.foot { border-top: 1px solid var(--line); padding-top: 14px; padding-bottom: 28px; color: var(--muted); font-size: .85rem; }
.foot p { max-width: 90ch; margin: 0; }
code { font-size: .9em; }
