/* =======================================================
   RESET + BASE
   ======================================================= */
:root {
  /* Viewport helpers (JS updates --vh at runtime) */
  --vh: 1vh;
  --vh100: calc(var(--vh) * 100);

  /* HUD vars */
  --hud-icon-size: clamp(24px, 4.2vh, 34px);
  --hud-icon-gap: 0px;
  --hud-chip-gap: 10px;

  /* Right-rail vars */
  --rail-w: 96px;        /* column width (desktop) */
  --rail-gap: 1px;      /* gap between game and rail */
  --rail-icon: 64px;     /* icon graphic size inside tile */
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: #a2d149; /* match game bg */
  overflow: hidden;
  user-select: none;
}

/* =======================================================
   PAGE GRID (game | right-rail)
   ======================================================= */
#page {
  display: grid;
  grid-template-columns: max-content var(--rail-w); /* <- key line */
  column-gap: var(--rail-gap);
  justify-content: center;  /* centers the pair on the page */
  align-items: center;
  width: 100vw;
  --vh100: calc(var(--vh, 1vh) * 100);
  min-height: var(--vh100);
  box-sizing: border-box;
  padding: 8px 12px;
}


/* =======================================================
   GAME CONTAINER (16:9, centered in grid column)
   ======================================================= */
#game-container {
  position: relative;
  margin: 0; /* grid handles alignment */

  /* Keep 16:9 while filling the space LEFT of the rail */
  width: min(
    calc(100vw - var(--rail-w) - var(--rail-gap) - 24px),
    calc(var(--vh100) * 16 / 9)
  );
  height: min(
    var(--vh100),
    calc((100vw - var(--rail-w) - var(--rail-gap) - 24px) * 9 / 16)
  );

  background: #a2d149;
  overflow: hidden;

  /* Shared geometry for the right-side time bar + digits */
  --bar-w: 12px;
  --bar-h: 60%;
  --bar-right: 12px;
}

/* When no rail (small screens), restore original sizing. */
@media (max-width: 900px) {
  #page { grid-template-columns: 1fr; }
  #game-container {
    width: min(100vw, calc(var(--vh100) * 16 / 9));
    height: min(var(--vh100), calc(100vw * 9 / 16));
  }
}

/* Utilities */
.hidden { display: none !important; }

/* Visually hidden but accessible (for SEO text) */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* =======================================================
   HUD (TOP BAR: icons + numbers)
   ======================================================= */
#hud-stats {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--hud-chip-gap);
  background-color: rgba(255, 255, 255, 0.4);
  padding: 8px 24px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 16px;
  color: #000;
  white-space: nowrap;
  z-index: 1000;
  backdrop-filter: blur(6px);
}

.hud-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--hud-icon-gap);
  background: rgba(255, 255, 255, 0.5);
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 700;
}

.hud-chip .hud-icon {
  width: var(--hud-icon-size);
  height: var(--hud-icon-size);
  display: block;
  flex-shrink: 0;
}

/* fixed-width numerals to avoid jitter */
.hud-chip span {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* (Legacy text HUD support, if you still show those anywhere) */
#hud-stats span { min-width: 80px; text-align: center; }

/* =======================================================
   Mobile Rotation 
   ======================================================= */

/* Rotate overlay (covers only the game container) */
#rotate-overlay{
  position:absolute;
  inset:0;
  display:none;                 /* JS toggles to flex */
  align-items:center;
  justify-content:center;
  background:rgba(0,0,0,.72);
  z-index:9999;                 /* above HUD/overlays */
  text-align:center;
  padding:24px;
  pointer-events:auto;          /* block clicks to game while showing */
}

#rotate-overlay .rotate-box{
  color:#fff;
  font-family: 'Press Start 2P', 'Audiowide', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  max-width:420px;
  width:86%;
  border:2px dashed rgba(255,255,255,.35);
  border-radius:12px;
  padding:18px 20px;
  backdrop-filter: blur(2px);
}

#rotate-overlay h2{ margin:6px 0 8px; font-size:20px; }
#rotate-overlay p{ margin:0; font-size:13px; opacity:.95; }

