/* ==========================================================================
   Plumification - Ergonomic, Eye-Friendly & Colorblind-Accessible Styling
   ========================================================================== */

@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-weight: 400 800;
  font-stretch: 100%;
  font-display: swap;
  src: url('../fonts/fredoka-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  /* Custom Color Palette Built Around #4E3A6F (Royal Plum), #D9963D (Harvest Gold), #555D8B (Slate Indigo) */
  --bg-deep: #1D152B;
  --bg-surface: #2E2244;
  --bg-card: #4E3A6F;
  --bg-card-hover: #5C4582;
  --border-subtle: #555D8B;
  --border-medium: #6770A3;
  --border-strong: #828BC0;

  /* Rich Plum & Press Tones (#4E3A6F) */
  --plum-primary: #4E3A6F;
  --plum-light: #6E5399;
  --plum-liquid: #7A4288;
  --plum-liquid-top: #A35BB5;
  --slate-indigo: #555D8B;
  --slate-indigo-dark: #3B4163;

  /* Warm Harvest Gold (#D9963D) & Accessible Accents */
  --accent-gold: #D9963D;
  --accent-gold-light: #F2B866;
  --accent-cyan: #58C4F6;
  --accent-teal: #14B8A6;
  --accent-teal-light: #5EEAD4;
  --accent-orange: #EA580C;

  /* High-Contrast, Glare-Free Typography */
  --text-primary: #FBF9FF;
  --text-secondary: #DED8EC;
  --text-muted: #B5ACC9;
  --text-highlight: #F9D59B;

  --font-family: 'Consolas', 'Courier New', 'Lucida Console', Monaco, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border-radius: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

body {
  font-family: var(--font-family);
  background: radial-gradient(circle at 50% 15%, #4E3A6F 0%, #2D2346 58%, #1B1429 100%);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

/* ==========================================================================
   Screen Management (Strict Single-Screen Visibility & Isolation)
   ========================================================================== */
.app-screen {
  display: none !important;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.app-screen.active {
  display: flex !important;
}

/* ==========================================================================
   SCREENS 1, 2, 4: Welcome, Setup & Results Screens
   ========================================================================== */
#welcomeScreen,
#setupScreen,
#resultsScreen,
#titleSetupScreen {
  padding: calc(14px + env(safe-area-inset-top, 0px)) 12px calc(36px + env(safe-area-inset-bottom, 0px)) 12px;
  overflow-y: auto;
  overflow-x: hidden;
  box-sizing: border-box;
  width: 100%;
}

.welcome-container,
.setup-container,
.results-container {
  width: 100%;
  max-width: 920px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin: 0 auto;
}

.title-header {
  width: 100%;
  padding: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 2px solid;
  border-color: #6C5784 #140E1B #140E1B #6C5784;
  border-radius: 0;
  box-shadow: inset 1px 1px 0px #8F76AB, inset -1px -1px 0px #09060D, 0 6px 18px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.title-header-main {
  width: 100%;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.logo-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.plum-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  animation: gentle-bounce 3s infinite ease-in-out;
}

.brand-plum-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  filter: drop-shadow(0 4px 10px rgba(168, 85, 247, 0.55));
}

/* Inline 3D UI & Button Icons */
.btn-inline-icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
  vertical-align: -3px;
  margin-right: 5px;
  display: inline-block;
}

.header-icon-img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  vertical-align: middle;
  display: inline-block;
}

.header-inline-trophy {
  width: 22px;
  height: 22px;
  object-fit: contain;
  vertical-align: -4px;
  margin-right: 4px;
  display: inline-block;
}

.tab-inline-icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
  vertical-align: middle;
  display: inline-block;
  margin-right: 5px;
}

.btn-peek-img {
  width: 26px;
  height: 22px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.modal-header-icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.results-hero-img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  display: block;
  margin: 0 auto 8px auto;
  filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.6));
}

.badge-mini-icon {
  width: 14px;
  height: 14px;
  object-fit: contain;
  display: inline-block;
  vertical-align: -2px;
}

.banner-inline-icon {
  width: 16px;
  height: 16px;
  object-fit: contain;
  display: inline-block;
  vertical-align: -2px;
  margin-right: 4px;
}

@keyframes gentle-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.title-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.title-group h1 {
  font-size: 1.85rem;
  letter-spacing: 1.5px;
  font-weight: 900;
  background: linear-gradient(135deg, #FCE588, #E0A82E, #E5C2D9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-transform: uppercase;
}

.subtitle {
  font-size: 0.82rem;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.welcome-tagline {
  font-family: var(--font-family);
  font-size: 0.82rem;
  color: var(--accent-gold-light);
  font-weight: 700;
  margin-top: 4px;
  transition: opacity 0.25s ease-in-out;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

/* Quick Action Bar under title (Rules button on top, Sound and Haptics toggles side-by-side below) */
.title-quick-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}

.title-toggles-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}

.btn-rules-bar {
  width: 100%;
  padding: 10px 8px;
  font-weight: 800;
  font-size: 0.92rem;
  letter-spacing: 0.5px;
}

.btn-quick-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 6px;
  background: #2D233C;
  border: 2px solid;
  border-color: #796194 #140E1B #140E1B #796194;
  border-radius: 0;
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  box-shadow: inset 1px 1px 0px #A38DC0, inset -1px -1px 0px #0F0A15;
  transition: transform 0.05s ease, background 0.1s ease;
  white-space: nowrap;
  touch-action: manipulation;
}

.btn-quick-bar:hover {
  background: #3D3052;
  color: var(--accent-gold-light);
}

.btn-quick-bar:active {
  transform: translateY(2px);
  border-color: #140E1B #796194 #796194 #140E1B;
  box-shadow: inset 2px 2px 3px rgba(0, 0, 0, 0.6);
}

/* Sticky Setup Header glued to top on scroll */
.setup-header-sticky {
  width: 100%;
  position: sticky;
  top: 0;
  z-index: 100;
  background: #231C2E;
  border-bottom: 2px solid #6C5784;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}

.setup-header-nav {
  width: 100%;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.setup-header-title {
  font-family: var(--font-family);
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--accent-gold-light);
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.multiplier-pill {
  font-family: var(--font-family);
  background: linear-gradient(135deg, #371D3A, #251228);
  color: var(--accent-gold-light);
  border: 2px solid;
  border-color: #A388C0 #372A45 #372A45 #A388C0;
  border-radius: 0;
  padding: 4px 10px;
  font-size: 0.85rem;
  font-weight: 800;
  box-shadow: inset 1px 1px 0 #D4C3E8, inset -1px -1px 0 #181120;
}

.welcome-action-row {
  width: 100%;
  margin-top: 4px;
}

/* High Score & Leaderboard Records Row */
.records-container {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 14px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
}

@media (max-width: 768px) {
  .records-container {
    grid-template-columns: minmax(0, 1fr);
  }
}

.best-record-card {
  background: linear-gradient(145deg, #2D243A, #201A2B);
  border: 2px solid rgba(240, 180, 41, 0.5);
  border-radius: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
}

.best-record-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.best-record-icon {
  font-size: 1.4rem;
}

.best-record-label {
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: var(--accent-gold-light);
  text-transform: uppercase;
}

.best-record-value {
  font-size: 3.2rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--accent-gold-light);
  text-shadow: 0 2px 10px rgba(240, 180, 41, 0.3);
}

.best-record-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.leaderboard-card {
  background: var(--bg-card);
  border: 2px solid #59476C;
  border-radius: 0;
  padding: 14px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
  overflow: hidden;
}

.leaderboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.leaderboard-title-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.leaderboard-heading {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-primary);
}

.btn-text {
  background: transparent;
  border: 1px solid #59476C;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 0;
}

.btn-text:hover {
  color: #FFA573;
  background: rgba(255, 255, 255, 0.06);
}

.leaderboard-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  background: #181322;
  padding: 3px;
  border-radius: 0;
  border: 1px solid #483A58;
}

.leaderboard-tabs .tab-btn {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-family);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 8px 10px;
  border-radius: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.12s ease;
}

.leaderboard-tabs .tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.leaderboard-tabs .tab-btn.active {
  background: #4A2446;
  color: #FFFFFF;
  border-color: #A05298;
  box-shadow: inset 1px 1px 0 #C47DBB, inset -1px -1px 0 #200D1E;
}

.leaderboard-notice {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding: 5px 8px;
  background: rgba(240, 180, 41, 0.08);
  border-left: 3px solid var(--accent-gold);
  border-radius: 0;
}

/* Mission Settings Card */
.setup-settings-card {
  background: var(--bg-card);
  border: 2px solid #59476C;
  border-radius: 0;
  padding: 18px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
}

.settings-heading {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  margin-bottom: 4px;
}

.settings-subheading {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.settings-section {
  margin-bottom: 16px;
}

.settings-section-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.settings-options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

/* 10x10 and 12x12 Grid Dimensions Sitting Side-by-Side */
.grid-dimensions-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr) !important;
  gap: 10px;
  width: 100%;
}

.option-card {
  background: var(--bg-surface);
  border: 1.5px solid var(--border-subtle);
  border-radius: 0;
  padding: 12px;
  cursor: pointer;
  transition: all 0.12s ease;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 68px;
  touch-action: manipulation;
}

.option-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.option-card.active {
  border-color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.12);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.25);
}

.option-card-title {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text-primary);
}

.option-card-desc {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.3;
}

.option-multiplier {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent-gold-light);
  margin-top: 2px;
}

/* Big Start Button */
.start-action-row {
  margin-top: 20px;
}

.btn-start-game {
  width: 100%;
  background: linear-gradient(135deg, var(--accent-gold), #D49B20);
  color: #17131F;
  border: 2px solid var(--accent-gold-light);
  border-radius: 0;
  min-height: 60px;
  padding: 12px 20px;
  cursor: pointer;
  font-family: inherit;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 16px rgba(240, 180, 41, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: all 0.12s ease;
  touch-action: manipulation;
}

.btn-start-game:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(240, 180, 41, 0.5);
}

.btn-start-game:active {
  transform: translateY(1px);
  box-shadow: 0 2px 8px rgba(240, 180, 41, 0.3);
}

.btn-start-game .btn-subtext {
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(23, 19, 31, 0.85);
  letter-spacing: normal;
}

/* ==========================================================================
   SCREEN 3: Active Gameplay Screen (Zero Scrolling)
   ========================================================================== */
#gameplayScreen {
  overflow: hidden !important;
  height: 100vh;
  height: 100dvh;
  touch-action: manipulation;
}

