/* Two themes on two axes — data-theme (dark|light) × data-contrast (normal|high).
   Dark = Evangelion/NERV amber-on-near-black; light = warm "paper". Nearly all
   color routes through these variables; globe.js + ui.js read the --globe-*,
   --tour-*, and --preview vars via getComputedStyle so there's one source of
   truth. High-contrast blocks override only what must change. */

/* ---- Base: Eva dark, normal contrast (default) ---- */
:root,
:root[data-theme="dark"] {
  --bg: #0a0705;
  --panel: rgba(18, 12, 8, 0.84);
  --border: #3a2a18;
  --text: #e8dccb;
  --muted: #8a7355;
  --accent: #ff9f1c;
  --accent-2: #ffd166;
  --good: #7bdc8f;
  --bad: #ff5d4d;
  --ai: #c792ea;

  --input-bg: rgba(8, 5, 2, 0.6);
  --glow: rgba(255, 159, 28, 0.45);
  --grid-overlay: rgba(255, 159, 28, 0.04);
  --row-hover: rgba(255, 159, 28, 0.08);
  --row-viewing: rgba(255, 159, 28, 0.14);
  --row-border: rgba(58, 42, 24, 0.6);

  /* Globe (read by globe.js) */
  --globe-bg: #0a0705;
  --globe-sphere: #14100a; /* ocean (dark) */
  --globe-land: #382c1b; /* land lifts to a warm tan above the dark sea */
  --globe-graticule: #3a2a18;
  --globe-point: #ffcf8a;

  /* Tour overlays (read by ui.js). Ordered for max separation between the
     first few; on near-black we exploit both hue and lightness (bright yellow
     vs deep red) for distinctiveness. */
  --tour-1: #ff9f1c; /* orange  (amber brand) */
  --tour-2: #2ee6e6; /* cyan */
  --tour-3: #ff5fa2; /* pink */
  --tour-4: #5fe06a; /* green */
  --tour-5: #ffe14d; /* yellow (brightest) */
  --tour-6: #b98cff; /* violet */
  --tour-7: #ff5347; /* red */
  --tour-8: #6ea4ff; /* blue */
  --preview: #cbd5e1; /* neutral light slate — reads as a draft, not a tour */

  /* Diff view (exactly two tours selected). Orange/blue is the colorblind-safe
     opposing pair — distinct under deuteranopia/protanopia. All lines solid;
     dashes proved illegible where arcs overlap. */
  --diff-add: #ff9f1c; /* edges only in the newer tour — amber brand */
  --diff-del: #6ea4ff; /* edges only in the older tour — blue */
  --diff-same: #7a6a52; /* edges in both — dim warm grey, recessive */

  font-size: 15px;
}

/* ---- Eva dark, HIGH contrast ---- */
:root[data-theme="dark"][data-contrast="high"] {
  --bg: #000000;
  --panel: rgba(8, 5, 2, 0.94);
  --border: #ff9f1c;
  --text: #ffffff;
  --muted: #d8b888;
  --accent: #ffb733;
  --accent-2: #ffe08a;
  --good: #5cff84;
  --bad: #ff6a5a;

  --input-bg: #000000;
  --glow: rgba(255, 183, 51, 0.55);
  --grid-overlay: rgba(255, 183, 51, 0.06);
  --row-hover: rgba(255, 183, 51, 0.14);
  --row-viewing: rgba(255, 183, 51, 0.22);
  --row-border: rgba(255, 159, 28, 0.35);

  --globe-bg: #000000;
  --globe-sphere: #050302; /* ocean (near-black) */
  --globe-land: #4a3514; /* brighter tan for the high-contrast read */
  --globe-graticule: #6b4a1f;
  --globe-point: #ffe3b0;

  --diff-add: #ffb733;
  --diff-del: #8ab4ff;
  --diff-same: #a08a68;
}

