* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: #000;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #fff;
  /* Prevent pull-to-refresh and accidental scroll on touch devices. */
  touch-action: none;
  overscroll-behavior: none;
}

canvas { display: block; }

/* ── Screens (start, difficulty, pause, end) ───────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 20;
  text-align: center;
  padding: 24px;
}

.screen.hidden { display: none; }

.screen h1 {
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: 3px;
  text-transform: uppercase;
  text-shadow: 0 2px 12px rgba(230, 57, 70, 0.55);
}

.screen .subtitle {
  font-size: 1.05rem;
  font-style: italic;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: #f0c64a;
  margin-top: -10px;
  opacity: 0.92;
}

.screen h2 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 1px;
}

.screen p {
  font-size: 1rem;
  opacity: 0.82;
  max-width: 540px;
  line-height: 1.5;
}

.screen .row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

.btn {
  padding: 12px 32px;
  font-size: 1.05rem;
  font-weight: 600;
  background: #e63946;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.15s, transform 0.1s;
  font-family: inherit;
}

.btn:hover { background: #c1121f; }
.btn:active { transform: translateY(1px); }

.btn.secondary { background: #5a6273; }
.btn.secondary:hover { background: #434957; }

.btn.tile {
  min-width: 180px;
  padding: 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  background: #2a3140;
  border: 2px solid #444b5c;
}
.btn.tile:hover { background: #38415a; border-color: #6c7793; }
.btn.tile strong { font-size: 1.25rem; letter-spacing: 1.5px; }
.btn.tile span { font-size: 0.85rem; opacity: 0.75; font-weight: 400; }

.badge-tag {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: #ffd166;
  color: #1a1a1a;
}

.score-big {
  font-size: 4rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-shadow: 0 2px 12px rgba(255, 209, 102, 0.4);
}

/* ── HUD ───────────────────────────────────────────────────────────────── */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  display: none;
}
#hud.show { display: block; }

#timer {
  position: absolute;
  top: 16px;
  left: 18px;
  background: rgba(0, 0, 0, 0.55);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
}
#timer.low { color: #ff6b6b; animation: pulse 0.8s infinite alternate; }
@keyframes pulse { from { opacity: 0.8; } to { opacity: 1; transform: scale(1.04); } }

#score {
  position: absolute;
  top: 16px;
  right: 18px;
  background: rgba(0, 0, 0, 0.55);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
}

#location {
  position: absolute;
  bottom: 18px;
  left: 18px;
  background: rgba(0, 0, 0, 0.55);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.95rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0.85;
}

#prompt {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 1rem;
  padding: 8px 20px;
  border-radius: 6px;
  display: none;
  pointer-events: none;
  z-index: 5;
  letter-spacing: 0.5px;
}

#toast-stack {
  position: fixed;
  top: 72px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 6;
  align-items: flex-end;
}
.toast {
  background: rgba(0, 0, 0, 0.78);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  animation: toastIn 0.25s ease-out;
}
.toast.plus { border-left: 4px solid #57c785; color: #d6f5e2; }
.toast.minus { border-left: 4px solid #ff6b6b; color: #ffd9d9; }
.toast.info { border-left: 4px solid #6cb4ff; color: #d6ebff; }
.toast.fading { opacity: 0; transition: opacity 0.4s; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── Objectives panel ──────────────────────────────────────────────────── */
#objectives {
  position: fixed;
  top: 72px;
  left: 18px;
  width: 280px;
  background: rgba(0, 0, 0, 0.62);
  border-radius: 10px;
  padding: 14px 16px;
  display: none;
  pointer-events: none;
  z-index: 5;
  backdrop-filter: blur(2px);
}
#objectives.show { display: block; }
#objectives h3 {
  font-size: 0.85rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  opacity: 0.7;
  margin-bottom: 10px;
}
#objectives ul { list-style: none; display: flex; flex-direction: column; gap: 6px; }
#objectives li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.92rem;
  line-height: 1.35;
}
#objectives li .checkbox {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid #cfd6e4;
  border-radius: 3px;
  flex-shrink: 0;
  margin-top: 1px;
  text-align: center;
  line-height: 14px;
  font-weight: 700;
  font-size: 0.95rem;
}
#objectives li.done { color: #95e3a8; }
#objectives li.done .checkbox { background: #2f8a4d; border-color: #2f8a4d; color: #fff; }
#objectives li.done .text { text-decoration: line-through; opacity: 0.75; }
#objectives li.failed { color: #ff9a9a; }
#objectives li.failed .checkbox { background: #b13434; border-color: #b13434; color: #fff; }
#objectives li.failed .text { text-decoration: line-through; opacity: 0.75; }

