/* Below / Above – client styles. Minimal, typographic, art-installation tone. */

:root {
  --ink: #f4f0e8;
  --ink-dim: rgba(244, 240, 232, 0.62);
  --ink-faint: rgba(244, 240, 232, 0.28);
  --scrim: rgba(12, 12, 14, 0.62);
  --scrim-strong: rgba(10, 10, 12, 0.86);
  --accent: #f2c14e;
  --error: #ff8a7a;
  --hud: rgba(226, 236, 230, 0.88);
  --hud-dim: rgba(226, 236, 230, 0.5);
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --serif: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #121214;
  color: var(--ink);
  font-family: var(--mono);
  font-weight: 300;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---------- stage ---------- */
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; outline: none; transition: filter 1.2s ease; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

body.lost #stage canvas { filter: grayscale(0.9) contrast(0.82) brightness(1.08); }
body.mode-drone #stage canvas { cursor: none; }

#flash {
  position: fixed; inset: 0; background: #fffdf6; opacity: 0;
  pointer-events: none; z-index: 30;
}

/* ---------- screens / panels ---------- */
.screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(180deg, rgba(12,12,14,0.35) 0%, var(--scrim) 60%, rgba(12,12,14,0.8) 100%);
  overflow-y: auto;
}
#screen-debrief { background: var(--scrim-strong); align-items: flex-start; }
#screen-disconnected { background: var(--scrim-strong); z-index: 40; }

.panel { width: 100%; max-width: 560px; margin: auto 0; }
.panel.lobby { max-width: 640px; }
.panel.debrief { max-width: 680px; padding: 6vh 0; }
.panel.narrow { max-width: 460px; }

h1, h2, h3 { font-family: var(--serif); font-weight: 400; margin: 0; letter-spacing: 0.01em; }
h1 { font-size: clamp(56px, 11vw, 104px); line-height: 0.95; margin: 4px 0 18px; }
h2 { font-size: clamp(26px, 4.4vw, 38px); line-height: 1.15; }
em { font-family: var(--serif); font-style: italic; font-size: 1.12em; }

.kicker {
  margin: 0; font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-dim);
}
.intro { font-family: var(--serif); font-size: 21px; line-height: 1.4; color: var(--ink); margin: 0 0 26px; max-width: 34em; }
.hint { color: var(--ink-dim); font-size: 12px; margin: 10px 0; }
.error { color: var(--error); min-height: 1.5em; margin: 14px 0 0; font-size: 13px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.field { display: block; margin-bottom: 16px; }
.field .kicker { display: block; margin-bottom: 6px; }

input[type="text"] {
  font: inherit; font-weight: 400; color: var(--ink);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--ink-faint); border-radius: 0;
  padding: 10px 12px; min-width: 0; width: 100%;
  outline: none; transition: border-color 0.2s, background 0.2s;
}
input[type="text"]:focus { border-color: var(--ink); background: rgba(255,255,255,0.1); }
input::placeholder { color: var(--ink-faint); }
#code-input { width: 7.5em; flex: 0 0 auto; text-transform: uppercase; letter-spacing: 0.3em; text-align: center; }

button {
  font: inherit; font-size: 12px; font-weight: 400; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ink); background: transparent;
  border: 1px solid var(--ink-dim); border-radius: 0;
  padding: 10px 18px; cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
button:hover, button:focus-visible { background: var(--ink); color: #111; border-color: var(--ink); outline: none; }
button.primary { border-color: var(--ink); }
button:disabled { opacity: 0.4; cursor: default; background: transparent; color: var(--ink); }

.or { display: flex; align-items: center; gap: 12px; margin: 22px 0 14px; color: var(--ink-dim); font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--ink-faint); }

/* ---------- lobby ---------- */
.lobby-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin-bottom: 22px; }
.room-code { font-family: var(--serif); font-size: clamp(64px, 13vw, 112px); line-height: 0.9; letter-spacing: 0.08em; }
.invite { flex: 1 1 240px; max-width: 340px; }
.invite-row { display: flex; gap: 6px; margin-top: 6px; }
.invite-row input { font-size: 12px; padding: 8px 10px; }
.invite-row button { padding: 8px 12px; }

