:root {
  --red: #b40000;
  --red-hi: #ff2a1a;
  --gold: #f4c542;
  --ink: #f2e9dc;
  --dim: #b9a99a;
  --panel: rgba(12, 6, 4, 0.86);
  --line: rgba(255, 200, 150, 0.18);
  --font: "VT323", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #000; color: var(--ink); font-family: var(--font); }
body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ───────── menus ───────── */
#menus {
  position: fixed; inset: 0; overflow-y: auto; z-index: 10;
  background: #000 url(title.png) center top / cover no-repeat;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
#menus::before {
  content: ""; position: fixed; inset: 0; pointer-events: none;
  background: linear-gradient(to bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,0.25) 40%, rgba(0,0,0,0.85) 100%);
}
.screen { position: relative; min-height: 100%; display: flex; align-items: flex-end; justify-content: center; }
@media (orientation: landscape) { .screen { align-items: center; justify-content: flex-end; } }

.card {
  width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}
h2 { margin: 0; font-size: 30px; font-weight: 400; color: var(--gold); letter-spacing: 1px; text-transform: uppercase; }
.small { margin: 0; font-size: 18px; color: var(--dim); text-align: center; }
.hint { margin: -4px 0 0; font-size: 18px; color: var(--dim); line-height: 1.1; }
.status { margin: 0; font-size: 22px; text-align: center; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 18px; color: var(--dim); }
.field span { display: flex; justify-content: space-between; }
input[type=text], input:not([type]), select {
  width: 100%; font-size: 24px; padding: 10px 12px; border-radius: 10px;
  background: rgba(0,0,0,0.6); border: 1px solid var(--line); color: var(--ink);
  -webkit-user-select: text; user-select: text;
}
select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--dim) 50%), linear-gradient(135deg, var(--dim) 50%, transparent 50%); background-position: calc(100% - 20px) 55%, calc(100% - 14px) 55%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 34px; }
input:focus, select:focus { outline: 2px solid var(--red-hi); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 22px; }
.check input { width: 22px; height: 22px; accent-color: var(--red); }

.btn {
  font-size: 26px; padding: 10px 14px; border-radius: 10px; cursor: pointer;
  background: rgba(255,255,255,0.08); border: 1px solid var(--line); text-transform: uppercase; letter-spacing: 1px;
}
.btn:active { transform: translateY(1px); filter: brightness(1.2); }
.btn.primary { background: linear-gradient(#d41a0a, #8a0000); border-color: #ff5a3a; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,0.5); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--dim); font-size: 22px; padding: 4px; }
.btn:disabled { opacity: 0.45; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 4px; text-align: center; }
.join-row .btn { flex: 0 0 auto; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; font-size: 22px; padding: 8px 4px; background: transparent; border: 0; color: var(--dim); }
.seg button.on { background: var(--red); color: #fff; }

.code { font-size: 84px; line-height: 0.9; text-align: center; letter-spacing: 12px; color: var(--gold); text-shadow: 0 3px 0 #6b0000, 0 0 24px rgba(255,80,0,0.35); }
#players { margin: 0; padding: 0 0 0 28px; font-size: 26px; min-height: 30px; }
#players li::marker { color: var(--dim); }
#players li.me { color: var(--gold); }

/* ───────── game ───────── */
#canvas {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  height: 100vh !important; height: 100dvh !important;
  width: calc(100vh * 4 / 3) !important; width: calc(100dvh * 4 / 3) !important;
  max-width: 100vw; background: #000; image-rendering: pixelated; z-index: 1;
  border: 0; padding: 0; outline: none;
}
body:not(.playing) #canvas { visibility: hidden; }

#pad { position: fixed; inset: 0; z-index: 5; touch-action: none; }
#pad button { touch-action: none; }

#stick-base {
  position: absolute; width: 132px; height: 132px; margin: -66px 0 0 -66px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.22); background: rgba(0,0,0,0.18); pointer-events: none;
  left: 18%; top: 68%; opacity: 0.55; transition: opacity 0.15s;
}
#stick-base.active { opacity: 1; transition: none; }
#stick-knob {
  position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%;
  background: rgba(255,255,255,0.35); border: 2px solid rgba(255,255,255,0.5);
}

.pb {
  position: absolute; border-radius: 50%; border: 2px solid rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.25); color: rgba(255,255,255,0.85); font-size: 22px; letter-spacing: 1px;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.pb.down { background: rgba(255,60,30,0.45); border-color: rgba(255,120,80,0.9); }
/* right-hand cluster: stacked so it lives in the bar beside the 4:3 picture */
#b-fire { width: 100px; height: 100px; right: max(20px, env(safe-area-inset-right)); bottom: 22px; font-size: 26px; border-color: rgba(255,90,60,0.7); background: rgba(160,0,0,0.3); }
#b-use  { width: 66px; height: 66px; right: calc(max(20px, env(safe-area-inset-right)) + 17px); bottom: 136px; }
#b-prev { width: 50px; height: 50px; right: calc(max(20px, env(safe-area-inset-right)) + 56px); bottom: 216px; }
#b-next { width: 50px; height: 50px; right: max(20px, env(safe-area-inset-right)); bottom: 216px; }

.top-bar { position: absolute; top: max(8px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); display: flex; gap: 8px; }
.tb { min-width: 46px; height: 40px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.3); background: rgba(0,0,0,0.35); color: rgba(255,255,255,0.85); font-size: 20px; padding: 0 10px; }

/* left-handed: mirror the right-hand cluster */
body.lefty #b-fire { right: auto; left: max(20px, env(safe-area-inset-left)); }
body.lefty #b-use  { right: auto; left: calc(max(20px, env(safe-area-inset-left)) + 17px); }
body.lefty #b-prev { right: auto; left: max(20px, env(safe-area-inset-left)); }
body.lefty #b-next { right: auto; left: calc(max(20px, env(safe-area-inset-left)) + 56px); }
body.lefty #stick-base { left: 82%; }

#toast {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); pointer-events: none;
  font-size: 22px; background: rgba(0,0,0,0.6); padding: 4px 12px; border-radius: 8px; opacity: 0; transition: opacity 0.3s;
}
#toast.show { opacity: 1; }

#sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet-card { width: 100%; max-width: 420px; max-height: 100%; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.macros { display: flex; flex-wrap: wrap; gap: 6px; }
.macros button { font-size: 20px; padding: 6px 10px; border-radius: 8px; background: rgba(255,255,255,0.08); border: 1px solid var(--line); }
input[type=range] { width: 100%; accent-color: var(--red); }

#rotate { display: none; }
@media (orientation: portrait) {
  body.playing #rotate {
    display: flex; position: fixed; inset: 0; z-index: 30; background: #000; align-items: center; justify-content: center; text-align: center; font-size: 30px; padding: 16px;
  }
}
.phone-icon { width: 54px; height: 90px; margin: 0 auto 16px; border: 4px solid var(--ink); border-radius: 10px; animation: tip 1.6s ease-in-out infinite; }
@keyframes tip { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