/* ---- Paper light, normal contrast ---- */
:root[data-theme="light"] {
  --bg: #f4f1ea;
  --panel: rgba(248, 246, 240, 0.9);
  --border: #c9bfa9;
  --text: #1c1813;
  --muted: #6f6450;
  --accent: #b3540a;
  --accent-2: #8a4a12;
  --good: #2f7d3a;
  --bad: #c0392b;
  --ai: #6a3fb0;

  --input-bg: rgba(255, 255, 255, 0.8);
  --glow: transparent;
  --grid-overlay: rgba(60, 48, 30, 0.035);
  --row-hover: rgba(179, 84, 10, 0.08);
  --row-viewing: rgba(179, 84, 10, 0.15);
  --row-border: rgba(201, 191, 169, 0.7);

  --globe-bg: #f4f1ea;
  --globe-sphere: #9aabb0; /* ocean inverts to a cooler, darker slate */
  --globe-land: #ece6d8; /* light warm land floats above the sea */
  --globe-graticule: #b6a98e;
  --globe-point: #b3540a;

  /* On cream every hue must stay dark enough to read, so this set leans on hue
     + saturation rather than lightness. */
  --tour-1: #c2410c; /* orange */
  --tour-2: #0e7490; /* teal */
  --tour-3: #a21caf; /* magenta */
  --tour-4: #15803d; /* green */
  --tour-5: #a16207; /* gold */
  --tour-6: #6d28d9; /* violet */
  --tour-7: #be123c; /* red */
  --tour-8: #1d4ed8; /* blue */
  --preview: #57534e; /* neutral warm grey — reads as a draft */

  --diff-add: #c2410c;
  --diff-del: #1d4ed8;
  --diff-same: #8f8674;
}

/* ---- Paper light, HIGH contrast ---- */
:root[data-theme="light"][data-contrast="high"] {
  --bg: #ffffff;
  --panel: rgba(255, 255, 255, 0.96);
  --border: #1c1813;
  --text: #000000;
  --muted: #3a3228;
  --accent: #8a3d00;
  --accent-2: #5e2c00;
  --good: #1c6b2a;
  --bad: #a31f12;
  --ai: #4a2a8a;

  --input-bg: #ffffff;
  --grid-overlay: rgba(0, 0, 0, 0.05);
  --row-hover: rgba(138, 61, 0, 0.12);
  --row-viewing: rgba(138, 61, 0, 0.2);
  --row-border: rgba(28, 24, 19, 0.4);

  --globe-bg: #ffffff;
  --globe-sphere: #7f9499; /* ocean: deeper slate for the high-contrast read */
  --globe-land: #f4eee0; /* near-white warm land */
  --globe-graticule: #9aaa9f;
  --globe-point: #8a3d00;

  --tour-1: #9a3412; /* orange */
  --tour-2: #155e75; /* teal */
  --tour-3: #86198f; /* magenta */
  --tour-4: #166534; /* green */
  --tour-5: #854d0e; /* gold */
  --tour-6: #5b21b6; /* violet */
  --tour-7: #9f1239; /* red */
  --tour-8: #1e40af; /* blue */
  --preview: #44403c; /* neutral warm grey — reads as a draft */

  --diff-add: #9a3412;
  --diff-del: #1e40af;
  --diff-same: #575042;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "SF Mono", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
}

/* Faint scanline/grid texture — barely visible, theme-driven. Sits over the
   globe canvas (z 0) but under the floating UI (z 10). */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    0deg, var(--grid-overlay) 0 1px, transparent 1px 3px);
}

#globe {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#tooltip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 4px 9px;
  font-size: 0.8rem;
  color: var(--accent);
  white-space: nowrap;
}

header {
  position: fixed;
  top: 18px;
  left: 22px;
  z-index: 10;
  pointer-events: none;
}

header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 0 18px var(--glow);
}

.tagline {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  max-width: 46ch;
}

/* Theme toggles and the mode switcher share one header row (the panel
   starts at 96px — a second row would collide with it). */
#theme-toggle,
#mode-switch {
  margin-top: 10px;
  display: inline-flex;
  vertical-align: top;
  gap: 6px;
  pointer-events: auto;
}

#theme-toggle { margin-right: 10px; }

#theme-toggle button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  cursor: pointer;
  color: var(--accent);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0;
  backdrop-filter: blur(8px);
}

#theme-toggle button:hover { border-color: var(--accent); }

/* Contrast button reads "pressed" (filled) when high contrast is active. */
#theme-toggle button.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

#theme-toggle svg { display: block; width: 18px; height: 18px; }

/* Mode switcher: same treatment as the theme buttons, but text-labelled.
   The active game mode reads "pressed" (filled). */
