* { box-sizing: border-box; }
:root {
  color-scheme: light;
  --ink: #1e3547;
  --ink-muted: #4c6273;
  --paper: #fffaf0;
  --sky-accent: #2788d8;
  --gold: #ffbe3b;
  --coral: #ff6b4a;
  --teal: #17a3a3;
  --line: #d4dfe6;
}
:root[data-coat="black"] {
  --ink: #222938;
  --sky-accent: #3d6396;
}

html, body, #game {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
body {
  font: 600 14px/1.4 "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: #8fd2ff;
}
#game {
  position: relative;
  isolation: isolate;
}
button, input { font: inherit; }
button {
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button:focus-visible, input:focus-visible {
  outline: 3px solid #ff9933;
  outline-offset: 2px;
}
button:disabled { opacity: .55; cursor: default; }
[hidden], body:not([data-mode="playing"]) :is(.controls, .telemetry, .announcement) {
  display: none !important;
}

.symbols { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon, .crest {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

#world {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 4;
  inset: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) auto max(14px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  background: #fffcf3eb;
  border: 1px solid #ffffff;
  border-radius: 16px;
  padding: 5px 12px 5px 6px;
  box-shadow: 0 6px 18px #15345020;
}
.crest {
  width: 38px;
  height: 38px;
  padding: 7px;
  border-radius: 12px;
  background: linear-gradient(155deg, #ff7d4d, #e44a32);
  color: #fffaf0;
}
.brand small {
  display: block;
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 9px;
  color: var(--ink-muted);
}
.brand strong {
  display: block;
  font: 800 18px/1.05 "Trebuchet MS", system-ui, sans-serif;
  letter-spacing: -.02em;
}
.tools {
  pointer-events: auto;
  display: flex;
  gap: 6px;
}
.tools button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: #fffcf4f2;
  border: 1px solid #d5e1e8;
  border-radius: 14px;
  box-shadow: 0 3px 0 #17354f22;
}
.tools [aria-pressed="true"] {
  background: #d8f4f2;
  border-color: var(--teal);
}

.telemetry {
  position: absolute;
  z-index: 2;
  top: max(64px, calc(env(safe-area-inset-top) + 56px));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 14px;
  background: #fffcf3eb;
  border: 1px solid #ffffff;
  box-shadow: 0 4px 14px #112d471d;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.pill-label { color: var(--ink-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.score-pill b { font-size: 18px; font-weight: 800; }
.multiplier {
  display: inline-grid;
  place-items: center;
  padding: 2px 7px;
  border-radius: 99px;
  background: linear-gradient(135deg, #ffd14c, #ff9929);
  color: #462300;
  font-size: 12px;
  font-weight: 900;
}
.route-pill { margin-left: auto; }
.magnet-badge {
  padding: 1px 6px;
  border-radius: 8px;
  background: #e1f6f5;
  color: #0e6363;
  font-size: 11px;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow: auto;
  overscroll-behavior: contain;
  display: grid;
  align-items: center;
  justify-items: start;
  padding: 66px 5vw 18px;
  background: linear-gradient(95deg, #eef7ff99, transparent 66%);
}
.card {
  width: min(395px, 100%);
  padding: clamp(16px, 2.8vw, 28px);
  border-radius: 24px;
  border: 2px solid #ffffff;
  background: #fffaf0f5;
  box-shadow: 0 18px 50px #0f325030;
}
body[data-mode="finished"] .overlay {
  justify-items: center;
  background: #14364f5e;
  backdrop-filter: blur(4px);
}
body[data-mode="finished"] .card {
  width: min(490px, 100%);
  text-align: center;
}
#result-kicker {
  margin: 0 0 6px;
  color: #b45309;
  font-size: 11px;
  letter-spacing: .16em;
  font-weight: 800;
}
h1 {
  margin: 0 0 8px;
  font: 800 clamp(26px, 3.8vw, 42px)/1.05 "Trebuchet MS", Georgia, sans-serif;
  letter-spacing: -.03em;
}
#description {
  margin: 0 0 12px;
  color: var(--ink-muted);
  font-size: 13.5px;
  line-height: 1.48;
  font-weight: 500;
}

.coat-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.coat-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 7px 10px;
  border-radius: 13px;
  border: 2px solid #d5dfe7;
  background: #ffffff;
  font-size: 13px;
  font-weight: 700;
  transition: transform .12s, border-color .12s, background .12s;
}
.coat-option[aria-pressed="true"] {
  border-color: var(--sky-accent);
  background: #eaf5ff;
  box-shadow: 0 2px 0 #2788d840;
}
.coat-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex: none;
  border: 2px solid #1e354740;
}
.swatch-white {
  background: radial-gradient(circle at 35% 30%, #fffdf8, #edd9b8);
  box-shadow: inset 0 -3px 0 #16a5a5;
}
.swatch-black {
  background: radial-gradient(circle at 35% 30%, #434b5c, #1d212b);
  box-shadow: inset 0 -3px 0 #ff6a47;
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 10px 0;
  padding: 8px;
  border-radius: 14px;
  background: #f2f7fb;
  border: 1px solid #d9e5ee;
}
.summary-stats span { display: block; font-size: 10px; color: var(--ink-muted); text-transform: uppercase; }
.summary-stats strong { display: block; font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }

.earned-badges {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0;
  padding: 10px 6px;
  border-radius: 16px;
  border: 1px solid #ebd7a7;
  background: #fff6de;
}
.earned-badges span {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: 0 auto 5px;
  border-radius: 50%;
  border: 2px solid #cbd3c8;
  background: #eff2eb;
  color: #8b9487;
  font-size: 22px;
}
.earned-badges [data-earned="true"] span {
  color: #8f580e;
  border-color: #eab440;
  background: radial-gradient(circle at 30% 25%, #fff9c9, #ffd056 72%);
}
.earned-badges strong { display: block; font-size: 11px; }
.earned-badges small { font-size: 10px; color: var(--ink-muted); }

.gentle-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 2px 10px;
  margin-bottom: 8px;
  border-radius: 11px;
  background: #f3f7fa;
  font-size: 13px;
  cursor: pointer;
}
.gentle-toggle input { width: 18px; height: 18px; accent-color: var(--sky-accent); }

.dialog-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.primary {
  width: 100%;
  min-height: 48px;
  padding: 11px 18px;
  border: 1px solid #d46e12;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffca47, #ff9628);
  color: #3a1b00;
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 3px 0 #c66308;
}
.secondary {
  width: 100%;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid #cbd7e0;
  border-radius: 12px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 700;
}

.announcement {
  position: absolute;
  z-index: 2;
  top: 114px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 14px;
  border-radius: 99px;
  background: #fffcf3f0;
  border: 1px solid #ffd586;
  box-shadow: 0 6px 20px #15314724;
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
  white-space: nowrap;
}
.announcement:empty { display: none; }

.controls {
  position: absolute;
  z-index: 2;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 10px;
  border-radius: 22px;
  border: 1px solid #ffffff;
  background: #fffcf3eb;
  box-shadow: 0 10px 30px #102d452b;
  user-select: none;
  -webkit-user-select: none;
}
.movement-controls {
  display: flex;
  flex: none;
  align-items: center;
  gap: 6px;
}
.directions, .cart-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}
.control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 72px;
  height: 50px;
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid #c9d8e2;
  background: linear-gradient(#ffffff, #e8f1f8);
  box-shadow: 0 3px 0 #b7c8d6;
  font-size: 13px;
  font-weight: 800;
  touch-action: none;
}
.duck-btn {
  border-color: #6bc4c4;
  background: linear-gradient(#edfcfc, #c7efef);
  box-shadow: 0 3px 0 #55aaaa;
  color: #0e4a4a;
}
.jump-btn {
  border-color: #e4972b;
  background: linear-gradient(#ffe38a, #ffb63b);
  box-shadow: 0 3px 0 #c57816;
  color: #462300;
}
.control:active, .control.held {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #a0b3c2;
}
.nojs { position: absolute; inset: 24%; background: var(--paper); padding: 18px; border-radius: 16px; }

@media (max-width: 850px), (pointer: coarse) {
  .hud {
    inset: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) auto max(8px, env(safe-area-inset-left));
  }
  .brand { padding: 4px 9px 4px 5px; border-radius: 13px; }
  .crest { width: 32px; height: 32px; padding: 5px; }
  .brand strong { font-size: 15px; }
  .telemetry {
    top: max(56px, calc(env(safe-area-inset-top) + 48px));
    left: 8px;
    right: 8px;
    gap: 4px;
  }
  .pill { padding: 4px 8px; font-size: 11px; border-radius: 10px; }
  .score-pill b { font-size: 15px; }
  .announcement { top: 96px; font-size: 12px; }
  .overlay {
    padding: 58px 12px 12px;
    justify-items: center;
    background: linear-gradient(180deg, #dff0ff88, #fff8eb66);
  }
  .card {
    padding: 14px 15px;
    border-radius: 20px;
  }
  .controls {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    transform: none;
    justify-content: space-between;
    gap: 6px;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    padding: 6px max(6px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }
  .movement-controls { --gc-pad-size: 74px; }
  .directions .control {
    min-width: 44px;
    width: 44px;
    height: 50px;
    padding: 2px;
    flex-direction: column;
    gap: 1px;
    font-size: 10px;
  }
  .directions .control .icon { width: 18px; height: 18px; }
  .cart-actions { margin-left: auto; gap: 5px; }
  .cart-actions .control {
    min-width: 56px;
    height: 52px;
    padding: 4px 7px;
    flex-direction: column;
    gap: 1px;
    font-size: 10.5px;
  }
  .cart-actions .control .icon { width: 18px; height: 18px; }
}

@media (max-width: 360px) {
  .brand small { display: none; }
  .controls { gap: 4px; padding-inline: 4px; }
  .movement-controls { --gc-pad-size: 68px; gap: 4px; }
  .cart-actions .control { min-width: 50px; padding: 3px 4px; font-size: 10px; }
}

@media (max-height: 500px) {
  .overlay { padding: 52px 12px 8px; }
  body:not([data-mode="finished"]) .card {
    width: min(640px, 100%);
    padding: 11px 16px;
    display: grid;
    grid-template:
      "title coat" auto
      "desc gentle" auto
      "actions actions" auto / 1.25fr 1fr;
    gap: 6px 14px;
    align-items: center;
  }
  body:not([data-mode="finished"]) #title { grid-area: title; font-size: 23px; margin: 0; }
  body:not([data-mode="finished"]) #description { grid-area: desc; font-size: 12px; margin: 0; line-height: 1.35; }
  body:not([data-mode="finished"]) #coat-picker { grid-area: coat; margin: 0; }
  body:not([data-mode="finished"]) #gentle-label { grid-area: gentle; margin: 0; min-height: 40px; }
  body:not([data-mode="finished"]) .dialog-actions { grid-area: actions; flex-direction: row; }
  .coat-option { min-height: 40px; padding: 5px 8px; font-size: 12px; }
  .primary, .secondary { min-height: 44px; padding: 8px 14px; }
  .telemetry { top: 10px; left: 205px; right: 195px; justify-content: center; }
  .route-pill { margin-left: 0; }
  .movement-controls { --gc-pad-size: 66px; }
  .directions .control, .cart-actions .control { height: 46px; min-height: 44px; flex-direction: row; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