/* Compact In-Game Top Bar */
.gameplay-header {
  width: 100%;
  max-width: 1400px;
  padding: 4px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(90deg, #522351 0%, #291228 100%);
  border-bottom: 2.5px solid;
  border-color: #795779 #140A14 #140A14 #795779;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  z-index: 10;
  flex-shrink: 0;
  min-height: 44px;
  box-sizing: border-box;
}

.retro-app-badge {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.74rem;
  font-weight: 900;
  background: #110A17;
  color: #38BDF8;
  padding: 2px 6px;
  border: 1px solid #38BDF8;
  border-radius: 0;
  letter-spacing: 0.5px;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.6);
}

.gameplay-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.gameplay-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.gameplay-header-right .btn-icon {
  flex-shrink: 0;
  min-width: 34px;
  width: 34px;
  height: 34px;
  padding: 0;
  justify-content: center;
  display: flex;
  align-items: center;
  border-radius: 0;
}

.btn-quit {
  background: #3B2E4D;
  border: 1.5px solid;
  border-color: #796194 #1C1326 #1C1326 #796194;
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 0;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-quit:hover {
  background: #523E6B;
  color: #FFA573;
}

.current-mode-tag {
  background: rgba(240, 180, 41, 0.15);
  border: 1px solid rgba(240, 180, 41, 0.4);
  color: var(--accent-gold-light);
  padding: 3px 8px;
  border-radius: 0;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

@media (max-width: 680px) {
  .current-mode-tag {
    display: none !important;
  }
}

@media (max-width: 580px) {
  .stat-goal {
    display: none !important;
  }
}

.gameplay-stats-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
  justify-content: center;
}

.mini-stat {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mini-stat-label {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
}

.mini-stat-val {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-primary);
}

.highlight-gold {
  color: var(--accent-gold-light) !important;
}

/* General Button Icon Styles */
.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  border-radius: 0;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 700;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 5px;
  touch-action: manipulation;
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--accent-gold);
}

.btn-icon.highlight-btn {
  background: linear-gradient(135deg, var(--plum-primary), #5B2B52);
  color: #FFFFFF;
  border-color: var(--plum-light);
}

/* ==========================================================================
   Main Arena Layout (Adaptive Landscape vs Portrait)
   ========================================================================== */
.main-content {
  width: 100%;
  max-width: 1400px;
  flex: 1;
  display: flex;
  overflow: hidden;
  padding: 4px 8px;
  gap: 8px;
}

/* LANDSCAPE ORIENTATION (Tablets, Desktops, Landscape Phones) */
/* Keypad sits strictly NEXT TO the grid on the RIGHT HAND SIDE */
@media (orientation: landscape) {
  .main-content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    height: calc(100vh - 50px);
    padding: 4px 8px;
    gap: 8px;
    overflow: hidden;
  }

  .arena-panel {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 4px;
    overflow: hidden;
  }

  .grid-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    overflow: auto;
    padding: 0;
    margin: 0;
  }

  .console-panel {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px;
    gap: 6px;
    overflow-y: auto;
  }

  .keypad-btn {
    min-height: 46px;
    font-size: 1.4rem;
    padding: 6px 0;
  }

  .btn-submit-pipe {
    min-height: 48px;
    font-size: 1.15rem;
  }
}

/* TABLET LANDSCAPE & DESKTOP (Width >= 960px & Height > 540px) */
/* Prominent industrial LCD readout and spacious buttons */
@media (orientation: landscape) and (min-width: 960px) and (min-height: 541px) {
  .main-content {
    grid-template-columns: minmax(0, 1fr) 390px;
    padding: 8px 14px;
    gap: 12px;
  }

  .console-panel {
    padding: 14px;
    gap: 10px;
  }

  .retro-control-hud {
    min-height: 70px;
  }

  .challenge-box.input-only-box {
    padding: 8px 12px;
  }

  .challenge-prompt {
    font-size: 0.82rem;
    letter-spacing: 0.8px;
  }

  .input-display-box {
    min-height: 48px;
    padding: 4px 12px;
  }

  .input-digits {
    font-size: 2.25rem;
  }

  .flow-gauge-card {
    padding: 8px 12px;
  }

  .gauge-title {
    font-size: 0.82rem;
  }

  .gauge-time {
    font-size: 1.35rem;
  }

  .progress-track {
    height: 12px;
  }

  .keypad-btn {
    min-height: 52px;
    font-size: 1.6rem;
  }

  .btn-submit-pipe {
    min-height: 52px;
    font-size: 1.25rem;
  }
}

/* PHONE LANDSCAPE (Height <= 540px) */
@media (orientation: landscape) and (max-height: 540px) {
  .gameplay-header {
    min-height: 38px;
    padding: 2px 10px;
  }

  .main-content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 270px;
    height: calc(100vh - 40px);
    padding: 2px 6px;
    gap: 6px;
    overflow: hidden;
  }

  .arena-panel {
    height: 100%;
    padding: 2px;
  }

  .board-banner {
    padding: 2px 6px;
    font-size: 0.74rem;
  }

  .console-panel {
    height: 100%;
    padding: 4px 6px;
    gap: 4px;
    overflow-y: auto;
  }

  .flow-gauge-card {
    padding: 4px 8px;
  }

  .progress-track {
    height: 8px;
  }

  .challenge-box {
    padding: 4px 8px;
  }

  .challenge-math {
    font-size: 1.25rem;
    margin: 1px 0;
  }

  .input-display-box {
    min-height: 28px;
    padding: 2px 8px;
  }

  .input-digits {
    font-size: 1.25rem;
  }

  .keypad-container {
    gap: 3px;
  }

  .keypad-btn {
    min-height: 34px;
    font-size: 1.15rem;
    padding: 3px 0;
  }

  .btn-submit-pipe {
    min-height: 38px;
    font-size: 0.95rem;
    padding: 6px;
  }
}

/* PORTRAIT ORIENTATION (Phones) */
/* Fits both Grid and Keypad on a single compact 9:16 phone screen */
@media (orientation: portrait) and (max-width: 767px) {
  #gameplayScreen.active {
    height: 100dvh;
    height: 100vh;
    max-height: 100dvh;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column;
  }

  .gameplay-header {
    height: calc(38px + env(safe-area-inset-top, 0px));
    min-height: calc(38px + env(safe-area-inset-top, 0px));
    max-height: calc(44px + env(safe-area-inset-top, 0px));
    flex: 0 0 auto;
    padding: calc(2px + env(safe-area-inset-top, 0px)) 6px 2px 6px;
    overflow: hidden;
  }

  .gameplay-header-left, .gameplay-header-right {
    flex-shrink: 0;
    gap: 4px;
  }

  .gameplay-header-right .btn-icon {
    min-width: 30px;
    width: 30px;
    height: 30px;
    font-size: 0.88rem;
  }

  .btn-quit {
    padding: 3px 6px;
    font-size: 0.74rem;
  }

  .current-mode-tag {
    display: none !important;
  }

  .stat-goal {
    display: none !important;
  }

  .gameplay-stats-bar {
    gap: 6px;
    flex: 1 1 auto;
    justify-content: center;
  }

  .mini-stat {
    gap: 3px;
  }

  .mini-stat-label {
    font-size: 0.62rem;
  }

  .mini-stat-val {
    font-size: 0.92rem;
  }

  .main-content {
    flex: 1 1 auto;
    min-height: 0;
    height: calc(100dvh - 38px - env(safe-area-inset-top, 0px));
    max-height: calc(100dvh - 38px - env(safe-area-inset-top, 0px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 3px 5px;
    gap: 4px;
  }

  .arena-panel {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2px 4px;
    width: 100%;
  }

  .arena-banner-row {
    flex: 0 0 auto;
    height: 26px;
    min-height: 26px;
    max-height: 26px;
    margin-bottom: 2px;
    width: 100%;
  }

  .board-banner {
    padding: 2px 6px;
    font-size: 0.72rem;
  }

  .btn-peek {
    padding: 2px 6px;
    font-size: 0.72rem;
    height: 24px;
  }

  .grid-wrapper {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .exit-arrow-indicator {
    flex: 0 0 auto;
    height: 18px;
    padding: 1px 6px;
    margin-top: 2px;
    font-size: 0.7rem;
  }

  .console-panel {
    flex: 0 0 auto;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 3px 5px;
    width: 100%;
  }

  .retro-control-hud {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    height: 44px;
    min-height: 44px;
    max-height: 44px;
    width: 100%;
  }

  .flow-gauge-card {
    height: 100%;
    padding: 2px 6px;
  }

  .challenge-box {
    height: 100%;
    padding: 2px 6px;
  }

  .challenge-prompt {
    font-size: 0.62rem;
  }

  .challenge-math {
    font-size: 1.1rem;
    margin: 0;
  }

  .input-display-box {
    min-height: 22px;
    padding: 1px 5px;
  }

  .input-digits {
    font-size: 1.15rem;
  }

  .feedback-banner {
    height: 18px;
    min-height: 18px;
    max-height: 18px;
    line-height: 16px;
    font-size: 0.7rem;
    padding: 1px 4px;
  }

  .keypad-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3px;
  }

  .keypad-btn {
    height: 35px;
    min-height: 35px;
    max-height: 38px;
    font-size: 1.25rem;
    padding: 0;
  }

  .keypad-btn.action-btn {
    font-size: 0.95rem;
  }

  .btn-submit-pipe {
    grid-column: span 3;
    height: 36px;
    min-height: 36px;
    max-height: 38px;
    font-size: 1.05rem;
    padding: 2px 6px;
  }
}

/* TABLET PORTRAIT ORIENTATION (Width >= 768px) */
/* Generous touch targets, full header stats, and large LCD answer display */
@media (orientation: portrait) and (min-width: 768px) {
  #gameplayScreen.active {
    height: 100vh;
    height: 100dvh;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column;
  }

  .gameplay-header {
    height: 52px;
    min-height: 52px;
    max-height: 52px;
    flex: 0 0 52px;
    padding: 6px 14px;
    overflow: visible;
  }

  .current-mode-tag {
    display: inline-block !important;
    font-size: 0.86rem;
  }

  .stat-goal {
    display: flex !important;
  }

  .gameplay-stats-bar {
    gap: 16px;
  }

  .mini-stat-label {
    font-size: 0.72rem;
  }

  .mini-stat-val {
    font-size: 1.15rem;
  }

  .main-content {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    padding: 8px 18px;
    gap: 10px;
    overflow: hidden;
  }

  .arena-panel {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 6px 12px;
    overflow: hidden;
  }

  .grid-wrapper {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
    margin: 0;
    padding: 0;
  }

  .console-panel {
    flex: 0 0 auto;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding: 12px 18px;
    gap: 10px;
  }

  .retro-control-hud {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    height: 72px;
    min-height: 72px;
    max-height: 78px;
  }

  .challenge-box.input-only-box {
    padding: 6px 12px;
  }

  .challenge-prompt {
    font-size: 0.82rem;
    letter-spacing: 0.8px;
  }

  .input-display-box {
    min-height: 48px;
    padding: 4px 12px;
  }

  .input-digits {
    font-size: 2.2rem;
  }

  .flow-gauge-card {
    padding: 6px 12px;
  }

  .gauge-title {
    font-size: 0.82rem;
  }

  .gauge-time {
    font-size: 1.35rem;
  }

  .progress-track {
    height: 14px;
  }

  .feedback-banner {
    height: 26px;
    min-height: 26px;
    font-size: 0.84rem;
    line-height: 24px;
  }

  .keypad-container {
    gap: 6px;
  }

  .keypad-btn {
    height: 54px;
    min-height: 54px;
    max-height: 58px;
    font-size: 1.6rem;
  }

  .btn-submit-pipe {
    height: 54px;
    min-height: 54px;
    max-height: 58px;
    font-size: 1.25rem;
  }
}

