/* =========================================================
 * Popping Bubbles — Consolidated Stylesheet (v8.6.7)
 * Owner: Ken Pao
 *
 * Organization:
 *  1) Base & Resets
 *  2) Top Bar (layout & chips)
 *  3) Buttons (global + variants)
 *  4) Modals (global) + Centered Modals
 *  5) Mode Picker (modal-specific)
 *  6) Splash Screen
 *  7) Login Modal overrides
 *  8) Hidden Webcam & Preview
 *  9) Centered End-game UI (overlay)
 * 10) Post-game Modal (bottom sheet behavior)
 * 11) Responsive Tweaks
 * 12) Utilities
 *
 * Notes:
 * - Mode chip color per mode is handled via body classes:
 *     body.mode-classic  #modeChip { ... }
 *     body.mode-challenge #modeChip { ... }
 *     body.mode-mood      #modeChip { ... }
 *   (Wired in JS setBodyModeClass())
 * ========================================================= */

/* v9.2.10 — Consolidate survey styles: remove earlier duplicate, keep final block */
/* v9.2.11 — Show post-game Close button (was hidden) */
/* v9.2.12 — Remove unused #modeBar rules + media tweak */

/* ========== 1) Base & Resets ========== */
html, body {
  margin: 0;
  padding: 0;
  height: 100vh;
  background: #cceeff;
  overflow: hidden;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial;
}
html { -webkit-text-size-adjust: 100%; }
body {
  /* Add these CSS variables for JS to control */
  --mood-background-color: #cceeff; /* Default light blue */
  --mood-emoji-url: ''; /* Default no emoji */

  background-color: var(--mood-background-color);
  transition: background-color 0.8s ease;
  position: relative; /* Needed for the emoji */
  z-index: 1;
}

/* ========== 2) Top Bar (layout & chips) ========== */
#topBar{
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 9999;
  padding-top: calc(6px + env(safe-area-inset-top, 0px));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: #ffffff;
  border-bottom: 1px solid rgba(0,0,0,.08);
  white-space: nowrap;
}
#topBar.hidden{ display: none !important; }
body.login-active #topBar,
body.mode-pick   #topBar{ display: none !important; }
body.game-active #topBar{ display: grid; }

#overlayUI{ grid-column: 1; justify-self: start; }
.hud{ display: flex; gap: 8px; align-items: center; }

#moodChip{ grid-column: 2; justify-self: center; align-self: center; }

#rightWrap{ grid-column: 3; justify-self: end; display: flex; align-items: center; gap: 8px; }

#modeChip{ align-self: center; }

/* Per-mode background */
body.mode-classic  #modeChip { background: #4da6ff; color: #ffffff; }
body.mode-challenge #modeChip { background: #ff944d; color: #ffffff; }
body.mode-mood      #modeChip { background: #66cc66; color: #0b2a45; }

#cameraBtn {
  display: none;
  align-self: center;
  background: rgba(0,0,0,.12);
  border-radius: 12px;
}

.chip{
  display: inline-flex;
  align-items: center;
  height: 28px;
  line-height: 28px;
  padding: 0 10px;
  margin: 0;
  background: #eef6ff;
  color: #0b2a45;
  border-radius: 14px;
}