.list-head { display: flex; justify-content: space-between; border-bottom: 1px solid var(--ink-faint); padding-bottom: 6px; }
.players { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow-y: auto; }
.players li {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 4px; border-bottom: 1px solid rgba(244,240,232,0.08);
}
.players li.clickable { cursor: pointer; }
.players li.clickable:hover, .players li.clickable:focus-visible { background: rgba(255,255,255,0.06); outline: none; }
.swatch { width: 14px; height: 14px; border-radius: 50%; background: var(--c, #ccc); flex: 0 0 auto; box-shadow: 0 0 0 2px rgba(0,0,0,0.25); }
.pname { flex: 1; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; padding: 2px 6px; border: 1px solid var(--ink-faint); color: var(--ink-dim); margin-left: 4px; }
.badge.drone { border-color: var(--ink); color: #111; background: var(--ink); }
.badge.host { border-color: var(--accent); color: var(--accent); }
.lobby-actions { margin-top: 14px; }

/* ---------- shared HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#round-timer {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  font-size: 15px; letter-spacing: 0.2em; color: var(--ink);
  text-shadow: 0 1px 6px rgba(0,0,0,0.5);
}
#btn-endround {
  position: absolute; top: 40px; left: 50%; transform: translateX(-50%); pointer-events: auto;
  font-size: 12px; padding: 6px 10px; opacity: 0.75;
}
#btn-endround:hover { opacity: 1; }
body.mode-drone #round-timer { color: var(--hud); top: 18px; font-size: 13px; }
#toast {
  position: absolute; top: 46px; left: 50%; transform: translateX(-50%);
  font-size: 12px; color: var(--ink); background: rgba(0,0,0,0.45); padding: 4px 10px;
  opacity: 0; transition: opacity 0.4s;
}
#toast.show { opacity: 1; }

/* ---------- civilian HUD ---------- */
#hud-civ { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#civ-hint {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: var(--ink-dim); text-shadow: 0 1px 4px rgba(0,0,0,0.6);
  white-space: nowrap; transition: opacity 1.5s;
}
#civ-hint.faded { opacity: 0.25; }
#flower-count {
  position: absolute; top: 14px; left: 16px;
  font-size: 13px; letter-spacing: 0.08em; color: #ffd9ec;
  text-shadow: 0 1px 4px rgba(0,0,0,0.65), 0 0 10px rgba(255,120,200,0.35);
}
#flower-count.bump { animation: flower-bump 0.6s ease-out; }
@keyframes flower-bump { 0% { transform: scale(1); } 30% { transform: scale(1.35); color: #fff; } 100% { transform: scale(1); } }
.tag .name .fl { margin-left: 5px; font-weight: 600; color: #ffc6e4; font-size: 0.9em; }
.names .fl { color: #ffc6e4; opacity: 0.85; }
.flowers-line { font-family: var(--serif); font-style: italic; color: #ffd9ec; margin-top: 10px; }
#chat-log {
  position: absolute; left: 16px; bottom: 64px; width: min(420px, calc(100vw - 32px));
  display: flex; flex-direction: column; gap: 3px; font-size: 13px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.75);
}
#chat-log .line { transition: opacity 1.5s; }
#chat-log .line.old { opacity: 0; }
#chat-log .who { font-weight: 500; }
#chat-form { position: absolute; left: 16px; bottom: 26px; width: min(420px, calc(100vw - 32px)); pointer-events: auto; }
#chat-input { background: rgba(10,10,12,0.6); }
#lost-note {
  position: absolute; top: 48px; left: 50%; transform: translateX(-50%);
  font-family: var(--serif); font-style: italic; font-size: 19px; color: var(--ink);
  text-align: center; max-width: calc(100vw - 32px); text-shadow: 0 1px 8px rgba(0,0,0,0.5);
}

/* name tags and chat bubbles (CSS2D) */
.tag { position: relative; width: 0; height: 0; }
.tag-inner {
  position: absolute; bottom: 0; left: 0; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  white-space: nowrap; pointer-events: none;
}
.tag .name {
  font-size: 11px; font-weight: 400; color: #fff; letter-spacing: 0.04em;
  text-shadow: 0 1px 3px rgba(0,0,0,0.85);
  display: flex; align-items: center; gap: 5px;
}
.tag .name i { width: 7px; height: 7px; border-radius: 50%; background: var(--c, #ccc); display: inline-block; }
.tag.ghost .name { color: rgba(255,255,255,0.55); font-style: italic; }
.bubble {
  width: max-content; max-width: 220px; white-space: normal; text-align: center;
  font-size: 12px; line-height: 1.35; color: #1b1b1b;
  background: rgba(255,253,246,0.94); padding: 5px 9px; border-radius: 10px;
  position: relative; opacity: 0; transform: translateY(4px); transition: opacity 0.3s, transform 0.3s;
}
.bubble.show { opacity: 1; transform: none; }
.bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -5px; margin-left: -5px;
  border: 5px solid transparent; border-bottom: 0; border-top-color: rgba(255,253,246,0.94);
}

/* ---------- drone HUD ---------- */
#hud-drone { position: fixed; inset: 0; pointer-events: none; z-index: 10; color: var(--hud); }
.tele { position: absolute; margin: 0; font-family: var(--mono); font-size: 12px; line-height: 1.6; letter-spacing: 0.08em; color: var(--hud); white-space: pre; }
.tl { top: 22px; left: 26px; }
.tr { top: 22px; right: 26px; text-align: right; }
.bl { bottom: 22px; left: 26px; white-space: normal; max-width: 55vw; }
.br { bottom: 22px; right: 26px; color: var(--hud-dim); font-size: 11px; white-space: normal; text-align: right; max-width: 40vw; }
#drone-status.deny { animation: deny 0.5s steps(2) 2; }
@keyframes deny { 50% { color: #fff; background: rgba(255,255,255,0.15); } }

#frame-marks i { position: absolute; width: 28px; height: 28px; border-color: var(--hud-dim); border-style: solid; border-width: 0; }
#frame-marks i:nth-child(1) { top: 12px; left: 12px; border-top-width: 1px; border-left-width: 1px; }
#frame-marks i:nth-child(2) { top: 12px; right: 12px; border-top-width: 1px; border-right-width: 1px; }
#frame-marks i:nth-child(3) { bottom: 12px; left: 12px; border-bottom-width: 1px; border-left-width: 1px; }
#frame-marks i:nth-child(4) { bottom: 12px; right: 12px; border-bottom-width: 1px; border-right-width: 1px; }

#crosshair { position: absolute; left: 0; top: 0; width: 60px; height: 60px; margin: -30px 0 0 -30px; will-change: transform; }
#crosshair svg { overflow: visible; }
#crosshair path { stroke: var(--hud); stroke-width: 1; fill: none; }
#crosshair circle { fill: var(--hud); }

#lockbox { position: absolute; left: 0; top: 0; width: 68px; height: 68px; margin: -34px 0 0 -34px; will-change: transform; }
#lockbox svg { overflow: visible; }
#lockbox .corners { stroke: #fff; stroke-width: 1.5; fill: none; }
#lockbox .ring-bg { stroke: rgba(255,255,255,0.15); stroke-width: 2; fill: none; }
#lockbox .ring { stroke: #fff; stroke-width: 3; fill: none; stroke-dasharray: 188.5; stroke-dashoffset: 188.5; transform: rotate(-90deg); }
#lock-label { position: absolute; left: 50%; top: 100%; transform: translateX(-50%); margin-top: 6px; font-size: 10px; letter-spacing: 0.2em; white-space: nowrap; }

#drone-countdown {
  position: absolute; top: 30%; left: 50%; transform: translate(-50%, -50%);
  font-size: 28px; letter-spacing: 0.3em; color: #fff;
}

/* ---------- debrief ---------- */
.debrief section { margin: 0 0 30px; }
.debrief h2 { margin: 6px 0 10px; }
.debrief .names { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 4px 18px; }
.debrief .names li { font-family: var(--serif); font-size: 26px; line-height: 1.25; }
.debrief .names.survivors li { font-size: 18px; color: var(--ink-dim); }
.debrief .names.survivors li span { color: var(--c); }
.debrief .stats { display: flex; flex-wrap: wrap; gap: 8px 28px; color: var(--ink-dim); font-size: 12px; letter-spacing: 0.08em; border-top: 1px solid var(--ink-faint); padding-top: 14px; }
.debrief .stats b { color: var(--ink); font-weight: 400; }
.debrief .reflect { font-family: var(--serif); font-style: italic; font-size: 22px; line-height: 1.45; margin: 0; }
.debrief .credit { color: var(--ink-dim); font-size: 12px; margin-top: 10px; }
.debrief .divider { width: 40px; height: 1px; background: var(--ink-faint); margin: 30px 0; }

.noscript { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  html, body { font-size: 13px; }
  .intro { font-size: 18px; }
  #civ-hint { white-space: normal; text-align: center; width: calc(100vw - 32px); }
  .tele { font-size: 10px; }
  .tl, .bl { left: 16px; }
  .tr, .br { right: 16px; }
  .br { display: none; }
  .debrief .names li { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  #stage canvas, .bubble, #chat-log .line { transition: none; }
}
.credit a, .kicker a { color: inherit; text-decoration: underline; text-underline-offset: 3px; }
.credit a:hover, .kicker a:hover { color: var(--ink); }