/* ── Crosshair ─────────────────────────────────────────────────────────── */
#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  display: none;
  z-index: 5;
}
#crosshair.show { display: block; }
#crosshair::before,
#crosshair::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 1px;
}
#crosshair::before {
  width: 2px;
  height: 100%;
  left: 50%;
  transform: translateX(-50%);
}
#crosshair::after {
  width: 100%;
  height: 2px;
  top: 50%;
  transform: translateY(-50%);
}

.controls-help {
  font-size: 0.88rem;
  opacity: 0.7;
  letter-spacing: 0.5px;
}
.controls-help kbd {
  background: #2a3140;
  border: 1px solid #444b5c;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.8rem;
  font-family: inherit;
}

/* ── Leaderboard on the menu screen (M6) ───────────────────────────────── */
#menu-leaderboard {
  margin-top: 12px;
  width: min(420px, 92vw);
  background: rgba(20, 28, 44, 0.7);
  border: 1px solid #444b5c;
  border-radius: 10px;
  padding: 14px 18px;
  color: #f0e8d0;
  text-align: center;
}
.lb-empty { font-style: italic; opacity: 0.7; }
.lb-title {
  font-size: 0.85rem; letter-spacing: 2px; text-transform: uppercase;
  margin-bottom: 8px; color: #f0c64a;
}
.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
}
.lb-table td { padding: 3px 6px; }
.lb-rank { width: 28px; color: #f0c64a; font-weight: 700; text-align: right; }
.lb-name { text-align: left; }
.lb-score { text-align: right; font-weight: 700; }
.lb-diff { text-align: right; opacity: 0.7; font-size: 0.85rem; }
.lb-stat {
  margin-top: 8px;
  font-size: 0.8rem;
  opacity: 0.7;
  letter-spacing: 1px;
}

/* ── End-screen submit-score panel (M6) ────────────────────────────────── */
#end-submit {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 10px 0 4px;
}
.end-submit-label {
  font-size: 0.85rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  opacity: 0.75;
}
#end-name-input {
  padding: 8px 14px;
  font-size: 1rem;
  font-family: inherit;
  background: #2a3140;
  border: 2px solid #444b5c;
  border-radius: 6px;
  color: #fff;
  width: 280px;
  text-align: center;
}
#end-name-input:focus { outline: none; border-color: #f0c64a; }
#end-submit-status { font-size: 0.85rem; opacity: 0.85; min-height: 1.1em; }

/* ── Seated question panel (non-modal — sits over the bottom of the view) */
#qpanel {
  position: fixed;
  left: 50%;
  bottom: 130px;
  transform: translateX(-50%);
  width: min(640px, 92vw);
  background: rgba(20, 28, 44, 0.92);
  border: 2px solid #f0c64a;
  border-radius: 12px;
  padding: 16px 22px;
  z-index: 8;
  color: #fff;
  pointer-events: none;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
#qpanel.hidden { display: none; }

