:root {
  /* Layout: one portrait column, the arena canvas on top and the thumb panel below. Single dark arena look by choice. */
  --ink: #191427;
  --panel: #120e1c;
  --stone: #2e2540;
  --stone-hi: #4a3d61;
  --sand: #e8d6b0;
  --sand-deep: #a88d5f;
  --hazard: #ffb31a;
  --hazard-deep: #b97800;
  --blood: #ff4b3e;
  --blood-deep: #a3241b;
  --text: #f6efe2;
  --muted: #b3a8c4;
  --display: 'Bungee', Impact, 'Arial Black', sans-serif;
  --body: 'Rubik', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ink);
  color: var(--text);
  overscroll-behavior: none;
}

body {
  font-family: var(--body);
  font-size: 14px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  background: var(--ink);
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

#frame {
  position: relative;
  width: 100%;
  max-width: 62vh;
  max-width: 62dvh;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--ink);
}

#stage { position: relative; flex: 1 1 auto; min-height: 0; }

#cv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* Thumb panel: joystick on the left, actions on the right. */
#controls {
  flex: none;
  height: clamp(168px, 27%, 232px);
  box-sizing: border-box;
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 10px;
  padding: 10px 16px 12px;
  background: var(--panel);
  border-top: 2px solid var(--stone-hi);
  touch-action: none;
  transition: opacity .2s;
}
#controls.idle { opacity: .3; pointer-events: none; }

.stick-zone {
  position: relative;
  border-radius: 18px;
  background: rgba(255, 255, 255, .035);
  border: 1.5px dashed rgba(255, 255, 255, .16);
  touch-action: none;
  overflow: hidden;
}
.stick-base {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 96px;
  height: 96px;
  margin: -48px 0 0 -48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .06);
  border: 2px solid rgba(255, 255, 255, .2);
  pointer-events: none;
  opacity: .55;
}
.stick-base.on { opacity: 1; }
.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: var(--sand);
  box-shadow: 0 3px 0 var(--sand-deep);
}
.zone-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  text-align: center;
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  pointer-events: none;
}

.actions { position: relative; display: grid; gap: 8px; min-width: 0; }
/* Small moves stacked on the left, a tall jump button under the right thumb. */
.runner-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); }
#b-sprint { grid-area: 1 / 1; }
#b-push { grid-area: 2 / 1; }
#b-decoy { grid-area: 3 / 1; }
#b-duck { grid-area: 1 / 2; }
#b-jump { grid-area: 2 / 2 / 4 / 3; }
.trapper-actions { grid-template-rows: 1.6fr 1fr; }

.btn {
  position: relative;
  overflow: hidden;
  min-width: 0;
  border: 0;
  border-radius: 14px;
  padding: 0 6px;
  font-family: var(--display);
  font-size: 14px;
  line-height: 1.05;
  color: var(--ink);
  background: var(--sand);
  box-shadow: 0 4px 0 var(--sand-deep);
  touch-action: none;
  cursor: pointer;
  transition: transform .05s, filter .15s;
}
.btn.small { font-size: 11px; }
.btn i {
  display: inline-block;
  min-width: 1.4em;
  margin-left: 2px;
  padding: 1px 4px;
  border-radius: 6px;
  font-style: normal;
  font-family: var(--body);
  font-weight: 700;
  font-size: 11px;
  background: var(--ink);
  color: var(--sand);
}
.btn.big { background: var(--hazard); box-shadow: 0 4px 0 var(--hazard-deep); font-size: 19px; }
.btn.danger { background: var(--blood); color: var(--text); box-shadow: 0 4px 0 var(--blood-deep); }
.btn.down { transform: translateY(3px); box-shadow: 0 1px 0 var(--sand-deep); }
.btn.big.down { box-shadow: 0 1px 0 var(--hazard-deep); }
.btn.danger.down { box-shadow: 0 1px 0 var(--blood-deep); }
.btn.off { filter: saturate(.25) brightness(.6); }
.btn::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: calc(var(--cd, 0) * 100%);
  background: rgba(25, 20, 39, .5);
  pointer-events: none;
}
.btn:focus-visible { outline: 3px solid var(--text); outline-offset: 2px; }
.btn.armed { animation: armed .6s ease-in-out infinite alternate; }
@keyframes armed { to { filter: brightness(1.18); transform: scale(1.02); } }
@media (hover: hover) { .btn:hover { filter: brightness(1.06); } }

