/* Layout: one solid board based on the printed box. Two mirrored sides meet at a center groove, so facing columns line up.
   The board is one SVG, so it scales as a single object. Each player's half carries its own color variables (src/colors.ts). */
:root {
  color-scheme: dark;
  --ground: #54545c;   /* render backdrop */
  --plate: #2b2b2c;    /* menu panels and buttons */
  --plate-dark: #141415;
  --go: #006400;
  --go-ink: #fff;
  --go-line: transparent;
  --white: #d6d6d6;
  --bright: #f0f0f0;
  --warn: #ffd9a0;
  --display: "Saira Stencil One", "Arial Narrow", Impact, sans-serif;
  --label: "Saira Condensed", "Arial Narrow", Arial, sans-serif;
}
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--white);
  transition: background-color .9s;
  font-family: var(--label);
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
#backdrop { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#app { position: relative; box-sizing: border-box; height: 100%; max-width: 520px; margin-inline: auto; }
.screen {
  box-sizing: border-box;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-block: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
#menu { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.screen.center { justify-content: center; }
h1, p { margin: 0; }
#logo { font-size: inherit; line-height: 0; }
#logo svg { display: block; width: 100%; height: auto; }

/* Plates: everything pressable is cut like the box's corners. */
button.plate {
  appearance: none; border: 0; cursor: pointer;
  background: var(--plate); color: var(--white);
  font: 600 15px/1 var(--label); letter-spacing: .03em;
  min-height: 40px; padding: 0 14px; white-space: nowrap;
  clip-path: polygon(6px 0, calc(100% - 6px) 0, 100% 6px, 100% calc(100% - 6px), calc(100% - 6px) 100%, 6px 100%, 0 calc(100% - 6px), 0 6px);
}
.panel button.plate { background: #3c3c3e; }
button.plate.go, .panel button.plate.go { background: var(--go); color: var(--go-ink); box-shadow: inset 0 0 0 2px var(--go-line); font: 400 19px/1 var(--display); min-height: 48px; width: 100%; }
button.plate[aria-pressed="true"], button.plate.armed { background: var(--go); color: var(--go-ink); box-shadow: inset 0 0 0 2px var(--go-line); }
button.plate:disabled { opacity: .45; cursor: default; }
button:focus-visible, input:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
button.link { appearance: none; border: 0; background: none; color: var(--white); font: 500 15px/1 var(--label); text-decoration: underline; padding: 8px 2px; cursor: pointer; align-self: center; }

.panel { display: flex; flex-direction: column; gap: 10px; background: var(--plate); padding: 12px; clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 10px, 100% calc(100% - 10px), calc(100% - 10px) 100%, 10px 100%, 0 calc(100% - 10px), 0 10px); }
.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--plate-dark); padding: 4px; }
.tabs[hidden] { display: none; }
.tab { appearance: none; border: 0; background: none; color: var(--white); font: 600 16px/1 var(--label); min-height: 40px; cursor: pointer; }
.tab[aria-pressed="true"] { background: var(--go); color: var(--go-ink); box-shadow: inset 0 0 0 2px var(--go-line); }
.tabs.small .tab { min-height: 34px; font-size: 15px; }

