:root {
  color-scheme: dark;
  font-family: Arial, sans-serif;
  background: #0a0808;
  --rage: #c83b32;
  --ember: #e7a053;
  --paper: #eee7dc;
  --smoke: #a49c91;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 18%, #36221b, #0a0808 64%);
}

body {
  display: grid;
  place-items: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#game-shell {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background:
    radial-gradient(circle at 72% 38%, rgba(132, 47, 31, .22), transparent 28%),
    linear-gradient(145deg, #211715 0%, #100d0d 58%, #080707 100%);
  background: #111;
  box-shadow: 0 22px 90px #000;
}

#game-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(191,67,45,.07), transparent 19%, transparent 82%, rgba(230,151,78,.05)),
    radial-gradient(circle at 76% 18%, rgba(255,190,107,.11), transparent 27%);
  mix-blend-mode: screen;
  opacity: .55;
  transition: opacity .12s ease;
}

body[data-weapon="pipe"] #game-shell::before {
  box-shadow: inset 0 0 74px rgba(255, 102, 38, .16);
}

body[data-weapon="chain"] #game-shell::before {
  box-shadow: inset 0 0 82px rgba(50, 190, 255, .17);
}

#game-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 45%, rgba(3, 2, 4, .42) 100%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.018) 0 1px, rgba(0,0,0,.016) 1px 3px);
  mix-blend-mode: multiply;
  opacity: .58;
}

body[data-damaged="1"] #game-shell::after {
  box-shadow: inset 0 0 92px 22px rgba(128, 8, 3, .27);
}

body[data-takedown="1"] #game-shell::before {
  opacity: 1;
  background:
    linear-gradient(90deg, rgba(255, 51, 28, .28), transparent 26%, transparent 74%, rgba(255, 177, 38, .24)),
    radial-gradient(circle at center, rgba(255, 241, 198, .12), transparent 48%);
}

canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

#scene {
  z-index: 0;
}
#game { z-index: 1; pointer-events: none; }
.screen-card { z-index: 4; }

#exit-button {
  position: absolute;
  z-index: 6;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  width: 48px;
  min-height: 48px;
  padding: 0;
  border: 1px solid rgba(255,255,255,.52);
  border-radius: 3px;
  color: var(--paper);
  background: rgba(12, 10, 12, .78);
  box-shadow: 0 5px 18px rgba(0,0,0,.52);
  font: 500 clamp(1.65rem, 2.7vw, 2.15rem)/1 Arial, sans-serif;
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

#exit-button:hover { background: rgba(92, 27, 24, .92); }
#exit-button:focus-visible {
  outline: 3px solid #fff2c7;
  outline-offset: 3px;
  background: rgba(125, 35, 30, .96);
}

.screen-card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  padding: clamp(28px, 5vw, 72px);
  text-align: left;
  background:
    linear-gradient(90deg, rgba(9, 7, 7, .92), rgba(9, 7, 7, .18) 52%, transparent 76%),
    linear-gradient(0deg, rgba(8, 6, 6, .90), transparent 58%);
  transition: opacity .22s ease;
}

#loading-status {
  margin: .72rem 0 0;
  color: rgba(241, 203, 158, .78);
  font-size: clamp(.64rem, .88vw, .82rem);
  font-weight: 750;
  letter-spacing: .22em;
  text-transform: uppercase;
}

#loading-status::after {
  content: "";
  display: inline-block;
  width: 1.8em;
  animation: loading-pulse 1.05s steps(4, end) infinite;
}

body[data-world-ready="1"] #loading-status { display: none; }

#start-button:disabled {
  cursor: wait;
  filter: saturate(.45);
  opacity: .54;
}

@keyframes loading-pulse {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75%, 100% { content: "..."; }
}

.hidden { display: none !important; }

#result-screen {
  align-items: center;
  justify-content: center;
  gap: clamp(.8rem, 2.2vh, 1.4rem);
  text-align: center;
  background: rgba(8, 6, 6, .78);
}

.brand-lockup {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: min(760px, 90vw);
}

.course-selector {
  width: min(720px, 90vw);
  min-inline-size: 0;
  margin: clamp(14px, 2.2vh, 22px) 0 0;
  padding: 0;
  border: 0;
}