/* Grid Arena Panel */
.arena-panel {
  background: var(--bg-card);
  border: 2px solid;
  border-color: #55446C #100918 #100918 #55446C;
  border-radius: 0;
  box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.1), inset -1px -1px 0 rgba(0, 0, 0, 0.6), 0 4px 18px rgba(0, 0, 0, 0.25);
  position: relative;
  display: flex;
  flex-direction: column;
}

.grid-wrapper {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  position: relative;
  margin: 0;
  padding: 0;
}

.arena-banner-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.board-banner {
  flex: 1;
  padding: 4px 8px;
  margin-bottom: 0;
  background: rgba(34, 30, 44, 0.85);
  border: 1.5px solid var(--border-strong);
  border-radius: 0;
  font-size: 0.82rem;
  text-align: center;
  color: var(--text-highlight);
  font-weight: 700;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Hold-to-Peek Button (Freezes timer and shows full overview) */
.btn-peek {
  background: linear-gradient(135deg, #372A4A, #281F38);
  border: 1.5px solid var(--accent-gold);
  color: var(--accent-gold-light);
  font-weight: 800;
  font-size: 0.82rem;
  padding: 4px 10px;
  border-radius: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  flex-shrink: 0;
  touch-action: none;
  transition: all 0.12s ease;
  user-select: none;
  -webkit-user-select: none;
}

.btn-peek:hover {
  background: rgba(240, 180, 41, 0.2);
}

.btn-peek:active, .btn-peek.pressed {
  background: var(--accent-gold);
  color: #17131F;
  transform: scale(0.96);
  box-shadow: 0 0 12px rgba(240, 180, 41, 0.6);
}

/* Exit Valve Direction Indicator Badge (Shown in camera mode when exit is offscreen) */
.exit-arrow-indicator {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(23, 19, 31, 0.92);
  border: 1.5px solid var(--accent-gold);
  border-radius: 0;
  padding: 4px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 30;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5), 0 0 10px rgba(240, 180, 41, 0.4);
  animation: pulse-exit-arrow 1.4s infinite alternate ease-in-out;
  pointer-events: none;
}

.exit-arrow-icon {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--accent-gold);
  display: inline-block;
  line-height: 1;
}

.exit-arrow-text {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  letter-spacing: 0.4px;
  text-transform: uppercase;
  white-space: nowrap;
}

@keyframes pulse-exit-arrow {
  0% { transform: translateY(0); border-color: var(--accent-gold); }
  100% { transform: translateY(-2px); border-color: var(--accent-gold-light); box-shadow: 0 4px 16px rgba(240, 180, 41, 0.6); }
}

/* Camera Grid Frame */
.camera-grid-frame {
  display: grid;
  grid-template-columns: var(--header-size, 30px) var(--viewport-w, auto);
  grid-template-rows: var(--header-size, 30px) var(--viewport-h, auto);
  gap: var(--grid-gap, 2px);
  background: #0D0A14;
  padding: 3px;
  border-radius: 6px;
  border: 2.5px solid;
  border-color: #07050A #5A476F #5A476F #07050A;
  position: relative;
  overflow: hidden;
  box-shadow: inset 2px 2px 6px rgba(0, 0, 0, 0.8), inset -1px -1px 0px rgba(255, 255, 255, 0.1);
  margin: 0 auto;
}