/* ========== 3) Buttons ========== */
.iconBtn {
  font-size: 18px;
  line-height: 1.3;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px;
  min-width: 44px; min-height: 44px;
  border-radius: 12px;
  background: #0077cc; color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  cursor: pointer;
  user-select: none; -webkit-user-select: none;
  transition: transform 120ms ease, box-shadow 150ms ease, background 150ms ease, opacity 150ms ease;
}
.iconBtn.small { padding: 8px; min-width: 40px; min-height: 40px; border-radius: 10px; }
.iconBtn:hover  { box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.iconBtn:active { transform: translateY(1px) scale(0.96); box-shadow: 0 1px 6px rgba(0,0,0,.15); }
.iconBtn:focus-visible { outline: 3px solid rgba(0,119,204,.5); outline-offset: 2px; }

/* ========== 4) Modals ========== */
.modal, .modal * { touch-action: auto; }
.modal.hidden { display: none; }
.modal {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0,0,0,.35);
  display: grid; place-items: center;
}
.modalContent {
  width: min(560px, 100vw);
  background: #fff;
  border-radius: 16px;
  padding: 12px 14px 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 24px rgba(0,0,0,.2);
  box-sizing: border-box;
}
.modalHeader { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modalRow { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0; }
.modalRow.stacked { flex-direction: column; align-items: stretch; }
.modalRow select { flex: 1 1 auto; max-width: 100%; border-radius: 10px; border: 1px solid rgba(0,0,0,.15); padding: 8px 10px; background: #fff; }

.btnRow {
  display: flex;
  gap: 10px;
  justify-content: flex-end; /* align to the right */
  padding-top: 2px;
}

.previewWrap { margin-top: 8px; display: flex; justify-content: center; }
.modalPreview { width: 220px; height: auto; border-radius: 8px; box-shadow: 0 6px 16px rgba(0,0,0,.18); transform: scaleX(-1); }

.modal.centered .modalContent {
  max-height: 80vh;
  overflow: auto;
  width: min(520px, 92vw);
  box-sizing: border-box;
}

/* ========== 5) Mode Picker ========== */
#modeModal .modalHeader { justify-content: center; }
#modeModal #modeTitle { text-align: center; width: 100%; }
#modeModal .modalRow.stacked { align-items: center; gap: 12px; }

/* ========== 6) Splash Screen ========== */
#splash {
  position: fixed; inset: 0; z-index: 9999;
  display: grid; place-items: center;
  background: linear-gradient(160deg, #9ad4ff 0%, #b8e1ff 40%, #eef7ff 100%);
  opacity: 0; pointer-events: none;
  transition: opacity 400ms ease;
}
@media (prefers-reduced-motion: reduce) { #splash { transition: none; } }
#splash.is-visible { opacity: 1; pointer-events: auto; }
#splash.is-fading-out { opacity: 0; pointer-events: none; }
.splash-inner {
  text-align: center; padding: 2rem 2.5rem; border-radius: 20px;
  background: rgba(255, 255, 255, 0.35);
  box-shadow: 0 10px 30px rgba(0,0,0,0.12);
  backdrop-filter: blur(6px);
}
.splash-title { margin: 0 0 0.4rem 0; font-size: clamp(2rem, 6vw, 3.2rem); line-height: 1.1; letter-spacing: 0.5px; color: #0c2a43; text-shadow: 0 1px 0 rgba(255,255,255,0.25); }

/* ========== 7) Login Modal overrides ========== */
#loginModal { place-items: center; z-index: 1000; }

/* Soft gradient backdrop for login modal */
#loginModal {
  background: linear-gradient(135deg, rgba(240,245,255,0.9), rgba(255,255,255,0.85));
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* Soft fade when leaving login */
#loginModal {
  transition: opacity 240ms ease, transform 240ms ease;
}
#loginModal.is-fading-out {
  opacity: 0;
  transform: scale(0.98);
  pointer-events: none;
}

/* Login modal: avoid bottom hairline on some browsers */
#loginModal .modalContent {
  box-shadow: 0 12px 28px rgba(0,0,0,.18);  /* symmetric shadow */
  border: 0;
  outline: 0;
  background-clip: padding-box;             /* prevents border bleed */
  -webkit-font-smoothing: antialiased;
}

/* Modern glassy login card */
#loginModal .modalContent {
  background: rgba(255,255,255,0.72);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  border-radius: 18px;
  padding: 16px 16px 18px;
  border: 1px solid rgba(255,255,255,0.65);
}

/* v9.5 — Login card micro pop-in on show */
#loginModal .modalContent {
  transform: translateY(4px) scale(0.985);
  opacity: 0;
  transition: transform 220ms ease, opacity 220ms ease;
}
#loginModal:not(.hidden) .modalContent {
  opacity: 1;
  transform: translateY(0) scale(1);
}
@media (prefers-reduced-motion: reduce) {
  #loginModal .modalContent { transition: none; }
}

/* Ensure visible text & caret in the login input (light mode defaults) */
#loginModal input[type="text"] {
  color: #0b2540;            /* dark blue on light background */
  caret-color: #0b2540;      /* caret matches text */
}
#loginModal input[type="text"]::placeholder {
  color: rgba(11, 37, 64, 0.50);
}

/* Dark mode: high-contrast text, caret, and placeholder — override autofill too */
@media (prefers-color-scheme: dark) {
  #loginModal input[type="text"] {
    color: #e6eef7;          /* light text on dark glass */
    caret-color: #e6eef7;    /* visible caret */
  }
  #loginModal input[type="text"]::placeholder {
    color: rgba(230, 238, 247, 0.55);
  }
  /* Safari/Chrome autofill can force low-contrast text; override it here */
  #loginModal input[type="text"]:-webkit-autofill,
  #loginModal input[type="text"]:-webkit-autofill:focus {
    -webkit-text-fill-color: #e6eef7 !important;
    caret-color: #e6eef7;
    /* keep your dark input fill instead of autofill’s yellow */
    box-shadow: 0 0 0px 1000px rgba(20, 24, 32, 0.92) inset;
  }
}

