:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #141821;
  --panel-2: #1b2030;
  --line: #262c3d;
  --text: #eef0f6;
  --text-2: #c7ccd9;
  --muted: #8b93a7;
  --amber-text: #ffc21a;
  --amber-line: #5c4a10;
  --red: #ff4d4d;
  --red-text: #ff8f8f;
  --red-line: #5a2630;
  --green: #2fd17a;
  --green-line: #1d5c3a;
  --blue: #2f9bff;
  --glass: #0b0d12e6;
  --map-bg: #0f1218;
  --pill-lobby: #2a3043;
  --ring: #ffffff14;
  --shadow: #0008;
  --scrim: #000b;
  --curse-a: #2a0f16;
  --curse-b: #160a10;
  --curse-stripe-1: #3a0d12;
  --curse-stripe-2: #2a080c;
  --curse-edge: #6b1b25;
  --on-green: #022312;
  --on-red: #2a0303;
  --amber: #ffc21a;
  --amber-ink: #1a1400;
  --radius: 14px;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sans: 'Instrument Sans', system-ui, -apple-system, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
/* Light theme: follows the phone unless the player picks one (html[data-theme]). */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f5f8;
    --panel: #ffffff;
    --panel-2: #eceef3;
    --line: #d9dce5;
    --text: #161922;
    --text-2: #3d4352;
    --muted: #5f6678;
    --amber-text: #8a5f00;
    --amber-line: #e6c35c;
    --red: #d92d2d;
    --red-text: #b42323;
    --red-line: #f0b8bd;
    --green: #138a4b;
    --green-line: #9fdcbb;
    --blue: #1f7ae0;
    --glass: #ffffffeb;
    --map-bg: #e5e7ec;
    --pill-lobby: #dde1ea;
    --ring: #00000014;
    --shadow: #0003;
    --scrim: #0007;
    --curse-a: #fff1f2;
    --curse-b: #ffe4e6;
    --curse-stripe-1: #ffe1e4;
    --curse-stripe-2: #ffd2d7;
    --curse-edge: #f0b8bd;
    --on-green: #ffffff;
    --on-red: #ffffff;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #eceef3;
  --line: #d9dce5;
  --text: #161922;
  --text-2: #3d4352;
  --muted: #5f6678;
  --amber-text: #8a5f00;
  --amber-line: #e6c35c;
  --red: #d92d2d;
  --red-text: #b42323;
  --red-line: #f0b8bd;
  --green: #138a4b;
  --green-line: #9fdcbb;
  --blue: #1f7ae0;
  --glass: #ffffffeb;
  --map-bg: #e5e7ec;
  --pill-lobby: #dde1ea;
  --ring: #00000014;
  --shadow: #0003;
  --scrim: #0007;
  --curse-a: #fff1f2;
  --curse-b: #ffe4e6;
  --curse-stripe-1: #ffe1e4;
  --curse-stripe-2: #ffd2d7;
  --curse-edge: #f0b8bd;
  --on-green: #ffffff;
  --on-red: #ffffff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 16px; -webkit-tap-highlight-color: transparent; }
body { overscroll-behavior: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.2em; margin: 0; font-size: .9rem; }
h2 { font-family: var(--mono); font-size: .8rem; letter-spacing: .14em; text-transform: uppercase; color: var(--amber-text); margin: 26px 0 10px; }
h2:first-child { margin-top: 4px; }
h3 { margin: 0 0 4px; font-size: 1.05rem; }
a { color: var(--amber-text); }
input, select, textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 12px; font: inherit; margin-top: 6px;
}
textarea { min-height: 80px; resize: none; max-height: 50vh; overflow-y: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--amber); outline-offset: 0; border-color: transparent; }
label { display: block; font-size: .85rem; color: var(--muted); font-weight: 500; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.row.tight > * { flex: 0 0 auto; }
.check { display: flex; gap: 10px; align-items: center; color: var(--text); font-size: .95rem; }
.check input { width: 20px; height: 20px; margin: 0; flex: 0 0 auto; accent-color: var(--amber-text); }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font: 600 .95rem var(--sans); padding: 11px 16px; border-radius: 10px; cursor: pointer; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--amber); color: var(--amber-ink); border-color: var(--amber-text); }
.btn.danger { background: transparent; color: var(--red); border-color: var(--red-line); }
.btn.good { background: var(--green); color: var(--on-green); border-color: var(--green); }
.btn.bad { background: var(--red); color: var(--on-red); border-color: var(--red); }
.btn.small { padding: 7px 11px; font-size: .82rem; border-radius: 8px; }
.btn.big { width: 100%; padding: 15px; font-size: 1.05rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; font: inherit; cursor: pointer; padding: 8px; }

