:root {
  --bg: #14161c;
  --panel: #1d212b;
  --panel-2: #262c39;
  --line: #333b4a;
  --text: #e6e9ef;
  --muted: #9aa3b2;
  --accent: #ffcf33;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.app {
  position: relative;     /* positioning context for the floating tool box */
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---- tool panel: a translucent box floating OVER the full-size map, same look and
   opacity as the stats box. The map always stays full size beneath it. ---- */
.panel {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 30;
  width: 230px;
  max-height: calc(100% - 24px);
  padding: 14px;
  overflow-y: auto;
  background: rgba(20, 22, 28, 0.74);   /* matches the stats box opacity */
  border: 1px solid var(--line);
  border-radius: 10px;
  backdrop-filter: blur(3px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .55);
  transition: width .18s ease, height .18s ease, padding .18s ease;
}

/* ---- shared fold pattern: BOTH the tool panel and the stats box are .foldbox'es
   that minimize to a small square showing only their ☰ button (the Tools behavior). ---- */
.foldbtn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 28px;
  height: 28px;
  min-width: 0;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  border-radius: 6px;
}
.foldbox.folded {
  width: 46px !important;
  height: 46px;
  max-height: 46px;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}
.foldbox.folded > :not(.foldbtn) { display: none; }
.foldbox.folded .foldbtn { top: 9px; right: 9px; }

.panel h1 {
  font-size: 18px;
  margin: 0 0 2px;
  padding-right: 30px;     /* keep the title/❔ clear of the ✕ in the corner */
  display: flex;
  align-items: center;
  gap: 8px;
}

#help-toggle {
  flex: 0 0 auto;
  min-width: 0;
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 14px;
  border-radius: 50%;
  margin-left: auto;
}

.panel .version {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 2px;
}

.panel .byline {
  font-size: 11px;
  color: var(--muted);
  margin: 0 0 14px;
}

.panel section { margin-bottom: 16px; }

/* section headings double as fold/unfold toggles */
.panel h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.panel h2::after { content: '▾'; margin-left: auto; font-size: 10px; color: var(--muted); }
.panel section.collapsed > h2 { margin-bottom: 0; }
.panel section.collapsed > h2::after { content: '▸'; }
.panel section.collapsed > :not(h2) { display: none; }

/* slider labels inside the Settings section */
.panel label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  margin: 10px 0 4px;
}

.val { color: var(--accent); font-weight: 700; }

/* ---- tool buttons ---- */
.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tools.col { flex-direction: column; }

/* icon-only tool grid: compact emoji squares (name shows on hover via title) */
.tools.icons button {
  flex: 0 0 auto;
  min-width: 0;
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

button {
  flex: 1 1 auto;
  min-width: 64px;
  padding: 8px 10px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  transition: border-color .12s, transform .05s, background .12s;
}
button:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }

button.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  background: #2f3545;
}

/* save slots: 1/2/3 picker; a filled slot (has a save) gets an amber marker */
.slot { min-width: 0; font-weight: 700; }
.slot.filled { border-left: 5px solid var(--accent); }
.slot-times {
  white-space: pre-line;
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* color swatches on terrain tools */
.t-deep     { border-left: 5px solid #1f4e79; }
.t-shallow  { border-left: 5px solid #2f6fb0; }
.t-sand     { border-left: 5px solid #d9c89a; }
.t-grass    { border-left: 5px solid #5a9e4b; }
.t-forest   { border-left: 5px solid #26602e; }
.t-hill     { border-left: 5px solid #6e5c49; }
.t-mountain { border-left: 5px solid #8e8b84; }
.t-snow     { border-left: 5px solid #e8eef2; }
.t-water    { border-left: 5px solid #2f6fb0; }
.t-road     { border-left: 5px solid #585a62; }
.t-wall     { border-left: 5px solid #9c8e78; }
.t-boat     { border-left: 5px solid #965f2d; }
.t-hand     { border-left: 5px solid #f0c987; }
.t-human    { border-left: 5px solid #ffcf33; }
.t-alien    { border-left: 5px solid #5be88a; }
.t-elf      { border-left: 5px solid #6ea8ff; }
.t-hybrid   { border-left: 5px solid #d83a3a; }
.t-penguin  { border-left: 5px solid #ff5722; }
.t-shark    { border-left: 5px solid #5b6b7d; }
.t-dino     { border-left: 5px solid #4a7a3a; }
.t-ufo      { border-left: 5px solid #5ad1ff; }
.t-plane    { border-left: 5px solid #e8eef5; }
.t-car      { border-left: 5px solid #e23b3b; }
.t-meteor    { border-left: 5px solid #ff7043; }
.t-quake     { border-left: 5px solid #9c6b3f; }
.t-tornado   { border-left: 5px solid #8a8d99; }
.t-hurricane { border-left: 5px solid #6fb7d8; }
.t-fire      { border-left: 5px solid #ff5722; }
.t-plague    { border-left: 5px solid #d14ee0; }

#pause.paused { border-color: #6fd07a; box-shadow: inset 0 0 0 1px #6fd07a; }
#toggle-homes.off { border-color: #d8643a; box-shadow: inset 0 0 0 1px #d8643a; color: var(--muted); }

input[type=range] { width: 100%; accent-color: var(--accent); }

/* ---- stats ---- */
.stats {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}
.stats div {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
}
.stats span { color: var(--muted); }
.stats b { color: var(--accent); }

.hint {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}
kbd {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  font-size: 10px;
}

/* ---- stage / canvas ---- */
.stage {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 40%, #1b1f29 0%, #0e1016 100%);
  padding: 8px;
  overflow: hidden;
}

/* live stats overlaid on the map; clicks pass straight through to the canvas */
.hud {
  position: absolute;
  top: 22px;
  right: 22px;
  background: rgba(20, 22, 28, 0.74);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px 10px 8px;   /* top strip leaves room for the fold button */
  font-size: 12px;
  color: var(--text);
  pointer-events: none;     /* HUD is click-through to the canvas... */
  backdrop-filter: blur(2px);
  max-width: 220px;
  transition: width .18s ease, height .18s ease, padding .18s ease;
}
.hud button { pointer-events: auto; }   /* ...but its buttons are tappable */
.hud-life { border-collapse: collapse; }
.hud-life th {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 600;
  text-align: right;
  padding: 0 5px 2px;
}
.hud-life td { text-align: right; padding: 1px 5px; font-variant-numeric: tabular-nums; }
.hud-life td:first-child { text-align: left; font-size: 14px; }
.hud-life td:nth-child(2) { color: var(--accent); font-weight: 700; }
.hud-life td:nth-child(3) { color: #e07a7a; }     /* deaths, in red */
.hud-extra {
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}
.hud-extra span { color: var(--accent); font-weight: 700; }

#world {
  width: min(100%, calc((100vh - 16px) * 1.6));
  height: auto;
  aspect-ratio: 192 / 120;
  image-rendering: pixelated;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
  cursor: crosshair;
  touch-action: none;
}