/* v9.8 — Dark-mode variant for the glassy login (auto via system preference) */
@media (prefers-color-scheme: dark) {
  /* Subtle darker backdrop behind the modal card */
  #loginModal {
    background: linear-gradient(135deg, rgba(10,14,20,0.88), rgba(18,22,28,0.88));
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  /* Smoky-glass card with light text */
  #loginModal .modalContent {
    background: rgba(20,24,32,0.72);
    border: 1px solid rgba(255,255,255,0.12);
    color: #e6eef7;
  }

  /* Inputs: darker fill + gentle focus glow */
  #loginModal input[type="text"] {
    background: rgba(20,24,32,0.92);
    border-color: rgba(255,255,255,0.12);
    color: #e6eef7;
  }
  #loginModal input[type="text"]::placeholder { color: rgba(230,238,247,0.55); }
  #loginModal input[type="text"]:focus {
    border-color: rgba(147,197,253,0.55);
    box-shadow: 0 0 0 3px rgba(30,64,175,0.35);
    outline: none;
  }

  /* Helper text colors tuned for dark backgrounds */
  #loginStatus.loginStatus.info { color: #9ecbff; }
  #loginStatus.loginStatus.ok   { color: #8fe3b3; }
  #loginStatus.loginStatus.err  { color: #ff9da1; }

  /* Splash screen dark variant */
  #splash {
    background: linear-gradient(160deg, #0d1117 0%, #1c1f26 100%);
    color: #e6eef7;
  }
  #splash .splash-inner {
    background: rgba(20,24,32,0.78);
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 8px 22px rgba(0,0,0,0.55);
  }

  /* Dark-mode tweak for primary button contrast */
  #loginModal .btnPrimary {
    background: linear-gradient(180deg, #3a82ea 0%, #2c6fcd 100%);
    box-shadow: 0 6px 18px rgba(0,0,0,.35);
  }
}

/* Compact header */
#loginModal .modalHeader {
  align-items: center;
  margin-bottom: 6px;
}
#loginModal .modalHeader h3 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: .2px;
}

/* Tighter row spacing */
#loginModal .modalRow { gap: 10px; }
#loginModal .loginRow { margin-top: 4px; }

/* Refined input (no layout shift) */
#loginModal input[type="text"] {
  height: 40px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(0,0,0,0.12);
  background: rgba(255,255,255,0.92);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
}
#loginModal input[type="text"]:focus {
  outline: none;
  border-color: rgba(26,115,232,0.5);
  box-shadow: 0 0 0 3px rgba(26,115,232,0.15);
}

/* Button row: balanced spacing, right-aligned */
#loginModal .btnRow {
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

#loginModal input[type="text"] { flex: 1 1 auto; border-radius: 10px; border: 1px solid rgba(0,0,0,.15); padding: 8px 10px; }
#loginModal .iconBtn.small { min-width: 64px; }

/* Login helper/status line */
#loginStatus.loginStatus {
  margin: 6px 0 8px;
  font-size: 13px;
  line-height: 1.35;
}
#loginStatus.loginStatus.info { color: #1a4366; }
#loginStatus.loginStatus.ok   { color: #0f6b3e; }
#loginStatus.loginStatus.err  { color: #8b1a1a; }

/* Smoothly animate login helper text updates */
#loginStatus.loginStatus {
  display: block;
  min-height: 1.3em;              /* reserve space to avoid jumps */
  transition: opacity 0.25s ease, transform 0.25s ease;
}
#loginStatus.loginStatus.updating {
  opacity: 0;
  transform: translateY(-3px);
}

/* Error 'shake' for login helper */
@keyframes subtle-shake {
  0% { transform: translateX(0); }
  15% { transform: translateX(-2px); }
  30% { transform: translateX(2px); }
  45% { transform: translateX(-2px); }
  60% { transform: translateX(2px); }
  75% { transform: translateX(-1px); }
  100% { transform: translateX(0); }
}
#loginStatus.loginStatus.shake {
  animation: subtle-shake 320ms ease;
}
@media (prefers-reduced-motion: reduce) {
  #loginStatus.loginStatus.shake { animation: none; }
}

body.login-active #topBar { display: none; }

/* Text button look (for "Feedback (optional)" under login) */
.textBtn {
  margin-top: 6px;
  background: transparent;
  border: none;
  color: #0066cc;
  padding: 6px 0;
  font-size: 14px;
  cursor: pointer;
}
.textBtn:hover { text-decoration: underline; }

