/* Tokens mirror travelwithchance.com (theme/css/main.css) so the game reads as part of the brand. */
:root {
  --bg: #F6F4F0;
  --surface: #FFFFFF;
  --surface-alt: #EDF6FA;
  --ink: #1A2535;
  --text: #2A3344;
  --muted: #5B6A7A;
  --border: #E0DDD8;
  --primary: #1A6B8A;
  --primary-dark: #124E67;
  --link: #1A6B8A;
  --accent: #E89B35;
  --accent-dark: #C47E20;
  --green: #2D7D5C;
  --green-soft: #E8F5EE;
  --warn-soft: #FDF3E3;
  --hero-start: #17435A;
  --hero-end: #1E6B8A;
  --floor: #EFEBE4;
  --furniture: #B9AD9C;
  --specimen: #F6F4F0;

  --ff-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --ff-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --r-sm: 0.375rem;
  --r: 0.75rem;
  --r-lg: 1.25rem;
  --shadow: 0 4px 16px rgba(26, 37, 53, .07), 0 2px 4px rgba(26, 37, 53, .04);
  --ease: 200ms ease;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101822;
    --surface: #1A2535;
    --surface-alt: #22324A;
    --ink: #F2F5F8;
    --text: #DCE3EA;
    --muted: #A3B1BF;
    --border: #33445A;
    --link: #7CC7E3;
    --green: #6FCF9F;
    --green-soft: #17382C;
    --warn-soft: #3A2C14;
    --floor: #22324A;
    --furniture: #55657A;
    --specimen: #EDEAE4;
    --shadow: 0 4px 16px rgba(0, 0, 0, .3);
  }
}

:root[data-theme="dark"] {
  --bg: #101822;
  --surface: #1A2535;
  --surface-alt: #22324A;
  --ink: #F2F5F8;
  --text: #DCE3EA;
  --muted: #A3B1BF;
  --border: #33445A;
  --link: #7CC7E3;
  --green: #6FCF9F;
  --green-soft: #17382C;
  --warn-soft: #3A2C14;
  --floor: #22324A;
  --furniture: #55657A;
  --specimen: #EDEAE4;
  --shadow: 0 4px 16px rgba(0, 0, 0, .3);
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ff-sans);
  font-size: 1rem;
  line-height: 1.6;
}

h1, h2, h3 { color: var(--ink); line-height: 1.2; margin: 0 0 0.75rem; text-wrap: balance; }
h1 { font-size: clamp(1.6rem, 5vw, 2.25rem); font-weight: 800; }
h2 { font-size: clamp(1.35rem, 4vw, 1.75rem); font-weight: 800; }
h3 { font-size: 1.2rem; font-weight: 700; }
h1:focus, h2:focus { outline: none; }
p { margin: 0 0 1rem; }
a { color: var(--link); }
ul { margin: 0 0 1rem; padding-left: 1.25rem; }
li { margin-bottom: 0.35rem; }

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

[hidden] { display: none !important; }

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

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 10;
  padding: 0.75rem 1rem;
  background: var(--surface);
  color: var(--link);
  border-radius: var(--r-sm);
}
.skip-link:focus { top: 1rem; }

/* ── Header and footer ─────────────────────────────────────── */

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, var(--hero-start), var(--hero-end));
  color: #fff;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; white-space: nowrap; }
.brand:hover { text-decoration: underline; }
.bar__progress {
  flex: 1;
  margin: 0;
  min-width: 8rem;
  font-family: var(--ff-mono);
  font-size: 0.8125rem;
  opacity: 0.9;
}
.bar__toggles { display: flex; gap: 0.5rem; }
.toggle {
  min-height: 44px;
  padding: 0 0.75rem;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .35);
  border-radius: var(--r-sm);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
}
.toggle:hover { background: rgba(255, 255, 255, .22); }

.stage {
  flex: 1;
  width: 100%;
  max-width: 46rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 2.5rem;
}
.stage:focus { outline: none; }

.foot {
  padding: 1.25rem 1rem 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.875rem;
}
.foot p { margin: 0 0 0.25rem; }

