:root {
  color-scheme: dark;
  --earth: #181916;
  --gold: #ffb467;
  --copper: #b87234;
  --cream: #f3ebdb;
  --ink: #25221c;
  --line: #494138;
  --mono: "Courier New", monospace;
  --serif: Georgia, "Times New Roman", serif;
  font-family: system-ui, sans-serif;
  color: var(--cream);
  background: var(--earth);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .46; }
:focus-visible { outline: 2px solid #be6c35; outline-offset: 3px; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
canvas { image-rendering: pixelated; }

.site-header { border-bottom: 1px solid #35332b; background: #151613; }
.header-inner, .frame { width: min(1300px, calc(100% - 96px)); margin-inline: auto; }
.header-inner { min-height: 73px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand { display: flex; flex-shrink: 0; align-items: center; gap: 12px; font: bold 17px/1 var(--serif); letter-spacing: .12em; }
.brand small { display: block; margin-top: 5px; color: #c59468; font: 10px/1 var(--mono); letter-spacing: .2em; }
.brand-mark { border: 1px solid #755437; width: 36px; height: 36px; display: grid; place-items: center; color: var(--gold); background: #2e241b; }
nav { display: flex; align-self: stretch; gap: clamp(14px, 3vw, 42px); align-items: stretch; }
nav a { display: flex; align-items: center; font-size: .83rem; color: #bdb3a1; border-block: 2px solid transparent; }
nav a:hover, nav a[aria-current] { color: var(--gold); }
nav a[aria-current] { border-bottom-color: var(--copper); }
.connection, .stage-label { display: flex; align-items: center; gap: 8px; color: #c5b9a2; font: 11px var(--mono); text-transform: uppercase; letter-spacing: .09em; white-space: nowrap; }
.connection i, .stage-label i { width: 7px; height: 7px; border-radius: 50%; background: #a48862; }
.connection.online i { background: #94b988; box-shadow: 0 0 10px #6b9a69; }
.frame { padding-block: clamp(32px, 5.5vh, 68px) 45px; }
.intro { margin-bottom: 28px; }
.intro h1 { font: normal clamp(42px, 5.5vw, 77px)/.93 var(--serif); letter-spacing: -.059em; }
.intro h1 span { color: var(--gold); }
.intro p { margin-top: 15px; color: #c4bcaa; line-height: 1.5; font-size: .96rem; }
.intro code { color: var(--gold); }
.studio-grid, .derby-grid { display: grid; grid-template-columns: minmax(0, 1.22fr) minmax(0, 1fr); gap: 18px; align-items: stretch; }
.stage, .race-board { position: relative; display: flex; flex-direction: column; overflow: hidden; min-width: 0; border: 1px solid #554637; background: #24261e; }
.stage-label { position: absolute; z-index: 1; top: 20px; left: 20px; color: #e8bb86; }
.stage-label i { background: var(--gold); box-shadow: 0 0 10px #d98f45; }
#scene { display: block; width: 100%; height: 100%; min-height: 330px; flex: 1 1 0; object-fit: contain; background: #28281f; }
.stage-caption { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 22px; border-top: 1px solid #514334; background: #202019; }
.stage-caption h2, .race-heading h2 { font: normal 29px/1.05 var(--serif); }
.stage-caption p { color: #c6b99e; font-size: .75rem; margin-top: 5px; }
.poses { display: flex; padding: 3px; gap: 2px; border: 1px solid #65513c; }
.poses button { border: 0; background: transparent; padding: 6px 10px; color: #d7c7ad; font-size: .76rem; }
.poses button[aria-pressed="true"] { background: #64452b; color: #fff0d1; }
.paper { background: var(--cream); color: var(--ink); color-scheme: light; padding: clamp(18px, 2.55vw, 32px); border: 1px solid #e4d5b9; min-width: 0; }
.paper h2 { font: normal clamp(26px, 3vw, 36px)/1 var(--serif); letter-spacing: -.04em; margin-bottom: 21px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend, .palette label, .save label, #chat-form label { display: block; font-weight: 700; font-size: .8rem; margin-bottom: 8px; }
.roles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.role { display: flex; align-items: center; text-align: left; min-width: 0; min-height: 49px; gap: 5px; border: 1px solid #cabda6; padding: 4px 6px; color: var(--ink); background: #f8f0e1; font-size: .72rem; line-height: 1.1; font-weight: 650; }
.role canvas { width: 27px; height: 32px; flex: 0 0 27px; }
.role:hover, .role[aria-pressed="true"] { border-color: #925222; background: #eed8ba; }
.role[aria-pressed="true"] { box-shadow: inset 0 0 0 1px #925222; }
.palette-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-block: 19px; }
.palette label span { color: #735e4b; font: 11px var(--mono); margin-left: 3px; }
.swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.swatch, .custom-color-wheel { width: 25px; height: 25px; border-radius: 50%; border: 1px solid #725840; }
.swatch[aria-pressed="true"] { outline: 1px solid #794720; outline-offset: 2px; }
.custom-color-wheel { position: relative; display: inline-grid; place-items: center; flex-shrink: 0; background: conic-gradient(#ed4b56, #f1c84f, #68bf65, #3cbac7, #6278dc, #c761c4, #ed4b56); cursor: pointer; }
.custom-color-icon { display: grid; place-items: center; width: 12px; height: 12px; border-radius: 50%; color: #25221c; background: #fff8eb; font: bold 12px/1 system-ui, sans-serif; pointer-events: none; }
.custom-color-wheel:focus-within { outline: 2px solid #794720; outline-offset: 2px; }
.custom-color { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; opacity: 0; cursor: pointer; }
.save, .host-controls { padding-top: 15px; border-top: 1px solid #d5c7ae; }
.save-row, .host-row { display: flex; gap: 7px; }
.save-row input { flex: 1; }
input:not([type="color"]) { width: 100%; min-width: 0; border: 1px solid #c6b69b; border-radius: 0; padding: 9px; color: var(--ink); background: #fbf5e9; font-size: .85rem; }
.button { border: 1px solid #31231a; background: #38281d; color: #fff1d5; padding: 9px 13px; white-space: nowrap; font-size: .8rem; font-weight: 650; }
.account { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; font-size: .8rem; }
.account button { padding: 5px 0 5px 10px; border: 0; background: none; color: #684326; text-decoration: underline; }
.button:not(:disabled):hover { background: #5e3c25; }
.button.secondary { border-color: #bba98d; background: transparent; color: #493525; }
.button.secondary:not(:disabled):hover { background: #ecdbc0; }
.button span { margin-left: 6px; }
.form-note { min-height: 1.1em; margin-top: 8px; color: #624c38; font-size: .75rem; line-height: 1.35; }
#chat-form > input { margin-bottom: 12px; }
.host-controls { margin-top: 18px; }
.host-controls h3 { font: normal 23px var(--serif); margin-bottom: 9px; }
.host-row { margin-top: 7px; flex-wrap: wrap; }
.race-heading { padding: 17px 20px; display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 10px; border-bottom: 1px solid #685039; background: #28241c; }
#race-status { font: 12px var(--mono); color: #efbd83; }
.track { padding: 10px; flex: 1; display: grid; align-content: center; gap: 3px; background: repeating-linear-gradient(135deg, #393022 0 4px, #372e21 4px 8px); }
.empty-track { align-self: center; justify-self: center; color: #ead7b6; padding: 45px 18px; text-align: center; }
.lane { display: grid; grid-template-columns: minmax(70px, 24%) minmax(0, 1fr); min-height: 64px; align-items: stretch; border: 1px solid #6b4e35; background: #35291d; }
.lane-name { align-self: center; padding-inline: 8px; overflow-wrap: anywhere; color: #f3dab4; font: 12px var(--mono); }
.lane-path { position: relative; min-width: 0; border-left: 1px solid #735131; background: repeating-linear-gradient(0deg, #503824 0 6px, #493220 6px 7px); }
.lane-path::after { content: ""; position: absolute; inset: 0 10px 0 auto; width: 12px; opacity: .67; background: repeating-conic-gradient(#e6c294 0% 25%, #513620 0% 50%) 50% / 12px 12px; }
.racer { height: 57px; width: 63px; position: absolute; bottom: 1px; left: 0; z-index: 1; }
.lane.winner .lane-name { color: var(--gold); font-weight: bold; }
html.overlay, .overlay body { background: transparent; }
.overlay .site-header, .overlay .intro, .overlay .race-controls { display: none; }
.overlay .frame { width: min(100%, 1020px); margin-inline: auto; padding: 0; }
.overlay .derby-grid { display: block; }
.overlay .race-board { border-color: #8e683f; }
.overlay #avatar-strip { position: fixed; inset: auto 0 0; padding: 6px clamp(4px, 1vw, 20px) 8px; pointer-events: none; }
#on-stage { display: flex; flex-wrap: wrap; justify-content: center; align-items: end; padding: 0; margin: 0; gap: 8px 6px; list-style: none; }
#on-stage li { display: grid; justify-items: center; row-gap: 4px; flex: 0 0 var(--stage-cell-width, 80px); min-width: 0; max-width: 100%; }
#on-stage canvas { display: block; width: var(--stage-avatar-width, 80px); max-width: 100%; height: auto; filter: drop-shadow(2px 2px 0 #201812); }
#on-stage span { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; color: #fff1d5; background: transparent; text-align: center; padding: 2px 4px; font: .875rem/1.35 var(--mono); width: 100%; height: calc(2.7em + 4px); min-width: 0; max-width: 100%; overflow: hidden; overflow-wrap: anywhere; }
.derby-grid:has(.race-controls[hidden]) { grid-template-columns: minmax(0, 1fr); }
.game-floor { flex: 1; padding: 20px; background: repeating-linear-gradient(135deg, #393022 0 4px, #372e21 4px 8px); }
#game-status { font: normal clamp(20px, 3vw, 33px)/1.15 var(--serif); color: #f5e0c0; }
#game-clock { font: 12px var(--mono); color: #efbd83; }
#game-scene { display: block; width: 100%; height: auto; margin-top: 16px; border: 1px solid #684a31; background: #23251d; }
#game-players { list-style: none; margin: 16px 0 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
#game-players:empty { margin: 0; }
#game-players li { display: flex; gap: 3px; align-items: center; min-width: 0; min-height: 58px; background: #282018; border: 1px solid #624b36; padding: 4px; }
#game-players canvas { flex: 0 0 32px; width: 32px; height: auto; }
#game-players strong, #game-players span { display: block; overflow-wrap: anywhere; }
#game-players strong { font-size: .78rem; color: #f3dab4; }
#game-players span { margin-top: 3px; font: 11px var(--mono); color: #d6baa0; }
#game-players .game-winner { border-color: var(--gold); background: #523723; }
.bell-cue .game-floor { background: #49371d; }
.bell-cue #game-status { font-weight: bold; color: var(--gold); }
.bell-cue #bell-move { background: #74411e; border-color: #74411e; }
#game-signin a { text-decoration: underline; }
#game-demo { margin-bottom: 12px; }
#game-demo label { display: block; margin-bottom: 6px; font-size: .8rem; font-weight: bold; }
.game-moves { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.game-moves p { grid-column: 1 / -1; font-weight: 650; margin-bottom: 3px; }
.game-moves button { white-space: normal; padding-inline: 4px; min-height: 48px; }
.game-moves small { display: block; margin-top: 3px; }
.overlay .game-controls { display: none; }
.overlay #game-players strong { font-size: 1rem; }
.overlay #game-players canvas { flex-basis: 48px; width: 48px; }

@media (max-width: 920px) {
  .header-inner, .frame { width: calc(100% - 44px); }
  .roles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 690px) {
  .header-inner, .frame { width: calc(100% - 28px); }
  .header-inner { min-height: 0; flex-wrap: wrap; gap: 0 14px; padding-top: 12px; }
  nav { order: 3; width: 100%; gap: 0 17px; min-height: 42px; flex-wrap: wrap; }
  nav a { font-size: .74rem; }
  .studio-grid, .derby-grid { grid-template-columns: minmax(0, 1fr); }
  .roles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #scene { min-height: 0; flex: none; height: clamp(180px, 52vw, 275px); object-fit: fill; }
  .stage-caption { padding: 13px; }
  .palette-grid { grid-template-columns: minmax(0, 1fr); gap: 13px; }
  .swatches { gap: 2px; }
  .swatch, .custom-color-wheel { width: 44px; height: 44px; }
  .custom-color-icon { width: 22px; height: 22px; font-size: 18px; }
  .button, input:not([type="color"]) { min-height: 44px; font-size: 1rem; }
  .account button { min-height: 44px; }
  .controls .save { position: sticky; bottom: 0; z-index: 2; background: var(--cream); padding-block: 12px max(9px, env(safe-area-inset-bottom)); }
  .controls .save-row { flex-wrap: wrap; }
  .controls .save-row > * { width: 100%; flex: auto; text-align: center; }
  .controls .save-row > input { text-align: left; }
  #game-players { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overlay #game-players { grid-template-columns: minmax(0, 1fr); }
  .game-floor { padding: 14px; }
}
@media (max-width: 350px) {
  .save-row { flex-wrap: wrap; }
}

.room-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.room-banner { margin-bottom: 22px; padding: 16px 20px; border: 1px solid #755437; background: #28241c; color: #f0d7b4; line-height: 1.5; font-size: 1rem; }
.room-banner a { text-decoration: underline; }
.room-card h2 { margin-bottom: 14px; }
.room-summary { font-size: 1rem; line-height: 1.5; }
.room-roster { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; padding: 0; list-style: none; }
.room-roster li { border: 1px solid #bba98d; padding: 5px 8px; overflow-wrap: anywhere; font-size: .875rem; }
.room-card .button, .source-card .button { font-size: .875rem; min-height: 44px; white-space: normal; }
.room-card .form-note { font-size: .875rem; }
.room-link { display: inline-block; margin-top: 14px; text-decoration: underline; font-size: 1rem; }
.room-sources { margin-top: 38px; }
.room-sources h2 { font: normal 36px var(--serif); }
#room-sources { display: grid; gap: 14px; }
.source-card { min-width: 0; border: 1px solid #755437; padding: 22px; background: #24261e; }
.source-card h3 { font: normal 26px var(--serif); color: #f0d7b4; }
.source-card p { margin-block: 9px 14px; font-size: 1rem; line-height: 1.5; color: #c4bcaa; }
.source-url { display: flex; align-items: stretch; flex-wrap: wrap; gap: 8px; }
.source-url input { flex: 1 1 360px; }
.source-card .button.secondary { color: #f0d7b4; border-color: #755437; }
.source-card .button.secondary:hover { background: #503824; }
.source-card details { margin-top: 16px; }
.source-card summary { cursor: pointer; padding-block: 8px; font-size: .875rem; color: #f0d7b4; }
.source-preview { display: block; width: 100%; aspect-ratio: 16 / 9; border: 1px solid #755437; background: repeating-conic-gradient(#30312e 0% 25%, #242522 0% 50%) 50% / 24px 24px; }
.room-feedback { color: #f0d7b4; font-size: .875rem; }
.overlay .race-controls { display: none; }
.overlay body { overflow: hidden; }
.overlay #games, .overlay #derby { transform: scale(var(--overlay-scale, 1)); transform-origin: top center; }
@media (min-width: 691px) { .overlay #game-players { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 690px) { .room-grid { grid-template-columns: minmax(0, 1fr); } .source-card { padding: 16px; } }

.stage-manager { margin-top: 18px; }
.stage-manager > .button { margin-top: 14px; }
.stage-manager li { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.stage-manager li button { padding: 6px 8px; min-height: 36px; border: 1px solid #bba98d; background: transparent; color: var(--ink); font-size: .875rem; }
.records-toolbar, .records-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.records-toolbar { justify-content: space-between; margin-bottom: 18px; }
.records-toolbar .button { font-size: .875rem; min-height: 44px; }
.records-filters [aria-pressed="true"] { background: #b87234; color: #181916; border-color: #ffb467; }
.records-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 24px; align-items: start; }
.records-explainer { font-size: 1rem; line-height: 1.5; margin-bottom: 20px; }
.records-history > h2 { font: normal 36px var(--serif); margin-bottom: 14px; }
.records-history > .records-explainer { color: #c4bcaa; }
.records-table-wrap { overflow-x: auto; }
.records-table { width: 100%; border-collapse: collapse; font-size: 1rem; }
.records-table th, .records-table td { text-align: left; padding: 12px 6px; border-bottom: 1px solid #bba98d; }
.records-table td:first-child { overflow-wrap: anywhere; }
.records-table th:not(:first-child), .records-table td:not(:first-child) { text-align: right; }
.records-empty { font-size: 1rem; line-height: 1.5; margin-top: 12px; }
.round-record { margin-bottom: 12px; border: 1px solid #755437; background: #24261e; }
.round-record summary { cursor: pointer; padding: 18px; font-size: 1rem; line-height: 1.5; }
.round-record summary strong { color: #ffb467; }
.round-record time { display: block; color: #c4bcaa; font-size: .875rem; }
.round-record summary > span { display: block; overflow-wrap: anywhere; }
.round-record ul { margin: 0; padding: 0 18px 12px; list-style: none; }
.round-record li { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; padding: 10px 0; border-top: 1px solid #554637; font-size: .875rem; }
.round-record li strong { overflow-wrap: anywhere; }
.round-record li span { color: #c4bcaa; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#moderator-entry a { text-decoration: underline; }
@media (max-width: 690px) { .records-grid { grid-template-columns: minmax(0, 1fr); } }