.btn.fast {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  background: var(--stone-hi);
  color: var(--text);
  box-shadow: 0 4px 0 var(--stone);
  font-size: 16px;
}
#controls.dead .runner-actions .btn:not(.fast) { visibility: hidden; }

/* Menu and round-end screens sit over the arena. */
.overlay {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  display: flex;
  background: rgba(25, 20, 39, .8);
}
.menu-inner {
  margin: auto 0;
  width: 100%;
  box-sizing: border-box;
  padding-block: 24px;
  padding-left: 20px;
  padding-right: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.eyebrow {
  margin: 0;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--hazard);
}
.logo {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(48px, 15vw, 72px);
  line-height: .88;
  color: var(--sand);
  text-shadow: 0 5px 0 #5b2a20;
}
.logo span { display: block; color: var(--blood); }
.stripe {
  height: 10px;
  width: 62%;
  border-radius: 3px;
  background: repeating-linear-gradient(-45deg, var(--hazard) 0 10px, var(--ink) 10px 20px);
}
.tag { margin: 0; font-size: 15px; line-height: 1.45; max-width: 34ch; color: var(--text); }
.menu-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.menu-btns .btn { height: 54px; font-size: 18px; }
.howto {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}
.howto b {
  display: block;
  margin-bottom: 3px;
  font-family: var(--display);
  font-weight: 400;
  font-size: 13px;
  color: var(--text);
}
.keys { margin: 0; font-size: 12px; line-height: 1.45; color: var(--muted); }
@media (hover: none) { .keys { display: none; } }
.link {
  align-self: flex-start;
  padding: 6px 0;
  background: none;
  border: 0;
  color: var(--muted);
  font: 500 13px var(--body);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.over-head {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(30px, 9vw, 42px);
  line-height: 1;
  color: var(--sand);
  text-wrap: balance;
}
.stats { margin: 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  .btn.armed { animation: none; }
}

/* Online screens */
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair .btn { height: 48px; font-size: 14px; }
.links { display: flex; flex-wrap: wrap; gap: 4px 20px; }
.hint { color: var(--sand); }

.field {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.field input, .join-row input {
  box-sizing: border-box;
  width: 100%;
  height: 50px;
  padding: 0 14px;
  border: 2px solid var(--stone-hi);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font: 500 18px var(--body);
  letter-spacing: normal;
  text-transform: none;
  -webkit-user-select: text;
  user-select: text;
}
.field input:focus, .join-row input:focus { outline: none; border-color: var(--hazard); }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.join-row input { font-family: var(--display); letter-spacing: .2em; text-transform: uppercase; }
.join-row .btn { height: 50px; padding: 0 18px; font-size: 15px; }
.or { margin: 4px 0 -4px; font-size: 13px; color: var(--muted); }
.error { margin: 0; font-size: 14px; color: #ff8a80; }

.room-code {
  font-family: var(--display);
  font-size: clamp(56px, 18vw, 84px);
  line-height: .9;
  letter-spacing: .08em;
  color: var(--sand);
  text-shadow: 0 5px 0 #5b2a20;
}
.invite-url {
  margin: -4px 0 0;
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
  -webkit-user-select: text;
  user-select: text;
}
.players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}
.players li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .06);
  font-size: 15px;
  font-weight: 500;
}
.players em {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--stone-hi);
  color: var(--sand);
  font-size: 11px;
  font-style: normal;
  letter-spacing: .04em;
}
.note { margin: 0; font-size: 13px; line-height: 1.45; color: var(--muted); }
.menu-inner > .btn { flex: none; height: 54px; font-size: 18px; }
.next { margin: 0; font-family: var(--display); font-size: 15px; color: var(--hazard); }

.toast {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--sand);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  z-index: 3;
}

/* Watching a round online: no controls, just a note. */
.spectate-note { display: none; }
#controls.watching > .stick-zone, #controls.watching > .actions { display: none !important; }
#controls.watching .spectate-note {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: center;
  margin: 0;
  text-align: center;
  font-family: var(--display);
  font-size: 15px;
  color: var(--muted);
}
