:root {
  --red: #8c1c22;
  --gold: #e0a92e;
  --ink: #2b2118;
  --paper: #f6efe0;
  --sea: #b9d4df;
  --land: #f1e6cc;
  --river: #3f86b0;
  --good: #2e8b57;
  --bad: #c0392b;
  --lbl: 13px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Georgia, "Times New Roman", serif;
  color: var(--ink);
  background: var(--paper);
  display: flex; flex-direction: column;
  height: 100dvh; overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
header {
  background: var(--red); color: #fff;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 12px;
}
h1 { font-size: 20px; margin: 0; font-variant: small-caps; letter-spacing: .5px; flex: 1; white-space: nowrap; }
a.home { color: #fff; text-decoration: none; font-size: 26px; line-height: 1; padding: 2px 8px; border-radius: 10px; background: rgba(255,255,255,.15); }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav button {
  font: inherit; font-size: 15px; border: 0; border-radius: 18px; padding: 7px 14px;
  background: rgba(255,255,255,.15); color: #fff; cursor: pointer;
}
nav button.on { background: var(--gold); color: var(--ink); font-weight: bold; }
nav a.help { font-size: 15px; border-radius: 18px; padding: 7px 14px; color: #fff; text-decoration: none; border: 1px solid #fff8; }
#maps button.on { background: #fff; color: var(--red); }
#maps { padding-right: 8px; border-right: 1px solid #fff5; }

main { flex: 1; display: flex; min-height: 0; }
#mapwrap { flex: 1; position: relative; min-width: 0; min-height: 0; background: var(--sea); }
#map { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
#map.dragging { cursor: grabbing; }
#zoom { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 6px; }
#zoom button {
  width: 44px; height: 44px; font-size: 24px; border-radius: 10px; border: 1px solid #0003;
  background: #fffe; color: var(--ink); cursor: pointer; line-height: 1;
}

#panel {
  width: 330px; flex: none; overflow-y: auto; padding: 14px 16px 30px;
  border-left: 3px solid var(--red); background: var(--paper);
}
@media (max-aspect-ratio: 1/1), (max-width: 760px) {
  main { flex-direction: column; }
  #panel { width: auto; max-height: 42%; border-left: 0; border-top: 3px solid var(--red); padding: 10px 14px 20px; }
  h1 { font-size: 17px; }
}