.course-selector legend {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  width: 100%;
  margin: 0 0 7px;
  padding: 0;
  color: var(--paper);
  font: 900 clamp(.66rem, 1vw, .82rem)/1 Arial, sans-serif;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.course-selector legend small {
  color: rgba(231, 160, 83, .82);
  font: 800 .68rem/1 Arial, sans-serif;
  letter-spacing: .18em;
}

.course-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.course-option {
  position: relative;
  min-width: 0;
  cursor: pointer;
}

.course-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.course-option-copy {
  position: relative;
  display: block;
  min-height: 49px;
  overflow: hidden;
  padding: 9px 12px 8px 15px;
  border: 1px solid rgba(238, 231, 220, .19);
  background:
    linear-gradient(110deg, rgba(39, 31, 29, .93), rgba(18, 16, 17, .82)),
    rgba(10, 8, 9, .78);
  box-shadow: inset 0 1px rgba(255,255,255,.035), 0 3px 10px rgba(0,0,0,.24);
  transition: border-color .14s ease, background .14s ease, transform .14s ease, box-shadow .14s ease;
}

.course-option-copy::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: rgba(200, 59, 50, .42);
  transition: width .14s ease, background .14s ease;
}

.course-option-copy strong,
.course-option-copy small {
  position: relative;
  z-index: 1;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.course-option-copy strong {
  color: var(--paper);
  font: 900 clamp(.67rem, .92vw, .78rem)/1 Arial, sans-serif;
  letter-spacing: .105em;
}

.course-option-copy small {
  margin-top: 5px;
  color: rgba(164, 156, 145, .88);
  font: 700 clamp(.55rem, .76vw, .67rem)/1 Arial, sans-serif;
  letter-spacing: .045em;
}

.course-option:hover .course-option-copy {
  border-color: rgba(231, 160, 83, .48);
  transform: translateY(-1px);
}

.course-option input:focus-visible + .course-option-copy {
  outline: 2px solid rgba(238, 231, 220, .88);
  outline-offset: 2px;
}

.course-option input:checked + .course-option-copy {
  border-color: rgba(231, 160, 83, .88);
  background:
    linear-gradient(110deg, rgba(102, 45, 34, .96), rgba(31, 21, 20, .92)),
    rgba(10, 8, 9, .88);
  box-shadow: inset 0 1px rgba(255,255,255,.09), 0 5px 15px rgba(0,0,0,.36);
}

.course-option input:checked + .course-option-copy::before {
  width: 6px;
  background: var(--ember);
}

.course-option input:checked + .course-option-copy small { color: rgba(238, 231, 220, .78); }

h1, h2 {
  margin: 0;
  color: var(--paper);
  letter-spacing: -.045em;
  text-shadow: 0 6px 18px rgba(0,0,0,.85), 0 2px 0 #000;
}

.brand-neighborhood {
  display: block;
  padding-left: .16em;
  font: 900 clamp(1.05rem, 2.5vw, 2rem)/1 "Arial Narrow", Arial, sans-serif;
  letter-spacing: .18em;
  color: var(--paper);
}

.brand-rage {
  display: block;
  margin-top: -.04em;
  font: 900 clamp(5rem, 13.4vw, 10.4rem)/.78 Impact, "Arial Narrow", "Arial Black", sans-serif;
  letter-spacing: -.035em;
  color: var(--rage);
}

h2 {
  max-width: 850px;
  font: 900 clamp(3rem, 8vw, 7rem)/.85 Impact, "Arial Narrow", "Arial Black", sans-serif;
}

button {
  border: 1px solid rgba(255,255,255,.34);
  border-radius: 2px;
  color: #0c0a0d;
  background: var(--rage);
  color: #fff;
  font: 900 1rem/1 Arial, sans-serif;
  letter-spacing: .08em;
  cursor: pointer;
}

.brand-lockup > button,
#result-screen > button {
  margin-top: clamp(12px, 1.8vw, 24px);
  padding: .9rem 2.45rem;
  box-shadow: 0 5px 18px rgba(0,0,0,.56), inset 0 1px rgba(255,255,255,.22);
  transform: none;
}

.brand-lockup > button:hover,
.brand-lockup > button:focus-visible,
#result-screen > button:hover,
#result-screen > button:focus-visible { background: #df4a3e; transform: translateY(-2px); outline: none; }

.control-strip {
  margin: 1rem 0 0;
  color: var(--smoke);
  font: 700 clamp(.62rem, 1vw, .78rem)/1.4 Arial, sans-serif;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.control-strip span { color: var(--paper); }

#result-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2rem;
  color: var(--paper);
  font: 700 1rem/1.4 Arial, sans-serif;
  text-transform: uppercase;
}

#result-stats strong { display: block; color: var(--ember); font-size: 1.7rem; }

#result-standings {
  display: grid;
  grid-template-columns: repeat(5, minmax(54px, 1fr));
  gap: 7px;
  width: min(720px, 90vw);
  color: var(--paper);
}

#result-standings:empty { display: none; }

#result-standings > * {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 7px 9px;
  border: 1px solid rgba(238, 231, 220, .16);
  border-top: 4px solid currentColor;
  background: rgba(18, 15, 16, .78);
  box-shadow: inset 0 1px rgba(255,255,255,.035), 0 3px 10px rgba(0,0,0,.28);
  font: 900 clamp(.68rem, 1.2vw, .88rem)/1 Arial, sans-serif;
  letter-spacing: .10em;
  text-transform: uppercase;
}

