:root {
  --teal: #2ec8c3;
  --teal-dim: #148f8c;
  --gold: #e8b86d;
  --ink: #1a120e;
  --panel: rgba(22, 14, 10, 0.74);
  --text: #f4efe6;
  --muted: #d4c4b0;
  --warn: #ffd36a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  height: 100svh;
  max-width: 100%;
  overflow: hidden;
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
  background: var(--ink);
  color: var(--text);
  font-family: Trebuchet MS, Arial Black, Impact, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

input,
textarea {
  user-select: text;
  -webkit-user-select: text;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#view {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.hidden {
  display: none !important;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hud-top,
.hud-bottom {
  position: absolute;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.hud-top {
  top: max(14px, env(safe-area-inset-top, 0px));
  left: max(16px, env(safe-area-inset-left, 0px));
  right: max(16px, env(safe-area-inset-right, 0px));
  align-items: flex-start;
}

.hud-bottom {
  bottom: max(14px, env(safe-area-inset-bottom, 0px));
  left: max(16px, env(safe-area-inset-left, 0px));
  right: max(16px, env(safe-area-inset-right, 0px));
  align-items: flex-end;
}

.brand .logo {
  font-size: 22px;
  letter-spacing: 0.14em;
  color: var(--teal);
  text-shadow: 0 0 18px rgba(46, 200, 195, 0.4);
}

.brand .circuit {
  font-size: 12px;
  letter-spacing: 0.18em;
  color: var(--muted);
  text-transform: uppercase;
}

.race-meta {
  display: flex;
  gap: 18px;
  background: var(--panel);
  border: 2px solid rgba(46, 200, 195, 0.4);
  padding: 8px 14px;
  border-radius: 8px;
}

.race-meta .label,
.speed-box .unit,
.bar-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--muted);
}

#lap,
#time {
  font-size: 26px;
  line-height: 1;
}

.speed-box {
  min-width: 110px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: right;
  background: var(--panel);
  border: 2px solid rgba(46, 200, 195, 0.4);
  padding: 6px 12px 8px;
  border-radius: 8px;
}

.speed-read {
  min-width: 88px;
}

.grip-meter {
  position: relative;
  width: 78px;
  height: 78px;
}

.grip-meter svg {
  position: absolute;
  inset: 0;
  width: 78px;
  height: 78px;
}

.grip-track {
  stroke: rgba(244, 239, 230, 0.22);
}

.grip-arc {
  stroke: #f4efe6;
  stroke-linecap: round;
  transition: stroke 0.12s linear;
}

.grip-meter.grip-yellow .grip-arc {
  stroke: #ffe566;
}

.grip-meter.grip-red .grip-arc {
  stroke: #ff2a44;
}

.grip-num {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#speed {
  font-size: 32px;
  line-height: 0.95;
  color: #fff;
}

.apex-chip {
  display: block;
  pointer-events: auto;
  flex: 0 0 auto;
  border: 1px solid rgba(46, 200, 195, 0.45);
  background: #1a120e;
  color: #7cffd4;
  font: 700 13px/1 "Trebuchet MS", sans-serif;
  letter-spacing: 0.08em;
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}

.apex-chip.assist-on {
  border-color: #2ec8c3;
  color: #7cffd4;
}

.apex-chip.assist-off {
  opacity: 0.5;
  color: #f4efe6;
}

.bars {
  min-width: 280px;
  background: var(--panel);
  border: 2px solid rgba(46, 200, 195, 0.4);
  padding: 10px 12px;
  border-radius: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 52px 1fr 36px;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

.bar {
  height: 12px;
  background: #2a2018;
  border-radius: 99px;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--teal-dim), var(--teal));
  transform-origin: left center;
}

#tire-fill {
  background: linear-gradient(90deg, #c4842a, var(--gold));
}

#mass-fill {
  background: linear-gradient(90deg, #5a4a38, #d4c4b0);
}

#temp-fill {
  background: linear-gradient(90deg, #3a4a88, #7ab0ff);
}

