/* Area code map quiz. Everything is scoped to .acg. */

/* Everything inside a map is stacked on its own, so its buttons, legend and cards can never rise above the page's sticky header
   (Material for MkDocs has its header at z-index 4) when the map scrolls under it. */
.acg { isolation: isolate; }
.acg {
  --acg-sea: #cfe3ee;
  --acg-land: #f1f4e9;
  --acg-land-hover: #cfe8c4;
  --acg-edge: #5f7f70;
  --acg-ink: var(--md-default-fg-color, #1c2a25);
  --acg-muted: var(--md-default-fg-color--light, #5a6a63);
  --acg-surface: var(--md-default-bg-color, #ffffff);
  --acg-line: var(--md-default-fg-color--lightest, #d5ddd8);
  --acg-accent: #0d7656;
  --acg-accent-ink: #ffffff;
  --acg-lcd-bg: #10372c;
  --acg-lcd-fg: #bdf5cf;
  --acg-hit: #1f9d8b;
  --acg-near: #e3a72f;
  --acg-miss: #d5532c;
  --acg-label-halo: #ffffff;
  /* styles used when a base map is showing underneath */
  --acg-land-t: rgba(13, 118, 86, 0.03);
  --acg-hover-t: rgba(13, 118, 86, 0.30);
  --acg-edge-t: rgba(6, 70, 50, 0.85);
  --acg-hit-t: rgba(31, 157, 139, 0.55);
  --acg-near-t: rgba(227, 167, 47, 0.6);
  --acg-miss-t: rgba(213, 83, 44, 0.55);

  margin: 1.2rem 0;
  border: 1px solid var(--acg-line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--acg-surface);
  color: var(--acg-ink);
  font-size: 0.8rem;
  line-height: 1.45;
}

[data-md-color-scheme="slate"] .acg {
  --acg-sea: #0b1820;
  --acg-land: #2f4a3f;
  --acg-land-hover: #447059;
  --acg-edge: #8fc2a9;
  --acg-accent: #3cc08c;
  --acg-accent-ink: #06261b;
  --acg-lcd-bg: #0a2219;
  --acg-hit: #2fb7a3;
  --acg-near: #e5b14a;
  --acg-miss: #ea7050;
  --acg-label-halo: #0e171b;
  --acg-land-t: rgba(60, 192, 140, 0.03);
  --acg-hover-t: rgba(60, 192, 140, 0.30);
  --acg-edge-t: rgba(120, 235, 185, 0.8);
  --acg-hit-t: rgba(47, 183, 163, 0.5);
  --acg-near-t: rgba(229, 177, 74, 0.55);
  --acg-miss-t: rgba(234, 112, 80, 0.5);
}

@media (prefers-color-scheme: dark) {
  body:not([data-md-color-scheme]) .acg {
    --acg-sea: #0b1820;
    --acg-land: #2f4a3f;
    --acg-land-hover: #447059;
    --acg-edge: #8fc2a9;
    --acg-surface: #161d1a;
    --acg-ink: #e4ede8;
    --acg-muted: #9aa9a2;
    --acg-line: #2b3631;
    --acg-accent: #3cc08c;
    --acg-accent-ink: #06261b;
    --acg-lcd-bg: #0a2219;
    --acg-hit: #2fb7a3;
    --acg-near: #e5b14a;
    --acg-miss: #ea7050;
    --acg-label-halo: #0e171b;
    --acg-land-t: rgba(60, 192, 140, 0.03);
    --acg-hover-t: rgba(60, 192, 140, 0.30);
    --acg-edge-t: rgba(120, 235, 185, 0.8);
    --acg-hit-t: rgba(47, 183, 163, 0.5);
    --acg-near-t: rgba(229, 177, 74, 0.55);
    --acg-miss-t: rgba(234, 112, 80, 0.5);
  }
}

.acg *, .acg *::before, .acg *::after { box-sizing: border-box; }
.acg p { margin: 0; }

/* ---------- top panel ---------- */
.acg-hud { padding: 0.75rem 0.9rem 0.6rem; }
.acg-hud-top {
  display: flex; align-items: stretch; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}
.acg-hud-sub {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; margin-top: 0.6rem; min-height: 2.1rem; flex-wrap: wrap;
}

.acg-lcd {
  display: flex; flex-direction: column;
  min-width: 10rem; padding: 0.35rem 1rem 0.4rem;
  border-radius: 8px;
  background: var(--acg-lcd-bg);
  color: var(--acg-lcd-fg);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.07), inset 0 -12px 20px rgba(0, 0, 0, 0.28);
}
.acg-lcd-label { font-size: 0.68rem; opacity: 0.7; }
.acg-lcd-digits {
  font-family: "Bahnschrift", "DIN Alternate", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  font-size: 2.4rem; line-height: 1.05; font-weight: 600;
  letter-spacing: 0.08em; font-variant-numeric: tabular-nums;
  text-shadow: 0 0 14px rgba(120, 255, 170, 0.35);
}
.acg-zero { opacity: 0.4; }

.acg-stats { display: flex; gap: 1.4rem; align-items: center; }
.acg-stat { display: flex; flex-direction: column; align-items: flex-end; }
.acg-stat-v { font-size: 1.5rem; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.acg-stat-l { font-size: 0.68rem; color: var(--acg-muted); }

.acg-msg { flex: 1 1 14rem; color: var(--acg-ink); }
.acg-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.acg[data-state="menu"] .acg-actions,
.acg[data-state="done"] .acg-actions { display: none; }

/* ---------- buttons ---------- */
.acg-btn, .acg-seg-btn, .acg-tool {
  font: inherit; color: inherit; cursor: pointer;
  border: 1px solid var(--acg-line);
  background: var(--acg-surface);
  border-radius: 6px;
}
.acg-btn { padding: 0.4rem 0.9rem; }
.acg-btn:hover, .acg-seg-btn:hover, .acg-tool:hover { border-color: var(--acg-accent); }
.acg-btn--primary { background: var(--acg-accent); color: var(--acg-accent-ink); border-color: transparent; font-weight: 600; }
.acg-btn--primary:hover { filter: brightness(1.08); border-color: transparent; }
.acg-btn--wide { width: 100%; padding: 0.55rem 1rem; }
.acg-btn[hidden] { display: none; }
.acg button:focus-visible { outline: 2px solid var(--acg-accent); outline-offset: 2px; }

/* ---------- map ---------- */
.acg-stage {
  position: relative;
  --acg-stage-h: clamp(380px, 70vh, 720px);
  height: var(--acg-stage-h);
  background: var(--acg-sea);
  border-top: 1px solid var(--acg-line);
  border-bottom: 1px solid var(--acg-line);
}
.acg-map {
  /* Fill the stage exactly, even if the theme styles svg elements (height: auto, max-width...) */
  position: absolute; inset: 0; z-index: 1;
  display: block; width: 100% !important; height: 100% !important; max-width: none !important; max-height: none !important;
  cursor: grab; user-select: none; -webkit-user-select: none;
  touch-action: pan-y pinch-zoom;
}
.acg[data-state="playing"] .acg-map,
.acg[data-state="feedback"] .acg-map { touch-action: none; }
.acg-map.is-dragging { cursor: grabbing; }

.acg-region {
  fill: var(--acg-land);
  fill-rule: evenodd;
  stroke: var(--acg-edge);
  stroke-width: var(--acg-border-w, 0.5px);
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
}
.acg-region:not([data-r]):hover { fill: var(--acg-land-hover); }
.acg-region[data-r="h1"] { fill: var(--acg-hit); }
.acg-region[data-r="h2"] { fill: var(--acg-near); }
.acg-region[data-r="m"]  { fill: var(--acg-miss); }

.acg-top { pointer-events: none; }
.acg-flash, .acg-reveal {
  fill: none; stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.acg-flash { stroke: var(--acg-miss); stroke-width: 4px; }
.acg-reveal { stroke: var(--acg-ink); stroke-width: 4px; animation: acg-pulse 0.9s ease-in-out 3; }
.acg-ring {
  fill: none; stroke: var(--acg-accent); stroke-width: 3.5px; stroke-dasharray: 8 5;
  vector-effect: non-scaling-stroke;
}
.acg-label {
  fill: var(--acg-ink); font-weight: 700;
  font-family: "Bahnschrift", "Segoe UI", system-ui, sans-serif;
  paint-order: stroke; stroke: var(--acg-label-halo); stroke-width: 5px; stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
@keyframes acg-pulse { 50% { stroke-opacity: 0.25; } }

/* ---------- zoom tools ---------- */
.acg-tools { position: absolute; z-index: 4; top: 0.6rem; right: 0.6rem; display: flex; flex-direction: column; gap: 0.3rem; }
.acg-tool { width: 2.1rem; height: 2.1rem; font-size: 1.1rem; line-height: 1; padding: 0; }
.acg-tool--text { font-size: 0.72rem; }

/* ---------- sheets ---------- */
.acg-sheet-host { position: absolute; z-index: 3; left: 0.6rem; bottom: 0.6rem; right: 3.6rem; display: flex; justify-content: flex-end; pointer-events: none; }
.acg-sheet {
  pointer-events: auto;
  width: min(25rem, 100%);
  max-height: calc(var(--acg-stage-h) - 1.2rem);
  overflow: auto;
  padding: 0.9rem 1rem 1rem;
  background: var(--acg-surface);
  border: 1px solid var(--acg-line);
  border-radius: 10px;
}
.acg-sheet-title { margin: 0 0 0.3rem; font-size: 1.1rem; font-weight: 600; line-height: 1.25; }
.acg-sheet-text { color: var(--acg-muted); margin-bottom: 0.7rem; }
.acg-field { margin-bottom: 0.7rem; }
.acg-field-label { font-size: 0.72rem; color: var(--acg-muted); margin-bottom: 0.25rem; }
.acg-seg { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.acg-seg-btn { padding: 0.2rem 0.65rem; font-size: 0.75rem; }
.acg-seg-btn[aria-checked="true"] {
  border-color: var(--acg-accent);
  box-shadow: inset 0 0 0 1px var(--acg-accent);
  font-weight: 600;
}
.acg-count { margin: 0.2rem 0 0.7rem; font-size: 0.72rem; color: var(--acg-muted); }
.acg-result { margin-bottom: 0.2rem; }
.acg-result-big { font-size: 2.2rem; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.acg-result-of { color: var(--acg-muted); }
.acg-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.acg-chip {
  padding: 0.05rem 0.5rem; border-radius: 4px;
  background: var(--acg-lcd-bg); color: var(--acg-lcd-fg);
  font-variant-numeric: tabular-nums; font-size: 0.75rem;
}
.acg-row { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.acg-help { padding: 0.55rem 0.9rem 0.7rem; color: var(--acg-muted); font-size: 0.72rem; }
.acg-error { padding: 1rem; color: var(--acg-miss); }

@media (max-width: 560px) {
  .acg-sheet { width: 100%; max-height: calc(70vh - 5rem); }
  .acg-tools { top: 0.4rem; right: 0.4rem; }
  .acg-lcd-digits { font-size: 2rem; }
}

@media (prefers-reduced-motion: reduce) {
  .acg-reveal { animation: none; }
}

/* ---------- base map tiles ---------- */
.acg-tiles { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.acg-tile {
  filter: var(--acg-tile-filter, grayscale(0.4) saturate(1.15) contrast(1.12));
  position: absolute; max-width: none !important; margin: 0 !important;
  opacity: 0; transition: opacity 0.15s; user-select: none; -webkit-user-drag: none;
}
[data-md-color-scheme="slate"] .acg.acg--map-auto .acg-tile { filter: grayscale(0.4) invert(1) hue-rotate(180deg) brightness(0.95) contrast(1.05); }
@media (prefers-color-scheme: dark) {
  body:not([data-md-color-scheme]) .acg.acg--map-auto .acg-tile { filter: grayscale(0.4) invert(1) hue-rotate(180deg) brightness(0.95) contrast(1.05); }
}
.acg--tiles .acg-region { fill: var(--acg-land-t); stroke: var(--acg-edge-t); stroke-width: var(--acg-border-w, 0.6px); }
.acg--tiles .acg-region:not([data-r]):hover { fill: var(--acg-hover-t); }
.acg--tiles .acg-region[data-r="h1"] { fill: var(--acg-hit-t); }
.acg--tiles .acg-region[data-r="h2"] { fill: var(--acg-near-t); }
.acg--tiles .acg-region[data-r="m"]  { fill: var(--acg-miss-t); }
.acg-tool[aria-pressed="true"] { border-color: var(--acg-accent); box-shadow: inset 0 0 0 1px var(--acg-accent); }
.acg-attrib {
  position: absolute; z-index: 2; left: 0; bottom: 0; padding: 0.1rem 0.45rem;
  font-size: 0.62rem; line-height: 1.4;
  background: color-mix(in srgb, var(--acg-surface) 80%, transparent); color: var(--acg-muted);
}
.acg-attrib a { color: inherit; }
@media (prefers-reduced-motion: reduce) { .acg-tile { transition: none; } }

/* Google base map: the map sits under the shapes and ignores the pointer */
.acg-tiles .gm-style { pointer-events: none; }

/* ---------- results ---------- */
.acg-rstats { display: flex; flex-wrap: wrap; gap: 0.6rem 1.2rem; margin: 0.3rem 0 0.9rem; }
.acg-rstat { display: flex; flex-direction: column; }
.acg-rstat-v { font-size: 2rem; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.acg-rstat-l { font-size: 0.72rem; color: var(--acg-muted); }

.acg-select {
  font: inherit; color: inherit; width: 100%; padding: 0.3rem 0.5rem;
  background: var(--acg-surface); border: 1px solid var(--acg-line); border-radius: 6px;
}
.acg-select:focus-visible { outline: 2px solid var(--acg-accent); outline-offset: 2px; }

.acg-check { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; font-size: 0.8rem; }
.acg-check input { width: 1.05rem; height: 1.05rem; accent-color: var(--acg-accent); cursor: pointer; }

/* the Start button stays in view when the setup panel has to scroll */
.acg-sheet .acg-btn--wide { position: sticky; bottom: 0; box-shadow: 0 -8px 8px -4px var(--acg-surface), 0 1rem 0 0 var(--acg-surface); }   /* the second shadow fills the gap under the button so nothing shows through below it */

/* on a narrow screen the setup panel takes the full width; the zoom buttons stay on top of it */
@media (max-width: 560px) { .acg-sheet-host { right: 0.6rem; } .acg-sheet { padding-right: 3.2rem; } }

/* modern prefecture borders above the shapes */
.acg-borders { pointer-events: none; }
.acg-pref-border {
  fill: none; stroke: var(--acg-ink); stroke-opacity: 0.6; stroke-width: var(--acg-pref-border-w, 1.5px);
  stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none;
}

/* The map itself stays light when the site is in dark mode (data-map-theme="auto" lets it follow the site) */
.acg:not(.acg--map-auto) .acg-map,
.acg:not(.acg--map-auto) .acg-tiles,
.acg:not(.acg--map-auto) .acg-stage {
  --acg-sea: #cfe3ee; --acg-land: #f1f4e9; --acg-land-hover: #cfe8c4; --acg-edge: #5f7f70;
  --acg-ink: #1c2a25; --acg-accent: #0d7656; --acg-label-halo: #ffffff;
  --acg-hit: #1f9d8b; --acg-near: #e3a72f; --acg-miss: #d5532c;
  --acg-land-t: rgba(13, 118, 86, 0.03); --acg-hover-t: rgba(13, 118, 86, 0.3); --acg-edge-t: rgba(6, 70, 50, 0.85);
  --acg-hit-t: rgba(31, 157, 139, 0.55); --acg-near-t: rgba(227, 167, 47, 0.6); --acg-miss-t: rgba(213, 83, 44, 0.55);
}

/* ---------- picture quiz (geo-click-game-images.js) ---------- */
.acg-qimg { margin: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 0.25rem; max-width: 18rem; }
.acg-qimg-img {
  display: block; max-width: 100%; max-height: var(--acg-qimg-h, 11rem); width: auto; object-fit: contain; cursor: zoom-in;
  border-radius: 8px; border: 1px solid var(--acg-line); background: #fff;
}
.acg-qimg.is-empty .acg-qimg-img { display: none; }
.acg-qimg-cap { font-size: 0.78rem; color: var(--acg-ink); max-width: 18rem; }
.acg-qimg-credit { color: var(--acg-muted); font-size: 0.68rem; }
.acg-chip-img { height: 1.3rem; width: auto; max-width: 2.4rem; object-fit: contain; border-radius: 3px; margin-right: 0.35rem; vertical-align: middle; background: #fff; }
.acg-lightbox {
  position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center; justify-content: center;
  padding: 1rem; background: rgba(0, 0, 0, 0.78); cursor: zoom-out;
}
.acg-lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; background: #fff; }

/* ---------- map viewer (geo-map.js) ---------- */
.acg--viewer .acg-stage { min-height: 320px; }
.acg-viewer-title { padding: 0.55rem 0.9rem; font-weight: 600; border-bottom: 1px solid var(--acg-line); }
.acg--viewer .acg-region { cursor: pointer; }
.acg--viewer .acg-region { fill-opacity: var(--acg-fill-opacity, 0.55); }
.acg--viewer .acg-region:hover, .acg--viewer .acg-region:focus-visible { stroke: var(--acg-ink); stroke-width: 1.6px; outline: none; }
.acg--viewer .acg-region.is-pinned { stroke: var(--acg-ink); stroke-width: 2.4px; }
.acg--viewer .acg-region.is-dim { opacity: 0.16; }
.acg-maplabel {
  fill: var(--acg-ink); stroke: var(--acg-label-halo, #fff); paint-order: stroke; stroke-linejoin: round;
  font-weight: 600; pointer-events: none; user-select: none;
}
.acg-swatch { display: inline-block; flex: none; width: 0.85rem; height: 0.85rem; border-radius: 3px; border: 1px solid rgba(0, 0, 0, 0.25); vertical-align: -0.1rem; margin-right: 0.45rem; }
.acg-legend {
  position: absolute; z-index: 4; left: 0.6rem; top: 0.6rem; width: max-content; max-width: min(17rem, 64%); max-height: calc(100% - 1.2rem);
  display: flex; flex-direction: column; background: var(--acg-surface); color: var(--acg-ink);
  border: 1px solid var(--acg-line); border-radius: 10px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18); font-size: 0.78rem;
}
.acg-legend-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; width: 100%; padding: 0.4rem 0.65rem;
  border: 0; background: none; color: inherit; font: inherit; font-weight: 600; cursor: pointer; text-align: left;
}
.acg-legend-head[aria-expanded="false"] .acg-legend-caret { transform: rotate(-90deg); }
.acg-legend-body { padding: 0 0.3rem 0.4rem; overflow: auto; }
.acg-legend.is-collapsed .acg-legend-body { display: none; }
.acg-legend-list { list-style: none; margin: 0; padding: 0; }
.acg-legend-item {
  display: flex; align-items: center; width: 100%; gap: 0; padding: 0.22rem 0.35rem; border: 0; border-radius: 6px; background: none;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.acg-legend-item:hover { background: rgba(127, 127, 127, 0.15); }
.acg-legend-item[aria-pressed="true"] { background: rgba(13, 118, 86, 0.18); font-weight: 600; }
.acg-legend-label { flex: 1; }
.acg-legend-n { margin-left: 0.5rem; color: var(--acg-muted); font-variant-numeric: tabular-nums; }
.acg-legend-grad { height: 0.7rem; margin: 0.2rem 0.35rem; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.2); }
.acg-legend-ends { display: flex; justify-content: space-between; margin: 0 0.35rem; color: var(--acg-muted); }
.acg-info {
  position: absolute; z-index: 4; left: 0.6rem; bottom: 0.6rem; width: max-content; max-width: min(19rem, calc(100% - 4.4rem));
  padding: 0.55rem 0.75rem 0.6rem; background: var(--acg-surface); color: var(--acg-ink);
  border: 1px solid var(--acg-line); border-radius: 10px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18); font-size: 0.8rem; pointer-events: none;
}
.acg-info.is-pinned { pointer-events: auto; }
.acg-info[hidden] { display: none; }
.acg-info-title { font-weight: 700; font-size: 0.9rem; padding-right: 1.4rem; }
.acg-info-list { display: grid; grid-template-columns: auto 1fr; gap: 0.12rem 0.7rem; margin: 0.35rem 0 0; }
.acg-info-list dt { color: var(--acg-muted); }
.acg-info-list dd { margin: 0; overflow-wrap: anywhere; }
.acg-info-close { display: none; position: absolute; top: 0.2rem; right: 0.35rem; border: 0; background: none; color: inherit; font-size: 1.2rem; line-height: 1; cursor: pointer; }
.acg-info.is-pinned .acg-info-close { display: block; }
.acg-zoomhint {
  position: absolute; z-index: 5; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 0.5rem 0.9rem; border-radius: 8px;
  background: rgba(0, 0, 0, 0.7); color: #fff; font-size: 0.85rem; opacity: 0; transition: opacity 0.2s; pointer-events: none; text-align: center;
}
.acg-zoomhint.is-on { opacity: 1; }
/* the legend and the info card stay light together with the map, unless data-map-theme="auto" */
.acg:not(.acg--map-auto) .acg-legend, .acg:not(.acg--map-auto) .acg-info {
  --acg-surface: #ffffff; --acg-ink: #1c2a25; --acg-line: #d3dbd7; --acg-muted: #5d6c66;
}
.acg-legend--num { min-width: 11rem; }

.acg-catlabel { font-weight: 800; letter-spacing: 0.02em; }

/* On a phone the viewer map takes the touch (drag moves it, two fingers zoom it). Without this the browser kept pinching and
   scrolling the whole page, because the quiz default only gives touch to the map while a game is being played.
   The map is kept shorter than the screen so there is always some page above or below it to scroll with. */
.acg--viewer .acg-map { touch-action: none; }
.acg--viewer .acg-stage { max-height: 80vh; max-height: 80svh; }
/* data-touch="page" lets the page scroll and zoom when you touch the map (then the map cannot be pinched) */
.acg--viewer.acg--touch-page .acg-map { touch-action: pan-y pinch-zoom; }

/* geo-map data-filter-field: the drop-down above the map */
.acg-filterbar { display: flex; align-items: center; gap: 0.8rem; padding: 0.45rem 0.9rem; border-bottom: 1px solid var(--acg-line); font-size: 0.85rem; }
.acg-filterbar label { display: flex; align-items: center; gap: 0.4rem; font-weight: 600; }
.acg-filterbar select { font: inherit; padding: 0.15rem 0.4rem; border: 1px solid var(--acg-line); border-radius: 0.3rem; background: inherit; color: inherit; }
.acg-filter-count { opacity: 0.7; }
