:root {
  --bg: #f3efe6;
  --panel: #fffdf8;
  --fg: #182226;
  --muted: #5e6b6f;
  --line: #d9d2c3;
  --accent: #0d8a68;
  --accent-fg: #fff;
  --hot: #d9480f;
  --sea: #1c6fd1;
  --ocean: #9cc3d8;
  --flat-land: #e6dfcc;
  --path: #7fffd4;
  --path-halo: #06261d;
  --villain: #b4236b;
  --shadow: 0 2px 12px rgb(0 0 0 / 0.12);
  --sans: "Petrov Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1214;
    --panel: #141c1f;
    --fg: #e6efec;
    --muted: #93a3a2;
    --line: #26343a;
    --accent: #7fffd4;
    --accent-fg: #06261d;
    --hot: #ff7a45;
    --sea: #6cb4ff;
    --villain: #ff5fa8;
    --ocean: #0e2531;
    --flat-land: #2a3633;
    --shadow: 0 2px 16px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 500 16px/1.4 var(--sans);
  -webkit-tap-highlight-color: transparent;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px max(16px, env(safe-area-inset-left)) 8px max(16px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
}

h1 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font: 400 24px/1 "Bungee", var(--sans);
  letter-spacing: 0.02em;
}

.logo { width: 34px; height: 34px; }

.when { display: flex; flex-direction: column; font-size: 14px; line-height: 1.2; margin-left: auto; text-align: right; }
.when .date { color: var(--muted); font-size: 12px; }

button {
  font: 600 15px/1 var(--sans);
  color: var(--fg);
  background: transparent;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 11px 14px;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.icon { width: 36px; height: 36px; padding: 0; border-radius: 50%; font-size: 17px; }
:focus-visible { outline: 3px solid var(--sea); outline-offset: 2px; }

main {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#map {
  flex: 1;
  min-height: 260px;
  background: var(--ocean);
  font-family: var(--sans);
}
#map.sat { background: #0a1418; }

.leaflet-container a { color: var(--sea); }
.leaflet-control-attribution { font-size: 10px; }

.panel {
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 12px max(16px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-bottom));
}

@media (min-width: 900px) {
  main { flex-direction: row; }
  .panel {
    width: 380px;
    border-top: 0;
    border-left: 1px solid var(--line);
    overflow-y: auto;
    padding: 16px 20px;
  }
}

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--muted);
  z-index: 1000;
  background: var(--bg);
}

.toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  margin: 0;
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

.who { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; font-size: 14px; color: var(--muted); }
.who img { width: 38px; height: 38px; flex: none; }
.who .reach { color: var(--accent); font-weight: 600; white-space: nowrap; }
.who b { color: var(--fg); font: 400 16px/1.2 "Bungee", var(--sans); }

.tries {
  display: flex;
  gap: 6px;
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
}
.tries li { flex: 1; }
.tries button {
  width: 100%;
  padding: 7px 4px;
  font-size: 13px;
  border-radius: 8px;
  color: var(--muted);
}
.tries button.done { color: var(--fg); }
.tries button.current { border-color: var(--accent); color: var(--fg); }
.tries button.best { box-shadow: inset 0 0 0 1.5px var(--hot); }

.stamina p { margin: 6px 0 0; font-size: 14px; color: var(--muted); }
.stamina b { color: var(--fg); font-size: 18px; }
.bar {
  height: 10px;
  border-radius: 5px;
  background: var(--line);
  overflow: hidden;
}
.bar span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--accent);
  transition: width 0.2s, background 0.2s;
}
.bar.low span { background: var(--hot); }

.status { margin: 8px 0 10px; font-size: 14px; min-height: 1.4em; }
.status.sea { color: var(--sea); }
.status.land { color: var(--hot); }

.buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.buttons .primary { flex: 1; }

.kicker { margin: 0; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; }
.score { margin: 2px 0; font-size: 15px; color: var(--muted); }
.score b { font: 400 30px/1.1 "Bungee", var(--sans); color: var(--hot); }
.verdict { margin: 0 0 8px; }
.note { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.note:empty { display: none; }

.hits {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  font-size: 14px;
  max-height: 6.2em;
  overflow-y: auto;
}
.hits li { display: flex; gap: 8px; padding: 2px 0; border-bottom: 1px solid var(--line); }
.hits li span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hits .n { font-variant-numeric: tabular-nums; }
.hits .part { color: var(--muted); font-size: 12px; align-self: center; }
@media (min-width: 900px) { .hits { max-height: 40vh; } }

dialog {
  max-width: min(520px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--fg);
  padding: 20px;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(0 0 0 / 0.5); }
dialog h2 { margin: 0 0 8px; font: 400 22px/1.2 "Bungee", var(--sans); }
dialog ul { padding-left: 20px; }
dialog li { margin: 6px 0; }
dialog .small { font-size: 12px; color: var(--muted); }
dialog a { color: var(--sea); }

/* Map furniture */
.kaiju-icon span { display: block; width: 100%; height: 100%; transition: transform 0.15s; }
.kaiju-icon span.flip { transform: scaleX(-1); }
.kaiju-icon img { width: 100%; height: 100%; filter: drop-shadow(0 2px 3px rgb(0 0 0 / 0.6)); }
.kaiju-icon.walking img { animation: stomp 0.35s infinite alternate ease-in-out; }
@keyframes stomp { from { transform: rotate(-6deg); } to { transform: rotate(6deg) translateY(-2px); } }

.step {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--path);
  border: 3px solid var(--path-halo);
  box-shadow: 0 0 0 2px rgb(255 255 255 / 0.7);
}
.step.end-sea { background: var(--sea); }
.step.end-land { background: var(--hot); }

.burst {
  pointer-events: none;
}
.burst i {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, #fff6c9 0%, #ffb347 35%, #ff4d1a 65%, transparent 70%);
  animation: burst 0.9s ease-out forwards;
}
@keyframes burst {
  from { transform: scale(0.2); opacity: 1; }
  to { transform: scale(1.6); opacity: 0; }
}

.leaflet-tooltip.city {
  font: 600 12px/1.2 var(--sans);
  padding: 3px 6px;
  border-radius: 6px;
  border: 0;
  background: rgb(10 14 16 / 0.85);
  color: #fff;
  box-shadow: none;
}
.leaflet-tooltip.city::before { display: none; }
.leaflet-tooltip.city small { color: #ffb08a; font-weight: 500; }

/* Bonus villains */
.bonus-open {
  width: 100%;
  margin: 0 0 10px;
  padding: 9px 12px;
  text-align: left;
  border-color: var(--villain);
  color: var(--fg);
  background: color-mix(in srgb, var(--villain) 14%, transparent);
}
.bonus-open b { color: var(--villain); }
.villain { display: flex; gap: 10px; align-items: center; margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.villain img { width: 48px; height: 48px; flex: none; }
.villain b { color: var(--villain); font: 400 16px/1.2 "Bungee", var(--sans); }
.villain .title { color: var(--fg); font-weight: 600; }
.rules { margin: 0 0 4px; font-size: 14px; }
button.villainous { background: var(--villain); border-color: var(--villain); color: #fff; }
#bonus-result .score b { color: var(--villain); }
.strike {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--villain);
  border: 3px solid #1a0610;
  box-shadow: 0 0 0 2px rgb(255 255 255 / 0.7);
}