/* Simple phone icon hint */
#rotate-overlay .phone-icon{
  width:56px; height:90px;
  border:2px solid #fff; border-radius:12px;
  margin:0 auto 12px; position:relative; opacity:.9;
}
#rotate-overlay .phone-icon::after{
  content:"";
  position:absolute; left:50%; top:50%;
  width:90px; height:56px; transform:translate(-50%,-50%) rotate(90deg);
  border:2px solid #fff; border-radius:12px; opacity:.35;
}

/* Mobile UX nicety: prevent scroll/zoom gestures over the game */
html, body { overscroll-behavior: none; }
#game-container, canvas { touch-action: none; -ms-touch-action: none; }

/* =======================================================
   VERTICAL TIME BAR (RIGHT SIDE)
   ======================================================= */
#hud-timebar {
  position: absolute;
  top: 50%;
  right: var(--bar-right, 12px);
  transform: translateY(-50%);
  width: var(--bar-w, 12px);
  height: var(--bar-h, 60%);
  background: rgba(255,255,255,.35);
  border-radius: 999px;
  overflow: hidden;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

#hud-timebar-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, #35d07f, #ffd166, #ef476f);
  clip-path: inset(0 0 0 0);
  transition: clip-path .28s ease;
  will-change: clip-path;
}

/* Seconds readout centered slightly below the bar bottom */
#hud-timebar-seconds {
  position: absolute;
  top: calc(50% + (var(--bar-h, 60%) / 2) + 8px);
  left: calc(100% - var(--bar-right, 12px) - (var(--bar-w, 12px) / 2));
  transform: translateX(-50%);
  font-family: 'Press Start 2P', 'Audiowide', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  font-weight: 700;
  font-size: 18px;
  line-height: 1;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  color: #35d07f;
  text-shadow: 0 0 6px rgba(0,0,0,.35);
  z-index: 1000;
}

/* Cyan pulse when bonus is unlocked */
@keyframes bonusPulse {
  0%, 100% { box-shadow: 0 0 10px rgba(0,255,255,0.35), 0 0 20px rgba(0,255,255,0.2); }
  50%      { box-shadow: 0 0 18px rgba(0,255,255,0.9),  0 0 36px rgba(0,255,255,0.6); }
}

/* Time bar pulse */
#hud-timebar.bonus {
  animation: bonusPulse 0.9s ease-in-out 2;
  border: 1px solid rgba(0,255,255,0.4);
}

/* Subtle glow when near the end (shared with the bar) */
@keyframes barPulse {
  0%,100% { box-shadow: 0 0 10px rgba(239,71,111,0.45), 0 0 20px rgba(239,71,111,0.25); }
  50%     { box-shadow: 0 0 18px rgba(239,71,111,0.9),  0 0 30px rgba(239,71,111,0.6); }
}
#hud-timebar.ending { animation: barPulse 1s ease-in-out infinite; border: 1px solid rgba(239,71,111,0.5); }

/* =======================================================
   LEADERBOARD TOGGLE + PANEL
   ======================================================= */
#hud-leaderboard {
  position: absolute;
  top: 8px;
  right: 16px;
  z-index: 3000;
}

.leaderboard-btn {
  background-color: #6bf0c8;
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease;
  pointer-events: auto;
}
.leaderboard-btn:hover { background-color: #83effb; }

#toggleLeaderboardBtn { z-index: 1000; cursor: pointer; }

#leaderboard {
  position: absolute;
  top: 60px;
  right: 16px;
  background-color: #fff;
  padding: 16px;
  border-radius: 8px;
  width: 260px;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 3100;
  display: none;
}
#leaderboard.show { display: block; opacity: 1; transition: opacity .3s ease-in-out; }
#leaderboard.hidden { display: none; }

#leaderboard h3 { margin: 0 0 8px 0; font-size: 18px; text-align: center; }
#leaderboard ul { list-style: none; margin: 0; padding: 0; }
#leaderboard li { font-size: 14px; padding: 4px 8px; border-bottom: 1px solid #eee; }

#leaderboard li.you {
  background: linear-gradient(90deg, rgba(214,72,129,0.15), rgba(214,72,129,0));
  border-left: 3px solid #d64881;
  font-weight: 700;
}
#leaderboard .privacy-mini { margin-top: 8px; font-size: 12px; color: #333; }
#leaderboard .privacy-mini summary { cursor: pointer; font-weight: 700; }
#leaderboard .privacy-mini summary::marker { content: ""; }