/* Feedback modal textarea */
#feedbackModal textarea {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,.15);
  padding: 10px 12px;
  resize: vertical;
}
#feedbackModal.modal {
  z-index: 1000; /* higher than other modals if needed */
}

/* ========== 8) Hidden Webcam & Preview ========== */
.hiddenVideo { position: fixed; left: -9999px; top: 0; width: 320px; height: auto; opacity: 0; pointer-events: none; }
#webcamPreview.preview { position: fixed; right: 16px; bottom: 16px; opacity: 1; width: 160px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); transform: scaleX(-1); pointer-events: none; z-index: 9998; }
.camHidden { width: 1px !important; height: 1px !important; opacity: 0 !important; }

/* ========== 9) Centered End-game UI ========== */
.centerMsg { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -60%); font-size: 28px; font-weight: 800; color: #00324d; text-align: center; text-shadow: 0 2px 6px rgba(0,0,0,.25); z-index: 20; }

/* ========== 10) Post-game Modal ========== */
#postGameModal{ place-items: end center; z-index: 15; background: rgba(0,0,0,.20); }
#postGameModal .modalHeader { justify-content: center; }
#postGameTitle { text-align: center; width: 100%; }
#postGameModal .modalContent { width: min(560px, 96vw); border-radius: 16px; box-sizing: border-box; }
#postGameModal .modalRow.stacked { flex-direction: row; justify-content: center; align-items: center; gap: 12px; }
#postGameModal .iconBtn { width: 88px; height: 88px; padding: 8px; border-radius: 14px; font-size: 0.9rem; line-height: 1.05; text-align: center; white-space: normal; }
#postPlayAgain { background: #0077cc; }
#postChangeMode { background: #cc66cc; }
#postPlayAgain:hover  { background: #0066b3; }
#postPlayAgain:active { background: #004c80; transform: translateY(1px) scale(0.96); }
#postChangeMode:hover { background: #b34db3; }
#postChangeMode:active{ background: #993399; transform: translateY(1px) scale(0.96); }
@media (min-height: 700px) { #postGameModal .modalContent { margin-bottom: 20px; } }
@media (max-width: 480px) { #postGameModal .modalContent { width: 100vw; max-width: 100vw; border-radius: 16px; margin-bottom: 12px; } }

/* Highlight / flash the player's row (Top 5 or the extra 6th row) */
.lbTable tr.meRow {
  background: rgba(15, 118, 110, 0.12);
  font-weight: 700;
  animation: mePulse 1.2s ease-in-out infinite;
}
@keyframes mePulse {
  0%   { box-shadow: inset 0 0 0 rgba(0,0,0,0); }
  50%  { box-shadow: inset 0 0 9999px rgba(15,118,110,0.08); }
  100% { box-shadow: inset 0 0 0 rgba(0,0,0,0); }
}

/* ========== 11) Responsive Tweaks ========== */
@media (max-width: 420px) {
  .modalPreview { width: 180px; }
}
@media (max-width: 480px) {
  #loginModal .modalRow { flex-direction: column; align-items: stretch; }
  #loginModal input[type="text"] { width: 100%; }
  #loginModal .iconBtn.small    { width: 100%; }
}

/* ========== 12) Utilities ========== */
.hidden     { display: none !important; }
.hiddenChip { visibility: hidden; opacity: 0; pointer-events: none; }
.srOnly     { position: absolute; left: -9999px; }
#overlayUI, #moodChip, #modeChip, #cameraBtn { position: static; }

/* =========================================================
   v9.1.2 — Mobile typing / auto-zoom fixes (iOS & Android)
   Place this block at the very end of style.css
   ========================================================= */

html, body {
  -webkit-text-size-adjust: 100%;  /* iOS text scaling guard */
}

/* KEY: keep inputs/textarea at >=16px to prevent iOS auto-zoom */
input,
select,
textarea {
  font-size: 16px;
  line-height: 1.2;
}

/* Ensure our specific fields also respect the 16px rule */
#loginModal input,
#feedbackModal textarea {
  font-size: 16px;
}

/* Better tap behavior; avoids double-tap zoom on older Safari */
button,
.iconBtn,
.textBtn {
  touch-action: manipulation;
}

/* Optional: keep small icon buttons finger-friendly on mobile */
.iconBtn.small {
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 10px;
  /* if you previously set font-size < 16px anywhere, this helps override */
  font-size: 16px;
}


/* =========================================================
   v9.2.2 — Login tidy + post-game rows + scrollable survey
   ========================================================= */

/* Login row: compact input + two buttons */
.loginRow {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}
.loginRow #usernameInput {
  min-width: 0;
  width: 100%;
  font-size: 16px;           /* prevent iOS auto-zoom */
  padding: 10px 12px;
  border: 1px solid rgba(0,0,0,.15);
  border-radius: 10px;
}
.loginRow .btnGroup {
  display: flex;
  gap: 8px;
}