.qpanel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.78rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  opacity: 0.7;
  margin-bottom: 4px;
}
.qpanel-timer { color: #ffd166; font-variant-numeric: tabular-nums; font-weight: 700; }
.qpanel-stand {
  background: #c1121f;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: 1px;
  cursor: pointer;
  touch-action: manipulation;
  pointer-events: auto;
  margin-left: 10px;
}
.qpanel-stand:hover { background: #e63946; }
.qpanel-question {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 6px 0 10px;
  line-height: 1.35;
}
.qpanel-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.qpanel-choice {
  display: flex; align-items: center; gap: 10px;
  background: rgba(50, 60, 80, 0.6);
  border: 1px solid #555f76;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.98rem;
  font-family: inherit;
  color: #fff;
  cursor: pointer;
  text-align: left;
  touch-action: manipulation;
  pointer-events: auto;
  transition: background 0.12s, border-color 0.12s;
}
.qpanel-choice:hover  { background: rgba(70, 84, 110, 0.85); border-color: #8893a8; }
.qpanel-choice:active { background: rgba(90, 104, 130, 1.0); }
.qpanel-key {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
  background: #f0c64a; color: #1a1a1a;
  border-radius: 4px; font-weight: 800; font-size: 0.9rem;
}
.qpanel-hint {
  margin-top: 8px; font-size: 0.78rem; opacity: 0.55; text-align: center;
}
.qpanel-hint kbd {
  background: #2a3140; border: 1px solid #444b5c;
  border-radius: 4px; padding: 1px 6px; font-size: 0.74rem; font-family: inherit;
}

/* ── Friend conversation panel ──────────────────────────────────────────── */
#conv-panel {
  position: fixed;
  left: 50%;
  bottom: 130px;
  transform: translateX(-50%);
  width: min(580px, 92vw);
  background: rgba(18, 30, 24, 0.94);
  border: 2px solid #4ac26a;
  border-radius: 12px;
  padding: 16px 22px 18px;
  z-index: 8;
  color: #fff;
  box-shadow: 0 10px 30px rgba(0,0,0,0.55);
}
#conv-panel.hidden { display: none; }

.conv-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.78rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  opacity: 0.75;
  margin-bottom: 6px;
}
.conv-speaker { color: #80e8a0; font-weight: 700; }
.conv-progress { color: #a0c8b0; }

.conv-speech {
  font-size: 1.1rem;
  font-weight: 500;
  line-height: 1.45;
  margin: 4px 0 12px;
  padding: 10px 14px;
  background: rgba(74, 194, 106, 0.12);
  border-left: 3px solid #4ac26a;
  border-radius: 0 6px 6px 0;
}

.conv-choices {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.conv-choice {
  display: flex; align-items: center; gap: 10px;
  background: rgba(50, 70, 58, 0.55);
  border: 1px solid #3a5a46;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.97rem;
  font-family: inherit;
  color: #e0f0e6;
  cursor: pointer;
  text-align: left;
  touch-action: manipulation;
  pointer-events: auto;
  transition: background 0.12s, border-color 0.12s;
}
.conv-choice:hover  { background: rgba(74, 194, 106, 0.22); border-color: #4ac26a; }
.conv-choice:active { background: rgba(74, 194, 106, 0.35); }
.conv-choice.wrong  { border-color: #e63946; background: rgba(200, 50, 50, 0.25); }
.conv-key {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; flex-shrink: 0;
  background: #4ac26a; color: #0a1a10;
  border-radius: 4px; font-weight: 800; font-size: 0.9rem;
}
.conv-hint {
  margin-top: 8px; font-size: 0.78rem; opacity: 0.5; text-align: center;
}

/* ── Sing timing bar ────────────────────────────────────────────────────── */
#sing-bar {
  position: fixed;
  bottom: 82px;
  left: 50%;
  transform: translateX(-50%);
  width: min(500px, 88vw);
  z-index: 7;
  pointer-events: none;
}
#sing-bar.hidden { display: none; }

.sing-label {
  text-align: center;
  color: #80e8a0;
  font-size: 0.72rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  opacity: 0.85;
  margin-bottom: 5px;
}
.sing-track {
  position: relative;
  height: 20px;
  background: rgba(8, 20, 12, 0.90);
  border: 1.5px solid rgba(74, 194, 106, 0.50);
  border-radius: 10px;
  overflow: hidden;
}
.sing-zone-good {
  position: absolute;
  top: 0; bottom: 0;
  left: 29%; width: 42%;
  background: rgba(74, 194, 106, 0.10);
}
.sing-zone {
  position: absolute;
  top: 0; bottom: 0;
  left: 41%; width: 18%;
  background: rgba(74, 194, 106, 0.38);
  border-left:  1.5px solid #4ac26a;
  border-right: 1.5px solid #4ac26a;
  box-shadow: inset 0 0 12px rgba(74, 194, 106, 0.4);
}
.sing-cursor {
  position: absolute;
  top: 0; bottom: 0;
  width: 4px;
  background: #ffffff;
  border-radius: 2px;
  box-shadow: 0 0 7px rgba(255, 255, 255, 0.85);
  transform: translateX(-50%);
  left: 50%;
  will-change: left;
}
.sing-hint {
  margin-top: 5px;
  text-align: center;
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.72rem;
}
.sing-hint kbd {
  background: #0e1e12; border: 1px solid #2e5a38;
  border-radius: 4px; padding: 1px 5px; font-size: 0.70rem; font-family: inherit;
}

/* ── Action bar — strip of 10 slots along the bottom centre ────────────── */
#actionbar {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: none;
  gap: 4px;
  z-index: 6;
  pointer-events: none;
}
#actionbar.show { display: flex; }

/* ── Touch / mobile ────────────────────────────────────────────────────── */
#touch-stick {
  position: fixed;
  left: 28px;
  bottom: 28px;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: rgba(20, 28, 44, 0.45);
  border: 2px solid rgba(240, 198, 74, 0.6);
  z-index: 9;
  display: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
#touch-stick.show { display: block; }
#touch-stick .knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: rgba(240, 198, 74, 0.85);
  pointer-events: none;
}

#touch-menu {
  position: fixed;
  right: 18px;
  top: 60px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(20, 28, 44, 0.75);
  border: 2px solid rgba(240, 198, 74, 0.6);
  color: #f0c64a;
  font-size: 28px;
  z-index: 10;
  display: none;
  cursor: pointer;
  touch-action: manipulation;
}
#touch-menu.show { display: block; }

/* Floating Interact button — bottom-right, above the action drawer */
#touch-interact {
  position: fixed;
  right: 28px;
  bottom: 36px;
  padding: 18px 28px;
  border-radius: 999px;
  background: #f0c64a;
  color: #1a1a1a;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 1px;
  border: none;
  z-index: 10;
  display: none;
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
  font-family: inherit;
  touch-action: manipulation;
}
#touch-interact.show { display: block; }

#touch-drawer {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 28, 0.85);
  z-index: 25;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
#touch-drawer.hidden { display: none; }
.drawer-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  width: min(640px, 92vw);
}
.drawer-grid .action-slot {
  min-width: 0;
  padding: 12px 8px;
  font-size: 0.92rem;
  border: 1px solid #444b5c;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-family: inherit;
}
.drawer-interact,
.drawer-close {
  padding: 12px 28px;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  font-family: inherit;
  cursor: pointer;
}
.drawer-interact { background: #f0c64a; color: #1a1a1a; }
.drawer-close    { background: #5a6273; color: #fff; }

/* Hide the bottom action bar on touch devices (drawer replaces it). */
@media (pointer: coarse) {
  #actionbar { display: none !important; }
}

/* Landscape hint on small portrait screens */
@media (max-width: 900px) and (orientation: portrait) {
  body::before {
    content: '🔄  Rotate your device to landscape';
    position: fixed;
    inset: 0;
    background: #0a101c;
    color: #f0c64a;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-family: inherit;
    text-align: center;
    z-index: 100;
  }
}

.action-slot {
  display: flex; flex-direction: column; align-items: center;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid #6c7793;
  border-radius: 6px;
  padding: 4px 8px 5px;
  min-width: 76px;
  font-size: 0.82rem;
  letter-spacing: 0.5px;
  color: #ffffff;
  font-family: inherit;
  cursor: pointer;
}
.action-slot.empty { opacity: 0.35; }
.action-slot:hover { background: rgba(20, 28, 44, 0.85); }
.action-key {
  background: #f0c64a; color: #1a1a1a;
  border-radius: 3px;
  padding: 1px 6px;
  font-weight: 800;
  font-size: 0.8rem;
  margin-bottom: 3px;
}
.action-label {
  color: #ffffff;
  font-weight: 600;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

/* ── Security camera PiP overlay ────────────────────────────────────────── */
#sec-cam-canvas {
  display: none;
  position: fixed;
  top: 16px;
  right: 16px;
  width: 256px;
  height: 192px;
  z-index: 12;
  border: 2px solid rgba(0, 210, 70, 0.65);
  border-radius: 4px;
  /* green-tint security-cam look */
  filter: sepia(80%) saturate(180%) hue-rotate(88deg) brightness(0.82) contrast(1.1);
  image-rendering: pixelated;
  box-shadow: 0 0 18px rgba(0, 200, 60, 0.35), inset 0 0 8px rgba(0,0,0,0.4);
  animation: cam-flicker 0.12s infinite;
}
#sec-cam-canvas.active { display: block; }

/* subtle scanline flicker */
@keyframes cam-flicker {
  0%   { opacity: 1.00; }
  50%  { opacity: 0.96; }
  100% { opacity: 1.00; }
}