/* ---------- map ---------- */
.land { fill: var(--land); stroke: #6b5a45; stroke-width: .7; vector-effect: non-scaling-stroke; }
.lake { fill: var(--sea); stroke: #6b5a45; stroke-width: .4; vector-effect: non-scaling-stroke; }
.bgriver { fill: none; stroke: var(--river); stroke-width: .9; opacity: .55; vector-effect: non-scaling-stroke; }
.decor { font-style: italic; fill: #7d6a52; font-size: calc(var(--lbl) * .95); pointer-events: none; letter-spacing: 1px; }
.decor.sea { fill: #4d7489; }

.place { cursor: pointer; }
.region { fill: var(--c, #c9a86a); fill-opacity: .3; stroke: #9b7a45; stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.sea .region { fill: #2c6d91; fill-opacity: .12; stroke: #2c6d91; }
.mount .region { fill: url(#peaks); fill-opacity: 1; stroke: none; }
.riverline { fill: none; stroke: var(--river); stroke-width: 2.2; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.riverhit { fill: none; stroke: transparent; stroke-width: 16; stroke-linecap: round; }
.dot { fill: var(--ink); stroke: #fff; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.volc { fill: #b33a1f; stroke: #fff; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.hit { fill: transparent; }

:where(body:not(.nohints)) .place:hover .region { fill-opacity: .35; }
:where(body:not(.nohints)) .place:hover .riverline { stroke-width: 3.5; }
.frame { fill: none; stroke: #222; stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: none; }

/* Plain mode: black lines on white, like the workbook / test map */
.plain #mapwrap { background: #fff; }
.plain .land { fill: #fff; stroke: #111; stroke-width: .9; }
.plain .lake { fill: #fff; stroke: #111; }
.plain .bgriver { stroke: #111; opacity: .9; stroke-width: .8; }
.plain .riverline { stroke: #111; stroke-width: .8; }
.plain .region, .plain .sea .region, .plain .mount .region { fill: #888; fill-opacity: 0; stroke: none; }
:where(body.plain:not(.nohints)) .place:hover .region { fill-opacity: .08; }
:where(body.plain:not(.nohints)) .place:hover .riverline { stroke-width: 2; }
.plain .decor { display: none; }
.plain .dot, .plain .volc { fill: #111; }

.lbl {
  font-size: var(--lbl); font-weight: bold; fill: var(--ink); pointer-events: none;
  paint-order: stroke; stroke: #fffc; stroke-width: 3px; stroke-linejoin: round;
  display: none;
}
.show-labels .lbl, .lbl.revealed, .lbl.picked, .lbl.wrong { display: inline; }
.lbl.revealed { fill: #1d6b40; }
.lbl.wrong { fill: var(--bad); }
.lbl.target { display: none !important; }
.place.revealed .region { fill: var(--good); fill-opacity: .28; }
.place.revealed .riverline { stroke: var(--good); }
.place.revealed .dot { fill: var(--good); }

.place.picked .region { fill: var(--gold); fill-opacity: .45; }
.place.picked .riverline { stroke: #c47f00; stroke-width: 4; }

.place.wrong .region { fill: var(--bad); fill-opacity: .4; }
.place.wrong .riverline { stroke: var(--bad); stroke-width: 4; }
.place.wrong .dot { fill: var(--bad); }

.place.target .region { fill: var(--gold); fill-opacity: .6; stroke: #a36b00; stroke-dasharray: none; stroke-width: 2.5; animation: pulse 1.2s ease-in-out infinite; }
.mount.target .region { fill: var(--gold); }
.place.target .riverline { stroke: #e08a00; stroke-width: 5; animation: pulse 1.2s ease-in-out infinite; }
.place.target .dot, .place.target .volc { fill: #e08a00; }
.ring { fill: none; stroke: #e08a00; stroke-width: 3; vector-effect: non-scaling-stroke; display: none; }
.place.target .ring { display: inline; animation: ring 1.2s ease-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
@keyframes ring { from { r: 6; opacity: 1; } to { r: 22; opacity: 0; } }

/* ---------- panel ---------- */
#panel h2 { margin: 2px 0 8px; font-size: 20px; color: var(--red); }
#panel p { margin: 6px 0; line-height: 1.4; }
.muted { color: #7a6b58; font-size: 14px; }
.big { font-size: 28px; font-weight: bold; margin: 6px 0; }
.card { background: #fff; border-radius: 12px; padding: 12px 14px; box-shadow: 0 1px 3px #0002; margin: 10px 0; }
.card .latin { font-size: 24px; font-weight: bold; color: var(--red); }
.card .en { font-style: italic; color: #5a4a38; }
.btn {
  font: inherit; font-size: 17px; border-radius: 10px; border: 2px solid var(--red);
  background: #fff; color: var(--red); padding: 10px 14px; cursor: pointer; margin: 4px 0;
}
.btn.primary { background: var(--red); color: #fff; }
.btn.small { font-size: 14px; padding: 6px 10px; }
.btn:disabled { opacity: .5; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.choices .btn { margin: 0; min-height: 52px; }
.btn.right { background: var(--good); border-color: var(--good); color: #fff; }
.btn.nope { background: var(--bad); border-color: var(--bad); color: #fff; }
.fb { font-size: 18px; font-weight: bold; min-height: 26px; margin: 8px 0; }
.fb.good { color: var(--good); }
.fb.bad { color: var(--bad); }
.bar { height: 8px; background: #e4d8bf; border-radius: 4px; overflow: hidden; margin: 6px 0 10px; }
.bar > div { height: 100%; background: var(--gold); transition: width .3s; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
input.answer {
  font: inherit; font-size: 22px; width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 2px solid #a8957a; background: #fff; margin: 6px 0;
}
input.answer:focus { outline: none; border-color: var(--red); }
.macrons { display: flex; gap: 6px; margin: 4px 0 8px; }
.macrons button { font: inherit; font-size: 20px; width: 44px; height: 40px; border-radius: 8px; border: 1px solid #a8957a; background: #fff; cursor: pointer; }
label.toggle { display: flex; gap: 8px; align-items: center; font-size: 15px; margin: 8px 0; cursor: pointer; }
label.toggle input { width: 20px; height: 20px; }
table.prog { width: 100%; border-collapse: collapse; font-size: 15px; }
table.prog td { padding: 5px 4px; border-bottom: 1px solid #e4d8bf; }
table.prog td.stars { color: var(--gold); letter-spacing: 2px; white-space: nowrap; text-align: right; }
.diff { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 18px; }
.diff .x { background: #f6c6c0; color: var(--bad); text-decoration: underline; }

/* ---------- printing (blank map / answer key) ---------- */
#printhead { display: none; }
@media print {
  @page { size: letter portrait; margin: 0.4in; }
  body { display: block; height: auto; overflow: visible; background: #fff; padding: 0; }
  header, #panel, #zoom { display: none !important; }
  main { display: block; }
  #printhead { display: flex; justify-content: space-between; gap: 12pt; font-size: 13pt; margin-bottom: 8pt; white-space: nowrap; }
  #printtitle { font-weight: bold; font-variant: small-caps; }
  #mapwrap { height: 9.2in; background: #fff; overflow: hidden; }
  html, body { height: auto; }
  #map { width: 100%; height: 100%; }
  .ring, .hit { display: none !important; }
  .dot { fill: #000 !important; stroke: none; }
}
