/* ==========================================================================
   GeoHub - Atlas Design System
   Shared tokens and components for the portal and every game.
   A page picks its accent with <body data-game="satelcity|flagquiz|georank|borderline|coatofarms|compass|mercator|furthernorth|neighbours|pinthecity">.
   Fonts (load in each page <head>):
   https://fonts.googleapis.com/css2?family=Newsreader:opsz,wght@6..72,500;6..72,600&family=Public+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap
   ========================================================================== */

:root {
  /* Paper and ink */
  --paper: #F3EEE3;
  --paper-raised: #FBF8F1;
  --paper-sunken: #ECE5D6;
  --ink: #1E2933;
  --ink-soft: #3D4852;
  --ink-muted: #5B6670;
  --rule: #D9D0BF;
  --rule-strong: #C2B7A2;

  /* Game legend colours */
  --sea: #1F6F78;
  --brick: #B5442A;
  --ochre: #7A5C0E;
  --plum: #6B3F7A;
  --heraldic: #24467A;
  --raspberry: #9B2D5C;
  --rust: #A4521A;
  --indigo: #3E3F96;
  --olive: #5B6B12;
  --cerulean: #1C6EA4;

  /* Feedback */
  --correct: #2E6B45;
  --correct-soft: #E1EEE3;
  --wrong: #A3392B;
  --wrong-soft: #F6E1DC;

  /* Default accent (portal); overridden per game below */
  --accent: var(--ink);
  --accent-soft: var(--paper-sunken);

  /* Type */
  --font-display: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-body: 'Public Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* Shape */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-card: 0 1px 0 rgba(30, 41, 51, 0.04), 0 8px 24px -16px rgba(30, 41, 51, 0.25);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  --page-max: 1120px;
  --gutter: clamp(16px, 4vw, 40px);
}

body[data-game="satelcity"]  { --accent: var(--sea);      --accent-soft: #DCE8E6; }
body[data-game="flagquiz"]   { --accent: var(--brick);    --accent-soft: #F1DDD5; }
body[data-game="georank"]    { --accent: var(--ochre);    --accent-soft: #EDE4CC; }
body[data-game="borderline"] { --accent: var(--plum);     --accent-soft: #E9DEEB; }
body[data-game="coatofarms"] { --accent: var(--heraldic); --accent-soft: #DEE3EC; }
body[data-game="compass"]      { --accent: var(--raspberry); --accent-soft: #F1DDE6; }
body[data-game="mercator"]     { --accent: var(--rust);      --accent-soft: #F3E2D4; }
body[data-game="furthernorth"] { --accent: var(--indigo);    --accent-soft: #E1E1F2; }
body[data-game="neighbours"]   { --accent: var(--olive);     --accent-soft: #E6E8D2; }
body[data-game="pinthecity"]   { --accent: var(--cerulean);  --accent-soft: #DCE8F1; }

/* ---------- Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  /* Keep content clear of the notch / Dynamic Island, rounded corners and home indicator
     when running full screen as an installed app (pages use viewport-fit=cover) */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background-color: var(--paper);
  /* Faint graticule, like an atlas page */
  background-image:
    linear-gradient(to right, rgba(194, 183, 162, 0.14) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(194, 183, 162, 0.14) 1px, transparent 1px);
  background-size: 96px 96px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.1;
  margin: 0;
  color: var(--ink);
}

p { margin: 0; }

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

img, svg {
  display: block;
  max-width: 100%;
}

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

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Inline stroke icons: <svg class="icon" viewBox="0 0 24 24" aria-hidden="true">…</svg> */
.icon {
  display: inline-block;
  width: 1.15em;
  height: 1.15em;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.2em;
}

/* ---------- Page shell ---------- */

.atlas-page {
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 20px var(--gutter) 48px;
}

.atlas-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 16px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--rule);
}

.atlas-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-soft);
  text-decoration: none;
}

.atlas-back:hover {
  color: var(--ink);
}

.atlas-title {
  font-family: var(--font-display);
  font-size: clamp(22px, 3vw, 28px);
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}

.atlas-eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

/* ---------- Panels ---------- */

.atlas-panel {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

/* ---------- Stats bar ---------- */

.atlas-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  padding: 10px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.atlas-stat {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
}

.atlas-stat-label {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.atlas-stat-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* A stats line right under the topbar (or first in the next block) shares the topbar's rule */
.atlas-topbar:has(+ .atlas-stats),
.atlas-topbar:has(+ * > .atlas-stats:first-child) {
  margin-bottom: 0;
}

.atlas-topbar + .atlas-stats,
.atlas-topbar + * > .atlas-stats:first-child {
  border-top: 0;
}

.atlas-topbar + .atlas-stats {
  margin-bottom: 20px;
}

.atlas-stats .atlas-btn {
  margin-left: auto;
}

/* ---------- Buttons ---------- */

.atlas-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--rule-strong);
  background: var(--paper-raised);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}

.atlas-btn:hover {
  border-color: var(--ink-muted);
}

.atlas-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.atlas-btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
}

.atlas-btn--primary:hover {
  background: var(--ink);
  border-color: var(--ink);
}

.atlas-btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
}

.atlas-btn--ghost:hover {
  border-color: var(--rule-strong);
  color: var(--ink);
}

.atlas-btn--sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
}

/* ---------- Answer options ---------- */

.atlas-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

@media (max-width: 520px) {
  .atlas-options {
    grid-template-columns: minmax(0, 1fr);
  }
}

.atlas-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--rule);
  background: #FFFFFF;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease);
}

.atlas-option:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.atlas-option:disabled {
  cursor: default;
}

.atlas-option-key {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-muted);
  flex-shrink: 0;
}

.atlas-option.is-correct {
  border: 2px solid var(--correct);
  background: var(--correct-soft);
}

.atlas-option.is-wrong {
  border: 2px solid var(--wrong);
  background: var(--wrong-soft);
}

.atlas-option.is-dimmed {
  opacity: 0.55;
}

/* ---------- Inputs ---------- */

.atlas-input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--rule-strong);
  background: #FFFFFF;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
}

.atlas-input::placeholder {
  color: var(--ink-muted);
}

.atlas-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- Chips / tags ---------- */

.atlas-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--paper-raised);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  white-space: nowrap;
}

.atlas-chip--accent {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Segmented toggle ---------- */

.atlas-segmented {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--rule);
  background: var(--paper-sunken);
}

.atlas-segmented button {
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-soft);
  font-weight: 600;
  cursor: pointer;
}

.atlas-segmented button.is-active,
.atlas-segmented button[aria-pressed="true"] {
  background: var(--paper-raised);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(30, 41, 51, 0.12);
}

/* ---------- Feedback banner ---------- */

.atlas-feedback {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--rule);
  background: var(--paper-raised);
  font-weight: 600;
}

.atlas-feedback.is-correct {
  border-color: var(--correct);
  background: var(--correct-soft);
  color: var(--correct);
}

.atlas-feedback.is-wrong {
  border-color: var(--wrong);
  background: var(--wrong-soft);
  color: var(--wrong);
}

/* ---------- Modal ---------- */

.atlas-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(30, 41, 51, 0.45);
}

.atlas-modal {
  width: 100%;
  max-width: 480px;
  max-height: 100%;
  overflow-y: auto;
  padding: 28px;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 48px -24px rgba(30, 41, 51, 0.45);
}

/* ---------- Motion preference ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