/* ── Shared pieces ─────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: clamp(1.25rem, 4vw, 2rem);
}
.card + .card { margin-top: 1.5rem; }

.eyebrow {
  margin: 0 0 0.5rem;
  color: var(--link);
  font-family: var(--ff-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.lede { font-size: 1.0625rem; }
.fine { color: var(--muted); font-size: 0.875rem; }
.actions + .fine { margin-top: 0.75rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0.6rem 1.25rem;
  background: var(--surface);
  color: var(--ink);
  border: 2px solid var(--border);
  border-radius: var(--r);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease);
  touch-action: manipulation;
}
.btn:hover { border-color: var(--primary); }
.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn--accent { background: var(--accent); border-color: var(--accent); color: #1A2535; }
.btn--accent:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.25rem; }

.readout {
  min-height: 3.25rem;
  margin: 1rem 0 0;
  padding: 0.75rem 1rem;
  background: var(--surface-alt);
  border-left: 4px solid var(--primary);
  border-radius: var(--r-sm);
  font-family: var(--ff-mono);
  font-size: 0.875rem;
}
.readout:empty::before { content: 'Awaiting input.'; color: var(--muted); }
.readout.is-good { background: var(--green-soft); border-left-color: var(--green); }
.readout.is-warn { background: var(--warn-soft); border-left-color: var(--accent); }

.meter { margin: 0.75rem 0 0; font-family: var(--ff-mono); font-size: 0.875rem; color: var(--muted); }

.score {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0 0 0.75rem;
  font-family: var(--ff-mono);
}
.score__value { color: var(--green); font-size: 3rem; font-weight: 700; line-height: 1; }
.score__unit { color: var(--muted); }

.expect { list-style: none; padding: 0; }
.expect li {
  position: relative;
  padding-left: 1.75rem;
}
.expect li::before {
  content: '';
  position: absolute;
  left: 0.25rem;
  top: 0.55em;
  width: 0.6rem;
  height: 0.6rem;
  background: var(--green);
  border-radius: 50%;
}

.controls {
  padding: 0.75rem 1rem;
  background: var(--surface-alt);
  border-radius: var(--r-sm);
  font-size: 0.9375rem;
}

.level__prompt { margin-bottom: 1rem; }

/* ── Module 1: identification ──────────────────────────────── */

.specimens { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
@media (min-width: 34rem) { .specimens { grid-template-columns: repeat(4, 1fr); } }

.specimen {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.75rem 0.5rem;
  background: var(--specimen);
  color: #2A3344;
  border: 2px solid var(--border);
  border-radius: var(--r);
  font: inherit;
  font-family: var(--ff-mono);
  font-size: 0.8125rem;
  cursor: pointer;
  touch-action: manipulation;
}
.specimen svg { width: 100%; max-width: 110px; height: auto; }
.specimen:hover { border-color: var(--primary); }
.specimen.is-wrong { opacity: 0.55; cursor: not-allowed; border-style: dashed; }
.specimen.is-correct { border-color: #2D7D5C; background: #E8F5EE; }
.specimen__stamp {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-8deg);
  padding: 0.15rem 0.5rem;
  background: #fff;
  border: 2px solid currentColor;
  border-radius: var(--r-sm);
  font-weight: 700;
  white-space: nowrap;
}
.specimen.is-correct .specimen__stamp { color: #2D7D5C; }

/* ── Module 2: egress ──────────────────────────────────────── */

.room {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  width: 100%;
  max-width: 30rem;
  margin: 0 auto;
  padding: 3px;
  background: var(--border);
  border-radius: var(--r);
}
.cell {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  background: var(--floor);
  border-radius: 4px;
  cursor: pointer;
}
.cell svg { width: 70%; height: 70%; }
.cell--wall { background: var(--furniture); cursor: default; }
.cell--exit { background: var(--green-soft); color: var(--green); }
.cell--player { color: var(--link); }
.cell--notif { color: var(--accent-dark); }
.cell--paused { background: var(--warn-soft); }

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 1rem;
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.8125rem;
}
.legend li { display: flex; align-items: center; gap: 0.35rem; margin: 0; }
.legend svg, .legend .swatch { width: 1.1rem; height: 1.1rem; }
.legend .swatch { display: inline-block; background: var(--furniture); border-radius: 3px; }
.legend .is-player { color: var(--link); }
.legend .is-notif { color: var(--accent-dark); }
.legend .is-exit { color: var(--green); }

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 4px;
  justify-content: center;
  margin-top: 1rem;
}
.dpad .btn { min-height: 0; padding: 0; font-size: 1.25rem; }
.dpad [data-dir="up"] { grid-column: 2; grid-row: 1; }
.dpad [data-dir="left"] { grid-column: 1; grid-row: 2; }
.dpad [data-dir="down"] { grid-column: 2; grid-row: 2; }
.dpad [data-dir="right"] { grid-column: 3; grid-row: 2; }