.field { display: flex; align-items: center; gap: 10px; font: 600 15px/1 var(--label); }
input[type="text"] {
  flex: 1; min-width: 0; box-sizing: border-box; border: 0; border-radius: 0;
  background: var(--plate-dark); color: #fff; font: 500 17px/1 var(--label); padding: 10px;
  -webkit-user-select: text; user-select: text;
}
input::placeholder { color: #8b8b90; }

#preview svg { display: block; width: 100%; height: auto; }
.swatches { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; }
.group { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.group h2 { margin: 0; font: 600 13px/1.4 var(--label); letter-spacing: .08em; text-transform: uppercase; color: #a9a9ae; }
.swatch { display: grid; grid-template-columns: 1fr 44px; align-items: center; gap: 6px; min-height: 36px; font: 500 15px/1.1 var(--label); }
.swatch small { display: block; font: 500 12px/1.2 var(--label); color: #a9a9ae; }
.swatch button { appearance: none; border: 0; background: none; color: #a9a9ae; font: 500 12px/1.2 var(--label); text-decoration: underline; padding: 0; cursor: pointer; display: block; }
input[type="color"] { appearance: none; -webkit-appearance: none; box-sizing: border-box; width: 44px; height: 32px; padding: 0; border: 2px solid var(--plate-dark); background: none; cursor: pointer; }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 0; }
input[type="color"]::-moz-color-swatch { border: 0; }

.join-row { display: flex; gap: 6px; }
.join-row button { padding: 0 10px; }
#code { width: 90px; flex: 1; font: 400 20px/1 var(--display); letter-spacing: .1em; text-transform: uppercase; }
.note { font: 500 14px/1.3 var(--label); color: #c4c4c8; }
.error { font: 600 15px/1.3 var(--label); color: var(--warn); }
.error:not(:empty) { background: var(--plate); padding: 8px 12px; }

/* Lobby */
#lobby .panel:first-child { align-items: center; text-align: center; flex: none; }
.lobby-list { flex: none; }
.eyebrow { font: 600 13px/1 var(--label); letter-spacing: .1em; text-transform: uppercase; color: #a9a9ae; }
.room-code { font: 400 52px/1 var(--display); letter-spacing: .1em; color: #fff; }
#qr { width: min(150px, 42vw); line-height: 0; }
#qr svg { width: 100%; height: auto; display: block; }
.link-text { overflow-wrap: anywhere; }

/* Game */
header { display: flex; flex-direction: column; gap: 6px; }
.controls { display: flex; gap: 6px; align-items: center; }
.spacer { flex: 1; }
#status { font: 500 16px/1.25 var(--label); min-height: 20px; color: var(--status, var(--bright)); transition: color .9s; }
#status.over { font-weight: 600; }
#stage { flex: 1; min-height: 0; display: flex; }
#board { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; }

.inlay { fill: var(--inlay); transition: fill .2s; }
.idle .inlay { fill: var(--inlay-off); }
svg text { font-family: var(--label); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
text.logo-word { font-family: var(--display); font-size: 31px; text-anchor: start; fill: var(--ink); }
text.total { font-family: var(--display); font-size: 44px; fill: var(--ink); }
text.who { font-size: 14px; font-weight: 600; letter-spacing: .08em; fill: var(--ink); }
text.who.long { font-size: 12px; letter-spacing: .02em; }
text.hint { font-size: 15px; font-weight: 600; fill: var(--ink); }
text.cs { font-family: var(--display); font-size: 19px; fill: var(--cs); font-variant-numeric: tabular-nums; }
text.cs.zero { fill: var(--cs-zero); }
text.cs.on { fill: var(--cs-on); }
.face-to-face text.far { transform-box: fill-box; transform-origin: center; transform: rotate(180deg); }
.hit { fill: transparent; cursor: pointer; outline: none; }
.hit[aria-disabled="true"] { cursor: default; }
.hit:focus-visible { stroke: #fff; stroke-width: 2; }

/* Lobby roster and bracket */
.toggle { display: flex; align-items: center; gap: 10px; min-height: 36px; font: 500 16px/1.2 var(--label); cursor: pointer; }
.toggle input { width: 22px; height: 22px; margin: 0; accent-color: var(--go); }
.row { display: flex; gap: 8px; }
.row > button { flex: 1; width: auto; }
.how { align-self: center; }
button.plate.icon { padding: 0; width: 40px; font-size: 18px; }
#lobby { overflow-y: auto; }
.roster { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.roster li { display: flex; align-items: center; gap: 8px; min-width: 0; font: 600 16px/1.2 var(--label); color: #fff; }
.roster span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster small { font: 500 12px/1 var(--label); color: #a9a9ae; letter-spacing: .06em; flex: none; }
.chip { flex: none; width: 14px; height: 14px; border: 2px solid var(--chip-edge, #000); background: var(--chip, #666); transform: rotate(-30deg); }
.roster li.off span { color: #a9a9ae; }
.grow { flex: 1; min-height: 0; }
.bracket-title { margin: 0; font: 400 24px/1.1 var(--display); color: #fff; }
.bracket-scroll { flex: 1; min-height: 0; overflow: auto; }
.bracket-grid { display: flex; gap: 12px; min-height: 100%; width: max-content; min-width: 100%; }
.bracket-col { display: flex; flex-direction: column; gap: 6px; flex: 1; width: 132px; }
.bracket-col h3 { margin: 0; font: 600 12px/1.4 var(--label); letter-spacing: .08em; text-transform: uppercase; color: #a9a9ae; }
.bracket-col > div { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: 6px; }
.b-match { background: var(--plate-dark); padding: 2px 0; border-left: 3px solid transparent; }
.b-match.live { border-left-color: #fff; }
.b-row { display: flex; align-items: center; gap: 6px; padding: 3px 6px; font: 500 14px/1.2 var(--label); color: #d6d6d6; min-width: 0; }
.b-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b-row b { font-weight: 600; font-variant-numeric: tabular-nums; }
.b-row.won { color: #fff; font-weight: 600; }
.b-row.lost { color: #85858b; }
.b-row.tbd { color: #707075; }
.b-row .chip { width: 10px; height: 10px; border-width: 1px; }

/* Party view: everything is sized from the screen, because it's read from a sofa. */
body.tv { overflow: hidden; }
body.tv #app { max-width: none; }
#party, #party > div { height: 100%; box-sizing: border-box; }
#tv-lobby { display: grid; grid-template-columns: 1fr 1fr; gap: 3vw; padding: 4vh 4vw; align-items: center; }
.tv-join { display: flex; flex-direction: column; align-items: center; gap: 1.5vh; min-width: 0; color: var(--status, #fff); }
.tv-join .eyebrow { color: inherit; font-size: 2.2vh; }
#tv-logo { width: min(100%, 46vw); }
#tv-logo svg { display: block; width: 100%; height: auto; }
.tv-code { font: 400 15vh/1 var(--display); letter-spacing: .1em; color: inherit; }
#tv-qr { width: 26vh; line-height: 0; }
#tv-qr svg { display: block; width: 100%; height: auto; }
.tv-url { font: 500 2.6vh/1.2 var(--label); color: inherit; overflow-wrap: anywhere; text-align: center; }
.tv-players { max-height: 88vh; overflow: hidden; padding: 3vh; gap: 2vh; }
.tv-players .eyebrow { font-size: 2.2vh; }
.tv-players .note { font-size: 2.6vh; }
.roster.big { gap: 1.6vh 2vw; }
.roster.big li { font-size: 3.4vh; }
.roster.big small { font-size: 1.8vh; }
.roster.big .chip { width: 2.2vh; height: 2.2vh; }
#tv-play { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 2vw; padding: 2.5vh 2.5vw; }
#tv-play > aside { min-height: 0; overflow: hidden; padding: 2.5vh; gap: 1.6vh; }
#tv-boards { min-width: 0; min-height: 0; display: grid; gap: 1.5vh 1.5vw; grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); grid-auto-rows: minmax(0, 1fr); }
.tv-board { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: .6vh; }
.tv-board svg { flex: 1; min-height: 0; width: 100%; display: block; }
.tv-board p { font: 600 2vh/1.2 var(--label); color: var(--status, #fff); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tv-title { margin: 0; font: 400 4.6vh/1.1 var(--display); color: #fff; }
.tv-line { font: 500 2.6vh/1.25 var(--label); color: #e4e4e6; min-height: 3.2vh; }
#tv-bracket .bracket-col { width: auto; min-width: 11vh; }
#tv-bracket .bracket-col h3 { font-size: 1.5vh; }
#tv-bracket .b-row { font-size: var(--b-font, 2vh); }
#tv-bracket .b-row .chip { width: 1.2vh; height: 1.2vh; }

/* How to play */
#rules { position: fixed; inset: 0; z-index: 5; background: rgba(0, 0, 0, .55); overflow-y: auto; -webkit-overflow-scrolling: touch; padding-block: 12px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.rules-card { box-sizing: border-box; max-width: 488px; margin-inline: auto; background: var(--plate); color: #eaeaea; padding: 16px; font: 500 16px/1.4 var(--label); display: flex; flex-direction: column; gap: 8px; clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 10px, 100% calc(100% - 10px), calc(100% - 10px) 100%, 10px 100%, 0 calc(100% - 10px), 0 10px); }
.rules-card h2 { margin: 0; font: 400 26px/1.1 var(--display); color: #fff; }
.rules-card h3 { margin: 8px 0 0; font: 600 13px/1.4 var(--label); letter-spacing: .08em; text-transform: uppercase; color: #a9a9ae; }
.rules-card p { max-width: 62ch; }
.rules-card ol, .rules-card ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.rule-example { display: flex; align-items: center; gap: 12px; background: var(--go); color: var(--go-ink); box-shadow: inset 0 0 0 2px var(--go-line); padding: 6px 10px; }
.rule-example span { flex: 1; min-width: 0; }
.rule-example b { font: 400 20px/1 var(--display); }
.dice-row { height: 40px; width: auto; flex: none; }

/* Dice. Single, pair and triple are told apart by the colors they use. */
.d-face { fill: var(--die); }
.d-edge { fill: var(--die-edge); }
.d-pip { fill: var(--pip); }
.t2 .d-pip { fill: var(--die-fl); }
.t3 .d-face { fill: var(--pip); }
.t3 .d-pip { fill: var(--die); }

/* The outer group places the die, the inner one moves it. */
.spin { transform-box: fill-box; transform-origin: center; }
.tumble .spin { animation: tumble .14s linear infinite; }
.settle .spin { animation: settle .22s ease-out; }
.fly .spin { animation: fly .26s cubic-bezier(.3,.7,.3,1) both; }
.land .spin { animation: land .16s ease-out; }
.knocked .spin { animation: knocked .3s ease-in both; }
.slide .spin { animation: slide .18s ease-out both; }
@keyframes tumble { from { transform: rotate(0) scale(1.08); } to { transform: rotate(180deg) scale(.95); } }
@keyframes settle { from { transform: rotate(-24deg) scale(1.12); } to { transform: none; } }
@keyframes fly { from { transform: translate(var(--dx), var(--dy)); } to { transform: none; } }
@keyframes land { from { transform: scale(1.12); } to { transform: none; } }
@keyframes knocked { 30% { transform: rotate(-16deg) scale(1.08); opacity: 1; } to { transform: rotate(120deg) scale(.1); opacity: 0; } }
@keyframes slide { from { transform: translateY(var(--dy)); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .tumble .spin, .settle .spin, .fly .spin, .land .spin, .knocked .spin, .slide .spin { animation: none; }
  .inlay, body, #status { transition: none; }
}