#mode-switch button {
  height: 30px;
  padding: 0 10px;
  cursor: pointer;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--accent);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0;
  backdrop-filter: blur(8px);
}

#mode-switch button:hover { border-color: var(--accent); }

#mode-switch button.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* "Placeholder rules" marker next to the tagline while a mode's real
   dataset/scoring are still in the shop. */
.badge.placeholder {
  margin-left: 6px;
  background: color-mix(in srgb, var(--bad) 14%, transparent);
  color: var(--bad);
  border: 1px solid color-mix(in srgb, var(--bad) 38%, transparent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#panel {
  position: fixed;
  top: 96px;
  left: 22px;
  bottom: 56px;
  z-index: 10;
  width: 360px;
  max-width: calc(100vw - 44px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0;
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

#tabs button {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px 0;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

#tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab {
  display: none;
  padding: 14px;
  overflow-y: auto;
  flex: 1;
}

.tab.active { display: block; }

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 0.8rem;
}

.check { color: var(--muted); cursor: pointer; }

select, input, textarea, button {
  font: inherit;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 0;
}

select { padding: 4px 6px; font-size: 0.8rem; }

textarea {
  width: 100%;
  resize: vertical;
  padding: 8px;
  font-size: 0.78rem;
  line-height: 1.5;
}

.field-label {
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

#submit-form, #history-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

#submit-form input, #history-form input { padding: 7px 9px; font-size: 0.82rem; }

.prov { font-size: 0.78rem; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.prov label { cursor: pointer; }

button[type="submit"], #history-form button {
  padding: 8px;
  cursor: pointer;
  color: var(--bg);
  background: var(--accent);
  border: none;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

button[type="submit"]:hover, #history-form button:hover { filter: brightness(1.15); }

.status { margin-top: 8px; font-size: 0.8rem; min-height: 1.2em; white-space: pre-wrap; }
.status .ok { color: var(--good); }
.status .err { color: var(--bad); }
.status .dim { color: var(--muted); }

.list { font-size: 0.8rem; }

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 6px;
  border-bottom: 1px solid var(--row-border);
  cursor: pointer;
}

.row:hover { background: var(--row-hover); }
.row.viewing { background: var(--row-viewing); }

/* Leading marker gutter (AI / verified) — its own flex item, so it is never
   clipped by .who's overflow and keeps the rank column aligned. */
.row .mark {
  flex: 0 0 auto;
  width: 1.2em;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.row .mark .m-ai { color: var(--ai); font-weight: 700; font-size: 0.58rem; letter-spacing: 0.03em; }
.row .mark .m-verified { color: var(--good); font-size: 0.85rem; }

/* Sized for two digits; a rare 3-digit rank just bleeds left. */
.row .rank { color: var(--muted); width: 1.5em; text-align: right; }
.row .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .who small { color: var(--muted); }
.row .km { color: var(--accent); }
.row input[type="checkbox"] { accent-color: var(--accent); }

.badge {
  font-size: 0.65rem;
  border-radius: 0;
  padding: 1px 5px;
  vertical-align: middle;
}

.badge.ai {
  background: color-mix(in srgb, var(--ai) 18%, transparent);
  color: var(--ai);
  border: 1px solid color-mix(in srgb, var(--ai) 40%, transparent);
}

.badge.verified {
  background: color-mix(in srgb, var(--good) 16%, transparent);
  color: var(--good);
  border: 1px solid color-mix(in srgb, var(--good) 38%, transparent);
}

#legend { padding: 8px 6px 2px; display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 0;
  padding: 2px 9px;
  border: 1px solid var(--border);
}
footer {
  position: fixed;
  bottom: 16px;
  left: 22px;
  z-index: 10;
  display: flex;
  gap: 16px;
  font-size: 0.75rem;
}

/* Map-style scale bar, bottom-right. Width + label are set live by globe.js. */
#scalebar {
  position: fixed;
  right: 22px;
  bottom: 16px;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

#scale-bar {
  height: 6px;
  min-width: 1px;
  border: 1px solid var(--muted);
  border-top: none;
}

footer a { color: var(--muted); text-decoration: none; }
footer a:hover { color: var(--accent); }

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

@media (max-width: 720px) {
  #panel { top: 120px; width: calc(100vw - 24px); left: 12px; bottom: 48px; }
  header { left: 12px; }
}