#fuel-num,
#tire-num {
  font-size: 13px;
  text-align: right;
}

.hint {
  max-width: 380px;
  text-align: right;
  font-size: 13px;
  line-height: 1.35;
  color: var(--muted);
  text-shadow: 0 2px 8px #000;
}

#callouts {
  position: absolute;
  top: 28%;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.banner {
  padding: 10px 22px;
  border-radius: 6px;
  font-size: 34px;
  letter-spacing: 0.2em;
  background: rgba(20, 143, 140, 0.94);
  color: #fff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.banner.warn {
  background: rgba(26, 18, 14, 0.88);
  color: var(--warn);
  font-size: 22px;
  letter-spacing: 0.12em;
}

.banner.warn.launch {
  font-size: 42px;
  letter-spacing: 0.18em;
  color: #fff;
  background: rgba(20, 143, 140, 0.94);
}

.banner.warn.dump {
  font-size: 42px;
  letter-spacing: 0.18em;
  color: #fff4d8;
  background: rgba(122, 16, 16, 0.94);
}

.banner.warn.late {
  background: rgba(122, 16, 16, 0.94);
  color: #fff4d8;
  font-size: 26px;
  letter-spacing: 0.08em;
  max-width: 92%;
  text-align: center;
}

.feel-pop {
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 28px;
  letter-spacing: 0.14em;
  background: rgba(20, 143, 140, 0.92);
  color: #fff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.feel-pop.good {
  background: rgba(20, 143, 140, 0.94);
}

.feel-pop.late {
  background: rgba(26, 18, 14, 0.9);
  color: #ffe566;
}

.feel-pop.green {
  background: rgba(14, 90, 48, 0.94);
  color: #7cffd4;
}

.feel-pop.purple {
  background: rgba(72, 28, 110, 0.94);
  color: #e4c2ff;
}

.feel-pop.warn {
  background: rgba(122, 16, 16, 0.92);
  color: #fff4d8;
  font-size: 22px;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: max(24px, env(safe-area-inset-top, 0px)) max(24px, env(safe-area-inset-right, 0px))
    max(24px, env(safe-area-inset-bottom, 0px)) max(24px, env(safe-area-inset-left, 0px));
  background: linear-gradient(180deg, rgba(26, 18, 14, 0.22), rgba(26, 18, 14, 0.62));
}

#title-screen,
#lobby-screen,
#finish-screen,
#pause-screen {
  justify-content: flex-start;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: max(20px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
    max(48px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}

.screen h1 {
  margin: 0;
  font-size: clamp(52px, 10vw, 92px);
  letter-spacing: 0.08em;
  color: var(--teal);
  text-shadow: 0 0 28px rgba(46, 200, 195, 0.45);
}

.eyebrow,
.sub,
.credit,
.result-line {
  margin: 6px 0;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

#boot-status {
  min-height: 1.3em;
  color: var(--teal);
}

#boot-status.err {
  color: var(--warn);
}

.tips {
  max-width: 620px;
  margin: 22px 0 8px;
  padding: 0;
  list-style: none;
  text-align: left;
}

.tips li {
  margin: 8px 0;
  padding: 8px 10px 8px 12px;
  border-left: 3px solid var(--teal);
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
  letter-spacing: 0.02em;
  text-transform: none;
}

.go {
  margin-top: 22px;
  font-size: 20px;
  letter-spacing: 0.08em;
}

kbd {
  display: inline-block;
  padding: 2px 8px;
  border: 2px solid var(--teal);
  border-radius: 4px;
  color: #fff;
}

.credit {
  margin-top: 28px;
  font-size: 13px;
}

.start-msg {
  margin: 0 0 18px;
  font-size: 42px;
  letter-spacing: 0.28em;
  color: #7ad7ff;
  text-shadow: 0 0 24px rgba(80, 180, 255, 0.7);
}

.start-msg.reds {
  color: #ff4d4d;
  text-shadow: 0 0 24px rgba(255, 40, 40, 0.55);
}