/* ---------- join ---------- */
.screen { min-height: 100%; }
#join { display: grid; place-items: center; padding: 24px 16px; }
.join-card { width: 100%; max-width: 380px; text-align: center; }
.join-card form { text-align: left; margin-top: 28px; }
.board-title { display: flex; justify-content: center; gap: 4px; margin-bottom: 18px; }
.board-title span {
  font: 800 1.7rem var(--mono); color: #ffc21a; background: #121620; width: 1.45em; height: 1.85em;
  display: grid; place-items: center; border-radius: 5px; position: relative; box-shadow: inset 0 -1px 0 #000;
  animation: flip .6s cubic-bezier(.3,.7,.4,1) both;
}
.board-title span::after { content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: #000; }
.board-title span.gap { background: none; width: .5em; box-shadow: none; }
.board-title span.gap::after { display: none; }
.board-title span:nth-child(2) { animation-delay: .06s } .board-title span:nth-child(3) { animation-delay: .12s }
.board-title span:nth-child(4) { animation-delay: .18s } .board-title span:nth-child(6) { animation-delay: .24s }
.board-title span:nth-child(7) { animation-delay: .3s } .board-title span:nth-child(8) { animation-delay: .36s }
.board-title span:nth-child(9) { animation-delay: .42s }
@keyframes flip { from { transform: rotateX(90deg); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---------- app shell ---------- */
#app { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-t)) 16px 10px; background: var(--bg); border-bottom: 1px solid var(--line); z-index: 5;
}
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.team-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; box-shadow: 0 0 0 3px var(--ring); }
.who-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-sub { font-size: .78rem; color: var(--muted); font-family: var(--mono); }
.cash { font: 800 1.5rem var(--mono); color: var(--amber-text); letter-spacing: -.02em; }
main { flex: 1; position: relative; overflow: hidden; }
.view { position: absolute; inset: 0; overflow-y: auto; padding: 16px 16px 40px; -webkit-overflow-scrolling: touch; }
#view-map { padding: 0; overflow: hidden; }
#map { position: absolute; inset: 0; background: var(--map-bg); }

.tabs {
  display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); z-index: 5;
}
.tabs button {
  flex: 1; background: none; border: 0; color: var(--muted); padding: 9px 2px 8px; font: 600 .68rem var(--sans);
  display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; cursor: pointer;
}
.tabs button i { font-style: normal; font-size: 1.15rem; line-height: 1.2; }
.tabs button.active { color: var(--amber-text); }
.badge { position: absolute; top: 4px; left: calc(50% + 6px); background: var(--red); color: #fff; font: 700 .65rem var(--mono); border-radius: 9px; padding: 2px 5px; }

.curse-banner { background: repeating-linear-gradient(-45deg, var(--curse-stripe-1), var(--curse-stripe-1) 12px, var(--curse-stripe-2) 12px, var(--curse-stripe-2) 24px); border-bottom: 1px solid var(--curse-edge); padding: 10px 16px; }
.curse-banner .c { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.curse-banner .c + .c { margin-top: 8px; }
.curse-banner strong { color: var(--red-text); font-family: var(--mono); text-transform: uppercase; letter-spacing: .08em; font-size: .8rem; }
.curse-banner p { margin: 2px 0 0; font-size: .9rem; }
.timer { font: 800 1.2rem var(--mono); color: var(--text); }
.status-banner { background: var(--amber); color: var(--amber-ink); padding: 9px 16px; font-weight: 700; text-align: center; font-size: .92rem; }

/* ---------- map ---------- */
.leaflet-container { font-family: var(--sans); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); border: 1px solid var(--line); }
.leaflet-popup-content { margin: 12px 14px; font-size: .9rem; line-height: 1.45; }
.leaflet-control-attribution { background: var(--glass) !important; color: var(--muted) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.pmark { display: flex; flex-direction: column; align-items: center; }
.pmark .dot {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #0b0d12;
  font: 800 .78rem var(--mono); border: 3px solid var(--bg); box-shadow: 0 2px 10px var(--shadow);
}
.pmark .tag { margin-top: 3px; background: var(--glass); color: var(--text); font: 700 .66rem var(--mono); padding: 2px 6px; border-radius: 6px; white-space: nowrap; }
.pmark.stale .dot { opacity: .45; filter: grayscale(.6); }
.pmark .tag.low { color: var(--red); }
.flag { font-size: 30px; filter: drop-shadow(0 2px 4px #000a); }
.pin { width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--amber); border: 3px solid var(--bg); }
.map-legend {
  position: absolute; top: 10px; left: 10px; right: 64px; z-index: 500; display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none;
}
.map-legend .chip { pointer-events: auto; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--glass); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 10px; font-size: .78rem; font-weight: 600; backdrop-filter: blur(6px); cursor: pointer;
}
.chip .sw { width: 9px; height: 9px; border-radius: 50%; }
.map-tools { position: absolute; right: 10px; top: 10px; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.fab {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--glass); color: var(--text);
  font-size: 1.25rem; cursor: pointer; backdrop-filter: blur(6px);
}
.fab.on { color: var(--green); border-color: var(--green-line); }

/* ---------- cards ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card + .card { margin-top: 10px; }
.card.dim { opacity: .55; }
.card-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.card p { margin: 6px 0 0; color: var(--text-2); font-size: .93rem; line-height: 1.45; }
.reward { font: 800 1.15rem var(--mono); color: var(--amber-text); white-space: nowrap; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag-s { font: 700 .66rem var(--mono); text-transform: uppercase; letter-spacing: .06em; padding: 4px 7px; border-radius: 6px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.tag-s.curse { color: var(--red-text); border-color: var(--red-line); }
.tag-s.pending { color: var(--amber-text); border-color: var(--amber-line); }
.tag-s.done { color: var(--green); border-color: var(--green-line); }
.card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.team-status { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.ts { display: inline-flex; align-items: center; gap: 5px; font-size: .75rem; padding: 3px 8px; border-radius: 999px; background: var(--panel-2); }
.ts.approved { color: var(--green); } .ts.pending { color: var(--amber-text); } .ts.todo { color: var(--muted); }

.big-cash { font: 800 3rem var(--mono); color: var(--amber-text); letter-spacing: -.03em; line-height: 1; }
.member { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.member:last-child { border-bottom: 0; }
.batt { font: 700 .82rem var(--mono); }
.batt.low { color: var(--red); } .batt.mid { color: var(--amber-text); } .batt.ok { color: var(--green); }
.ledger-row { display: flex; justify-content: space-between; gap: 12px; font-size: .88rem; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.ledger-row b { font-family: var(--mono); }
.plus { color: var(--green); } .minus { color: var(--red); }

.curse-card { background: linear-gradient(160deg, var(--curse-a), var(--curse-b)); border-color: var(--red-line); }
.curse-card h3 { color: var(--red-text); }

.media { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; margin-top: 10px; }
.media img, .media video { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: #000; cursor: pointer; }
.tally { display: flex; gap: 14px; font: 700 .85rem var(--mono); margin-top: 10px; color: var(--muted); }
.tally .y { color: var(--green); } .tally .n { color: var(--red); }

.feed-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.feed-item time { font: 500 .75rem var(--mono); color: var(--muted); flex: 0 0 48px; padding-top: 2px; }
.feed-item .sw { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: 0 0 auto; }

.copy-box { font: 500 .8rem var(--mono); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; word-break: break-all; user-select: all; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: .88rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-family: var(--mono); word-break: break-all; }
.steps { padding-left: 20px; line-height: 1.6; color: var(--text-2); }
.steps li + li { margin-top: 6px; }

#adminMap { height: 260px; border-radius: 12px; margin-top: 10px; border: 1px solid var(--line); }
.seg { display: flex; background: var(--panel-2); border-radius: 10px; padding: 3px; border: 1px solid var(--line); }
.seg button { flex: 1; background: none; border: 0; color: var(--muted); padding: 8px; border-radius: 8px; font: 600 .85rem var(--sans); cursor: pointer; }
.seg button.on { background: var(--amber); color: var(--amber-ink); }
.admin-list .item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.admin-list .item .grow { flex: 1; min-width: 0; }
.admin-list .item .sub { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.admin-list select { width: auto; margin: 0; padding: 7px; }
.status-pill { font: 800 .8rem var(--mono); padding: 5px 10px; border-radius: 999px; text-transform: uppercase; letter-spacing: .08em; }
.status-pill.lobby { background: var(--pill-lobby); } .status-pill.active { background: var(--green); color: var(--on-green); } .status-pill.finished { background: var(--amber); color: var(--amber-ink); }
details summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 8px 0; }

/* ---------- modal + toast ---------- */
.modal { position: fixed; inset: 0; background: var(--scrim); z-index: 2000; display: flex; align-items: flex-end; justify-content: center; }
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px 20px 0 0; width: 100%; max-width: 560px;
  max-height: 92dvh; overflow-y: auto; padding: 22px 18px calc(22px + var(--safe-b)); position: relative; animation: up .22s ease-out;
}
@media (min-width: 700px) { .modal { align-items: center; } .modal-card { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0 } to { transform: none; opacity: 1 } }
.modal-close { position: absolute; top: 10px; right: 12px; background: none; border: 0; color: var(--muted); font-size: 1.8rem; cursor: pointer; line-height: 1; padding: 4px 8px; }
.modal-card h3 { font-size: 1.25rem; margin-bottom: 6px; padding-right: 30px; }
.progress { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--amber); transition: width .2s; }
.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%); z-index: 3000;
  background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-weight: 600; font-size: .9rem; max-width: 90vw; box-shadow: 0 8px 30px var(--shadow);
}
.toast.err { background: var(--red); color: #fff; }
.lightbox { position: fixed; inset: 0; background: #000; z-index: 4000; display: grid; place-items: center; }
.lightbox img, .lightbox video { max-width: 100vw; max-height: 100dvh; }

/* ---------- design workshop ---------- */
.dtabs { display: flex; gap: 22px; border-bottom: 1px solid var(--line); }
.dtabs button { background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; color: var(--muted); font: 600 .95rem var(--sans); padding: 10px 0; cursor: pointer; }
.dtabs button span { font: 500 .78rem var(--mono); opacity: .7; margin-left: 2px; }
.dtabs button.on { color: var(--text); border-bottom-color: var(--amber-text); }
.dbar { display: flex; justify-content: space-between; align-items: center; padding: 8px 0 2px; }
.dsort { background: none; border: 0; color: var(--muted); font: 500 .85rem var(--sans); padding: 6px 0; cursor: pointer; }
.drow { padding: 13px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.drow-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.drow-title { font-weight: 600; }
.drow-reward { font: 700 .9rem var(--mono); color: var(--amber-text); white-space: nowrap; }
.drow-desc { color: var(--muted); font-size: .87rem; line-height: 1.4; margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.drow-meta { display: flex; gap: 10px; align-items: center; margin-top: 7px; font-size: .78rem; color: var(--muted); flex-wrap: wrap; }
.drow-meta .facts { margin-left: auto; text-align: right; }
.drow-meta .hl, .drow-status .ok { color: var(--amber-text); font-weight: 600; }
.drow-status { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.drow-status .ok { color: var(--green); }
.drow-idea.dropped { color: var(--muted); text-decoration: line-through; }
.vote { background: none; border: 0; color: var(--muted); padding: 2px 0; font: 600 .78rem var(--sans); cursor: pointer; }
.vote.on.up { color: var(--green); }
.vote.on.down { color: var(--red); }
.idea-form { display: flex; gap: 8px; align-items: flex-end; padding: 10px 0 4px; }
.idea-form textarea { flex: 1; margin: 0; min-height: 44px; }
.dlog { margin-top: 18px; }
.dlog-item { font-size: .82rem; color: var(--muted); padding: 5px 0; }
.dlog-item b { color: var(--text); font-weight: 600; }
.small { font-size: .8rem; }
.ph { color: var(--text); font-weight: 600; }
.comment { border-top: 1px solid var(--line); padding: 9px 0; font-size: .9rem; }
.comment b { font-size: .82rem; }
.comment .muted { font-size: .74rem; }
.pin-banner { background: var(--panel-2); color: var(--text); border-bottom: 1px solid var(--line); font-weight: 600; }

.theme-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); font-size: 1rem; cursor: pointer; flex: 0 0 auto; }