#result-standings .standing-color,
#result-standings .result-standing-color {
  width: 10px;
  height: 10px;
  margin-right: 7px;
  border: 1px solid rgba(255,255,255,.55);
  background: var(--standing-color, currentColor);
  box-shadow: 0 0 8px currentColor;
}

#touch-controls { display: none; }

@media (pointer: coarse), (max-width: 720px) {
  .controls-grid { display: none; }
  #touch-controls {
    position: absolute;
    inset: auto 0 max(12px, env(safe-area-inset-bottom)) 0;
    z-index: 4;
    display: flex;
    justify-content: space-between;
    padding: 0 3vw;
    pointer-events: none;
  }
  .touch-cluster { display: flex; gap: 8px; align-items: end; pointer-events: auto; }
  .touch-cluster button {
    width: clamp(44px, 9.2vw, 70px);
    height: clamp(48px, 11vw, 70px);
    color: white;
    background: rgba(20, 17, 24, .72);
    border: 2px solid rgba(255,255,255,.52);
    font-size: clamp(.65rem, 2vw, .85rem);
    backdrop-filter: blur(5px);
  }
  .touch-cluster button.throttle { height: clamp(66px, 16vw, 98px); background: rgba(219, 39, 32, .8); }
  .touch-cluster button.brace { background: rgba(73, 79, 91, .84); }
  .touch-cluster button.kick { background: rgba(119, 67, 42, .90); }
  .touch-cluster button.wheelie { background: rgba(171, 113, 48, .88); }
  .screen-card:not(.hidden) ~ #touch-controls { display: none; }
  .screen-card { justify-content: center; padding: 7vw; }
  .brand-lockup { width: min(92vw, 760px); }
  .course-selector { width: 100%; margin-top: 10px; }
  .course-selector legend { margin-bottom: 5px; }
  .course-options { gap: 4px; }
  .course-option-copy { min-height: 38px; padding: 8px 8px 7px 11px; }
  .course-option-copy strong { font-size: clamp(.54rem, 1.8vw, .68rem); }
  .course-option-copy small { display: none; }
  .control-strip { display: none; }
  #exit-button {
    min-width: 44px;
    width: 44px;
    min-height: 44px;
    padding: 0;
    font-size: 1.55rem;
  }
}

@media (pointer: coarse) and (max-width: 520px) {
  #touch-controls { align-items: end; }
  .touch-cluster { gap: 6px; }
  .touch-cluster.actions {
    display: grid;
    grid-template-columns: repeat(4, 44px);
    justify-content: end;
  }
  .touch-cluster.actions button,
  .touch-cluster.actions button.throttle {
    width: 44px;
    height: 44px;
  }
}

@media (pointer: coarse) and (orientation: portrait) {
  .screen-card { padding: 10px 12px; }
  .brand-neighborhood { font-size: .5rem; }
  .brand-rage { font-size: 2.75rem; }
  .course-selector { margin-top: 4px; }
  .course-selector legend {
    margin-bottom: 3px;
    font-size: .48rem;
  }
  .course-selector legend small { font-size: .45rem; }
  .course-options {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
  }
  .course-option-copy {
    min-height: 25px;
    padding: 6px 4px 4px 7px;
  }
  .course-option-copy::before { width: 2px; }
  .course-option input:checked + .course-option-copy::before { width: 3px; }
  .course-option-copy strong { font-size: .42rem; letter-spacing: .04em; }
  .brand-lockup > button {
    margin-top: 4px;
    padding: .45rem 1.25rem;
    font-size: .68rem;
  }
  #loading-status { margin-top: 3px; font-size: .45rem; }
  #result-screen { gap: 4px; }
  #result-screen h2 { font-size: 2rem; }
  #result-stats { gap: .65rem; font-size: .58rem; }
  #result-stats strong { font-size: 1rem; }
  #result-standings { gap: 3px; }
  #result-standings > * {
    min-height: 25px;
    padding: 3px 4px;
    border-top-width: 3px;
    font-size: .52rem;
  }
  #result-screen > button {
    margin-top: 3px;
    padding: .45rem 1.25rem;
    font-size: .68rem;
  }
}

@media (max-height: 500px) {
  .screen-card { padding: 5vh 5vw; }
  .brand-neighborhood { font-size: min(4vh, 1rem); }
  .brand-rage { font-size: min(24vh, 7rem); }
  .course-selector { margin-top: 2vh; }
  .course-selector legend { margin-bottom: 4px; }
  .course-option-copy { min-height: 34px; padding: 6px 7px 5px 10px; }
  .course-option-copy small { display: none; }
  .brand-lockup > button { margin-top: 2vh; padding: .7rem 1.9rem; }
  .control-strip { display: none; }
}