.start-msg.go {
  color: #fff;
  font-size: 88px;
}

.light-row {
  display: flex;
  gap: 14px;
}

.start-light {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #2a1818;
  border: 3px solid #4a2020;
  box-shadow: inset 0 0 8px #000;
}

.start-light.on {
  background: #ff1a1a;
  border-color: #ff6a6a;
  box-shadow: 0 0 18px #ff2a2a;
}

#countdown.blue-flash .start-msg {
  animation: bluepulse 0.35s linear infinite;
}

@keyframes bluepulse {
  50% {
    opacity: 0.35;
  }
}

#rev-wrap {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, 86vw);
  pointer-events: none;
  text-align: center;
}

.rev-label {
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--muted);
}

.rev-track {
  position: relative;
  height: 16px;
  margin: 6px 0;
  background: #2a2018;
  border: 2px solid rgba(46, 200, 195, 0.45);
  border-radius: 99px;
  overflow: hidden;
}

#rev-sweet {
  position: absolute;
  left: 58%;
  width: 22%;
  top: 0;
  bottom: 0;
  background: rgba(61, 255, 154, 0.35);
}

#rev-wrap.sweet #rev-sweet {
  background: rgba(61, 255, 154, 0.62);
}

#rev-wrap.hot #rev-fill {
  background: linear-gradient(90deg, #ffe08a, #ff2d8a, #7a1010);
}

#rev-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0;
  background: linear-gradient(90deg, #ffe08a, #ff2d8a);
}

#rev-needle {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 3px;
  margin-left: -2px;
  left: 0;
  background: #f4efe6;
  box-shadow: 0 0 8px #2ec8c3;
  border-radius: 2px;
}

#rev-hint {
  font-size: 13px;
  color: var(--muted);
}

.result-time {
  margin: 8px 0 18px;
  font-size: 64px;
  color: #fff;
}

#lobby-screen .lobby-row,
#pause-screen .lobby-row,
#finish-screen .lobby-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 14px 0 8px;
}

.lobby-btn,
.lobby-input {
  font-family: inherit;
  font-size: 16px;
  letter-spacing: 0.08em;
  border-radius: 6px;
  border: 2px solid var(--teal);
  background: var(--panel);
  color: var(--text);
  padding: 8px 14px;
}

.lobby-btn {
  cursor: pointer;
  text-transform: uppercase;
}

.lobby-btn.solo,
.lobby-btn.campus {
  border-color: var(--gold);
}

.lobby-btn.campus {
  min-height: 48px;
  padding: 10px 16px;
}

.circuit-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 8px 0 4px;
}

.lobby-btn.circuit {
  font-size: 13px;
  letter-spacing: 0.06em;
  padding: 6px 10px;
}

.lobby-btn.circuit.on {
  border-color: var(--gold);
  background: #2a2018;
}

.lobby-input {
  width: 140px;
  text-align: center;
}

.lobby-input.name-input {
  width: min(280px, 80vw);
  text-align: left;
  letter-spacing: 0.06em;
  text-transform: none;
}

#room-code {
  font-size: 42px;
  letter-spacing: 0.28em;
  color: var(--teal);
  margin: 8px 0 0;
}

#roster {
  min-width: 280px;
  max-width: 420px;
  margin: 12px 0;
  padding: 0;
  list-style: none;
  text-align: left;
}

#roster li {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  padding: 6px 10px;
  border-left: 3px solid var(--teal);
  background: var(--panel);
  cursor: pointer;
}

#roster li.ghost {
  opacity: 0.5;
}

#roster li.bot {
  border-left-color: var(--gold);
}

#roster li.pick {
  outline: 2px solid var(--teal);
}

#roster .star {
  color: var(--gold);
  width: 1em;
}

.host-tools {
  width: min(420px, 92vw);
}

.host-tools.hidden {
  display: none;
}

.host-row {
  align-items: stretch;
}

.bot-pair {
  display: flex;
  gap: 0;
}