/* ── Module 3: calibration ─────────────────────────────────── */

.rig {
  position: relative;
  width: 11rem;
  height: 22rem;
  margin: 0 auto;
  overflow: hidden;
  background: linear-gradient(#DCEEF6, #F3F8F4);
  border: 2px solid var(--border);
  border-radius: var(--r);
}
/* Depth 0-100% is measured along the track, which starts one hand-height down
   so the raised hand is fully visible. */
.rig__track { position: absolute; inset: 5.25rem 0 0; }
.rig__grass { position: absolute; left: 0; right: 0; bottom: 0; }
.rig__grass svg { display: block; width: 100%; height: 100%; }
.rig__zone {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 3px dashed #124E67;
  border-bottom: 3px dashed #FFFFFF;
}
.rig__zone span {
  position: absolute;
  right: 0.25rem;
  top: -1.5rem;
  padding: 0 0.25rem;
  background: rgba(255, 255, 255, .85);
  border-radius: 3px;
  color: #124E67;
  font-family: var(--ff-mono);
  font-size: 0.6875rem;
}
.rig__hand {
  position: absolute;
  left: 38%;
  width: 3.25rem;
  transform: translate(-50%, -100%);
}
.rig__hand svg { display: block; width: 100%; height: auto; }

/* ── Module 4: sustained contact ───────────────────────────── */

.notif-slot { min-height: 4.25rem; margin-bottom: 1rem; }
.notif {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  min-height: 4.25rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--accent);
  border-radius: var(--r);
  font: inherit;
  text-align: left;
  cursor: pointer;
  animation: notif-in 260ms ease;
}
.notif__open { color: var(--link); font-weight: 700; }
@keyframes notif-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

.patch {
  position: relative;
  display: block;
  width: min(100%, 17rem);
  margin: 0 auto;
  padding: 0.75rem 0.75rem 0.5rem;
  background: var(--specimen);
  color: #2A3344;
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.patch svg { display: block; width: 100%; height: auto; }
.patch__hand {
  position: absolute;
  left: 50%;
  top: 6%;
  width: 26%;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity var(--ease), top var(--ease);
}
.patch[aria-pressed="true"] { border-color: #2D7D5C; background: #E8F5EE; }
.patch[aria-pressed="true"] .patch__hand { opacity: 1; top: 22%; }

.progressbar {
  height: 0.75rem;
  margin-top: 1rem;
  overflow: hidden;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.progressbar__fill { width: 0; height: 100%; background: var(--green); }

.ambient { min-height: 1.6rem; margin: 0.75rem 0 0; color: var(--muted); font-style: italic; text-align: center; }

/* ── Field assessment and certificate ──────────────────────── */

.field { display: grid; gap: 0.35rem; margin-top: 1.25rem; }
.field label { font-weight: 600; }
.field input {
  width: 100%;
  max-width: 24rem;
  min-height: 48px;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  color: var(--ink);
  border: 2px solid var(--border);
  border-radius: var(--r-sm);
  font: inherit;
}

.preview { margin-top: 1rem; }
.preview canvas {
  display: block;
  max-width: 100%;
  max-height: 20rem;
  width: auto;
  height: auto;
  border: 1px solid var(--border);
  border-radius: var(--r);
}

.certificate {
  display: block;
  width: 100%;
  max-width: 27rem;
  height: auto;
  margin: 1rem auto;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow);
}

.share-fallback { margin-top: 1rem; }
.share-fallback textarea {
  width: 100%;
  min-height: 5rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font: inherit;
  font-size: 0.9375rem;
}

.cta { background: var(--surface-alt); border-color: transparent; }

/* ── Reduced motion: honour the system setting and the in-game toggle ── */

:root[data-motion="reduce"] *,
:root[data-motion="reduce"] *::before,
:root[data-motion="reduce"] *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}

@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion="full"]) *,
  :root:not([data-motion="full"]) *::before,
  :root:not([data-motion="full"]) *::after {
    animation: none !important;
    transition: none !important;
  }
}