.studyNote {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.35;
  color: #34536d;
}
.disclaimerBox {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.4;
  color: #2b4a62;
  background: rgba(0,0,0,.04);
  padding: 10px 12px;
  border-radius: 12px;
}

/* Buttons: colors + hover/active */
/* Primary/Accent buttons (Login) */
.btnPrimary,
.btnAccent {
  font-size: 17px;      /* bigger than default */
  font-weight: 600;     /* stronger emphasis */
}

.btnPrimary,
.btnAccent,
.iconTile {
  cursor: pointer;
  transition: transform .05s ease, filter .12s ease, background-color .12s ease;
}
.btnPrimary { background: #1a73e8; color: #fff; border: none; border-radius: 10px; padding: 10px 14px; }
.btnPrimary:hover { filter: brightness(1.05); }
.btnPrimary:active { transform: translateY(1px); }

/* Sleek pill primary button */
.btnPrimary {
  border-radius: 999px;                    /* pill */
  padding: 10px 18px;
  box-shadow: 0 6px 16px rgba(0,0,0,.12);  /* soft lift */
  background: linear-gradient(180deg, #1a73e8 0%, #1767cf 100%);
}
.btnPrimary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(26,115,232,.28), 0 6px 16px rgba(0,0,0,.12);
}

/* Busy state: dim label, show centered spinner overlay */
.btnPrimary.is-busy {
  position: relative;
  pointer-events: none;
  filter: saturate(.9) brightness(.98);
}
.btnPrimary.is-busy > * { opacity: 0; }   /* hide inner label without shifting */
.btnPrimary.is-busy::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-bottom-color: transparent;
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btnAccent { background: #008080; color: #fff; border: none; border-radius: 10px; padding: 10px 12px; }
.btnAccent:hover { filter: brightness(1.05); }
.btnAccent:active { transform: translateY(1px); }

/* Post-game tiles with distinct colors */
.iconTile { min-width: 112px; min-height: 84px; border-radius: 16px; border: none; font-size: 20px; }
.tilePlay   { background: #22863a; color: #fff; }
.tilePlay:hover { filter: brightness(1.05); }
.tilePlay:active { transform: translateY(1px); }

.tileMode   { background: #6f42c1; color: #fff; }
.tileMode:hover { filter: brightness(1.05); }
.tileMode:active { transform: translateY(1px); }

.tileAccent { background: #006666; color: #fff; }
.tileAccent:hover { filter: brightness(1.05); }
.tileAccent:active { transform: translateY(1px); }

/* Disabled look (reused) */
.iconBtn.is-disabled, .iconTile.is-disabled, .btnAccent.is-disabled {
  opacity: .55; pointer-events: none; filter: grayscale(15%);
}

/* Scrollable survey: fixed header/footer, scrolling body */
#feedbackModal .modalContent {
  display: flex;
  flex-direction: column;
  max-height: min(92vh, 560px);
}
#feedbackModal .modalHeader { flex: 0 0 auto; }
#feedbackModal .modalRow.stacked { flex: 1 1 auto; overflow: auto; }
#feedbackModal .modalRow:last-child { flex: 0 0 auto; }

/* Mobile: two-column radio grid for compactness */
.choiceGroup { display: grid; gap: 6px; }
@media (max-width: 480px) {
  .choiceGroup { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .choiceRow { padding: 6px 8px; border-radius: 10px; border: 1px solid rgba(0,0,0,.08); }
  .choiceRow input[type="radio"] { transform: scale(1.2); }
}

/* ==== v9.8.1 — Dark-mode input visibility hard overrides (placed last to win cascade) ==== */
@media (prefers-color-scheme: dark) {
  /* Ensure the login input uses dark fill + light text regardless of earlier rules */
  #loginModal input[type="text"] {
    background: rgba(20,24,32,0.92) !important;
    border-color: rgba(255,255,255,0.12) !important;
    color: #e6eef7 !important;
    caret-color: #e6eef7 !important;
  }
  #loginModal input[type="text"]::placeholder {
    color: rgba(230,238,247,0.60) !important;
  }

  /* Defeat WebKit autofill’s light text and yellow fill in dark mode */
  #loginModal input[type="text"]:-webkit-autofill,
  #loginModal input[type="text"]:-webkit-autofill:focus {
    -webkit-text-fill-color: #e6eef7 !important;
    caret-color: #e6eef7 !important;
    box-shadow: 0 0 0 1000px rgba(20,24,32,0.92) inset !important;
    -webkit-box-shadow: 0 0 0 1000px rgba(20,24,32,0.92) inset !important;
  }
}

/* =========================================================
   v9.9 — Unified Button System + Splash CTA (teal)
   ========================================================= */
:root{
  --btn-bg:#0f766e;         /* teal 700 */
  --btn-bg-hover:#0b605b;   /* teal 800 */
  --btn-bg-active:#094e4a;  /* teal 900 */
  --btn-fg:#ffffff;
  --btn-focus:rgba(15,118,110,0.35);
}

/* Primary buttons (iconBtn + Login primary) — keeps Mode Picker tiles teal too */
.iconBtn,
#loginModal .btnPrimary{
  background:var(--btn-bg) !important;
  color:var(--btn-fg) !important;
  border:none !important;
  box-shadow:0 6px 18px rgba(0,0,0,.18);
  font-weight:700; font-size:16px; line-height:1.2;
  border-radius:14px; padding:12px 16px;
}
.iconBtn:hover,#loginModal .btnPrimary:hover{ background:var(--btn-bg-hover) !important; }
.iconBtn:active,#loginModal .btnPrimary:active{ background:var(--btn-bg-active) !important; transform:translateY(1px) scale(0.98); }
.iconBtn:focus-visible,#loginModal .btnPrimary:focus-visible{ outline:none; box-shadow:0 0 0 3px var(--btn-focus); }

@media (prefers-color-scheme: dark){
  :root{
    --btn-bg:#14a39a;        /* brighter teal for dark surfaces */
    --btn-bg-hover:#118c84;
    --btn-bg-active:#0d726c;
  }
}

/* =========================================================
   v9.9.2 — Splash Start card teal CTA (wins in cascade)
   ========================================================= */
#splash #splashCard {
  background: var(--btn-bg);
  color: var(--btn-fg);
  border-radius: 20px;
  padding: 2rem 2.5rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  backdrop-filter: blur(6px);
  cursor: pointer;
  outline: none;
  transform: translateY(0);
  transition: transform 120ms ease, filter 120ms ease, background 120ms ease;
}
#splash #splashCard:hover    { filter: brightness(1.05); }
#splash #splashCard:active   { transform: translateY(1px) scale(0.98); }
#splash #splashCard:focus-visible { box-shadow: 0 0 0 6px var(--btn-focus), 0 10px 30px rgba(0,0,0,0.18); }