/* Lay out the sound icon and the Leaderboard button side by side */
#hud-leaderboard {
  display: flex;
  align-items: center;
  gap: 8px;     /* spacing between icon and button */
}

/* Icon-only sound toggle */
#audioToggleBtn {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  margin: 0;
  line-height: 1;
  font-size: 28px;          /* 🔊 make it bigger */
  cursor: pointer;
  color: inherit;           /* ensure no weird text color */
}

/* No hover tint */
#audioToggleBtn:hover,
#audioToggleBtn:focus {
  background: transparent !important;
  outline: none;
  filter: none;
}

/* If you want the icon a bit larger on phones in landscape */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  #audioToggleBtn { font-size: 32px; }
}


/* =======================================================
   SCORE SUBMIT POPUP (nested under game-complete)
   ======================================================= */
#score-submit-popup {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,.6);
  display: none;
  align-items: center; justify-content: center;
  z-index: 2000;
}

#score-submit-popup .popup-content {
  background: #fff;
  border: 4px solid #000;
  padding: 20px 30px;
  max-width: 400px; width: 90%;
  border-radius: 10px;
  text-align: center;
  color: #000;
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

#score-submit-popup label { display: block; margin-bottom: 8px; font-size: 14px; }
#score-submit-popup input[type="text"] {
  width: 100%; padding: 10px; font-family: inherit; font-size: 14px;
  border: 2px solid #000; border-radius: 5px; margin-bottom: 10px;
}
#score-submit-popup small {
  display: block; font-size: 10px; color: #444; margin-top: 5px; line-height: 1.4;
}
#score-submit-popup button {
  background-color: #4CAF50; color: #fff; border: none;
  padding: 8px 14px; margin: 10px 5px 0 5px; border-radius: 6px; cursor: pointer;
}
#score-submit-popup button:disabled { background-color: #aaa; cursor: not-allowed; }
.privacy-notice { font-size: 12px; color: #555; margin-top: 12px; display: block; text-align: left; }

/* =======================================================
   OVERLAYS (Start / Time Up / Level Complete / Game Complete / Game Over)
   ======================================================= */
.game-overlay {
  position: absolute;
  top: 50%; left: 50%;
  width: 100%; height: 100%;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.6);
  z-index: 1500;
}

.game-message-box {
  font-family: 'Press Start 2P', 'Audiowide', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  background: rgba(67, 63, 63, 0.6);
  color: #39ff14;
  border: 3px solid #b5f0ae;
  padding: 20px 24px;
  border-radius: 12px;
  max-width: 360px; width: 90%;
  max-height: 70vh; overflow-y: auto;
  text-align: center;
  box-shadow: 0 0 10px #73cc63, 0 0 20px #98e08b;
  animation: pulseGlow 2s infinite;
}

.game-message-box h2 {
  font-size: 24px;
  color: #00ffff;
  text-shadow: 0 0 8px #7a8181;
  margin-bottom: 16px;
}

/* Start popup: bulletless list + typographic scale for strong vs body */
.game-overlay[data-popup="start"] .game-message-box ul { list-style: none; padding-left: 0; margin: 0; }
.game-overlay[data-popup="start"] .game-message-box li { margin: 12px 0; }

.game-overlay .game-message-box li strong {
  display: block;
  font-size: clamp(16px, 1.6vw, 20px);
  line-height: 1.15;
  margin-bottom: 6px;
}
.game-overlay .game-message-box li p {
  margin: 0;
  font-size: clamp(12px, 1.1vw, 14px);
  line-height: 1.4;
  color: #c8f7c5;
  text-shadow: none;
  opacity: 0.95;
}

/* Buttons */
.btn-primary {
  background-color: #d64881;
  color: white;
  font-weight: bold;
  border: 2px solid #d64881;
  box-shadow: 0 0 8px #d64881;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
}
.btn-primary:hover {
  background-color: #ff6666;
  box-shadow: 0 0 16px #ff66aa;
  animation: bounce 0.5s;
}

/* Fullscreen button (hidden by JS on desktop; keep CSS just in case) */
#fs-toggle {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 1200;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  font: 600 13px/1 system-ui, -apple-system, Segoe UI, Roboto, Arial;
  background: rgba(0,0,0,.55);
  color: #fff;
  backdrop-filter: blur(6px);
  cursor: pointer;
}
#fs-toggle:hover { filter: brightness(1.1); }