.camera-corner {
  grid-column: 1;
  grid-row: 1;
  width: var(--header-size, 30px);
  height: var(--header-size, 30px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1C1525;
  border: 1.5px solid;
  border-color: #554269 #0A070F #0A070F #554269;
  border-radius: 3px;
  color: #8C7C9E;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.85rem;
  font-weight: 900;
  box-shadow: inset 0.5px 0.5px 0px rgba(255, 255, 255, 0.15);
}

.col-headers-window {
  grid-column: 2;
  grid-row: 1;
  overflow: hidden;
  width: var(--viewport-w, 100%);
  height: var(--header-size, 30px);
  position: relative;
}

.col-headers-track {
  display: flex;
  gap: var(--grid-gap, 2px);
  transition: transform 0.22s cubic-bezier(0.25, 1, 0.5, 1);
  will-change: transform;
}

.row-headers-window {
  grid-column: 1;
  grid-row: 2;
  overflow: hidden;
  width: var(--header-size, 30px);
  height: var(--viewport-h, 100%);
  position: relative;
}

.row-headers-track {
  display: flex;
  flex-direction: column;
  gap: var(--grid-gap, 2px);
  transition: transform 0.22s cubic-bezier(0.25, 1, 0.5, 1);
  will-change: transform;
}

.tiles-window {
  grid-column: 2;
  grid-row: 2;
  overflow: hidden;
  width: var(--viewport-w, 100%);
  height: var(--viewport-h, 100%);
  position: relative;
}

.tiles-track {
  display: grid;
  gap: var(--grid-gap, 2px);
  transition: transform 0.22s cubic-bezier(0.25, 1, 0.5, 1);
  will-change: transform;
}

/* While Peeking, speed up transform transition */
.camera-grid-frame.peeking .col-headers-track,
.camera-grid-frame.peeking .row-headers-track,
.camera-grid-frame.peeking .tiles-track {
  transition: transform 0.18s cubic-bezier(0.25, 1, 0.5, 1);
}

/* Header Cell inside Tracks */
.header-cell {
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: 'Consolas', 'Courier New', monospace;
  font-weight: 900;
  font-size: 0.95rem;
  color: #FCE588;
  background: #231B2D;
  border: 1.5px solid;
  border-color: #58446E #0B0810 #0B0810 #58446E;
  border-radius: 3px;
  box-shadow: inset 0.5px 0.5px 0px rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

.col-headers-track .header-cell {
  width: var(--tile-size, 52px);
  height: var(--header-size, 30px);
}

.row-headers-track .header-cell {
  width: var(--header-size, 30px);
  height: var(--tile-size, 52px);
}

/* Pipe Grid Tiles */
.grid-tile {
  width: var(--tile-size, clamp(36px, min(6.8vw, 7.8vh), 58px));
  height: var(--tile-size, clamp(36px, min(6.8vw, 7.8vh), 58px));
  background: #1B1524;
  border: 1.5px solid;
  border-color: #4C3A5F #0D0913 #0D0913 #4C3A5F;
  border-radius: 4px;
  position: relative;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.08s ease;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: inset 1px 1px 0px rgba(255, 255, 255, 0.15), inset -1px -1px 0px rgba(0, 0, 0, 0.5);
}

.grid-tile:hover {
  background: #281F34;
  border-color: #6C5586 #110C1A #110C1A #6C5586;
}

/* Formula shown inside unvisited squares (e.g. 7×8) */
.tile-formula {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: clamp(0.68rem, 1.4vw, 0.85rem);
  font-weight: 800;
  color: #E2DCED;
  letter-spacing: 0.2px;
  pointer-events: none;
  z-index: 2;
}

/* Product shown ONLY after square is solved/filled */
.tile-product {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: clamp(0.8rem, 1.8vw, 1rem);
  font-weight: 900;
  color: #FFFFFF;
  z-index: 2;
  display: none;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* 12x12 grid cell sizing */
.grid-12 .grid-tile {
  width: clamp(30px, min(5.5vw, 6.4vh), 48px);
  height: clamp(30px, min(5.5vw, 6.4vh), 48px);
}

.grid-12 .tile-formula {
  font-size: clamp(0.56rem, 1.2vw, 0.72rem);
}

.grid-12 .tile-product {
  font-size: clamp(0.68rem, 1.4vw, 0.85rem);
}

.grid-12 .header-cell.col-header {
  height: clamp(22px, 3.2vh, 30px);
  font-size: 0.85rem;
}

.grid-12 .header-cell.row-header {
  width: clamp(22px, 3.2vh, 30px);
  font-size: 0.85rem;
}

/* Obstacle Tile */
.grid-tile.obstacle {
  background: #140E1B !important;
  border: 1.5px solid #4D3A63 !important;
  cursor: not-allowed;
  box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid-tile.obstacle .tile-formula {
  display: none;
}

.grid-tile.obstacle::after {
  content: '';
  width: 76%;
  height: 76%;
  background: url('../icons/block-3d.png') no-repeat center center;
  background-size: contain;
  display: block;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.7));
}

/* Start Valve */
.grid-tile.start-valve {
  border: 2px solid var(--accent-teal) !important;
  box-shadow: 0 0 10px rgba(20, 184, 166, 0.4) !important;
  animation: pulse-start-valve 1.8s infinite ease-in-out;
}

@keyframes pulse-start-valve {
  0%, 100% { border-color: var(--accent-teal); box-shadow: 0 0 6px rgba(20, 184, 166, 0.3); }
  50% { border-color: var(--accent-teal-light); box-shadow: 0 0 14px rgba(20, 184, 166, 0.6); }
}

.valve-badge {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 0.52rem;
  font-weight: 800;
  color: var(--accent-teal-light);
  background: rgba(16, 32, 28, 0.88);
  padding: 0 3px;
  border-radius: 3px;
  pointer-events: none;
  z-index: 3;
}

.grid-tile.start-valve:not(.filled) .tile-formula {
  margin-top: 10px;
  color: #FFFFFF;
}

/* End Valve (Golden Pit) */
.grid-tile.end-valve {
  border: 2px dashed var(--accent-gold) !important;
  box-shadow: 0 0 10px rgba(240, 180, 41, 0.4) !important;
}

.grid-tile.end-valve::before {
  content: '';
  position: absolute;
  inset: 14%;
  background: url('../icons/Golden Pit.png') no-repeat center center;
  background-size: contain;
  opacity: 0.28;
  pointer-events: none;
  z-index: 1;
}

.recent-pit-icon {
  width: 72%;
  height: 72%;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.goal-badge {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 0.6rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  background: rgba(36, 26, 10, 0.85);
  padding: 1px 3px;
  border-radius: 3px;
  pointer-events: none;
  z-index: 3;
}

/* Filled Tile */
.grid-tile.filled {
  background: #381E33;
  border-color: var(--border-strong);
}

.grid-tile.filled .tile-formula {
  display: none;
}

.grid-tile.filled .tile-product {
  display: block;
}

/* Flowing Liquid Inside Active Tile */
.grid-tile.flowing {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

.liquid-fill-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0%;
  background: linear-gradient(180deg, var(--plum-liquid-top), var(--plum-liquid));
  opacity: 0.92;
  transition: height 0.05s linear;
  z-index: 1;
}

.grid-tile.filled:not(.flowing) .liquid-fill-overlay {
  height: 100% !important;
  background: linear-gradient(180deg, var(--plum-liquid), #5A274F);
}

/* Available Neighbor Choice (Vibrant Teal Border) */
.grid-tile.available-next {
  border: 2.5px solid var(--accent-teal) !important;
  background: rgba(20, 184, 166, 0.16);
  box-shadow: inset 0 0 6px rgba(94, 234, 212, 0.35), 0 0 8px rgba(20, 184, 166, 0.45);
  cursor: pointer;
  animation: neighbor-teal-glow 1.4s infinite ease-in-out;
}

@keyframes neighbor-teal-glow {
  0%, 100% {
    transform: scale(1);
    border-color: var(--accent-teal);
    box-shadow: inset 0 0 6px rgba(94, 234, 212, 0.3), 0 0 6px rgba(20, 184, 166, 0.35);
  }
  50% {
    transform: scale(1.04);
    border-color: var(--accent-teal-light);
    box-shadow: inset 0 0 10px rgba(94, 234, 212, 0.55), 0 0 12px rgba(94, 234, 212, 0.6);
  }
}

.grid-tile.available-next:hover {
  background: rgba(20, 184, 166, 0.28);
  border-color: var(--accent-teal-light) !important;
}

/* Selected Target to Solve */
.grid-tile.selected-target {
  border: 3px solid var(--accent-teal-light) !important;
  background: rgba(20, 184, 166, 0.32) !important;
  box-shadow: 0 0 16px rgba(94, 234, 212, 0.7), inset 0 0 8px rgba(94, 234, 212, 0.5) !important;
  transform: scale(1.06);
  z-index: 5;
}

/* Ambiguous Matching Choice Candidate Tile (Pulsing Gold / Amber) */
.grid-tile.choice-candidate {
  border: 3px solid var(--accent-gold) !important;
  background: rgba(240, 180, 41, 0.3) !important;
  box-shadow: 0 0 16px rgba(240, 180, 41, 0.8), inset 0 0 8px rgba(240, 180, 41, 0.5) !important;
  animation: choice-pulse 0.9s infinite alternate;
  cursor: pointer;
  z-index: 6;
}

@keyframes choice-pulse {
  from {
    transform: scale(1.03);
    filter: brightness(1);
    box-shadow: 0 0 12px rgba(240, 180, 41, 0.6), inset 0 0 6px rgba(240, 180, 41, 0.4);
  }
  to {
    transform: scale(1.08);
    filter: brightness(1.25);
    box-shadow: 0 0 20px rgba(252, 229, 136, 0.9), inset 0 0 10px rgba(252, 229, 136, 0.6);
  }
}

.choice-arrow-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: #17131F;
  color: var(--accent-gold-light);
  border: 1px solid var(--accent-gold);
  font-size: 0.68rem;
  font-weight: 900;
  padding: 1px 4px;
  border-radius: 0;
  line-height: 1;
  z-index: 8;
  pointer-events: none;
}

/* ==========================================================================
   Plumber Console & Retro Industrial Keypad
   ========================================================================== */
.console-panel {
  background: transparent;
  border-top: 3px solid #8D74AC;
  border-left: 3px solid #755E92;
  border-right: 3px solid #100A18;
  border-bottom: 3px solid #08050C;
  border-radius: 0;
  box-shadow: 
    inset 1.5px 1.5px 0px rgba(255, 255, 255, 0.22),
    inset -1.5px -1.5px 0px rgba(0, 0, 0, 0.85),
    inset 0 0 14px rgba(0, 0, 0, 0.45),
    0 6px 18px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
}

/* Retro Control HUD: Hydraulic Flow Meter (Left) + Digital LCD Math (Right) */
.retro-control-hud {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  width: 100%;
}

/* Flow Gauge Timer */
.flow-gauge-card {
  background: #150F1E;
  border: 2px solid;
  border-color: #0A0610 #5A486E #5A486E #0A0610;
  border-radius: 0;
  padding: 4px 8px;
  box-shadow: inset 1.5px 1.5px 3px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.gauge-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}

.gauge-title {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  color: #C8C2D4;
  letter-spacing: 0.5px;
}

.gauge-time {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.88rem;
  font-weight: 900;
  color: #FCE588;
  text-shadow: 0 0 5px rgba(252, 229, 136, 0.5);
}

.progress-track {
  width: 100%;
  height: 10px;
  background: #0A0710;
  border: 1px solid #3F3350;
  border-radius: 0;
  overflow: hidden;
  position: relative;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.9);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(90deg, #14B8A6 0px, #14B8A6 5px, #0A0710 5px, #0A0710 7px);
  transition: width 0.05s linear;
}

.progress-fill.danger-urgent {
  background: repeating-linear-gradient(90deg, #EA580C 0px, #EA580C 5px, #0A0710 5px, #0A0710 7px);
  animation: urgent-pulse 0.35s infinite alternate;
}

@keyframes urgent-pulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.4); }
}

/* Target Challenge Box */
.challenge-box {
  background: #150F1E;
  border: 2px solid;
  border-color: #0A0610 #5A486E #5A486E #0A0610;
  border-radius: 0;
  padding: 4px 8px;
  text-align: center;
  box-shadow: inset 1.5px 1.5px 3px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.challenge-prompt {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #9D8BB0;
  margin-bottom: 1px;
}

.challenge-math {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 1.15rem;
  font-weight: 800;
  margin: 0;
}

.math-num {
  color: var(--accent-gold-light);
}

.math-op {
  color: var(--accent-cyan);
  margin: 0 2px;
}

/* Input Display Box */
.input-display-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #08050C;
  border: 1.5px solid;
  border-color: #040206 #5B4870 #5B4870 #040206;
  border-radius: 3px;
  min-height: 24px;
  min-width: 44px;
  padding: 1px 6px;
  margin-left: 3px;
  box-shadow: inset 1.5px 1.5px 3px rgba(0, 0, 0, 0.9);
}

.input-digits {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: 2px;
  color: #38BDF8;
  text-shadow: 0 0 6px rgba(56, 189, 248, 0.6);
}

.cursor-blink {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: var(--accent-cyan);
  margin-left: 3px;
  animation: blink 0.9s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Feedback Message Banner */
.feedback-banner {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.76rem;
  font-weight: 800;
  text-align: center;
  min-height: 20px;
  padding: 2px 8px;
  border-radius: 4px;
  background: #140E1B;
  border: 1.5px solid #3F324E;
  color: #C8C2D4;
  letter-spacing: 0.3px;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.6);
  transition: all 0.15s ease;
}

.feedback-banner.success {
  color: #5EEAD4;
  background: #0D2320;
  border-color: #14B8A6;
  text-shadow: 0 0 4px rgba(94, 234, 212, 0.4);
}

.feedback-banner.error {
  color: #FFA573;
  background: #2E150F;
  border-color: #EA580C;
  animation: shake 0.3s;
}

/* Direction Choice Selector (Ambiguous Matches) */
.choice-prompt-container {
  width: 100%;
  background: linear-gradient(135deg, #371D3A, #251228);
  border: 2px solid var(--accent-gold);
  border-radius: 0;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: choice-banner-slide 0.2s ease-out;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

@keyframes choice-banner-slide {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.choice-prompt-title {
  font-family: var(--font-family);
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  text-align: center;
  letter-spacing: 0.4px;
}

.choice-buttons-row {
  display: flex;
  gap: 6px;
  width: 100%;
}

.btn-choice-direction {
  flex: 1;
  background: #3B2E4D;
  color: #FFFFFF;
  border: 2px solid;
  border-color: #A38DC0 #140E1B #140E1B #A38DC0;
  border-radius: 0;
  padding: 8px 6px;
  font-family: var(--font-family);
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: inset 1px 1px 0 #D4C3E8, inset -1px -1px 0 #0F0A15;
  transition: transform 0.05s ease, background 0.1s ease;
  white-space: nowrap;
}

.btn-choice-direction:hover {
  background: #523E6B;
  color: var(--accent-gold-light);
  border-color: var(--accent-gold-light);
}

.btn-choice-direction:active {
  transform: translateY(2px);
  border-color: #140E1B #A38DC0 #A38DC0 #140E1B;
}

/* Chunky 3D Mechanical Keypad */
.keypad-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.keypad-btn {
  background: linear-gradient(180deg, #443755 0%, #30263D 100%);
  border: 2px solid;
  border-color: #796194 #130C1A #130C1A #796194;
  border-radius: 5px;
  color: #FFFFFF;
  font-size: 1.4rem;
  font-weight: 900;
  font-family: inherit;
  min-height: 42px;
  padding: 4px 0;
  cursor: pointer;
  box-shadow: inset 1px 1px 0px #987EB7, inset -1px -1px 0px #09060D, 0 2px 0 #110B17;
  transition: transform 0.05s ease, background 0.05s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  touch-action: manipulation;
}

.keypad-btn:hover {
  background: linear-gradient(180deg, #4E4062 0%, #3A2F49 100%);
  border-color: #8C72A9 #170E20 #170E20 #8C72A9;
}

.keypad-btn:active, .keypad-btn.pressed {
  transform: translateY(2px);
  border-color: #130C1A #796194 #796194 #130C1A;
  box-shadow: inset 1.5px 1.5px 3px rgba(0, 0, 0, 0.7);
  background: #251D30;
}

.keypad-btn.action-btn {
  font-size: 1rem;
  background: linear-gradient(180deg, #372C46 0%, #251D30 100%);
  border-color: #634F7A #0E0814 #0E0814 #634F7A;
  color: #C8C2D4;
}

.keypad-btn.action-btn:hover {
  color: #FFFFFF;
  background: linear-gradient(180deg, #423654 0%, #2E243B 100%);
}

/* Keypad Bottom Action Row: Connect Pipe + Square Peek Button */
.keypad-action-row {
  grid-column: span 3;
  display: flex;
  gap: 6px;
  width: 100%;
  align-items: stretch;
  margin-top: 2px;
}

.btn-submit-pipe {
  flex: 1;
  background: linear-gradient(180deg, #D9963D 0%, #B37422 100%);
  border: 2px solid;
  border-color: #F5C77E #4A2D08 #4A2D08 #F5C77E;
  border-radius: 0;
  color: #1A1103;
  font-size: 1.08rem;
  font-weight: 900;
  font-family: inherit;
  min-height: 44px;
  padding: 8px;
  cursor: pointer;
  box-shadow: inset 1px 1px 0px #FFE3B3, inset -1px -1px 0px #2D1B02, 0 2px 0 #201300;
  letter-spacing: 0.5px;
  transition: transform 0.05s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 0;
  touch-action: manipulation;
}

.btn-submit-pipe:hover {
  background: linear-gradient(180deg, #E5A44B 0%, #C28029 100%);
  border-color: #FFE0AD #5C390A #5C390A #FFE0AD;
}

.btn-submit-pipe:active {
  transform: translateY(2px);
  border-color: #4A2D08 #F5C77E #F5C77E #4A2D08;
  box-shadow: inset 2px 2px 3px rgba(0, 0, 0, 0.6);
}

.btn-peek-square {
  min-width: 128px;
  width: auto;
  min-height: 44px;
  padding: 4px 10px;
  background: linear-gradient(180deg, #555D8B 0%, #3B4163 100%);
  border: 2px solid;
  border-color: #D9963D #1F2338 #1F2338 #D9963D;
  border-radius: 0;
  color: #FBF9FF;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  box-shadow: inset 1px 1px 0px #8B94C4, inset -1px -1px 0px #151828, 0 0 10px rgba(217, 150, 61, 0.35);
  transition: transform 0.05s ease, box-shadow 0.15s ease;
  touch-action: none;
  flex-shrink: 0;
}

.peek-btn-text-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.1;
  text-align: left;
}

.peek-btn-title {
  font-size: 0.74rem;
  font-weight: 900;
  color: var(--accent-gold-light);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.peek-btn-sub {
  font-size: 0.6rem;
  font-weight: 700;
  color: #E2E6F8;
  white-space: nowrap;
}

.btn-peek-square:active, .btn-peek-square.pressed, .btn-peek-square.holding {
  transform: translateY(2px);
  border-color: #1F2338 #D9963D #D9963D #1F2338;
  background: #2B304C;
  box-shadow: inset 2px 2px 4px rgba(0, 0, 0, 0.65), 0 0 14px rgba(217, 150, 61, 0.65);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ==========================================================================
   Modals (Victory, Game Over, Help)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(14, 12, 19, 0.88);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 20px;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: #252030;
  border: 1.5px solid var(--border-strong);
  border-radius: 0;
  max-width: 520px;
  width: 100%;
  padding: 24px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
  text-align: center;
  transform: scale(0.92);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-card.modal-card-scrollable {
  max-height: 88vh;
  max-width: 580px;
  display: flex;
  flex-direction: column;
  padding: 20px 20px 16px 20px;
}

.modal-header-area {
  flex-shrink: 0;
  text-align: center;
}

.modal-nav-tabs {
  display: flex;
  gap: 6px;
  margin: 12px 0 10px 0;
  background: #181322;
  padding: 4px;
  border: 1px solid #483A58;
}

.modal-nav-tab {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-family);
  font-weight: 700;
  font-size: 0.82rem;
  padding: 8px 6px;
  border-radius: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.12s ease;
}

.modal-nav-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.modal-nav-tab.active {
  background: #4A2446;
  color: #FFFFFF;
  border-color: #A05298;
  box-shadow: inset 1px 1px 0 #C47DBB, inset -1px -1px 0 #200D1E;
}

.modal-body-scrollable {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-right: 6px;
  margin-bottom: 12px;
}

.modal-body-scrollable::-webkit-scrollbar {
  width: 6px;
}

.modal-body-scrollable::-webkit-scrollbar-track {
  background: #140F1D;
}

.modal-body-scrollable::-webkit-scrollbar-thumb {
  background: #5A4372;
}

.modal-body-scrollable::-webkit-scrollbar-thumb:hover {
  background: #755E92;
}

.modal-footer-area {
  flex-shrink: 0;
  padding-top: 4px;
}

.rule-card {
  background: #1B1526;
  border: 1px solid #3A2E4C;
  border-left: 3px solid #9D4EDD;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.rule-card.legal-card {
  border-left-color: var(--accent-teal-light);
}

.rule-card-title {
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.rule-card p {
  font-size: 0.85rem;
  color: #C8C2D4;
  line-height: 1.45;
  margin-bottom: 4px;
}

.rule-list {
  padding-left: 18px;
  margin: 4px 0;
  font-size: 0.84rem;
  color: #C8C2D4;
  line-height: 1.45;
}

.rule-list li {
  margin-bottom: 4px;
}

.rule-badges-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.rule-badge {
  background: #2D233E;
  border: 1px solid #5A4372;
  padding: 3px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.rule-badge-arrow {
  color: var(--accent-teal-light);
  font-weight: 800;
}

/* Legal Footer Links on Welcome Screen */
.welcome-legal-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding-bottom: 6px;
}

.legal-text-link {
  background: transparent;
  border: none;
  color: #8F82A4;
  font-family: inherit;
  font-size: 0.76rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 2px 4px;
  transition: color 0.15s ease;
}

.legal-text-link:hover {
  color: #FFA573;
}

.legal-bullet {
  color: #5A4372;
  font-size: 0.76rem;
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

.modal-icon {
  font-size: 3.2rem;
  margin-bottom: 8px;
}

.modal-title {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  margin-bottom: 6px;
}

.modal-body {
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text-secondary);
  margin-bottom: 18px;
  text-align: left;
}

.modal-body p {
  margin-bottom: 8px;
}

.modal-body ul {
  padding-left: 20px;
  margin-bottom: 8px;
}

.modal-body li {
  margin-bottom: 5px;
}

.modal-stat-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px;
  margin: 12px 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  text-align: center;
}

.modal-stat-title {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.modal-stat-number {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-primary);
}

.modal-btn {
  background: linear-gradient(135deg, var(--accent-gold), #D49B20);
  color: #17131F;
  border: 1px solid var(--accent-gold-light);
  border-radius: 0;
  padding: 12px 24px;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
  width: 100%;
}

.modal-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(240, 180, 41, 0.4);
}

.trophy-sparkle {
  animation: trophy-rotate 2s infinite ease-in-out;
  display: inline-block;
}

@keyframes trophy-rotate {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.15) rotate(5deg); }
}

/* High Score Celebration Badge */
.new-highscore-badge {
  background: linear-gradient(135deg, #F0B429, #EA580C);
  color: #17131F;
  font-weight: 800;
  font-size: 0.92rem;
  letter-spacing: 0.5px;
  padding: 6px 14px;
  border-radius: 0;
  margin-bottom: 10px;
  animation: pulse-high-score 1.2s infinite alternate;
  display: inline-block;
  box-shadow: 0 4px 14px rgba(240, 180, 41, 0.5);
}

@keyframes pulse-high-score {
  from { transform: scale(0.96); filter: brightness(1); }
  to { transform: scale(1.04); filter: brightness(1.2); }
}

/* Leaderboard Table */
.leaderboard-table-container {
  max-height: 180px;
  width: 100%;
  max-width: 100%;
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-subtle);
  border-radius: 0;
  background: var(--bg-surface);
  box-sizing: border-box;
  min-width: 0;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  text-align: left;
}

.leaderboard-table th {
  background: #17131F;
  color: var(--accent-gold-light);
  padding: 8px 10px;
  font-weight: 800;
  border-bottom: 1.5px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
}

.leaderboard-table td {
  padding: 7px 10px;
  border-bottom: 1px solid rgba(69, 59, 89, 0.4);
  color: var(--text-primary);
  white-space: nowrap;
}

@media (max-width: 580px) {
  .leaderboard-table th,
  .leaderboard-table td {
    padding: 6px 6px;
    font-size: 0.76rem;
  }
}

.leaderboard-table tr:hover {
  background: rgba(255, 255, 255, 0.04);
}

.leaderboard-table .rank-gold {
  color: var(--accent-gold-light);
  font-weight: 800;
}

.leaderboard-empty {
  padding: 18px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ==========================================================================
   SCREEN 4: Results Screen & Current Run Highlight
   ========================================================================== */
.results-header-bar {
  width: 100%;
  padding: 8px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.results-hero-card {
  background: var(--bg-card);
  border: 2px solid #59476C;
  border-radius: 0;
  box-shadow: inset 1px 1px 0px #8F76AB, inset -1px -1px 0px #09060D, 0 4px 14px rgba(0, 0, 0, 0.35);
  padding: 18px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.results-hero-icon {
  font-size: 3.2rem;
  line-height: 1;
  margin-bottom: 2px;
}

.results-hero-title {
  font-family: var(--font-family);
  font-size: 1.45rem;
  font-weight: 900;
  color: var(--text-primary);
  letter-spacing: 0.5px;
  margin: 0;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.results-hero-desc {
  font-size: 0.92rem;
  color: var(--text-secondary);
  max-width: 520px;
  line-height: 1.4;
  margin: 0;
}

.results-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 540px;
  margin-top: 6px;
}

.results-stat-card {
  background: var(--bg-surface);
  border: 1.5px solid #59476C;
  border-radius: 0;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  box-shadow: inset 1px 1px 0 #120D18;
}

.results-stat-label {
  font-family: var(--font-family);
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.results-stat-number {
  font-family: var(--font-family);
  font-size: 1.35rem;
  font-weight: 900;
  color: var(--accent-gold-light);
  line-height: 1.1;
}

.results-stat-status {
  font-family: var(--font-family);
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.4;
}

.results-rank-banner {
  width: 100%;
  max-width: 540px;
  background: rgba(30, 24, 38, 0.85);
  border: 1.5px solid var(--border-subtle);
  border-radius: 0;
  padding: 10px 14px;
  font-size: 0.9rem;
  color: var(--text-primary);
  margin-top: 4px;
  text-align: center;
}

.results-rank-banner.ranked {
  background: linear-gradient(135deg, rgba(88, 38, 86, 0.65), rgba(41, 18, 40, 0.85));
  border-color: var(--accent-gold);
  color: var(--accent-gold-light);
  box-shadow: 0 0 14px rgba(240, 180, 41, 0.25);
}

.results-records-container {
  width: 100%;
}

.results-action-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
}

.btn-secondary-action {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  background: #3B2E4D;
  color: #F8F7FA;
  border: 2px solid;
  border-color: #796194 #1C1326 #1C1326 #796194;
  border-radius: 0;
  box-shadow: inset 1px 1px 0px #A38DC0, inset -1px -1px 0px #0F0A15, 0 4px 10px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  font-family: var(--font-family);
  font-weight: 900;
  font-size: 1.05rem;
  letter-spacing: 0.5px;
  transition: transform 0.08s ease, filter 0.08s ease;
}

.btn-secondary-action:active {
  transform: translateY(2px);
  border-color: #1C1326 #796194 #796194 #1C1326;
  box-shadow: inset 2px 2px 3px rgba(0, 0, 0, 0.6);
}

/* Highlight Player's Current Run Row */
.leaderboard-table tr.current-run-row {
  background: linear-gradient(90deg, rgba(240, 180, 41, 0.28) 0%, rgba(234, 88, 12, 0.2) 100%) !important;
  border: 2px solid var(--accent-gold-light);
  box-shadow: inset 0 0 12px rgba(240, 180, 41, 0.4);
  animation: current-run-pulse 1.8s infinite alternate;
}

.leaderboard-table tr.current-run-row td {
  color: #FFFFFF !important;
  font-weight: 900 !important;
}

@keyframes current-run-pulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.25); }
}

/* Quit Confirmation Modal Actions */
.modal-button-row {
  display: flex;
  gap: 12px;
  width: 100%;
  margin-top: 14px;
}

.modal-btn.secondary {
  background: #3B2E4D;
  border-color: #796194 #1C1326 #1C1326 #796194;
  box-shadow: inset 1px 1px 0px #A38DC0, inset -1px -1px 0px #0F0A15;
}

.modal-btn.danger {
  background: #8A1C1C;
  border-color: #CC4444 #380B0B #380B0B #CC4444;
  box-shadow: inset 1px 1px 0px #EE7777, inset -1px -1px 0px #1E0505;
}

/* ==========================================================================
   RESULTS SCREEN 2-COLUMN RESPONSIVE LAYOUT (Tablet & Desktop)
   ========================================================================== */
.results-main-layout {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
}

@media (min-width: 768px) {
  .results-container {
    max-width: 1040px;
  }

  .results-main-layout {
    display: grid;
    grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
  }

  .results-left-col {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .results-right-col {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .results-hero-card {
    max-width: 100%;
  }

  .results-action-row {
    max-width: 100%;
  }
}

/* ==========================================================================
   RECENT COURSE REVIEW MODAL & INTERACTIVE MAP
   ========================================================================== */
.course-review-modal-card {
  max-width: 820px;
  width: 95%;
  max-height: 88vh;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.modal-header-row {
  width: 100%;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border-bottom: 2px solid var(--border-medium);
  flex-shrink: 0;
}

.modal-title-with-icon {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-icon-badge {
  font-size: 1.4rem;
  line-height: 1;
}

.modal-close-btn {
  font-size: 1.1rem;
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.course-review-body {
  padding: 14px 16px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.course-review-body *,
.recent-course-board-wrapper,
.recent-course-grid,
.recent-tile {
  touch-action: pan-x pan-y !important;
}

.recent-course-banner {
  background: rgba(30, 24, 38, 0.95);
  border: 1.5px solid var(--border-subtle);
  border-radius: 0;
  padding: 12px 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.recent-course-banner.victory {
  background: linear-gradient(135deg, rgba(88, 38, 86, 0.75), rgba(41, 18, 40, 0.9));
  border-color: var(--accent-gold);
  box-shadow: 0 0 16px rgba(240, 180, 41, 0.25);
}

.course-status-badge {
  display: inline-block;
  padding: 2px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.course-banner-title {
  font-size: 1.25rem;
  font-weight: 900;
  color: var(--text-primary);
  margin: 2px 0;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.course-banner-meta {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.course-stats-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
}

.course-stat-chip {
  background: var(--bg-surface);
  border: 1.5px solid #59476C;
  border-radius: 0;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  box-shadow: inset 1px 1px 0 #120D18;
}

.chip-label {
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 0.4px;
}

.chip-val {
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--text-primary);
  line-height: 1.2;
}

.recent-course-board-wrapper {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: block;
  padding: 12px;
  background: #171124;
  border: 2px solid var(--slate-indigo);
  box-shadow: inset 2px 2px 6px rgba(0, 0, 0, 0.7);
  width: 100%;
  box-sizing: border-box;
  flex-shrink: 0;
}

.recent-course-grid {
  display: grid;
  gap: 2px;
  margin: 0 auto;
}

.recent-tile {
  background: rgba(30, 24, 38, 0.9);
  border: 1px solid #4A3958;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  font-family: var(--font-family);
  font-size: 0.72rem;
  font-weight: 800;
  user-select: none;
  box-sizing: border-box;
}

.recent-tile.is-start {
  background: rgba(13, 148, 136, 0.65) !important;
  border: 1.5px solid #2DD4BF !important;
  box-shadow: inset 0 0 8px rgba(45, 212, 191, 0.8);
  color: #FFFFFF;
}

.recent-tile.is-pit {
  background: rgba(240, 180, 41, 0.5) !important;
  border: 1.5px solid #F0B429 !important;
  box-shadow: inset 0 0 10px rgba(240, 180, 41, 0.8);
  color: #FFFFFF;
}

.recent-tile.is-obstacle {
  background: #231C2C !important;
  border-color: #382B45 !important;
  opacity: 0.5;
}

.recent-tile.is-pipe {
  background: linear-gradient(135deg, #7E22CE 0%, #4A154B 100%) !important;
  border: 1.5px solid #C084FC !important;
  color: #FFFFFF !important;
  box-shadow: 0 0 8px rgba(192, 132, 252, 0.45);
}

.recent-tile.is-burst {
  background: rgba(234, 88, 12, 0.75) !important;
  border: 1.5px solid #F97316 !important;
  box-shadow: 0 0 12px rgba(249, 115, 22, 0.7);
  animation: burst-pulse 1.2s infinite alternate;
}

@keyframes burst-pulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.3); }
}

.recent-step-num {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 0.58rem;
  font-weight: 900;
  color: #F0B429;
  line-height: 1;
}

.recent-tile-formula {
  font-size: 0.62rem;
  color: #E2D9F3;
  margin-top: 6px;
  line-height: 1;
}

.recent-tile-val {
  font-size: 0.72rem;
  font-weight: 900;
  color: #FFFFFF;
  line-height: 1.1;
}

.course-legend-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  background: rgba(20, 15, 26, 0.85);
  border: 1px solid #4A3958;
  font-size: 0.74rem;
  color: var(--text-secondary);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend-dot {
  font-size: 0.88rem;
  line-height: 1;
}

/* ==========================================================================
   PRIZES & OBJECTIVES / TROPHY CABINET STYLES
   ========================================================================== */
/* ==========================================================================
   PRIZES & OBJECTIVES / TROPHY CABINET STYLES
   ========================================================================== */
.title-action-buttons-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}

.title-action-buttons-row .btn-quick-bar {
  width: 100%;
}

.btn-prizes-bar {
  background: linear-gradient(135deg, #3D2D20 0%, #2D233C 100%);
  border-color: #A67C1E #140E1B #140E1B #D4AF37;
  color: var(--accent-gold-light);
  box-shadow: inset 1px 1px 0px #F5D77F, inset -1px -1px 0px #0F0A15;
}

.btn-prizes-bar:hover {
  background: linear-gradient(135deg, #573E28 0%, #3D3052 100%);
  color: #FFF2A8;
  border-color: #F0C43F #140E1B #140E1B #F0C43F;
}

/* Welcome Screen Trophy Shelf Preview Card */
.trophy-shelf-card {
  width: 100%;
  background: linear-gradient(145deg, #2A2038 0%, #1A1424 100%);
  border: 2px solid #5A446E;
  border-radius: 0;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  box-shadow: inset 1px 1px 0px #80629C, inset -1px -1px 0px #0C0812, 0 4px 14px rgba(0, 0, 0, 0.35);
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
  text-align: left;
  box-sizing: border-box;
  font-family: inherit;
  color: inherit;
}

.trophy-shelf-card:hover {
  background: linear-gradient(145deg, #362948 0%, #221A30 100%);
  border-color: var(--accent-gold);
  transform: translateY(-2px);
  box-shadow: inset 1px 1px 0px #F5D77F, 0 6px 18px rgba(240, 180, 41, 0.25);
}

.trophy-shelf-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.trophy-shelf-title {
  font-family: var(--font-family);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
}

.trophy-shelf-count {
  font-family: var(--font-family);
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  background: rgba(240, 180, 41, 0.18);
  border: 1px solid rgba(240, 180, 41, 0.5);
  padding: 2px 8px;
}

.trophy-shelf-icons {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 6px;
  width: 100%;
  align-items: center;
}

.trophy-shelf-mini {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.trophy-shelf-mini.is-locked {
  opacity: 0.28;
  filter: grayscale(100%) brightness(40%);
}

.trophy-shelf-mini.is-unlocked {
  opacity: 1;
  filter: drop-shadow(0 2px 6px rgba(240, 180, 41, 0.45));
}

.trophy-shelf-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
  text-align: right;
  letter-spacing: 0.3px;
}

/* Results Screen Compact Trophy Notification Strip */
.results-trophy-strip {
  background: linear-gradient(135deg, rgba(58, 28, 66, 0.95), rgba(45, 26, 16, 0.95));
  border: 1.5px solid var(--accent-gold);
  padding: 10px 14px;
  margin-top: 6px;
  width: 100%;
  max-width: 540px;
  box-shadow: 0 4px 14px rgba(240, 180, 41, 0.25);
  box-sizing: border-box;
  animation: trophyGlow 2.5s infinite alternate;
}

@keyframes trophyGlow {
  0% { border-color: #D4AF37; box-shadow: 0 0 10px rgba(212, 175, 55, 0.25); }
  100% { border-color: #FFE082; box-shadow: 0 0 18px rgba(240, 180, 41, 0.5); }
}

.results-trophy-heading {
  font-family: var(--font-family);
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  text-align: center;
}

.results-trophy-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  width: 100%;
}

.results-trophy-chip {
  background: #231930;
  border: 1.5px solid #755B25;
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease, background 0.1s ease;
  font-family: inherit;
  color: inherit;
}

.results-trophy-chip:hover {
  background: #34244A;
  border-color: var(--accent-gold);
  transform: translateY(-1px);
}

.results-trophy-chip-icon {
  width: 26px;
  height: 26px;
  object-fit: contain;
  flex-shrink: 0;
}

.results-trophy-chip-title {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--accent-gold-light);
}

.results-trophy-chip-action {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 700;
}

/* ==========================================================================
   TROPHY CABINET MODAL (Redesigned with Spotlight + Grid)
   ========================================================================== */
.trophy-cabinet-card {
  max-width: 860px;
  width: 94%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  background: #1C1625;
  border: 3px solid;
  border-color: #8C6A9E #0E0A12 #0E0A12 #8C6A9E;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.85), inset 2px 2px 0px #B496C9;
}

.trophy-cabinet-card .modal-header-row {
  padding: 14px 20px;
}

.trophy-cabinet-title-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.trophy-cabinet-body {
  padding: 14px 18px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  box-sizing: border-box;
}

.trophy-cabinet-progress {
  background: rgba(36, 27, 49, 0.95);
  border: 1.5px solid #5A446D;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  box-sizing: border-box;
}

.trophy-cabinet-progress-count {
  font-family: var(--font-family);
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  white-space: nowrap;
}

.trophy-progress-track {
  flex: 1;
  height: 10px;
  background: #120C1A;
  border: 1px solid #4D3960;
  overflow: hidden;
}

.trophy-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #E0981E, #F7C948, #2ECC71);
  box-shadow: 0 0 8px rgba(247, 201, 72, 0.5);
  transition: width 0.3s ease;
}

.trophy-cabinet-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

@media (max-width: 720px) {
  .trophy-cabinet-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Spotlight: Detailed inspector for tapped trophy */
.trophy-spotlight {
  background: #241A32;
  border: 2px solid #59446D;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  box-shadow: inset 1px 1px 0 #7A5E94, inset -1px -1px 0 #100A17;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.trophy-spotlight.is-unlocked {
  background: linear-gradient(150deg, #2E1F42 0%, #3D2B1C 100%);
  border-color: #D4AF37 #755513 #755513 #D4AF37;
  box-shadow: inset 1px 1px 0 #F5D77F, 0 4px 14px rgba(212, 175, 55, 0.2);
}

.trophy-spotlight-art {
  width: 84px;
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle, rgba(240, 180, 41, 0.15) 0%, rgba(20, 14, 26, 0.6) 70%);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.trophy-spotlight-art img {
  max-width: 72px;
  max-height: 72px;
  object-fit: contain;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6));
}

.trophy-spotlight-art img.faded-icon {
  filter: grayscale(100%) brightness(40%) contrast(120%);
  opacity: 0.45;
}

.trophy-spotlight-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
}

.trophy-spotlight-category {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 2px 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.trophy-spotlight.is-unlocked .trophy-spotlight-category {
  background: rgba(240, 180, 41, 0.2);
  color: var(--accent-gold-light);
  border-color: rgba(240, 180, 41, 0.4);
}

.trophy-spotlight-title {
  font-family: var(--font-family);
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--text-primary);
  margin: 2px 0 0 0;
}

.trophy-spotlight.is-unlocked .trophy-spotlight-title {
  color: var(--accent-gold-light);
}

.trophy-spotlight-label {
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-top: 4px;
}

.trophy-spotlight-desc {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.35;
  margin: 0;
  min-height: 38px;
}

.trophy-spotlight-status {
  margin-top: 4px;
  width: 100%;
}

.trophy-status-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 10px;
  letter-spacing: 0.4px;
}

.trophy-status-pill.unlocked {
  background: rgba(46, 204, 113, 0.2);
  color: #2ECC71;
  border: 1px solid rgba(46, 204, 113, 0.4);
}

.trophy-status-pill.locked {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.trophy-spotlight-progress {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 4px;
}

.trophy-spotlight-progress-text {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--accent-gold-light);
}

/* Trophy Grid: 12 available trophies (unearned faded, earned glowing) */
.trophy-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

@media (max-width: 520px) {
  .trophy-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }
}

.trophy-grid-item {
  background: #231930;
  border: 2px solid #443254;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  position: relative;
  transition: transform 0.1s ease, border-color 0.12s ease, background 0.12s ease;
  font-family: inherit;
  color: inherit;
  min-width: 0;
  width: 100%;
}

.trophy-grid-item:hover {
  background: #2D203E;
  border-color: #7A5E94;
  transform: translateY(-2px);
}

.trophy-grid-item.active-selection {
  border-color: var(--accent-gold-light) !important;
  box-shadow: 0 0 12px rgba(240, 180, 41, 0.45), inset 0 0 6px rgba(240, 180, 41, 0.2);
  background: #342448;
}

.trophy-grid-item.is-locked {
  opacity: 0.42;
  background: #191222;
  border-color: #32243F;
}

.trophy-grid-item.is-locked:hover {
  opacity: 0.78;
}

.trophy-grid-item.is-unlocked {
  background: linear-gradient(145deg, #291D38, #352622);
  border-color: #8C6A2E;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.trophy-item-art {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.trophy-item-img {
  max-width: 44px;
  max-height: 44px;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
}

.trophy-item-img.faded-icon {
  filter: grayscale(100%) brightness(40%) contrast(110%);
}

.trophy-item-check {
  position: absolute;
  bottom: -2px;
  right: -2px;
  background: #2ECC71;
  color: #0E2015;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 900;
  line-height: 1;
}

.trophy-item-lock {
  position: absolute;
  bottom: -2px;
  right: -2px;
  background: #140E1B;
  border: 1px solid #483A58;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  line-height: 1;
}

.trophy-item-name {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  white-space: normal;
  word-break: break-word;
  line-height: 1.15;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  height: 2.3em;
}

.trophy-grid-item.is-unlocked .trophy-item-name {
  color: var(--accent-gold-light);
}

.trophy-cabinet-card .modal-footer-area {
  padding: 10px 18px 12px 18px;
  background: #171120;
  border-top: 1.5px solid #483A58;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
}

.trophy-cabinet-card .modal-footer-area .modal-btn {
  max-width: 280px;
  padding: 10px 18px;
  font-size: 0.95rem;
}

/* Tablet Layout Enhancements */
@media (min-width: 768px) {
  .welcome-container {
    max-width: 860px;
    gap: 20px;
  }

  .trophy-cabinet-card {
    max-width: 920px;
    width: 92%;
  }

  .trophy-cabinet-card .modal-header-row {
    padding: 16px 24px;
  }

  .trophy-cabinet-body {
    padding: 18px 24px;
    gap: 16px;
  }

  .trophy-cabinet-layout {
    grid-template-columns: 270px minmax(0, 1fr);
    gap: 18px;
  }

  .trophy-shelf-icons {
    gap: 12px;
  }

  .trophy-shelf-mini {
    max-width: 44px;
  }

  .trophy-grid {
    gap: 10px;
  }

  .trophy-grid-item {
    padding: 8px 6px;
  }

  .trophy-item-art {
    width: 50px;
    height: 50px;
  }

  .trophy-item-img {
    max-width: 46px;
    max-height: 46px;
  }

  .trophy-item-name {
    font-size: 0.72rem;
  }

  .trophy-spotlight {
    padding: 16px 14px;
  }

  .trophy-spotlight-art {
    width: 92px;
    height: 92px;
  }

  .trophy-spotlight-art img {
    max-width: 80px;
    max-height: 80px;
  }

  .trophy-cabinet-card .modal-footer-area {
    padding: 12px 24px 14px 24px;
  }

  .trophy-cabinet-card .modal-footer-area .modal-btn {
    max-width: 320px;
  }
}

/* ==========================================================================
   WEB-ONLY EDITION: Side-Rail Kid-Friendly Ads & Store Download Badges
   ========================================================================== */
.web-side-rail {
  display: none;
}

@media (min-width: 1320px) {
  body.web-only-edition .web-side-rail {
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 184px;
    z-index: 30;
    pointer-events: auto;
  }

  body.web-only-edition .web-left-rail {
    left: max(12px, calc(50vw - 665px));
  }

  body.web-only-edition .web-right-rail {
    right: max(12px, calc(50vw - 665px));
  }
}

.web-rail-card {
  background: var(--bg-card);
  border: 2px solid;
  border-color: #6C5784 #140E1B #140E1B #6C5784;
  box-shadow: inset 1px 1px 0px #8F76AB, inset -1px -1px 0px #09060D, 0 8px 20px rgba(0, 0, 0, 0.45);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.web-rail-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.web-rail-plum {
  width: 34px;
  height: 34px;
  object-fit: contain;
  flex-shrink: 0;
}

.web-rail-title {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  letter-spacing: 0.04em;
}

.web-rail-subtitle {
  font-size: 0.66rem;
  color: var(--accent-teal-light);
  font-weight: 700;
}

.web-rail-desc {
  font-size: 0.7rem;
  line-height: 1.35;
  color: var(--text-secondary);
}

.web-store-badges-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.web-store-badge-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 11px;
  background: #130F1C;
  border: 1.5px solid #7A6396;
  color: #FFFFFF;
  text-decoration: none;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
}

.web-store-badge-btn:hover {
  background: #1F182D;
  border-color: var(--accent-gold);
  transform: translateY(-1px);
}

.web-store-badge-btn:active {
  transform: translateY(0);
}

.store-badge-svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  color: var(--accent-gold-light);
}

.store-android .store-badge-svg {
  color: var(--accent-teal-light);
}

.store-badge-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  text-align: left;
}

.store-badge-Overline {
  font-size: 0.56rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.store-badge-Title {
  font-size: 0.82rem;
  font-weight: 800;
  color: #FFFFFF;
  letter-spacing: 0.02em;
}

.web-ad-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 5px;
}

.coppa-pill {
  background: rgba(20, 184, 166, 0.18);
  border: 1px solid rgba(94, 234, 212, 0.45);
  color: var(--accent-teal-light);
  padding: 1px 5px;
  font-size: 0.55rem;
  font-weight: 800;
}

.web-ad-slot-box {
  position: relative;
  width: 160px;
  min-height: 280px;
  margin: 0 auto;
  background: rgba(16, 13, 22, 0.65);
  border: 1px dashed rgba(149, 140, 166, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.web-ad-slot-tall {
  min-height: 480px;
}

.web-ad-ins {
  position: relative;
  z-index: 2;
}

.web-ad-fallback {
  position: absolute;
  inset: 0;
  z-index: 1;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
}

.web-ad-fallback-img {
  width: 68px;
  height: 68px;
  object-fit: contain;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
}

.web-ad-fallback-title {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  line-height: 1.25;
}

.web-ad-fallback-copy {
  font-size: 0.68rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

/* In-flow Mobile / Tablet / Desktop Store Download Banner */
.web-inline-store-banner {
  width: 100%;
  background: linear-gradient(135deg, rgba(45, 39, 59, 0.95) 0%, rgba(30, 24, 42, 0.98) 100%);
  border: 2px solid;
  border-color: #6C5784 #140E1B #140E1B #6C5784;
  box-shadow: inset 1px 1px 0px #8F76AB, inset -1px -1px 0px #09060D, 0 6px 16px rgba(0, 0, 0, 0.35);
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.web-inline-store-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 260px;
}

.web-inline-store-icon {
  width: 42px;
  height: 42px;
  object-fit: contain;
  flex-shrink: 0;
}

.web-inline-store-title {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  letter-spacing: 0.03em;
}

.web-inline-store-sub {
  font-size: 0.74rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.web-inline-store-banner .web-store-badges-group {
  flex-direction: row;
  flex-wrap: wrap;
  width: auto;
  gap: 10px;
}

.web-inline-store-banner .web-store-badge-btn {
  min-width: 155px;
}

/* Horizontal Kid-Safe Ad Banner (Above Main Menu Leaderboard, Results Leaderboard & Setup) */
.records-container > .web-horizontal-ad-card {
  grid-column: 1 / -1;
  order: -1;
}

.web-horizontal-ad-card {
  width: 100%;
  background: var(--bg-card);
  border: 2px solid;
  border-color: #6C5784 #140E1B #140E1B #6C5784;
  box-shadow: inset 1px 1px 0px #8F76AB, inset -1px -1px 0px #09060D, 0 6px 16px rgba(0, 0, 0, 0.38);
  padding: 10px 14px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 4px;
}

#setupScreen .web-horizontal-ad-card {
  margin-bottom: 14px;
}

.web-horizontal-ad-slot {
  position: relative;
  width: 100%;
  min-height: 92px;
  background: rgba(16, 13, 22, 0.65);
  border: 1px dashed rgba(149, 140, 166, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 6px 10px;
}

.web-horizontal-ad-fallback {
  position: absolute;
  inset: 0;
  z-index: 1;
  padding: 8px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.web-horiz-fallback-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 220px;
}

.web-horiz-fallback-icon {
  width: 38px;
  height: 38px;
  object-fit: contain;
  flex-shrink: 0;
}

.web-horiz-fallback-title {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  letter-spacing: 0.03em;
}

.web-horiz-fallback-sub {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.web-horizontal-ad-fallback .web-store-badges-group {
  flex-direction: row;
  flex-wrap: wrap;
  width: auto;
  gap: 8px;
}

.web-horizontal-ad-fallback .web-store-badge-btn {
  padding: 6px 10px;
  min-width: 140px;
}

/* Pre-Game Sponsor Interstitial Modal (Shown between Customization and Gameplay Board) */
.web-pregame-ad-overlay {
  z-index: 2500;
}

.web-pregame-ad-card {
  max-width: 520px;
  width: 94%;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.web-pregame-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.web-pregame-status-pill {
  background: rgba(20, 184, 166, 0.18);
  border: 1px solid rgba(94, 234, 212, 0.45);
  color: var(--accent-teal-light);
  padding: 4px 10px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.web-pregame-title {
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--accent-gold-light);
  margin-top: 2px;
}

.web-pregame-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
  max-width: 420px;
  line-height: 1.35;
}

.web-pregame-ad-stage {
  width: 100%;
  background: rgba(16, 13, 22, 0.75);
  border: 1.5px solid #59476C;
  padding: 10px 12px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.web-pregame-ad-box {
  position: relative;
  width: 100%;
  min-height: 254px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed rgba(149, 140, 166, 0.35);
  overflow: hidden;
}

.web-pregame-ad-box .web-store-badges-group {
  flex-direction: row;
  justify-content: center;
  flex-wrap: wrap;
  width: auto;
  gap: 8px;
  margin-top: 4px;
}

.web-pregame-actions {
  width: 100%;
}

.web-btn-continue-board {
  width: 100%;
}

/* Strictly block any floating side rails or AdSense auto-placed/anchor ads from covering the answer or keypad */
.web-side-rail,
.google-auto-placed,
ins.adsbygoogle:not(.web-ad-ins),
ins.adsbygoogle[data-anchor-status],
#gameplayScreen ins.adsbygoogle {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.web-beta-steps-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.web-beta-step-card {
  background: rgba(16, 13, 22, 0.78);
  border: 1.5px solid #59476C;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.web-beta-step-label {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  letter-spacing: 0.05em;
}

.web-beta-step-desc {
  font-size: 0.76rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

.web-beta-step-btn {
  width: 100%;
  text-decoration: none;
  text-align: center;
  padding: 11px 14px;
}

.web-beta-step-btn.step-one-btn {
  background: linear-gradient(135deg, #1E7E72, #115E59);
  border-color: #5EEAD4 #0A3633 #0A3633 #5EEAD4;
}

/* ==========================================================================
   Story Banner, Mobile Peek Hint & Share Score Picture Modal
   ========================================================================== */
.story-mission-banner {
  width: 100%;
  background: linear-gradient(135deg, rgba(85, 93, 139, 0.42) 0%, rgba(46, 34, 68, 0.85) 100%);
  border: 1.5px solid var(--accent-gold);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: inset 0 0 12px rgba(217, 150, 61, 0.16);
}

.story-banner-icon {
  font-size: 1.45rem;
  flex-shrink: 0;
  line-height: 1;
}

.story-banner-text {
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--text-primary);
  text-align: left;
}

.story-banner-text strong {
  color: var(--accent-gold-light);
}

.exit-arrow-indicator {
  cursor: pointer;
  touch-action: none;
}

.exit-arrow-peek-hint {
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--accent-gold-light);
  margin-left: 4px;
}

.btn-share-score-highlight {
  background: linear-gradient(135deg, #555D8B 0%, #3F466E 100%) !important;
  border-color: #D9963D #1E2238 #1E2238 #D9963D !important;
  box-shadow: inset 1px 1px 0px #919AC9, 0 4px 12px rgba(0, 0, 0, 0.35) !important;
}

.btn-share-score-highlight span:first-child {
  color: var(--accent-gold-light) !important;
  font-weight: 900;
}

.course-review-footer-row,
.share-score-footer-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.course-review-footer-row .modal-btn,
.share-score-footer-row .modal-btn {
  flex: 1 1 160px;
}

.btn-share-modal-cta {
  background: linear-gradient(180deg, #D9963D 0%, #B37422 100%) !important;
  border-color: #F5C77E #4A2D08 #4A2D08 #F5C77E !important;
  color: #1A1103 !important;
  font-weight: 900 !important;
}

.share-score-modal-card {
  max-width: 540px;
  width: 94%;
  max-height: 90vh;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.share-score-body {
  padding: 14px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.share-score-hint {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: center;
}

.share-score-preview-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  background: #140F1F;
  border: 2px solid var(--slate-indigo);
  padding: 8px;
}

.share-score-preview-img {
  max-width: 100%;
  max-height: 54vh;
  height: auto;
  object-fit: contain;
  display: block;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
}