/* Ensure the texts inside the card stay high-contrast */
#splash #splashCard .splash-title{
  color: #fff;
  text-shadow: none;
}

/* Dark-mode: keep the same teal so it doesn’t go low-contrast */
@media (prefers-color-scheme: dark) {
  #splash { background: linear-gradient(160deg, #0b3a4b 0%, #0e4a60 40%, #0f566e 100%); }
  #splash #splashCard { background: var(--btn-bg); }
}

/* v9.9.5 — Responsive full-width Mode Picker buttons */
.modeBarBtn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;                /* spacing between emoji and text */
  width: 100%;              /* full width of modal */
  padding: 14px 18px;
  margin: 8px 0;
  font-size: 18px;
  font-weight: 600;
  border-radius: 14px;
  background: #008080;      /* teal */
  color: #fff;
  border: none;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

.modeBarBtn:hover,
.modeBarBtn:focus {
  background: #009999;
  transform: scale(1.02);
}

.modeBarBtn:active {
  background: #007070;
  transform: scale(0.98);
}

/* v9.9.6 — Post-game stats & leaderboard */
.statsBlock {
  font-size: 16px;
  line-height: 1.5;
  font-weight: 600;
  color: #0b2540;
}
.leaderboardBlock {
  font-size: 15px;
  line-height: 1.4;
  text-align: left;
  max-width: 280px;
  margin: 0 auto;
}

/* v9.9.7 — Leaderboard table styles */
.lbTable {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 14px;
}
.lbTable th, .lbTable td {
  padding: 4px 6px;
  border-bottom: 1px solid rgba(0,0,0,.1);
  text-align: left;
}
.lbTable th { font-weight: 600; }
.lbTable tr:nth-child(even) { background: rgba(0,0,0,.03); }
/* Optional: tidy up table alignment */
.lbTable th:nth-child(1), .lbTable td:nth-child(1) { width: 44px; text-align: right; }
.lbTable th:nth-child(3), .lbTable td:nth-child(3) { text-align: right; } /* Score */
.lbTable th:nth-child(4), .lbTable td:nth-child(4) { text-align: right; } /* Acc */