/* Final score emphasis */
.final-score-text { font-size: 16px; color: #fff; }

/* =======================================================
   ANIMATIONS
   ======================================================= */
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 10px #959994, 0 0 20px #39ff14; }
  50%      { box-shadow: 0 0 20px #9aa19a, 0 0 30px #00ff00; }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  30%      { transform: translateY(-2px); }
  60%      { transform: translateY(0); }
}

/* Generic cap so the start popup never gets huge on desktop */
#start-popup .game-message-box {
  max-height: 76vh;
  overflow: auto;
}

/* Mobile-only downsizing for the start popup — LANDSCAPE ONLY */
@media (pointer: coarse) and (orientation: landscape) {
  #start-popup .game-message-box {
    max-width: 50%;
    width: auto;
    max-height: calc(var(--vh, 1vh) * 84);
    overflow: auto;
    padding: 12px 14px;
    border-width: 1px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }
  #start-popup .game-message-box h2 {
    font-size: clamp(16px, 2.4vh, 18px);
    margin-bottom: 8px;
  }
  .game-overlay[data-popup="start"] .game-message-box li strong {
    font-size: clamp(12px, 1.6vw, 14px);
    margin-bottom: 4px;
  }
  .game-overlay[data-popup="start"] .game-message-box li p {
    font-size: clamp(10px, 1.3vw, 12px);
    line-height: 1.35;
  }
  #start-popup #readyButton.btn-primary {
    font-size: 14px;
    padding: 10px 14px;
    margin-top: 12px;
  }
}

/* ========= Mobile-only HUD + Leaderboard sizing (landscape) ========= */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  :root {
    --hud-icon-size: clamp(20px, 3.2vh, 36px);
    --hud-icon-gap: 2px;
    --hud-chip-gap: 6px;
  }
  #hud-stats {
    top: 1px;
    padding: 4px 8px;
    gap: var(--hud-chip-gap);
    font-size: 12px;
    border-radius: 5px;
  }
  .hud-chip { padding: 6px 8px; font-weight: 700; }
  #game-container {
    --bar-w: 8px;
    --bar-h: 45%;
    --bar-right: 8px;
  }
  #hud-timebar-seconds { font-size: 12px; }
  #hud-leaderboard { top: 1px; right: 10px; }
  .leaderboard-btn { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
  #leaderboard { width: 240px; max-height: 340px; }
  #leaderboard h3 { font-size: 16px; }
  #leaderboard li { font-size: 13px; }
}

/* Ultra-small phones: one more nudge */
@media (max-width: 360px) and (hover: none) and (pointer: coarse) {
  :root { --hud-icon-size: clamp(14px, 2.4vh, 24px); }
  #hud-stats { font-size: 10px; padding: 2px 10px; }
  .leaderboard-btn { font-size: 10px; padding: 2px 8px; }
  #hud-timebar-seconds { font-size: 14px; }
}

/* =======================================================
   RIGHT RAIL (vertical icon list)
   ======================================================= */
#right-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-height: var(--vh100);
  overflow: auto;
  padding: 8px 0;
  z-index: 900; /* below overlays/hud (1000+) */
}

#right-rail .rail-icon {
  display: inline-block;
  width: calc(var(--rail-icon) + 8px);
  height: calc(var(--rail-icon) + 8px);
  border-radius: 12px;
  background: rgba(0,0,0,0.25);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,0.15);
  line-height: 0;
  display: grid;
  place-items: center;
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
}
#right-rail .rail-icon:hover { transform: translateY(-2px); filter: brightness(1.08); }

#right-rail .rail-icon img {
  width: var(--rail-icon);
  height: var(--rail-icon);
  display: block;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
}

/* Tablet: slightly narrower rail & icons */
@media (max-width: 1100px) {
  :root { --rail-w: 84px; --rail-icon: 56px; }
}

/* Mobile & small screens: hide the rail */
@media (max-width: 900px) {
  #right-rail { display: none; }
}

/* Ultra-wide: give icons a little extra presence */
@media (min-width: 1600px) {
  :root { --rail-w: 112px; --rail-icon: 72px; }
}

/* =======================================================
   MISC
   ======================================================= */
#restartGameButton { display: none; } /* toast handles replay */
