:root {
  --bg: #14181f;
  --panel: rgba(20, 24, 31, 0.94);
  --card: #1f2530;
  --line: #2e3644;
  --text: #e9edf3;
  --muted: #95a0b2;
  --accent: #3dff8b;
  --danger: #ff5a5a;
  --warn: #ffd166;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
button { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: #1d6b45; border-color: #2a9c63; }
button.danger { background: #6b1d1d; border-color: #a63232; }
input, select { font: inherit; color: var(--text); background: #10141a; border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; min-width: 0; }
h1, h2, h3 { margin: 0 0 6px; }
h3 { font-size: 15px; }
.muted, .hint { color: var(--muted); font-size: 13px; }

#map { position: fixed; inset: 0; }
.leaflet-container { background: #0d1015; }
.leaflet-tile-pane { filter: saturate(.35) brightness(.6) contrast(1.1); }
.poi.faint { font-size: 14px; opacity: .45; }
.poi { font-size: 22px; line-height: 28px; text-align: center; filter: drop-shadow(0 1px 2px #000); }

#hud { position: fixed; top: 0; left: 0; right: 0; z-index: 1000; display: flex; gap: 8px; align-items: center;
  flex-wrap: wrap; padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; background: linear-gradient(var(--panel), rgba(20,24,31,.6)); }
#who { font-weight: 600; white-space: nowrap; }
.hex-chip { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 3px 8px; border-radius: 999px; color: var(--muted); }
.hex-chip:hover { color: var(--text); }
code.hexid { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; background: #10141a; border: 1px solid var(--line);
  border-radius: 6px; padding: 1px 6px; user-select: all; }
#inv { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.chip { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; font-size: 13px; white-space: nowrap; }
.hud-btns { display: flex; gap: 6px; margin-left: auto; }
.hud-btns button { padding: 6px 10px; }

#dpad { position: fixed; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 28px); z-index: 1000; display: grid;
  grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 44px); }
#dpad[hidden] { display: none; }
#devbar { position: fixed; left: 12px; bottom: calc(env(safe-area-inset-bottom) + 28px); z-index: 1000; display: flex; flex-wrap: wrap;
  align-items: center; gap: 6px; max-width: calc(100vw - 190px); padding: 6px 8px; font-size: 12px; border-radius: 10px;
  background: var(--panel, rgba(20, 24, 30, .9)); border: 1px dashed #e0a800; }
#devbar[hidden] { display: none; }
#devbar select { font-size: 12px; padding: 2px 4px; }
#dpad button { padding: 0; opacity: .85; }
#dpad [data-dir=n] { grid-column: 2; grid-row: 1; }
#dpad [data-dir=w] { grid-column: 1; grid-row: 2; }
#dpad [data-dir=e] { grid-column: 3; grid-row: 2; }
#dpad [data-dir=s] { grid-column: 2; grid-row: 3; }

/* The panel drops down from the top bar; --hud-h is the bar's real height (it wraps on phones), set from JS. */
/* Hangs under its ☰ button: right edge lined up with the button's, a notch pointing up at it. */
#panel { position: fixed; right: var(--panel-right, 8px); top: calc(var(--hud-h, 56px) + 6px); z-index: 1001;
  display: flex; flex-direction: column; width: min(720px, calc(100vw - var(--panel-right, 8px) - 8px));
  max-height: min(60vh, calc(100vh - var(--hud-h, 56px) - 102px));
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px 4px 16px 16px;
  box-shadow: 0 10px 24px rgba(0,0,0,.35); transform-origin: top right;
  animation: drop-panel .18s ease-out; }
#panel::before { content: ''; position: absolute; top: -7px; right: var(--notch-right, 12px); width: 12px; height: 12px;
  background: var(--panel); border-left: 1px solid var(--line); border-top: 1px solid var(--line);
  transform: rotate(45deg); }
@keyframes drop-panel { from { opacity: 0; transform: translateY(-6px) scale(.98); } }
@media (prefers-reduced-motion: reduce) { #panel { animation: none; } }
#panel.collapsed { display: none; }
#panelToggle[aria-expanded="true"] { background: var(--card); border-color: var(--accent); }
#panel nav { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); }
#panel nav button { flex: 1; padding: 6px 4px; font-size: 13px; background: transparent; border-color: transparent; }
#panel nav button.on { background: var(--card); border-color: var(--line); }
.tab { display: none; overflow-y: auto; padding: 10px 12px 14px; }
.tab.on { display: block; }
.tab form { display: flex; gap: 6px; margin: 8px 0; }
.tab form input { flex: 1; }
#orderForm input { width: 70px; flex: 0 1 70px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 8px; }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.row button small { color: var(--muted); }
.hp { height: 6px; background: #10141a; border-radius: 3px; overflow: hidden; margin: 6px 0; }
.hp > i { display: block; height: 100%; background: var(--accent); }
.hp.low > i { background: var(--danger); }
.storm { color: #9fb4ff; }
.order { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.chat { max-height: 160px; overflow-y: auto; font-size: 14px; }
.chat b { color: var(--warn); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
td { padding: 3px 4px; border-top: 1px solid var(--line); }

#toasts { position: fixed; top: calc(var(--hud-h, 56px) + var(--panel-h, 0px) + 14px); left: 50%; transform: translateX(-50%); z-index: 3000;
  display: flex; flex-direction: column; gap: 6px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 10px;
  padding: 8px 12px; animation: drop .25s ease-out; }
.toast.ok { border-left-color: var(--accent); }
.toast.error { border-left-color: var(--danger); }
.toast.event { border-left-color: var(--warn); }
@keyframes drop { from { opacity: 0; transform: translateY(-8px); } }

.overlay { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; background: rgba(8, 10, 14, .85); padding: 16px; }
.overlay[hidden] { display: none; }
#welcome .card { max-width: 420px; padding: 20px; }
#welcome input { width: 100%; margin: 8px 0; }
#welcome .row button { flex: 1 1 100%; }

#ar { background: radial-gradient(circle at 50% 30%, #2d5a3a, #0b1a10); overflow: hidden; display: block; padding: 0; }
#ar[hidden] { display: none; }
#ar video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#ar.noar video { display: none; }
#arLayer { position: absolute; inset: -10%; transition: transform .1s linear; }
.node { position: absolute; font-size: 48px; transform: translate(-50%, -50%); user-select: none; cursor: pointer;
  filter: drop-shadow(0 0 12px rgba(255, 230, 140, .9)); animation: bob 1s ease-in-out infinite alternate; touch-action: none; }
.node.pop { animation: pop .25s ease-out forwards; pointer-events: none; }
@keyframes bob { to { margin-top: -10px; } }
@keyframes pop { to { transform: translate(-50%, -50%) scale(1.8); opacity: 0; } }
#arHud { position: absolute; top: calc(env(safe-area-inset-top) + 12px); left: 12px; right: 12px; display: flex; justify-content: space-between;
  font-size: 28px; font-weight: 700; text-shadow: 0 2px 6px #000; }
#arScore::before { content: "✨ "; }
#arTime::after { content: "s"; }
#arHint { position: absolute; bottom: 80px; width: 100%; text-align: center; text-shadow: 0 2px 6px #000; }
#arQuit { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 20px); left: 50%; transform: translateX(-50%); }
.floors { display: flex; flex-wrap: wrap; gap: 4px; }
.floors button { width: 38px; padding: 4px 0; font-size: 13px; }
.floors button.on { outline: 2px solid var(--text); }
.floors button.mine { background: #1d6b45; border-color: #2a9c63; }
.floors button.taken { background: #6b1d1d; border-color: #a63232; }
.poi.find { font-size: 20px; animation: sparkle 1.6s ease-in-out infinite alternate; }
@keyframes sparkle { from { opacity: .55; transform: scale(.9); } to { opacity: 1; transform: scale(1.1); } }
.poi.lm { font-size: 17px; line-height: 22px; }
.poi.lm.stamped { opacity: .6; }
.card.spotted { border-color: var(--warn); }
.between { display: flex; justify-content: space-between; gap: 8px; }
.codex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; margin-bottom: 10px; }
.sp { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: grid; justify-items: center; gap: 2px; text-align: center; }
.sp span { font-size: 26px; line-height: 1.1; }
.sp small { font-size: 11px; color: var(--muted); line-height: 1.2; }
.sp b { font-size: 12px; }
.sp.locked span { color: var(--muted); font-weight: 700; }
.sp.locked { opacity: .55; }
a.link { color: var(--accent); align-self: center; font-size: 13px; }
@media (prefers-reduced-motion: reduce) { .poi.find { animation: none; } }
.map-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-bottom: 8px; font-size: 13px; }
.map-opts .toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.map-opts .toggle input { accent-color: var(--accent); width: 15px; height: 15px; }
.res-key { font-size: 12px; }
.poi.res { font-size: 13px; line-height: 18px; opacity: .9; filter: drop-shadow(0 1px 1px #000); pointer-events: none; }

/* Damaged plots: a badge on the map, a count in the top bar, and highlighted cards in Realm. Amber = damaged, red = critical. */
.dmg-badge { font: 600 11px/20px system-ui, sans-serif; text-align: center; border-radius: 999px; white-space: nowrap;
  color: #1b1300; background: #ffb347; border: 1px solid rgba(0,0,0,.35); box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.dmg-badge.crit { color: #fff; background: var(--danger); animation: dmg-pulse 1.2s ease-in-out infinite alternate; }
@keyframes dmg-pulse { from { box-shadow: 0 0 0 0 rgba(255,77,77,.7); } to { box-shadow: 0 0 0 6px rgba(255,77,77,0); } }
.repair-chip { padding: 3px 9px; border-radius: 999px; font-size: 13px; font-weight: 600; color: #1b1300; background: #ffb347; border-color: transparent; }
.repair-chip.crit { color: #fff; background: var(--danger); }
.card.dmg.warn { border-color: #ffb347; }
.card.dmg.crit { border-color: var(--danger); box-shadow: inset 3px 0 0 var(--danger); }
.dmg-note { font-size: 13px; font-weight: 600; margin-bottom: 4px; color: #ffb347; }
.card.crit .dmg-note, .crit-txt { color: #ff8080; }
.dmg-summary { margin: 0 0 8px; font-size: 13px; }
button.repair { border-color: #ffb347; }
@media (prefers-reduced-motion: reduce) { .dmg-badge.crit { animation: none; } }

/* Gold coin, drawn in CSS so it looks gold everywhere (the 🪙 emoji is silver on most platforms). Scales with font size. */
.coin { display: inline-block; width: 1em; height: 1em; border-radius: 50%; vertical-align: -0.14em;
  background: radial-gradient(circle at 34% 30%, #fff7cc 0 10%, #ffdd55 28%, #e9b021 58%, #b07a0c 100%);
  box-shadow: inset 0 0 0 0.08em #a8740a, inset 0 0 0 0.15em #ffe58a, 0 0.04em 0.08em rgba(0,0,0,.55); }
.poi .coin, #arLayer .coin { vertical-align: middle; }

h4.sub { margin: 10px 0 2px; font-size: 13px; font-weight: 600; }
.deal { color: var(--accent); font-weight: 600; }

/* Buildings on a plot: a compact row of icons under the hex centre. */
.bld-pill { display: inline-flex !important; gap: 1px; width: auto !important; height: auto !important; transform-origin: center;
  translate: -50% -50%; padding: 2px 7px; gap: 3px; border-radius: 999px; font-size: 17px; line-height: 22px; white-space: nowrap;
  background: rgba(14, 18, 24, .85); border: 2px solid #3dff8b; box-shadow: 0 1px 3px rgba(0,0,0,.5); pointer-events: none; }
.bld-pill.theirs { border-color: #ff4d4d; }
.bld-pill small { font-size: 11px; color: #cfd6df; margin-left: 1px; }

/* NPC neighbours on the map: a robot with a name tag. */
.npc-pin { display: inline-flex !important; align-items: center; gap: 3px; width: auto !important; height: auto !important;
  translate: -50% -50%; font-size: 18px; line-height: 20px; white-space: nowrap; filter: drop-shadow(0 1px 2px #000); }
.npc-pin span { font: 600 11px/16px system-ui, sans-serif; color: #e8f0ff; background: rgba(40, 60, 110, .85);
  border: 1px solid #8fb1ff; border-radius: 999px; padding: 0 6px; }

/* Landmark challenges */
.chal { padding: 6px 0; border-top: 1px solid var(--line); }
.chal:first-child { border-top: 0; }
.chal .hp { margin: 4px 0; }
.chal.done .hp > i { background: #ffd34d; }
.chal .reward { font-size: 12px; }
.badges { margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 4px; }

/* Landmarks: ready to re-stamp pulses gently; featured ones carry a star. */
.poi.lm.ready { animation: sparkle 1.6s ease-in-out infinite alternate; }
.poi.lm.featured::after { content: '⭐'; position: absolute; right: -8px; top: -8px; font-size: 11px; line-height: 1; }
@media (prefers-reduced-motion: reduce) { .poi.lm.ready { animation: none; } }

/* Harvest ready on your plots: green pill with what's waiting; gold and pulsing when storage is full. */
.ready-badge { display: inline-flex !important; width: auto !important; height: auto !important; translate: -50% -50%;
  padding: 1px 7px; border-radius: 999px; white-space: nowrap; font: 700 12px/18px system-ui, sans-serif;
  color: #062b14; background: #3dff8b; border: 1px solid rgba(0,0,0,.35); box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.ready-badge .coin { vertical-align: -0.15em; }
.ready-badge.full { color: #2b1d00; background: #ffd34d; animation: ready-pulse 1.1s ease-in-out infinite alternate; }
@keyframes ready-pulse { from { box-shadow: 0 0 0 0 rgba(255,211,77,.8); } to { box-shadow: 0 0 0 7px rgba(255,211,77,0); } }
@media (prefers-reduced-motion: reduce) { .ready-badge.full { animation: none; } }

.form-hint { margin: -4px 0 8px; font-size: 12px; }

/* Market finder: what each nearby market wants and sells */
.book-line { font-size: 12px; color: var(--muted); }
.chip.book { font-size: 12px; padding: 0 6px; }
.chip.book.wants { border-color: #3dff8b66; }

/* Market Quarter stalls on the map, and the report-a-place box */
.poi.stall { font-size: 13px; line-height: 18px; opacity: .9; }
details.report { margin: 6px 0; font-size: 13px; }
details.report .row input[name="note"] { flex: 1; min-width: 140px; }

/* The main "Report a map problem here" control on the Here tab */
details.report-main { margin: 4px 0 10px; }
details.report-main > summary.report-btn { display: inline-block; cursor: pointer; list-style: none; padding: 6px 12px; border-radius: 999px;
  border: 1px solid #ffb347; color: #ffd9a3; font-size: 13px; font-weight: 600; }
details.report-main > summary.report-btn::-webkit-details-marker { display: none; }
details.report-main[open] > summary.report-btn { background: #3a2a10; }
.report-form { display: grid; gap: 6px; margin-top: 8px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.report-form label { display: grid; gap: 3px; font-size: 13px; }
.report-form select, .report-form input { width: 100%; }
/* A building on your own plot, with a small ✕ to take it down. */
.bld { position: relative; display: inline-block; margin-right: 6px; }
.bld .x { position: absolute; top: -6px; right: -10px; padding: 0 3px; font-size: 9px; line-height: 1.2; border-radius: 999px; opacity: .55; }
.bld .x:hover { opacity: 1; }
/* Reassuring notice (e.g. fenced in: here's your outpost). */
.note-ok { margin: 6px 0; padding: 8px 10px; border-radius: 8px; font-size: 13px; line-height: 1.4;
  background: color-mix(in srgb, #3fb68b 14%, transparent); border: 1px solid color-mix(in srgb, #3fb68b 45%, transparent); }
/* Public marks: a tidy row of emblems with names; the form to leave one. */
.marks { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.mark { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line, #333); font-size: 16px; }
.mark small { font-size: 11px; opacity: .8; max-width: 12em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mark.mine { border-color: var(--accent); }
.emblems label { font-size: 18px; cursor: pointer; }
.emblems input { display: none; }
.emblems input:checked + * , .emblems label:has(input:checked) { outline: 2px solid var(--accent); border-radius: 6px; }
.poi.wonder { filter: drop-shadow(0 0 4px #ffd36b); }
/* Public signals on other settlers' plots. */
.signals { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.sig { font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line, #333); }
.sig.warn { border-color: #d9a441; color: #d9a441; }
.sig.raider { border-color: #d9534f; color: #d9534f; }
.poi.seam { color: #ffcc33; font-size: 18px; text-shadow: 0 0 6px #000; }

/* Public marks in the AR view */
#ar.marks-mode #arHud, #ar.marks-mode #arHint { display: none; }
.armark { position: absolute; transform: translate(-50%, -50%); background: rgba(20, 24, 30, .78); color: #fff; border-radius: 12px;
  padding: 6px 10px; text-align: center; min-width: 70px; max-width: 160px; box-shadow: 0 2px 10px rgba(0,0,0,.4); }
.armark span { font-size: 30px; display: block; }
.armark small { display: block; font-size: 12px; }
.armark i { display: block; font-size: 10px; opacity: .7; }
.armark.mine { outline: 2px solid #4caf50; }
.armark-title { position: absolute; top: max(56px, 9%); left: 50%; transform: translateX(-50%); color: #fff; font-weight: 600;
  background: rgba(0,0,0,.5); padding: 4px 12px; border-radius: 999px; }