/* v9.9.8 — Pre-game Loading Overlay */
#loadingOverlay { place-items: center; z-index: 2000; }
#loadingOverlay .modalContent {
  max-width: 320px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.loadingBarWrap {
  margin: 12px auto 0;
  width: 100%;
  height: 10px;
  border-radius: 6px;
  background: rgba(0,0,0,.1);
  overflow: hidden;
}
.loadingBar {
  width: 0%;
  height: 100%;
  background: var(--btn-bg, #0f766e);
  transition: width 0.6s ease;
}

/* v10.0.0 */
.comboBadge{position:fixed;top:8px;right:8px;background:#0f766e;color:#fff;padding:6px 10px;border-radius:12px;
  font-weight:700;transform:scale(0.9);transition:transform .15s ease;z-index:1200}
.comboBadge.active{transform:scale(1.05)}
.fly{position:absolute;pointer-events:none;font-weight:700;opacity:.95;transform:translate(-50%,-50%);
  animation:flyUp .9s ease forwards}
.fly.neg{color:#c62828}.fly.pos{color:#0f766e}
@keyframes flyUp{0%{opacity:0;transform:translate(-50%,-20%)}20%{opacity:1}100%{opacity:0;transform:translate(-50%,-120%)}}

/* === Score Flyout Animation === */
.flyoutScore {
  position: absolute;
  pointer-events: none;
  font-weight: 700;
  text-shadow: 0 2px 6px rgba(0,0,0,.3);
  transform: translate(-50%, -50%);
  animation: flyoutUp 1s ease-out forwards;
  z-index: 9999;
}

.flyoutScore::before {
  content: "";
}

.flyoutScore {
  color: #0f766e; /* teal for good pops */
}

.flyoutScore:contains("-") {
  color: #c62828; /* red penalty */
}

@keyframes flyoutUp {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  to   { opacity: 0; transform: translate(-50%, -120%) scale(1.3); }
}

/* Combo pops: gold + faster, higher flyout */
.flyoutCombo {
  color: #e6b800 !important;
  text-shadow:
    0 0 6px rgba(255, 215, 0, 0.9),
    0 0 12px rgba(255, 200, 0, 0.75),
    0 0 20px rgba(255, 180, 0, 0.6);
  font-weight: 900;
  letter-spacing: 0.5px;
  animation: flyoutComboUp 0.8s ease-out forwards;
}

@keyframes flyoutComboUp {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  to   { opacity: 0; transform: translate(-50%, -160%) scale(1.4); }
}

/* === Bubble Burst Particles === */
.burstParticle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  opacity: 0.9;
  transform: translate(-50%, -50%);
  animation: burstAnim 0.6s ease-out forwards;
}

@keyframes burstAnim {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  to   { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.3); }
}

#soundTogglePre, #soundTogglePost {
  transform: scale(1.2);
}

/* v10.3.4 — Top bar middle cluster & compact Quit */
#centerWrap {
  grid-column: 2;                 /* put this in the middle grid column */
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;           /* keep on one line */
}

/* v10.3.5 — Top bar: collapse hidden mood chip and cap center width */

/* Collapse hidden chips so they don't reserve space */
.hiddenChip {
  display: none !important;            /* was: visibility/opacity only */
}

/* Center cluster (mood + Quit) stays on one line but can't grow too wide */
#centerWrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  max-width: 52vw;                     /* keeps room for the right cluster */
  overflow: hidden;                    /* safety */
}

/* Right cluster: allow the Mode chip to truncate gracefully on phones */
#rightWrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-self: end;
}

@media (max-width: 430px) {
  /* Make the Quit button small only on phone widths */
  #centerWrap #quitBtn {
    font-size: 14px !important;
    line-height: 1.1 !important;
    padding: 4px 8px !important;
    min-width: auto !important;
    min-height: 32px !important;
    border-radius: 10px !important;
  }

  /* Let Mode chip shrink instead of pushing off-screen */
  #modeChip {
    max-width: 44vw;                   /* leave room for camera/spacing */
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Optional: if space is still tight on very narrow phones, hide camera */
  /* #cameraBtn { display: none !important; } */
}

/* Post-game actions: force 3–2 on wide, 2–3 on small */
#postGameModal .postActions {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr));
  gap: 12px;
  justify-items: stretch;
  align-items: stretch;
}

