:root {
  --bg: #101418;
  --panel: #1a2129;
  --edge: #2c3844;
  --text: #e8eef4;
  --dim: #93a4b3;
  --accent: #d8890b;
  --danger: #d64545;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Segoe UI", sans-serif;
}

button {
  background: var(--edge);
  color: var(--text);
  border: 1px solid #3d4c5c;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 14px;
}
button:hover { background: #38465a; }
button.tiny { padding: 1px 6px; font-size: 11px; color: var(--dim); }
/* touch devices need real tap targets */
@media (pointer: coarse) {
  button.tiny { padding: 6px 10px; font-size: 13px; }
}

.error { color: var(--danger); font-weight: 600; }
.room > .error {
  position: sticky; top: 0; z-index: 90;
  background: var(--panel); border: 1px solid var(--danger); border-radius: 8px;
  padding: 6px 10px; margin: 0 0 8px;
}
.error a { color: var(--text); }

/* ---- lobby ---- */
.lobby { max-width: 560px; margin: 6vh auto; padding: 0 16px; }
.lobby h1 { color: var(--accent); margin-bottom: 0; }
.tagline { color: var(--dim); margin-top: 4px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 16px;
  margin: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.panel h2 { margin: 0; font-size: 16px; }
.panel label { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.panel input, .panel select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--edge);
  border-radius: 6px;
  padding: 6px 8px;
}
.lobby footer { color: var(--dim); font-size: 11px; margin-top: 24px; line-height: 1.5; }
.lobby footer a { color: var(--dim); }

/* ---- room ---- */
.room { padding: 12px; }
.room-header {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: baseline; margin-bottom: 12px;
}
.badge {
  background: var(--accent); color: #1c1206; border-radius: 5px;
  padding: 2px 8px; font-size: 12px; font-weight: 700; text-transform: uppercase;
}
.code { color: var(--dim); }
.me { margin-left: auto; color: var(--dim); }

.table-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); }
.table-grid.seats-2 { grid-template-columns: 1fr 1fr; }
.table-grid.seats-5, .table-grid.seats-6 { grid-template-columns: repeat(3, 1fr); }

/* spotlight: one enlarged tile, the rest as a thumbnail strip (client-side) */
.table-grid.spotlight { grid-template-columns: 1fr 230px; align-content: start; }
.table-grid.spotlight .seat:not(.spot) { grid-column: 2; }
.table-grid.spotlight .seat:not(.spot) .counters,
.table-grid.spotlight .seat:not(.spot) .zone-editor,
.table-grid.spotlight .seat:not(.spot) .cam-panel { display: none; }
.table-grid.spotlight .seat.spot { grid-column: 1; grid-row: 1 / span 6; }

.seat {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 10px;
  overflow: hidden;
}
.seat.mine { border-color: var(--accent); }

.video-slot {
  aspect-ratio: 16 / 9;
  background: #000;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.video-slot video { width: 100%; height: 100%; object-fit: cover; }
.video-placeholder { color: var(--dim); font-size: 13px; padding: 0 12px; text-align: center; }
.overlay-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
}
.hover-zoom {
  position: fixed; z-index: 50; width: 244px; border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .6); pointer-events: none;
}

