:root {
  color-scheme: dark;
  --bg: #12141a;
  --panel: #1b1e27;
  --glass: rgba(18, 20, 26, 0.84);
  --line: #2c313d;
  --text: #e8eaf0;
  --dim: #a3aabb;
  --accent: #3b5bdb;
  --accent-hi: #4c6ef5;
  --error: #ff8787;
  --gold: #ffd43b;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { overscroll-behavior: none; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 17px/1.45 var(--font); -webkit-text-size-adjust: 100%; overflow-wrap: anywhere;
}
body.playing { overflow: hidden; }
h1 { font-size: 30px; line-height: 1.2; margin: 0 0 8px; }
h2 { font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--dim); font-weight: 700; margin: 24px 0 8px; }
p { margin: 8px 0; }
.dim { color: var(--dim); }
.lead { font-size: 19px; color: var(--dim); margin-bottom: 24px; }
.hint { color: var(--dim); font-size: 15px; margin-top: 24px; }
.error { color: var(--error); font-weight: 600; min-height: 0; }
.error:empty { display: none; }

button, input { font: inherit; color: var(--text); }
button {
  min-height: 48px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line);
  background: #262a36; font-weight: 600; cursor: pointer; touch-action: manipulation;
}
button.primary { background: var(--accent); border-color: var(--accent); }
button.primary:hover:not(:disabled) { background: var(--accent-hi); }
button:disabled { opacity: 0.55; cursor: default; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
input {
  min-height: 48px; min-width: 0; flex: 1 1 auto; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); font-size: 17px;
}
label { display: block; color: var(--dim); margin-bottom: 6px; }
.row { display: flex; gap: 8px; align-items: stretch; }

.page { max-width: 560px; margin: 0 auto; padding: 24px 16px calc(32px + env(safe-area-inset-bottom)); }
.share { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--line); }
.share input { font-size: 15px; color: var(--dim); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 12px; border-bottom: 1px solid var(--line); }
.list li:first-child { border-top: 1px solid var(--line); }
.tag { font-size: 13px; font-weight: 700; color: var(--bg); background: var(--dim); border-radius: 6px; padding: 1px 7px; white-space: nowrap; }
.tag.host { background: var(--gold); }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 16px 0; }
.segmented { display: flex; gap: 6px; }
.segmented button { min-width: 52px; padding: 0 12px; }
.segmented button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }
#start, #rematch { width: 100%; margin-top: 8px; }