.bot-pair .lobby-btn:first-child {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.bot-pair .lobby-btn:last-child {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left: 0;
}

.lobby-btn.bowie {
  text-transform: none;
  letter-spacing: 0.04em;
  border-color: var(--gold);
}

.lobby-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.race-names {
  position: absolute;
  left: max(14px, env(safe-area-inset-left, 0px));
  top: max(248px, calc(env(safe-area-inset-top, 0px) + 234px));
  margin: 0;
  padding: 0;
  list-style: none;
  pointer-events: none;
  max-width: 160px;
}

.race-names li {
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--text);
  background: var(--panel);
  border-left: 3px solid var(--teal);
  padding: 3px 7px;
  margin: 3px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.race-names li.me {
  border-left-color: #2ec8c3;
  color: #2ec8c3;
}

.race-names li.bot {
  border-left-color: var(--gold);
}

#lobby-status,
#lobby-err {
  min-height: 1.2em;
  color: var(--muted);
}

#lobby-err,
#pause-err {
  color: var(--warn);
}

#pause-err {
  min-height: 1.2em;
}

#pause-screen {
  z-index: 45;
  background: linear-gradient(180deg, rgba(26, 18, 14, 0.78), rgba(26, 18, 14, 0.9));
}

#pause-screen h1 {
  font-size: clamp(40px, 8vw, 72px);
}

#pause-roster {
  min-width: 280px;
  max-width: 420px;
  margin: 12px 0;
  padding: 0;
  list-style: none;
  text-align: left;
}

#pause-roster li {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  padding: 6px 10px;
  border-left: 3px solid var(--teal);
  background: var(--panel);
  cursor: pointer;
}

#pause-roster li.ghost {
  opacity: 0.5;
}

#pause-roster li.bot {
  border-left-color: var(--gold);
}

#pause-roster li.pick {
  outline: 2px solid var(--teal);
}

#pause-roster .star {
  color: var(--gold);
  width: 1em;
}

.menu-btn {
  position: absolute;
  top: max(118px, calc(env(safe-area-inset-top, 0px) + 104px));
  right: max(16px, env(safe-area-inset-right, 0px));
  z-index: 16;
  pointer-events: auto;
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border: 2px solid var(--teal);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  padding: 6px 12px;
  cursor: pointer;
}

.minimap {
  position: absolute;
  left: max(14px, env(safe-area-inset-left, 0px));
  top: max(88px, calc(env(safe-area-inset-top, 0px) + 74px));
  width: 148px;
  height: 148px;
  border-radius: 50%;
  border: 2px solid rgba(46, 200, 195, 0.6);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4);
  background: rgba(18, 12, 8, 0.35);
}

@media (max-width: 800px) {
  .hint {
    display: none;
  }

  #speed {
    font-size: 28px;
  }

  .bars {
    min-width: 200px;
  }

  .tips {
    display: none;
  }

  .screen h1 {
    font-size: clamp(36px, 12vw, 64px);
  }

  .go {
    font-size: 15px;
  }
}

#countdown {
  pointer-events: none;
}

#touch-layer {
  position: absolute;
  inset: 0;
  z-index: 6;
  touch-action: none;
  pointer-events: auto;
}

#rev-btn {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom, 0px));
  width: 42px;
  height: 42px;
  margin-left: -21px;
  border-radius: 50%;
  border: 2px solid rgba(244, 239, 230, 0.55);
  background: rgba(22, 14, 10, 0.55);
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  letter-spacing: 0.08em;
  pointer-events: auto;
  z-index: 7;
}

#rev-btn.held {
  border-color: var(--gold);
  color: var(--gold);
}

#mobile-hint {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 14;
  pointer-events: none;
  padding: 6px 12px;
  border-radius: 99px;
  background: rgba(22, 14, 10, 0.82);
  color: var(--text);
  font-size: 13px;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