.nameplate {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--edge);
}
.pname { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.team { color: var(--dim); font-size: 12px; margin-left: auto; }

.counters { padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
.counter { display: flex; align-items: center; gap: 6px; }
.counter.life .value {
  font-size: 26px; font-weight: 700; min-width: 52px; text-align: center;
}
.counter.small { color: var(--dim); font-size: 13px; }
.counter.small button { padding: 0 7px; font-size: 12px; }

.cmdr summary { cursor: pointer; color: var(--dim); font-size: 13px; }
.cmdr-row { display: flex; gap: 6px; align-items: center; font-size: 13px; padding: 2px 0; }

/* ---- sidebar ---- */
.room-body { display: flex; gap: 12px; align-items: flex-start; }
.room-body .table-grid { flex: 1; }
.sidebar {
  width: 300px; flex-shrink: 0;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 10px;
  max-height: calc(100vh - 80px); overflow-y: auto;
}
.tabs { display: flex; border-bottom: 1px solid var(--edge); }
.tabs button {
  flex: 1; border: none; border-radius: 0; background: none; color: var(--dim);
  padding: 8px 0;
}
.tabs button.active { color: var(--text); border-bottom: 2px solid var(--accent); }
.tab-body { padding: 10px; }
.tab-body h3 { font-size: 13px; color: var(--dim); margin: 10px 0 4px; }
.tab-body input {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--edge); border-radius: 6px; padding: 6px 8px;
}
.card-list { list-style: none; margin: 6px 0; padding: 0; }
.card-list li {
  padding: 5px 4px; border-bottom: 1px solid var(--edge); font-size: 13px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
}
.card-list li.departed { opacity: .45; }
.cname { font-weight: 600; cursor: default; }
.cname.unknown { color: var(--danger); font-weight: 400; }
.ctype { color: var(--dim); font-size: 12px; width: 100%; }
.zone-chip {
  background: var(--edge); border-radius: 4px; padding: 0 6px;
  font-size: 11px; color: var(--dim);
}

/* ---- zone-area editor (drag rectangles on your own camera) ---- */
button.tiny.active { color: var(--accent); border-color: var(--accent); }
.zone-editor {
  padding: 6px 8px; background: var(--panel);
  border-top: 1px dashed var(--edge); font-size: 12px;
}
.zone-editor .hint { margin: 0 0 6px; color: var(--dim); font-size: 11px; }
.zone-palette { display: flex; flex-wrap: wrap; gap: 4px; }
.zone-btn {
  padding: 1px 8px; font-size: 11px; border-radius: 10px;
  border: 1.5px solid var(--zc); color: var(--zc); background: transparent;
}
.zone-btn:hover { background: var(--edge); }
.zone-btn.active { background: var(--zc); color: var(--bg); font-weight: 600; }
.zone-region-list { list-style: none; margin: 6px 0 0; padding: 0; }
.zone-region-list li {
  display: flex; align-items: center; gap: 6px; padding: 1px 0; color: var(--dim);
}
.zone-dot {
  width: 10px; height: 10px; border-radius: 3px;
  background: var(--zc); display: inline-block;
}

/* ---- small screens (phones join via the QR invite) ---- */
@media (max-width: 900px) {
  .room-body { flex-direction: column; }
  .sidebar { width: 100%; max-height: 45vh; }
  .table-grid, .table-grid.seats-5, .table-grid.seats-6 {
    grid-template-columns: 1fr 1fr;
  }
}
@media (max-width: 560px) {
  .table-grid, .table-grid.seats-5, .table-grid.seats-6 {
    grid-template-columns: 1fr;
  }
}

/* ---- recording & replay ---- */
.rec-chip {
  background: var(--danger); color: #fff; border-radius: 10px;
  padding: 1px 8px; font-size: 11px; font-weight: 700; white-space: nowrap;
  animation: mh-rec 2s ease-in-out infinite;
}
@keyframes mh-rec { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
.replay-page .digital-slot { background: #131f19; }
.replay-controls {
  display: flex; align-items: center; gap: 8px; padding: 8px 0;
}
.replay-controls input[type=range] { flex: 1; accent-color: var(--accent); }
.tiny-select {
  background: var(--edge); color: var(--text); border: 1px solid #3d4c5c;
  border-radius: 6px; font-size: 11px; padding: 1px 4px;
}
.tiny-link { color: var(--dim); font-size: 12px; }
.rcam-wrap {
  aspect-ratio: 16 / 9; background: #000; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
/* while drawing zone rectangles, the finger must not scroll the page */
.seat.zone-editing .video-slot { touch-action: none; }
.rcam { width: 100%; height: 100%; object-fit: cover; display: none; }
.rlife { margin-left: auto; font-weight: 700; color: var(--accent); }
.rside-h { margin: 10px 10px 4px; font-size: 13px; color: var(--accent); }
.ranalytics { padding: 0 10px 12px; font-size: 12px; }
.ranalytics .rstat { margin: 8px 0; color: var(--dim); }
.ranalytics .rstat strong { color: var(--text); }
.life-chart {
  width: 100%; background: var(--bg); border: 1px solid var(--edge);
  border-radius: 8px;
}

/* ---- digital table view ---- */
.view-seg { display: inline-flex; gap: 2px; }
.view-seg .tiny.active { color: var(--accent); border-color: var(--accent); }
.digital-slot { display: none; position: relative; background: #131f19; }
.view-digital .digital-slot, .view-both .digital-slot { display: block; }
.view-digital .video-slot {
  height: 0; min-height: 0; aspect-ratio: auto; overflow: hidden;
}
.table-grid.spotlight .seat:not(.spot) .digital-slot { display: none; }
.dfield {
  position: relative; aspect-ratio: 16 / 9; overflow: hidden;
  background: radial-gradient(ellipse at center, #1c3126 0%, #131f19 100%);
}
.dcard { position: absolute; cursor: pointer; }
.dcard img {
  width: 100%; display: block; border-radius: 5.5% / 4%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .55);
}
.dcard.unknown {
  aspect-ratio: 63 / 88; background: #2c3844; border: 1px dashed #55636f;
  border-radius: 6px; color: var(--dim);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.dcard.pinged { outline: 3px solid var(--accent); border-radius: 6px; }
.dcnt {
  position: absolute; top: -7px; right: -7px; z-index: 2;
  background: var(--accent); color: var(--bg); border-radius: 50%;
  min-width: 18px; height: 18px; padding: 0 3px; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.dpiles { display: flex; gap: 10px; padding: 6px 8px; min-height: 16px; }
.dpile { position: relative; cursor: pointer; text-align: center; }
.dpile-top { width: 42px; min-height: 20px; color: var(--dim); }
.dpile-top img { width: 100%; border-radius: 4px; display: block; }
.dpile-label { font-size: 10px; color: var(--dim); white-space: nowrap; }
.dpile-panel {
  position: absolute; bottom: calc(100% + 4px); left: 0; z-index: 40;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 8px;
  padding: 8px; display: flex; flex-wrap: wrap; gap: 6px;
  width: max-content; max-width: 330px; max-height: 300px; overflow-y: auto;
}
.dpile-item { color: var(--dim); }
.dpile-item img { width: 70px; border-radius: 4px; display: block; }
.dmenu {
  position: fixed; z-index: 80;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 8px;
  padding: 6px; display: flex; flex-direction: column; gap: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .5);
}
.dmenu-row { display: flex; gap: 3px; }
.ping-ring {
  position: absolute; z-index: 6; width: 26px; height: 26px;
  margin: -13px 0 0 -13px; border: 3px solid var(--accent); border-radius: 50%;
  pointer-events: none; animation: mh-ping 1.5s ease-out forwards;
}
@keyframes mh-ping {
  0% { transform: scale(.6); opacity: 1; }
  100% { transform: scale(2.6); opacity: 0; }
}

/* ---- turns, KO, dice, quick life edit ---- */
.turn-chip {
  background: var(--edge); border-radius: 10px; padding: 1px 10px;
  font-size: 12px; color: var(--accent); white-space: nowrap;
}
.seat.active-turn { box-shadow: 0 0 0 2px var(--accent); border-radius: 8px; }
.seat.dead .video-slot { filter: grayscale(1) brightness(.55); }
.seat.dead .pname { text-decoration: line-through; color: var(--dim); }
.skull { color: var(--danger); }
.cmdr-names { color: var(--dim); font-size: 11px; font-style: italic; }
.cmdr-form { display: flex; gap: 4px; margin-top: 4px; }
.cmdr-form input { flex: 1; min-width: 0; }
.cnt-chip {
  background: var(--accent); color: var(--bg); border-radius: 8px;
  padding: 0 6px; font-size: 11px; font-weight: 700;
}
.cnt-buttons { display: flex; gap: 2px; }
.tab-badge {
  background: var(--accent); color: var(--bg); border-radius: 8px;
  padding: 0 5px; font-size: 10px; font-weight: 700;
}
.value.editable { cursor: pointer; }
.value.editable:hover { color: var(--accent); }
.life-form { display: inline; }
.life-input {
  width: 3.6em; background: var(--edge); color: var(--text);
  border: 1px solid var(--accent); border-radius: 6px; font-size: 14px;
  text-align: center; padding: 1px 2px;
}
.dice-row {
  display: flex; align-items: center; gap: 4px; padding: 6px 10px;
  border-bottom: 1px solid var(--edge); flex-wrap: wrap;
}
.dice-row .hint { font-size: 11px; color: var(--dim); }
button.tiny.danger { color: var(--danger); border-color: var(--danger); }

/* ---- invite (header) ---- */
.qr-pop { position: relative; display: inline-block; }
.qr-pop summary {
  cursor: pointer; list-style: none; font-size: 11px; color: var(--dim);
  border: 1px solid #3d4c5c; border-radius: 6px; padding: 1px 6px;
}
.qr-pop[open] summary { color: var(--accent); border-color: var(--accent); }
.qr-body {
  position: absolute; top: 26px; left: 0; z-index: 60;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 8px;
  padding: 10px; display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.qr-body img { display: block; }
.qr-body .hint { font-size: 10px; color: var(--dim); white-space: nowrap; }

/* ---- A/V state ---- */
button.av-btn.active { color: var(--danger); border-color: var(--danger); }
.recog-dot {
  position: absolute; bottom: 6px; right: 6px; z-index: 5;
  width: 8px; height: 8px; border-radius: 50%;
  background: #5a6672; pointer-events: none;
}
.recog-dot.live { background: #3fa66a; }
.av-badge {
  position: absolute; top: 6px; right: 6px; z-index: 5;
  background: rgba(10, 14, 18, .8); color: var(--text);
  border-radius: 6px; padding: 2px 7px; font-size: 13px; pointer-events: none;
}
.dev-label { display: flex; align-items: center; gap: 6px; width: 100%; }
.dev-label select {
  flex: 1; min-width: 0; background: var(--edge); color: var(--text);
  border: 1px solid #3d4c5c; border-radius: 6px; padding: 2px 4px; font-size: 11px;
}

/* ---- camera panel (rotation + recognition tuning) ---- */
.cam-panel {
  padding: 6px 8px; background: var(--panel);
  border-top: 1px dashed var(--edge); font-size: 12px;
}
.cam-panel .hint { color: var(--dim); font-size: 11px; margin: 0; }
.cam-row { display: flex; align-items: center; gap: 8px; margin: 2px 0; }
.cam-form label { display: block; margin: 6px 0 2px; color: var(--text); }
.cam-form input[type=range] { width: 100%; accent-color: var(--accent); }
.cam-form input[type=checkbox] { accent-color: var(--accent); }
.zone-buttons { margin-left: auto; display: flex; gap: 2px; }
.fix-form { display: flex; gap: 4px; width: 100%; }
.fix-form input[name=name] { flex: 1; }
.log-list { list-style: none; margin: 8px 0; padding: 0; font-size: 12px; }
.log-list li { padding: 3px 0; border-bottom: 1px solid var(--edge); }
.ltime { color: var(--dim); margin-right: 6px; }

/* ---- combat ---- */
.combat-banner { color: var(--accent); font-weight: 600; }
button.danger { border-color: var(--danger); color: var(--danger); }
.attack-btn { border-color: var(--accent); color: var(--accent); }
.combat-panel { padding: 10px; border-bottom: 2px solid var(--accent); }
.combat-panel h3 { margin: 0 0 4px; font-size: 14px; color: var(--accent); }
.combat-panel .hint { font-size: 12px; color: var(--dim); margin: 0 0 6px; }
.arrow-layer {
  position: fixed; inset: 0; width: 100vw; height: 100vh;
  pointer-events: none; z-index: 40;
}
.arrow-layer .arrow {
  fill: none; stroke: var(--danger); stroke-width: 3.5; opacity: .85;
  stroke-linecap: round;
}
.arrow-layer .arrow.blocked { stroke-dasharray: 8 6; opacity: .6; }
.arrow-layer .arrow-head { fill: var(--danger); opacity: .9; }
.arrow-layer .arrow-head.blocked { opacity: .55; }
.arrow-layer .block-line {
  stroke: #4d9be6; stroke-width: 3; opacity: .85; stroke-linecap: round;
}
