:root {
  --gold: #ffd23f;
  --navy: #1b2a4d;
  --red: #c0392b;
  --bg: #07090f;
  --panel: rgba(10, 14, 26, 0.92);
  --line: #2b3a5c;
  --text: #eef2fb;
  --muted: #98a3bf;
  --font: 'Press Start 2P', 'Courier New', Courier, monospace;
  /* safe-area insets in real px (used by the un-scaled chrome / overlay) */
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; }
html {
  height: 100%;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
html, body {
  margin: 0; padding: 0; width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
body {
  position: fixed; inset: 0;
  height: 100%;
  height: 100dvh;          /* mobile address bars: dynamic viewport */
}
button, a { -webkit-touch-callout: none; }
input, textarea { -webkit-user-select: text; user-select: text; }

/* the 540-tall logical stage, uniformly scaled by game.js (fit()) */
#stage {
  position: absolute; left: 0; top: 0;
  width: 960px; height: 540px;
  transform-origin: 0 0;
  background: #0b1220;
  /* logical-px safe insets, set by fit(): inset / scale */
  --sl: 0px; --sr: 0px; --sb: 0px; --st: 0px;
}
#game {
  display: block; width: 960px; height: 540px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: crosshair;
}
.ui { position: absolute; }
.hidden { display: none !important; }
#safeProbe {
  position: fixed; left: 0; top: 0; width: 0; height: 0; visibility: hidden; pointer-events: none;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
}

/* device-specific hint text: body gets .is-touch or .is-desktop */
.kbd-only { display: none; }
.touch-only { display: none; }
body.is-desktop .kbd-only { display: inline; }
body.is-touch .touch-only { display: inline; }

/* ---- real-pixel chrome: corner buttons (never scaled, 44px tall on touch) */
#chrome {
  position: fixed; left: 0; right: 0; top: 0; z-index: 7;
  display: flex; align-items: flex-start; gap: 8px;
  padding: calc(6px + var(--sat)) calc(8px + var(--sar)) 0 calc(8px + var(--sal));
  pointer-events: none;
}
#chrome .spacer { flex: 1; }
.cornerbtn {
  pointer-events: auto;
  height: 36px; min-width: 36px; padding: 0 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: rgba(5,8,16,.8); border: 2px solid var(--line); border-radius: 4px;
  color: var(--text); text-decoration: none; font: inherit; font-size: 10px; letter-spacing: 1px;
  cursor: pointer; text-transform: uppercase; white-space: nowrap;
}
.cornerbtn:hover { border-color: var(--gold); color: var(--gold); }
body.is-touch .cornerbtn { height: 44px; padding: 0 14px; font-size: 11px; }
body.compact .cornerbtn { height: 44px; min-width: 44px; padding: 0 8px; font-size: 10px; }
body.compact #backBtn { width: 44px; padding: 0; font-size: 14px; }

/* ---- bottom play-call panel (logical px, scaled with the stage) */
#playPanel {
  left: 0; right: 0; bottom: 0; z-index: 4;
  display: flex; align-items: stretch; gap: 8px;
  padding: 6px calc(10px + var(--sr)) calc(6px + var(--sb)) calc(10px + var(--sl));
  background: linear-gradient(to top, rgba(5,8,16,.96), rgba(5,8,16,.75));
  border-top: 2px solid var(--line);
}
#playCards { display: flex; flex: 1; gap: 8px; min-width: 0; }
.play-card {
  flex: 1 1 0; min-width: 0; min-height: 64px;
  background: #121a2c; border: 2px solid var(--line); border-radius: 4px;
  padding: 5px 6px 4px; cursor: pointer; text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  transition: transform .08s ease, border-color .08s ease;
}
.play-card:hover { border-color: var(--gold); transform: translateY(-2px); }
.play-card.selected { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(255,210,63,.35), 0 0 16px rgba(255,210,63,.3); background: #1a2238; }
.play-card canvas { width: 96px; height: 40px; max-width: 100%; image-rendering: pixelated; border-radius: 2px; }
.play-card .name { font-size: 9px; letter-spacing: 1px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.play-card .key { font-size: 9px; color: var(--muted); }
#snapHint {
  flex: 0 0 160px; min-height: 64px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 8px;
  background: var(--gold); color: #1a1200; border-radius: 4px; cursor: pointer;
  font-size: 14px; letter-spacing: 2px; text-align: center; line-height: 1.5;
}
#snapHint small { font-size: 9px; letter-spacing: 1px; opacity: .75; }
#snapHint:hover { filter: brightness(1.08); }

/* ---- 4th-down / PAT decision */
#fourthPanel, #patPanel {
  left: 0; right: 0; bottom: 0; z-index: 4;
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  padding: 12px calc(10px + var(--sr)) calc(12px + var(--sb)) calc(10px + var(--sl));
  background: linear-gradient(to top, rgba(5,8,16,.96), rgba(5,8,16,.8));
  border-top: 2px solid var(--line);
}
#fourthPanel .label, #patPanel .label { font-size: 12px; color: var(--gold); letter-spacing: 1px; margin-right: 8px; }
.bigbtn {
  font: inherit; font-size: 12px; letter-spacing: 1px; text-transform: uppercase;
  min-height: 64px; padding: 10px 18px; border-radius: 4px; cursor: pointer;
  background: #121a2c; color: var(--text); border: 2px solid var(--line);
  line-height: 1.4;
}
.bigbtn:hover { border-color: var(--gold); color: var(--gold); }
.bigbtn.primary { background: var(--gold); color: #1a1200; border-color: var(--gold); }
.bigbtn.primary:hover { filter: brightness(1.08); color: #1a1200; }
.bigbtn:disabled { opacity: .4; cursor: not-allowed; }

/* run (scramble) button for touch players, thumb zone bottom-right */
#runBtn {
  right: calc(14px + var(--sr)); bottom: calc(14px + var(--sb)); z-index: 4;
  width: 92px; height: 92px; border-radius: 50%;
  background: rgba(255,210,63,.9); color: #1a1200; border: 3px solid #1a1200;
  font: inherit; font-size: 13px; letter-spacing: 1px; cursor: pointer;
  box-shadow: 0 6px 0 #7a5c00, 0 10px 20px rgba(0,0,0,.5);
  touch-action: none;
}
#runBtn:active { transform: translateY(4px); box-shadow: 0 2px 0 #7a5c00; }

/* ---- rotate hint for phones in portrait */
#rotateHint {
  position: fixed; inset: 0; z-index: 50; display: none;
  align-items: center; justify-content: center; flex-direction: column; gap: 18px;
  background: #07090f; color: var(--gold); text-align: center;
  font-size: clamp(12px, 3.6vw, 16px); line-height: 1.9; padding: 24px;
}
#rotateHint small { display: block; color: var(--muted); font-size: .7em; margin-top: 6px; }
#rotateHint .phone {
  width: 38px; height: 66px; border: 3px solid var(--gold); border-radius: 7px;
  animation: rot 1.6s ease-in-out infinite;
}
@keyframes rot { 0%, 20% { transform: rotate(0); } 60%, 100% { transform: rotate(90deg); } }
@media (orientation: portrait) and (max-width: 900px) {
  #rotateHint { display: flex; }
}