#tilt-btn {
  position: absolute;
  top: max(48px, calc(env(safe-area-inset-top, 0px) + 36px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 14;
  pointer-events: auto;
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 2px solid var(--teal);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  padding: 6px 12px;
}

#rotate-hint {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a120e;
  color: var(--text);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 22px;
  pointer-events: auto;
}

html.race-portrait #view,
html.race-portrait #hud,
html.race-portrait #rev-wrap,
html.race-portrait #touch-layer,
html.race-portrait #mobile-hint,
html.race-portrait #countdown {
  visibility: hidden;
}

html.race-portrait #rotate-hint,
html.race-portrait #rotate-hint.hidden {
  display: flex !important;
  visibility: visible !important;
  z-index: 40;
}

@media (orientation: portrait) {
  html.race-live #view,
  html.race-live #hud,
  html.race-live #rev-wrap,
  html.race-live #touch-layer,
  html.race-live #mobile-hint,
  html.race-live #countdown {
    visibility: hidden;
  }

  html.race-live #rotate-hint,
  html.race-live #rotate-hint.hidden {
    display: flex !important;
    visibility: visible !important;
    z-index: 40;
  }
}

html.race-portrait #tilt-btn,
html.race-portrait #btn-menu {
  z-index: 41;
}

.garage {
  width: min(420px, 92vw);
  margin: 8px 0 0;
  text-align: left;
}

.garage-label {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 8px 0 4px;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(244, 239, 230, 0.35);
  padding: 0;
  cursor: pointer;
}

.swatch.on {
  outline: 2px solid var(--teal);
  border-color: #fff;
}

#track-screen {
  --tile: 72px;
  justify-content: flex-start;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
  padding: 8px 10px 10px;
  gap: 4px;
  z-index: 8;
  min-height: 0;
}

#track-screen > :not(.tile-map-host) {
  flex: 0 0 auto;
}

#track-screen h1 {
  font-size: clamp(22px, 5.5vw, 44px);
}

.tile-palette {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 10px;
  width: min(960px, 96vw);
  overflow-x: auto;
  overflow-y: hidden;
  padding: 10px 12px 16px;
  margin: 0;
  touch-action: none;
  -webkit-overflow-scrolling: touch;
  background: rgba(18, 14, 10, 0.55);
  border: 1px solid rgba(244, 239, 230, 0.12);
  border-radius: 10px;
}

.palette-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  min-width: var(--tile);
  touch-action: none;
}