#postGameModal .postActions .iconTile {
  width: auto;              /* grid controls width */
  height: 92px;
  padding: 8px;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.1;
  text-align: center;
}

/* On small screens → 2 columns */
@media (max-width: 480px) {
  #postGameModal .postActions {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}


/* Stats tile color (distinct but friendly) */
.tileStats { background: #0ea5e9; }            /* sky-500 */
.tileStats:hover { background: #0284c7; }
.tileStats:active { background: #0369a1; transform: translateY(1px) scale(0.96); }

/* Leaderboard: highlight your own row (you already added this; keep if present) */
.lbTable tr.meRow {
  background: rgba(15, 118, 110, 0.12);
  font-weight: 700;
  animation: mePulse 1.2s ease-in-out infinite;
}
@keyframes mePulse {
  0%   { box-shadow: inset 0 0 0 rgba(0,0,0,0); }
  50%  { box-shadow: inset 0 0 9999px rgba(15,118,110,0.08); }
  100% { box-shadow: inset 0 0 0 rgba(0,0,0,0); }
}

/* Stats table smaller font on mobile */
.statsTable { width: 100%; }
.statsTable th, .statsTable td { padding: 6px 8px; }
@media (max-width: 420px){
  .postActions .iconTile { width: 46%; min-width: 146px; }
}
/* === Fix: Post-game actions layout (3–2 on wide, 2 cols on small) === */
#postGameModal .postActions {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr));
  gap: 12px;
  justify-items: stretch;
  align-items: stretch;
}
#postGameModal .postActions .iconTile {
  width: auto; /* let the grid control width; keeps your existing colors */
}
@media (max-width: 480px) {
  #postGameModal .postActions {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

/* Optional: Stats tile color only (does NOT touch .tileAccent / Feedback) */
.iconTile.tileStats { background: #0ea5e9; }
.iconTile.tileStats:hover { background: #0284c7; }
.iconTile.tileStats:active { background: #0369a1; transform: translateY(1px) scale(0.96); }

/* Disable legacy survey modal entirely */
#feedbackModal { display: none !important; }

/* --- Accessibility: readable helper text on dark backgrounds --- */
@media (prefers-color-scheme: dark) {
  /* Login helper line colors are already defined; ensure good contrast for other helpers */
  .studyNote {
    color: #cfe7ff !important;         /* light blue for readability */
  }
  .disclaimerBox {
    color: #e8eef6 !important;
    background: rgba(255,255,255,0.06) !important;
    border-color: rgba(255,255,255,0.16) !important;
  }
  /* Chips & tiny UI bits stay readable in dark */
  .chip { color: #0b2a45; }             /* already good on light chips */
}

/* ===== GAME BACKGROUND RELIABILITY =====
   Ensure the page always paints a bright, splash-matching background,
   and the p5 canvas never forces black. */

:root {
  /* Keep whatever you already use here;
     this is just a safe default for early frames */
  --mood-background-color: #b8e1ff;
}

/* Page background follows the variable with a safe fallback */
body {
  background: var(--mood-background-color, #b8e1ff) !important;
}

/* p5 canvas should never fight the page background */
canvas {
  background: transparent !important;
}

/* === v10.5.3 — Unified Background & Modal Theming === */

/* 1.  Safe default for every screen after splash */
:root {
  --mood-background-color: #b8e1ff; /* light-blue base, same as splash mid-tone */
}
body {
  background: var(--mood-background-color) !important;
  transition: background 0.6s ease;
}

/* 2.  Prevent black flash between splash → login → mode select → game */
canvas { background: transparent !important; }

/* 3.  Login & Mode Select pop-ups — soft glass, not pure white */
#loginModal .modalContent,
#modeModal  .modalContent {
  background: rgba(255,255,255,0.78);
  backdrop-filter: blur(12px) saturate(120%);
  -webkit-backdrop-filter: blur(12px) saturate(120%);
  border: 1px solid rgba(255,255,255,0.5);
  color: #0b2540;
}

/* 4.  Post-game modal — neutral gray glass for consistency */
#postGameModal .modalContent {
  background: rgba(250,250,252,0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(0,0,0,0.06);
}

/* 5.  Dark-mode variants: smoky glass cards, light text */
@media (prefers-color-scheme: dark) {
  body {
    --mood-background-color: #1a1f27;
    background: var(--mood-background-color) !important;
  }
  #loginModal .modalContent,
  #modeModal  .modalContent,
  #postGameModal .modalContent {
    background: rgba(24,28,36,0.78);
    border: 1px solid rgba(255,255,255,0.12);
    color: #e6eef7;
  }
}