.swatch { flex: none; width: 14px; height: 14px; border-radius: 50%; background: var(--dim); }
.scores li { display: flex; align-items: center; gap: 8px; }
.scores .who { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scores .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.scores .you .who { font-weight: 700; }
.cards { list-style: none; margin: 0; padding: 0; }
.cards li { padding: 6px 0; border-top: 1px solid var(--line); }
.cards li:first-child { border-top: 0; }
.cards .card-name { font-weight: 700; }
.cards .left { color: var(--gold); font-variant-numeric: tabular-nums; font-size: 0.9em; margin-left: 6px; white-space: nowrap; }
.cards .card-desc { color: var(--dim); }
.cards .none { color: var(--dim); }
#end .list li .pts { margin-left: auto; }
#end .cards li { padding: 10px 0; }

/* The match. Nothing in it scrolls or zooms the page; only the scores and cards area may scroll itself. */
#match { position: fixed; inset: 0; overflow: hidden; background: var(--bg); touch-action: none; }
#match * { touch-action: none; }
#match .hud-side, #match .hud-side * { touch-action: pan-y; }
#stage { position: absolute; inset: 0; }
#arena {
  display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
.hud-top, .hud-side .panel {
  background: var(--glass); border: 1px solid var(--line); border-radius: 10px; pointer-events: none;
}
.hud-top, .hud-side { z-index: 1; }
.hud-top { padding: 6px 14px; }
.clock { font-size: 26px; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; white-space: nowrap; overflow-wrap: normal; }
.objective { font-size: 15px; line-height: 1.3; }
.hud-side { display: flex; gap: 8px; }
.hud-side .panel {
  width: clamp(150px, 22vw, 260px); max-height: calc(100vh - 16px); overflow: hidden; padding: 6px 10px 8px;
  font-size: 15px; line-height: 1.35;
}
.hud-side h2 { margin: 2px 0 4px; font-size: 12px; }
.hud-side .scores { list-style: none; margin: 0; padding: 0; }
.hud-side .scores li { padding: 2px 0; }

/* Landscape: the panels sit beside the arena, never over it. main.ts sets data-layout and the sizes from
   landscapeLayout in view.ts; the 8px here is HUD_GAP. */
@media (orientation: landscape) {
  #match[data-layout] { display: grid; grid-template-rows: auto minmax(0, 1fr); }
  #match[data-layout] #stage { position: relative; inset: auto; grid-row: 1 / -1; min-width: 0; min-height: 0; }
  #match[data-layout] .hud-top, #match[data-layout] .hud-side .panel { pointer-events: auto; }

  /* One column of panels on the right; the arena is letterboxed into the rest. */
  #match[data-layout="column"] { grid-template-columns: minmax(0, 1fr) calc(var(--side) + 8px); column-gap: 8px; row-gap: 8px; }
  #match[data-layout="column"] #stage { grid-column: 1; }
  #match[data-layout="column"] .hud-top { grid-column: 2; grid-row: 1; margin: 8px 8px 0 0; }
  #match[data-layout="column"] .hud-side {
    grid-column: 2; grid-row: 2; margin: 0 8px 8px 0; min-height: 0; overflow-y: auto; flex-direction: column;
  }
  #match[data-layout="column"] .hud-side .panel { width: auto; max-height: none; overflow: visible; flex: none; }

  /* The arena takes the full height; the clock and scores go in the bar on its left, the cards on its right. */
  #match[data-layout="bars"] { grid-template-columns: minmax(0, 1fr) var(--arena-w) minmax(0, 1fr); }
  #match[data-layout="bars"] #stage { grid-column: 2; }
  #match[data-layout="bars"] .hud-top { grid-column: 1; grid-row: 1; margin: 8px 8px 0; padding: 6px 10px; }
  #match[data-layout="bars"] .hud-side { display: contents; }
  #match[data-layout="bars"] .hud-side .panel {
    width: auto; min-width: 0; margin: 8px; align-self: start; max-height: calc(100% - 16px); overflow-y: auto;
  }
  #match[data-layout="bars"] .hud-side .panel:first-child { grid-column: 1; grid-row: 2; }
  #match[data-layout="bars"] .hud-side .panel:last-child { grid-column: 3; grid-row: 1 / -1; }
  /* Narrow bars: names wrap at word breaks rather than being cut short, numbers stay whole, and your row is
     marked by bold alone. */
  #match[data-layout="bars"] .hud-side .panel { padding: 5px 8px 6px; line-height: 1.3; }
  #match[data-layout="bars"] .scores li { gap: 5px; }
  #match[data-layout="bars"] .scores .swatch { width: 10px; height: 10px; }
  #match[data-layout="bars"] .scores .who { white-space: normal; overflow: visible; overflow-wrap: break-word; }
  #match[data-layout="bars"] .scores .pts { flex: none; white-space: nowrap; overflow-wrap: normal; }
  #match[data-layout="bars"] .scores .tag { display: none; }
}
/* A phone on its side: smaller type, so three cards still fit. */
@media (orientation: landscape) and (max-height: 500px) {
  .hud-side .panel { font-size: 13px; }
  .clock { font-size: 20px; }
  .objective { font-size: 13px; }
  #match[data-layout="bars"] .hud-side .panel, #match[data-layout="bars"] .objective { font-size: 12px; }
}

.callout {
  position: absolute; z-index: 2; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(92%, 540px); max-height: 94%;
  overflow: hidden; pointer-events: none; text-align: center; background: rgba(18, 20, 26, 0.95);
  border: 2px solid var(--gold); border-radius: 14px; padding: 14px 20px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  animation: pop 180ms ease-out;
}
.callout .kicker { color: var(--gold); font-size: 14px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.callout .item + .item { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.callout .card-name { font-size: 28px; font-weight: 800; line-height: 1.2; }
.callout .card-desc { font-size: 19px; line-height: 1.35; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -50%) scale(0.92); } }

/* Portrait: the arena across the top, the clock above it, the scores and cards below it. */
@media (orientation: portrait) {
  #match { display: flex; flex-direction: column; }
  .hud-top {
    position: static; transform: none; width: auto; max-width: none; display: flex; align-items: baseline; gap: 12px;
    text-align: left; border-radius: 0; border-width: 0 0 1px; padding: calc(6px + env(safe-area-inset-top)) 12px 6px;
  }
  .clock { font-size: 24px; flex: none; }
  #stage { position: relative; inset: auto; flex: none; width: 100%; aspect-ratio: 3 / 2; }
  .hud-side {
    position: static; flex: 1 1 auto; min-height: 0; overflow-y: auto; flex-direction: column; align-items: stretch;
    justify-content: flex-start;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); pointer-events: auto;
  }
  .hud-side .panel { width: auto; font-size: 16px; }
  .callout { padding: 8px 12px; }
  .callout .kicker { font-size: 12px; }
  .callout .card-name { font-size: 20px; }
  .callout .card-desc { font-size: 15px; }
  .callout .item + .item { margin-top: 6px; padding-top: 6px; }
}

.notice {
  position: fixed; z-index: 20; top: calc(8px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  background: var(--gold); color: var(--bg); font-weight: 700; font-size: 15px; padding: 6px 14px; border-radius: 999px;
  pointer-events: none;
}
.backdrop {
  position: fixed; z-index: 30; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(0, 0, 0, 0.72);
}
.dialog {
  max-width: 420px; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 24px; text-align: center;
}
.dialog p { font-size: 20px; font-weight: 600; margin: 0 0 20px; }
.dialog button { width: 100%; }