.palette-name {
  font-size: clamp(8px, calc(var(--tile) * 0.145), 10px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  pointer-events: none;
  line-height: 1.15;
  text-align: center;
  overflow: visible;
  white-space: nowrap;
}

.palette-tile,
.tile-cell,
.tile-ghost {
  display: block;
  padding: 0;
  border: 0;
  background-color: transparent;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  touch-action: none;
  cursor: grab;
  overflow: hidden;
}

.palette-tile {
  width: var(--tile);
  height: var(--tile);
  aspect-ratio: 1 / 1;
  flex: none;
  border-radius: 0;
  box-shadow: 0 2px 0 #3d3932, 0 5px 10px rgba(0, 0, 0, 0.4);
  background-color: #6a655c;
  background-size: 100% 100%;
  overflow: hidden;
}

.palette-tile svg,
.tile-cell svg,
.tile-ghost svg {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.palette-tile.wide {
  width: calc(var(--tile) * 2);
  height: var(--tile);
  max-height: var(--tile);
  aspect-ratio: 2 / 1;
  flex: none;
}

.palette-tile.block {
  width: calc(var(--tile) * 2);
  height: calc(var(--tile) * 2);
  aspect-ratio: 1 / 1;
  flex: none;
}

.palette-tile.picked,
.tile-cell.picked {
  outline: 3px solid var(--gold);
  outline-offset: -2px;
}

.tile-map-host {
  flex: 1 1 auto;
  min-height: min(240px, 42vh);
  min-width: 0;
  width: min(960px, 96vw);
  display: flex;
  align-items: center;
  justify-content: center;
  container-type: size;
  touch-action: none;
}

.tile-map {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  grid-template-rows: repeat(12, 1fr);
  gap: 0;
  width: min(100%, calc(100cqh * 16 / 12));
  aspect-ratio: 16 / 12;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  padding: 0;
  margin: 0;
  background: #6a655c;
  background-image: linear-gradient(rgba(26, 18, 14, 0.22) 1px, transparent 1px),
    linear-gradient(90deg, rgba(26, 18, 14, 0.22) 1px, transparent 1px);
  background-size: calc(100% / 16) calc(100% / 12);
  border: 3px solid #3d3932;
  border-radius: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  touch-action: none;
  position: relative;
}

.tile-cell {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  position: relative;
  border-radius: 0;
  background-size: 100% 100%;
  overflow: hidden;
}

.tile-cell.empty {
  background-image: none;
  background-color: transparent;
  cursor: copy;
}

.tile-cell.drop {
  box-shadow: inset 0 0 0 3px var(--gold);
}

.tile-trash.drop {
  outline: 3px solid var(--gold);
}

.tile-ghost {
  position: fixed;
  z-index: 30;
  width: 80px;
  height: 80px;
  pointer-events: none;
  margin: 0;
  opacity: 0.96;
  transform: translate(-50%, -50%);
  border-radius: 0;
  background-size: 100% 100%;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.5);
}

.tile-rot,
.tile-trash {
  min-width: 112px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 16px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 8px;
  border: 3px solid var(--gold);
  background: #3f3c36;
  color: var(--text);
  padding: 0 16px;
  touch-action: none;
  cursor: pointer;
}

.tile-rot {
  min-width: 148px;
}

.tile-rot:disabled {
  opacity: 0.38;
  cursor: default;
}

.tile-rot-handle {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: min(44px, 70%);
  height: min(44px, 70%);
  aspect-ratio: 1 / 1;
  min-width: 22px;
  min-height: 22px;
  border-radius: 50%;
  border: 3px solid #1a120e;
  background: var(--gold);
  color: #1a120e;
  font-size: clamp(12px, 2.8vmin, 22px);
  line-height: 1;
  z-index: 3;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.editor-dock {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  width: min(960px, 96vw);
  margin: 0;
}

#track-screen .lobby-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  width: min(960px, 96vw);
  margin: 0;
}

.track-share {
  flex: 1 1 160px;
  min-width: 120px;
}

.editor-help {
  max-width: 680px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.03em;
  text-transform: none;
  margin: 2px 0 2px;
}

#track-code-view {
  word-break: break-all;
}

.board-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: rgba(244, 239, 230, 0.55);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 13px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

@media (max-height: 700px) {
  #track-screen {
    padding: 6px 8px 8px;
    gap: 3px;
  }

  #track-screen .eyebrow,
  #track-screen .editor-help {
    display: none;
  }

  #track-screen h1 {
    font-size: clamp(20px, 4.4vw, 28px);
  }

  #track-screen .sub {
    margin: 2px 0;
    font-size: 12px;
  }

  #track-screen .circuit-row {
    margin: 2px 0;
  }

  #track-screen .lobby-btn.circuit {
    padding: 4px 8px;
    font-size: 12px;
  }

  .tile-palette {
    padding: 6px 8px 14px;
    gap: 8px;
  }

  .tile-rot,
  .tile-trash {
    min-height: 44px;
    min-width: 88px;
    font-size: 14px;
  }

  .tile-rot {
    min-width: 120px;
  }
}

@media (max-height: 480px) {
  .tile-rot,
  .tile-trash {
    min-height: 38px;
    font-size: 13px;
    padding: 0 12px;
  }
}

@media (max-width: 700px) {
  .tile-palette {
    gap: 8px;
    padding: 8px 8px 14px;
  }

  .palette-name {
    letter-spacing: 0.03em;
  }

  .tile-rot,
  .tile-trash {
    min-width: 0;
    flex: 1 1 96px;
  }
}
