/**
 * Shikaku Puzzle Quest - Design System & Custom Styling
 * 
 * Implements high-impact visual aesthetics, modern typography, glassmorphism panels,
 * 5 distinct difficulty themes, fluid animations, and robust mobile-first layouts.
 */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&family=Plus+Jakarta+Sans:wght@300;400;600;700&display=swap');

/* ==========================================
   CSS GLOBAL TOKENS & UTILITIES
   ========================================== */
:root {
  --font-title: 'Outfit', sans-serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;

  /* Theme variables - will change dynamically per world */
  --primary-color: #00f3ff;
  --primary-glow: rgba(0, 243, 255, 0.4);
  --accent-color: #ff00f3;
  --bg-color: #0a0a14;
  --glass-bg: rgba(15, 15, 27, 0.65);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-glow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --text-primary: #f5f6fa;
  --text-secondary: #a0a5c0;

  /* World Theme Specific Tokens */
  --w1-primary: #00ffa2;
  --w1-glow: rgba(0, 255, 162, 0.4);
  --w2-primary: #00f3ff;
  --w2-glow: rgba(0, 243, 255, 0.4);
  --w3-primary: #0099ff;
  --w3-glow: rgba(0, 153, 255, 0.4);
  --w4-primary: #ff4500;
  --w4-glow: rgba(255, 69, 0, 0.4);
  --w5-primary: #bf00ff;
  --w5-glow: rgba(191, 0, 255, 0.4);
  --w6-primary: #ffcc00;
  --w6-glow: rgba(255, 204, 0, 0.4);
  --w7-primary: #ff007f;
  --w7-glow: rgba(255, 0, 127, 0.4);
  --w8-primary: #e6e6fa;
  --w8-glow: rgba(230, 230, 250, 0.45);
  --w9-primary: #ffaa00;
  --w9-glow: rgba(255, 170, 0, 0.45);
  --w10-primary: #9933ff;
  --w10-glow: rgba(153, 51, 255, 0.45);

  --cell-size: 50px;
  --grid-border: rgba(255, 255, 255, 0.12);
  --grid-bg: rgba(255, 255, 255, 0.02);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-drag: none;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-color);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  width: 100dvw;
  position: relative;
}

/* Background & Overlays */
#bg-canvas, #victory-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

#victory-canvas {
  z-index: 99; /* Draw confetti on top of everything */
}

/* Glassmorphism utility */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-glow);
  border-radius: 20px;
}

/* ==========================================
   APP STAGE LAYOUTS (SPA System)
   ========================================== */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transform: scale(0.97);
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.screen.active {
  opacity: 1;
  transform: scale(1);
  pointer-events: all;
}

/* Global Navigation Header Toggles Wrapper
   Fixed positioning so it never bleeds into screen layouts regardless of scroll position */
.global-header-toggles {
  display: flex;
  gap: 10px;
  align-items: center;
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  right: calc(16px + env(safe-area-inset-right));
  z-index: 200;
  pointer-events: auto;
}

/* Audio & Share Controller Badges */
.sound-toggle, .qr-toggle {
  z-index: 100;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  background: #0d0d1a !important;
}
.sound-toggle {
  border: 1.5px solid #ffffff !important;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.3) !important;
}
.qr-toggle {
  border: 1.5px solid #00f3ff !important;
  box-shadow: 0 0 8px rgba(0, 243, 255, 0.4) !important;
}

.sound-toggle:hover {
  transform: scale(1.1) !important;
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.7), 0 0 24px rgba(255, 255, 255, 0.3) !important;
}
.qr-toggle:hover {
  transform: scale(1.1) !important;
  box-shadow: 0 0 16px rgba(0, 243, 255, 0.8), 0 0 32px rgba(0, 243, 255, 0.4) !important;
}

.sound-toggle svg {
  fill: #ffffff !important;
  width: 22px;
  height: 22px;
  transition: filter 0.25s ease !important;
}
.qr-toggle svg, .qr-toggle svg path {
  fill: #00f3ff !important;
  color: #00f3ff !important;
  width: 22px;
  height: 22px;
  transition: filter 0.25s ease !important;
}

.sound-toggle:hover svg {
  filter: drop-shadow(0 0 5px #ffffff) !important;
}
.qr-toggle:hover svg {
  filter: drop-shadow(0 0 5px #00f3ff) drop-shadow(0 0 10px rgba(0, 243, 255, 0.7)) !important;
}


/* ==========================================
   1. SPLASH SCREEN (Opening Screen)
   ========================================== */
#splash-screen {
  gap: 30px;
}

.title-container {
  text-align: center;
  position: relative;
}

.game-logo {
  font-family: var(--font-title);
  font-size: 3.5rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 4px;
  background: linear-gradient(135deg, #ffffff 30%, var(--primary-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 4px 20px rgba(0, 243, 255, 0.25);
  margin-bottom: 5px;
  animation: floatTitle 4s ease-in-out infinite;
}

.game-subtitle {
  font-family: var(--font-title);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 6px;
  text-transform: uppercase;
}

.menu-options {
  display: flex;
  flex-direction: column;
  gap: 15px;
  width: 280px;
}

.btn {
  font-family: var(--font-title);
  font-size: 1.05rem;
  font-weight: 600;
  padding: 14px 28px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-color), #0099ff);
  color: #030a10;
  box-shadow: 0 6px 20px var(--primary-glow);
}
.btn-primary:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 10px 25px var(--primary-glow);
  filter: brightness(1.1);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.btn-facebook {
  background: #1877f2;
  color: #fff !important;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 15px rgba(24, 119, 242, 0.2);
}
.btn-facebook:hover {
  background: #1565c0;
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 20px rgba(24, 119, 242, 0.4);
}

/* ==========================================
   2. TUTORIAL MODAL
   ========================================== */
.tutorial-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(4, 4, 8, 0.8);
  backdrop-filter: blur(8px);
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.tutorial-panel {
  max-width: 500px;
  width: 100%;
  padding: 30px;
  text-align: left;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.tutorial-title {
  font-family: var(--font-title);
  font-size: 1.8rem;
  color: var(--primary-color);
}

.tutorial-body {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tutorial-body strong {
  color: var(--text-primary);
}

.tutorial-gif {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255,255,255,0.02);
  padding: 10px;
  display: flex;
  justify-content: center;
}

.tutorial-grid-demo {
  display: grid;
  grid-template-columns: repeat(4, 35px);
  gap: 4px;
  justify-content: center;
  background: rgba(0,0,0,0.2);
  padding: 12px;
  border-radius: 8px;
}
.demo-cell {
  width: 35px;
  height: 35px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: bold;
}
.demo-cell.filled {
  background: rgba(0, 243, 255, 0.2);
  border-color: var(--primary-color);
}

.close-tutorial {
  align-self: flex-end;
  margin-top: 10px;
}

/* Tutorial Tabs */
.tutorial-tabs {
  display: flex;
  margin-bottom: 15px;
  width: 100%;
  padding: 4px;
  border-radius: 10px;
  background: rgba(15, 15, 27, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.tutorial-tab {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--text-secondary);
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.25s ease;
  text-align: center;
}

.tutorial-tab:hover {
  color: #fff;
}

.tutorial-tab.active {
  background: linear-gradient(135deg, var(--primary-color) 0%, #0099ff 100%);
  color: #030a10;
  box-shadow: 0 3px 8px var(--primary-glow);
}

.tutorial-tab-content {
  display: none;
  flex-direction: column;
  gap: 12px;
  animation: fadeIn 0.25s ease forwards;
}

.tutorial-tab-content.active-content {
  display: flex;
}

/* ==========================================
   3. LEVEL SELECTOR SCREEN
   ========================================== */
#level-select-screen {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  justify-content: flex-start;
  overflow-y: auto;
  padding-top: calc(84px + env(safe-area-inset-top));
  padding-left: calc(20px + env(safe-area-inset-left));
  padding-right: calc(20px + env(safe-area-inset-right));
}

/* Battle Lobby Screen — needs padding-top to clear the fixed global toggles */
#battle-lobby-screen {
  justify-content: flex-start !important;
  overflow-y: auto !important;
  padding-top: calc(84px + env(safe-area-inset-top)) !important;
  padding-left: calc(20px + env(safe-area-inset-left)) !important;
  padding-right: calc(20px + env(safe-area-inset-right)) !important;
  padding-bottom: 40px !important;
}

.header-row {
  display: flex;
  align-items: center;
  width: 100%;
  position: relative;
  margin-bottom: 25px;
  min-height: 44px;
  /* Right padding creates a permanent safe zone so the fixed toggles never overlap header items */
  padding-right: calc(110px + env(safe-area-inset-right));
  box-sizing: border-box;
  gap: 10px;
}
.header-row .btn-back {
  flex-shrink: 0;
  z-index: 5;
}
.page-title {
  font-family: var(--font-title);
  font-size: 2.2rem;
  background: linear-gradient(135deg, #fff 40%, var(--primary-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  flex: 1;
  text-align: center;
  margin: 0;
  /* Allow wrapping so long titles never overflow on narrow screens */
  white-space: normal;
  word-break: break-word;
  line-height: 1.2;
}
.header-row #level-select-user-badge,
.header-row #battle-lobby-user-badge {
  flex-shrink: 0;
  z-index: 5;
}

/* Worlds Container */
.worlds-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 30px;
  padding-bottom: 40px;
}

.world-group {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.world-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 8px;
}

.world-title {
  font-family: var(--font-title);
  font-size: 1.3rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.world-badge {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  font-weight: bold;
}

/* World Color Palettes */
.world-1 .world-title { color: var(--w1-primary); }
.world-1 .world-badge { background: rgba(0, 255, 162, 0.15); border: 1px solid var(--w1-primary); }
.world-2 .world-title { color: var(--w2-primary); }
.world-2 .world-badge { background: rgba(0, 243, 255, 0.15); border: 1px solid var(--w2-primary); }
.world-3 .world-title { color: var(--w3-primary); }
.world-3 .world-badge { background: rgba(0, 153, 255, 0.15); border: 1px solid var(--w3-primary); }
.world-4 .world-title { color: var(--w4-primary); }
.world-4 .world-badge { background: rgba(255, 69, 0, 0.15); border: 1px solid var(--w4-primary); }
.world-5 .world-title { color: var(--w5-primary); }
.world-5 .world-badge { background: rgba(191, 0, 255, 0.15); border: 1px solid var(--w5-primary); }
.world-6 .world-title { color: var(--w6-primary); }
.world-6 .world-badge { background: rgba(255, 204, 0, 0.15); border: 1px solid var(--w6-primary); }
.world-7 .world-title { color: var(--w7-primary); }
.world-7 .world-badge { background: rgba(255, 0, 127, 0.15); border: 1px solid var(--w7-primary); }
.world-8 .world-title { color: var(--w8-primary); }
.world-8 .world-badge { background: rgba(230, 230, 250, 0.15); border: 1px solid var(--w8-primary); }
.world-9 .world-title { color: var(--w9-primary); }
.world-9 .world-badge { background: rgba(255, 170, 0, 0.15); border: 1px solid var(--w9-primary); }
.world-10 .world-title { color: var(--w10-primary); }
.world-10 .world-badge { background: rgba(153, 51, 255, 0.15); border: 1px solid var(--w10-primary); }

.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 15px;
}

.level-card {
  height: 110px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.2);
}

.level-card:hover {
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.2);
}

.level-card.locked {
  cursor: not-allowed;
  opacity: 0.55;
  background: rgba(255, 255, 255, 0.02);
}
.level-card.locked:hover {
  transform: none;
  border-color: var(--glass-border);
}

.level-num {
  font-family: var(--font-title);
  font-size: 1.8rem;
  font-weight: 800;
}

.level-stars {
  display: flex;
  gap: 3px;
}
.star-icon {
  width: 14px;
  height: 14px;
  fill: #8088a0;
}
.star-icon.earned {
  fill: #ffcc00;
  filter: drop-shadow(0 0 3px rgba(255, 204, 0, 0.5));
}

.lock-icon {
  width: 24px;
  height: 24px;
  fill: var(--text-secondary);
}

/* Card World Modifiers */
.world-1 .level-card:not(.locked):hover { border-color: var(--w1-primary); box-shadow: 0 4px 15px var(--w1-glow); }
.world-2 .level-card:not(.locked):hover { border-color: var(--w2-primary); box-shadow: 0 4px 15px var(--w2-glow); }
.world-3 .level-card:not(.locked):hover { border-color: var(--w3-primary); box-shadow: 0 4px 15px var(--w3-glow); }
.world-4 .level-card:not(.locked):hover { border-color: var(--w4-primary); box-shadow: 0 4px 15px var(--w4-glow); }
.world-5 .level-card:not(.locked):hover { border-color: var(--w5-primary); box-shadow: 0 4px 15px var(--w5-glow); }
.world-6 .level-card:not(.locked):hover { border-color: var(--w6-primary); box-shadow: 0 4px 15px var(--w6-glow); }
.world-7 .level-card:not(.locked):hover { border-color: var(--w7-primary); box-shadow: 0 4px 15px var(--w7-glow); }
.world-8 .level-card:not(.locked):hover { border-color: var(--w8-primary); box-shadow: 0 4px 15px var(--w8-glow); }
.world-9 .level-card:not(.locked):hover { border-color: var(--w9-primary); box-shadow: 0 4px 15px var(--w9-glow); }
.world-10 .level-card:not(.locked):hover { border-color: var(--w10-primary); box-shadow: 0 4px 15px var(--w10-glow); }

/* ==========================================
   4. GAMEPLAY SCREEN
   ========================================== */
#game-screen {
  gap: 15px;
  padding: calc(10px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 10px calc(10px + env(safe-area-inset-left));
}

.game-header {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 500px;
  min-height: 44px;
  gap: 10px;
  /* Right padding clears the fixed toggles on the game screen */
  padding-right: calc(110px + env(safe-area-inset-right));
  box-sizing: border-box;
}
.game-header .btn-back {
  flex-shrink: 0;
  z-index: 5;
}

.game-title-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex: 1;
  margin: 0 80px;
  min-width: 0;
}

.active-level-name {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.active-world-name {
  font-family: var(--font-title);
  font-size: 1.15rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Game Info Bar */
.game-stats-bar {
  width: 100%;
  max-width: 500px;
  padding: 12px 20px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.stat-lbl {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}
.stat-val {
  font-family: var(--font-title);
  font-size: 1.1rem;
  font-weight: 700;
}

/* Gameplay Grid Board Container */
.board-outer-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 500px;
  max-height: 500px;
  aspect-ratio: 1 / 1;
  position: relative;
  touch-action: none; /* Crucial: stops touch page-scroll scrolling during drags */
}

.shikaku-board {
  position: relative;
  display: grid;
  background: var(--grid-bg);
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  width: 100%;
  height: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  touch-action: none;
}

.board-cell {
  position: relative;
  border-right: 1px solid var(--grid-border);
  border-bottom: 1px solid var(--grid-border);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
  min-width: 0;
  min-height: 0;
  touch-action: none;
}

/* Thick borders for subgrid isolation elements if needed, or outer boundaries */
.board-cell.edge-right { border-right-width: 1px; }
.board-cell.edge-bottom { border-bottom-width: 1px; }

.cell-val {
  font-family: var(--font-title);
  font-size: 1.35rem;
  font-weight: bold;
  z-index: 2;
  pointer-events: none;
}

/* User Drawn Rectangles */
.shikaku-rectangle {
  position: absolute;
  border-radius: 8px;
  border: 2.5px solid var(--rect-color, #fff);
  background: var(--rect-bg, rgba(255, 255, 255, 0.12));
  z-index: 5;
  transition: all 0.12s ease-out;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  touch-action: none;
}

.shikaku-rectangle:hover {
  filter: brightness(1.15);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

/* Real-time active drawing overlay */
.shikaku-overlay {
  position: absolute;
  border-radius: 8px;
  border: 2.5px dashed var(--overlay-color, var(--primary-color));
  background: var(--overlay-bg, rgba(0, 243, 255, 0.1));
  z-index: 6;
  pointer-events: none;
}

/* Visual dimensions pill label inside rectangles */
.rect-label {
  position: absolute;
  bottom: 4px;
  right: 4px;
  font-family: var(--font-title);
  font-size: 0.65rem;
  font-weight: bold;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  padding: 1px 5px;
  border-radius: 10px;
  border: 0.5px solid rgba(255, 255, 255, 0.15);
  pointer-events: none;
  z-index: 7;
}

/* Control Action Bar */
.game-controls {
  width: 100%;
  max-width: 500px;
  display: flex;
  gap: 10px;
}

.btn-ctrl {
  flex: 1;
  font-family: var(--font-title);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 10px 5px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.btn-ctrl svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ==========================================
   5. VICTORY OVERLAY SCREEN
   ========================================== */
.victory-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(4, 4, 8, 0.85);
  backdrop-filter: blur(12px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.victory-panel {
  max-width: 420px;
  width: 100%;
  padding: 35px 25px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  transform: scale(0.9);
  animation: popPanel 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.25) forwards;
}

.victory-title {
  font-family: var(--font-title);
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--w1-primary);
  text-shadow: 0 4px 15px rgba(0, 255, 162, 0.3);
  text-transform: uppercase;
}

.victory-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
}

.victory-stars {
  display: flex;
  gap: 15px;
  margin: 10px 0;
}
.victory-stars .star-icon {
  width: 44px;
  height: 44px;
  opacity: 0.2;
  transform: scale(0.6);
}

.victory-stars .star-icon.earned {
  opacity: 1;
  transform: scale(1);
  animation: starPopIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.4) forwards;
}
.victory-stars .star-icon.earned:nth-child(2) { animation-delay: 0.15s; }
.victory-stars .star-icon.earned:nth-child(3) { animation-delay: 0.3s; }

.victory-scores {
  width: 100%;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.score-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}
.score-row.total {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 8px;
  font-weight: bold;
  font-size: 1.1rem;
  color: var(--primary-color);
}

.leaderboard-name-input {
  width: 100%;
  padding: 10px 15px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.95rem;
  text-align: center;
}
.leaderboard-name-input:focus {
  border-color: var(--primary-color);
  outline: none;
}

.victory-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
}
.victory-actions .btn {
  padding: 12px 8px;
  font-size: 0.9rem;
}
#btn-victory-continue {
  grid-column: span 3;
  padding: 14px 28px;
  font-size: 1.05rem;
}

.share-message-banner {
  width: 100%;
  padding: 10px 15px;
  background: rgba(0, 255, 162, 0.15);
  border: 1px solid rgba(0, 255, 162, 0.3);
  border-radius: 8px;
  color: #00ffa2;
  font-size: 0.85rem;
  text-align: center;
  margin-bottom: 12px;
  box-sizing: border-box;
  animation: popPanel 0.3s ease;
}

/* ==========================================
   6. PERSISTENT LEADERBOARD SCREEN
   ========================================== */
#leaderboard-screen {
  max-width: 500px;
  width: 100%;
  justify-content: flex-start;
  overflow-y: auto;
  padding-top: calc(84px + env(safe-area-inset-top));
}

.leaderboard-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-bottom: 30px;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard-table th {
  text-align: left;
  padding: 12px 10px;
  font-family: var(--font-title);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.leaderboard-table td {
  padding: 14px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 0.95rem;
}

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

.rank-cell {
  font-family: var(--font-title);
  font-weight: 800;
  width: 60px;
}
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 0.8rem;
}
.rank-1 .rank-badge { background: gold; color: #000; }
.rank-2 .rank-badge { background: silver; color: #000; }
.rank-3 .rank-badge { background: #cd7f32; color: #000; }

.score-cell {
  font-family: var(--font-title);
  font-weight: 700;
  color: var(--primary-color);
}

.leaderboard-empty {
  text-align: center;
  padding: 40px 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* ==========================================
   ANIMATIONS & HAPTICS (Visual Feedback)
   ========================================== */
@keyframes floatTitle {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-8px); }
  100% { transform: translateY(0px); }
}

@keyframes popPanel {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes starPopIn {
  0% { transform: scale(0.3); opacity: 0; }
  70% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

.shake {
  animation: screenShake 0.35s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes screenShake {
  10%, 90% { transform: translate3d(-2px, 0, 0); }
  20%, 80% { transform: translate3d(4px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
  40%, 60% { transform: translate3d(6px, 0, 0); }
}

/* Responsive Scaling details */
@media (max-width: 480px) {
  .game-logo {
    font-size: 2.5rem;
  }
  .page-title {
    font-size: 1.4rem !important;
  }
  .cell-val {
    font-size: 1.1rem;
  }
  .board-outer-container {
    max-width: min(90vw, 42vh) !important;
    max-height: min(90vw, 42vh) !important;
  }
  .header-row {
    margin-bottom: 12px;
    min-height: 36px;
  }
  .btn-back {
    padding: 6px 10px !important;
    font-size: 0.75rem !important;
    height: 30px !important;
    gap: 3px !important;
  }
  .btn-back svg {
    width: 12px !important;
    height: 12px !important;
  }
  .user-profile-badge {
    padding: 3px 6px !important;
    gap: 4px !important;
    height: 30px !important;
  }
  .lobby-badge {
    padding: 3px 10px !important;
    font-size: 0.75rem !important;
    height: 30px !important;
  }
  .user-profile-badge .badge-info {
    display: none !important;
  }
  .badge-action-btn {
    padding: 2px 6px !important;
    font-size: 0.7rem !important;
  }
  .game-header {
    min-height: 36px;
    padding: 0;
  }
  /* Table Compactness to Prevent Right-side Clipping */
  .leaderboard-container {
    padding: 10px !important;
  }
  .leaderboard-table th, 
  .leaderboard-table td {
    padding: 8px 4px !important;
    font-size: 0.75rem !important;
  }
  .rank-cell {
    width: 32px !important;
  }
  .rank-badge {
    width: 20px !important;
    height: 20px !important;
    font-size: 0.7rem !important;
  }
  .game-title-panel {
    align-items: center;
    text-align: center;
    flex: 1;
  }
  .active-level-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
  }
  #game-screen {
    gap: 8px !important;
    padding: calc(6px + env(safe-area-inset-top)) calc(6px + env(safe-area-inset-right)) 6px calc(6px + env(safe-area-inset-left)) !important;
  }
  .game-stats-bar {
    padding: 8px 12px !important;
    margin-bottom: 2px;
  }
  .stat-val {
    font-size: 0.95rem !important;
  }
  .stat-lbl {
    font-size: 0.65rem !important;
  }
  .btn-ctrl {
    padding: 6px 4px !important;
    font-size: 0.75rem !important;
    height: 44px !important;
    border-radius: 8px !important;
    gap: 2px !important;
  }
  .btn-ctrl svg {
    width: 15px !important;
    height: 15px !important;
  }
  .game-controls {
    gap: 6px !important;
  }
}

/* Height-Constrained Responsive Queries */
@media (max-height: 740px) {
  #game-screen {
    gap: 8px !important;
    padding: calc(6px + env(safe-area-inset-top)) calc(6px + env(safe-area-inset-right)) 6px calc(6px + env(safe-area-inset-left)) !important;
  }
  .game-stats-bar {
    padding: 6px 12px !important;
  }
  .stat-val {
    font-size: 0.95rem !important;
  }
  .stat-lbl {
    font-size: 0.65rem !important;
  }
  .btn-ctrl {
    padding: 6px 4px !important;
    font-size: 0.75rem !important;
    height: 40px !important;
    gap: 2px !important;
  }
  .btn-ctrl svg {
    width: 15px !important;
    height: 15px !important;
  }
  .board-outer-container {
    max-width: min(90vw, 42vh) !important;
    max-height: min(90vw, 42vh) !important;
  }
}

@media (max-height: 640px) {
  #splash-screen {
    gap: 15px !important;
  }
  .game-logo {
    font-size: 2.2rem !important;
  }
  .game-subtitle {
    font-size: 0.9rem !important;
    letter-spacing: 4px !important;
  }
  .menu-options {
    gap: 10px !important;
    width: 240px !important;
  }
  .btn {
    padding: 10px 20px !important;
    font-size: 0.95rem !important;
  }
}

/* Modal and Panel Mobile Responsiveness */
@media (max-width: 480px), (max-height: 700px) {
  .victory-panel {
    padding: 15px 15px !important;
    gap: 10px !important;
    border-radius: 16px !important;
  }
  .victory-title {
    font-size: 1.6rem !important;
  }
  .victory-subtitle {
    font-size: 0.85rem !important;
  }
  .victory-stars .star-icon {
    width: 32px !important;
    height: 32px !important;
  }
  .victory-scores {
    padding: 8px 12px !important;
    gap: 6px !important;
  }
  .score-row {
    font-size: 0.8rem !important;
  }
  .score-row.total {
    font-size: 0.95rem !important;
  }
  .victory-leaderboard-section {
    padding: 8px !important;
    gap: 6px !important;
    margin: 2px 0 !important;
  }
  .victory-leaderboard-title {
    font-size: 0.75rem !important;
  }
  .victory-leaderboard-text {
    font-size: 0.75rem !important;
  }
  .victory-actions {
    gap: 6px !important;
  }
  .victory-actions .btn {
    padding: 8px 12px !important;
    font-size: 0.85rem !important;
    height: 38px !important;
  }
  #btn-victory-continue {
    padding: 10px 16px !important;
    font-size: 0.95rem !important;
    height: 40px !important;
  }
  
  .auth-panel {
    padding: 20px !important;
    gap: 12px !important;
  }
  .auth-panel-title {
    font-size: 1.2rem !important;
  }
  .auth-panel-subtitle {
    font-size: 0.8rem !important;
    margin-bottom: 5px !important;
  }
  .input-group {
    margin-bottom: 10px !important;
    gap: 4px !important;
  }
  .input-group input {
    padding: 10px 12px !important;
    font-size: 0.85rem !important;
  }
  .auth-submit-btn {
    padding: 10px !important;
    font-size: 0.95rem !important;
  }

  .tutorial-panel {
    padding: 15px !important;
    gap: 10px !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
  }
  .tutorial-title {
    font-size: 1.4rem !important;
  }
  .tutorial-body {
    font-size: 0.8rem !important;
    line-height: 1.4 !important;
    gap: 6px !important;
  }
  .tutorial-grid-demo {
    padding: 6px !important;
  }
  .demo-cell {
    width: 28px !important;
    height: 28px !important;
    font-size: 0.75rem !important;
  }
  .close-tutorial {
    padding: 8px 16px !important;
    font-size: 0.9rem !important;
    height: 38px !important;
  }
}

/* ==========================================
   7. USER AUTHENTICATION & PROFILE BADGES STYLES
   ========================================== */
.auth-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(4, 4, 8, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.3s ease forwards;
}

.auth-panel {
  max-width: 400px;
  width: 100%;
  padding: 30px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 20px;
  transform: scale(0.92);
  opacity: 0;
  animation: popPanelIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.25) forwards;
}

.auth-close-btn {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.8rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.auth-close-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.auth-tabs {
  display: flex;
  border-bottom: 2px solid rgba(255, 255, 255, 0.05);
  margin-bottom: 10px;
}

.auth-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-title);
  font-size: 1.1rem;
  font-weight: 600;
  padding: 12px 5px;
  cursor: pointer;
  position: relative;
  transition: all 0.25s ease;
  text-align: center;
}

.auth-tab:hover {
  color: #fff;
}

.auth-tab.active {
  color: var(--primary-color);
  font-weight: 700;
}

.auth-tab.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--primary-color);
  box-shadow: 0 0 10px var(--primary-glow);
}

.auth-panel-title {
  font-family: var(--font-title);
  font-size: 1.4rem;
  color: #fff;
  margin-bottom: 4px;
}

.auth-panel-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 15px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
  text-align: left;
}

.input-group label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: 0.5px;
}

.input-group input {
  width: 100%;
  padding: 12px 15px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.95rem;
  transition: all 0.25s ease;
}

.input-group input:focus {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--primary-color);
  box-shadow: 0 0 12px var(--primary-glow);
  outline: none;
}

.auth-message-banner {
  font-size: 0.85rem;
  padding: 10px 15px;
  border-radius: 8px;
  margin-bottom: 18px;
  display: none;
  font-weight: 500;
  text-align: center;
}

.auth-message-banner.error {
  display: block;
  background: rgba(255, 69, 0, 0.15);
  border: 1px solid #ff4500;
  color: #ff8855;
  box-shadow: 0 4px 15px rgba(255, 69, 0, 0.15);
}

.auth-message-banner.success {
  display: block;
  background: rgba(0, 255, 162, 0.15);
  border: 1px solid #00ffa2;
  color: #88ffcc;
  box-shadow: 0 4px 15px rgba(0, 255, 162, 0.15);
}

.auth-submit-btn {
  width: 100%;
  padding: 14px;
}

/* User Badges in Headers */
.splash-badge-container {
  position: absolute;
  top: calc(20px + env(safe-area-inset-top));
  left: calc(20px + env(safe-area-inset-left));
  z-index: 100;
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-radius: 30px;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-glow);
  font-size: 0.85rem;
  font-family: var(--font-title);
  height: 44px;
  transition: all 0.3s ease;
}

.user-profile-badge:hover {
  border-color: rgba(255, 255, 255, 0.18);
}

.badge-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.badge-username {
  font-weight: 700;
  color: #fff;
}

.badge-status {
  font-size: 0.65rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.badge-action-btn {
  background: linear-gradient(135deg, var(--primary-color), #0099ff);
  color: #030a10;
  font-family: var(--font-title);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 20px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.badge-action-btn:hover {
  transform: scale(1.05);
  filter: brightness(1.1);
}

.badge-action-btn.logout {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.badge-action-btn.logout:hover {
  background: rgba(255, 69, 0, 0.15);
  border-color: #ff4500;
  color: #fff;
  transform: scale(1.05);
}

/* Victory leaderboard section prompt styles */
.victory-leaderboard-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  margin: 5px 0;
  width: 100%;
}

.victory-leaderboard-title {
  font-family: var(--font-title);
  font-size: 0.85rem;
  font-weight: bold;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.victory-leaderboard-text {
  font-size: 0.85rem;
  color: var(--text-primary);
  text-align: center;
}

.victory-leaderboard-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}

.victory-leaderboard-actions .btn {
  padding: 10px 15px;
  font-size: 0.85rem;
  flex: 1;
}

/* Transitions */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popPanelIn {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Custom locked cards styling */
.level-card.locked .lock-icon {
  fill: var(--text-secondary);
  opacity: 0.7;
  filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.5));
  animation: pulseLock 2s infinite ease-in-out;
}

@keyframes pulseLock {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* ==========================================
   8. QR CODE SHARING MODAL & UTILITY
   ========================================== */

.qr-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(5, 4, 8, 0.92); /* Deep high-opacity carbon overlay */
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.qr-panel {
  max-width: 380px;
  width: 100%;
  padding: 35px 25px;
  text-align: center;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-radius: 24px;
  background: rgba(18, 13, 10, 0.94); /* Warm charcoal-bronze dark backing */
  border: 1.5px solid transparent;
  background-clip: padding-box, border-box;
  background-origin: padding-box, border-box;
  background-image: linear-gradient(to right, #120d0a, #120d0a), linear-gradient(135deg, #ffd700, #ff3b00); /* Glowing gold-to-coral border */
  box-shadow: 0 15px 50px rgba(255, 94, 0, 0.35), inset 0 1px 1px rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  animation: qrModalIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.15) forwards;
}

@keyframes qrModalIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(15px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.qr-close-btn {
  position: absolute;
  top: 15px;
  right: 20px;
  background: none;
  border: none;
  color: #a0a5c0;
  font-size: 1.8rem;
  cursor: pointer;
  transition: all 0.25s ease;
  line-height: 1;
}

.qr-close-btn:hover {
  color: #ffd700; /* Vibrant gold hover */
  transform: scale(1.15) rotate(90deg);
}

.qr-panel-title {
  font-family: var(--font-title);
  font-size: 1.75rem;
  font-weight: 800;
  background: linear-gradient(135deg, #ffffff 15%, #ffd700 65%, #ff3b00 100%); /* Gold metallic gradient */
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 2px;
  letter-spacing: 0.5px;
}

.qr-panel-subtitle {
  font-size: 0.85rem;
  color: #d4cbb8; /* High-readability sandy gold */
  margin-bottom: 5px;
}

.qr-code-container {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 5px auto;
  padding: 10px;
  background: #ffffff; /* Solid white background for perfect scanner resolution */
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-code-glow {
  position: absolute;
  top: -6px;
  left: -6px;
  right: -6px;
  bottom: -6px;
  background: linear-gradient(135deg, #ffd700, #ff3b00);
  z-index: -1;
  border-radius: 18px;
  filter: blur(18px);
  opacity: 0.85;
}

.qr-code-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.qr-link-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 170, 0, 0.05); /* Soft glowing gold interior */
  border: 1px solid rgba(255, 170, 0, 0.25);
  border-radius: 12px;
  padding: 12px 16px;
  margin-top: 5px;
  gap: 10px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.qr-link-text {
  font-family: var(--font-title);
  color: #ffeebf; /* Warm sandy text */
  font-size: 0.95rem;
  font-weight: 600;
}

.btn-copy-link {
  background: linear-gradient(135deg, #ffd700, #ff3b00); /* Brilliant sunset gradient */
  color: #0c0803; /* Extra deep brown for stark text contrast */
  border: none;
  padding: 8px 16px;
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 0.85rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 4px 14px rgba(255, 59, 0, 0.35);
  flex-shrink: 0;
}

.btn-copy-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 59, 0, 0.5);
  filter: brightness(1.15);
}

.qr-toast-message {
  font-size: 0.85rem;
  color: #ffd700; /* Warm gold toast notifications */
  font-weight: 700;
  margin-top: 5px;
  animation: fadeIn 0.3s ease;
}

/* ==========================================
   9. FLEX SCORE SHARING MODAL
   ========================================== */
.modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(4, 4, 8, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 180;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.3s ease forwards;
}

.modal-content {
  transform: scale(0.92);
  opacity: 0;
  animation: qrModalIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.15) forwards;
}

/* Level Card Share Button on Level Select Screen */
.level-card-share-btn {
  position: absolute !important;
  top: 8px !important;
  right: 8px !important;
  z-index: 10 !important;
  width: 28px !important;
  height: 28px !important;
  border-radius: 50% !important;
  background: #0d0d1a !important;
  border: 1.5px solid #00f3ff !important;
  color: #00f3ff !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
  padding: 0 !important;
  box-shadow: 0 0 6px rgba(0, 243, 255, 0.35) !important;
}

.level-card-share-btn:hover {
  background: #0d0d1a !important;
  border-color: #00f3ff !important;
  color: #00f3ff !important;
  transform: scale(1.15) !important;
  box-shadow: 0 0 14px rgba(0, 243, 255, 0.8), 0 0 28px rgba(0, 243, 255, 0.4) !important;
}

.level-card-share-btn svg {
  fill: #00f3ff !important;
  width: 13px !important;
  height: 13px !important;
  transition: filter 0.25s ease, transform 0.25s ease !important;
}

.level-card-share-btn svg path {
  fill: #00f3ff !important;
}

.level-card-share-btn:hover svg {
  filter: drop-shadow(0 0 5px #00f3ff) drop-shadow(0 0 10px rgba(0, 243, 255, 0.7)) !important;
  transform: scale(1.1) !important;
}

.level-card-share-btn:hover svg path {
  fill: #00f3ff !important;
}

/* Allow text selection & touch focus on inputs/forms for mobile viewports */
input, textarea, select, [contenteditable="true"] {
  user-select: text !important;
  -webkit-user-select: text !important;
  pointer-events: auto !important;
}

/* ==========================================
   BATTLE ARENA CUSTOM SYSTEM STYLES (NEW)
   ========================================== */

/* Battle Button (Splash Menu) */
.btn-battle {
  background: linear-gradient(135deg, #bf00ff 0%, #7d00ff 50%, #ffd700 100%) !important;
  color: #fff !important;
  border: 1.5px solid rgba(255, 255, 255, 0.2) !important;
  box-shadow: 0 6px 20px rgba(191, 0, 255, 0.45) !important;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5) !important;
}
.btn-battle:hover {
  transform: translateY(-3px) scale(1.03) !important;
  box-shadow: 0 10px 25px rgba(191, 0, 255, 0.7), 0 0 15px rgba(255, 215, 0, 0.4) !important;
  border-color: rgba(255, 255, 255, 0.45) !important;
}

/* Leaderboard Tabs */
.leaderboard-tabs {
  display: flex;
  margin: 0 auto 20px auto;
  max-width: 400px;
  width: 100%;
  padding: 6px;
  border-radius: 12px;
  background: rgba(15, 15, 27, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.05);
}
.leaderboard-tab {
  flex: 1;
  background: none;
  border: none;
  padding: 10px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.25s ease;
}
.leaderboard-tab.active {
  background: linear-gradient(135deg, var(--primary-color) 0%, #0099ff 100%);
  color: #030a10;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.lobby-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 30px;
  background: rgba(255, 215, 0, 0.1);
  border: 1px solid rgba(255, 215, 0, 0.35);
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.15);
  font-size: 0.85rem;
  font-family: var(--font-title);
  font-weight: bold;
  color: #ffd700;
  height: 44px;
  transition: all 0.3s ease;
}

/* Battle Lobby Layout */
.battle-lobby-container {
  display: flex;
  gap: 20px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}
.lobby-panel {
  flex: 1;
  padding: 30px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
  border-radius: 20px;
  box-shadow: var(--glass-glow);
}
.panel-tag {
  font-size: 0.7rem;
  font-weight: bold;
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  margin-bottom: 12px;
  display: inline-block;
}
.panel-tag.gold {
  background: rgba(255, 215, 0, 0.15);
  color: #ffd700;
  border: 1px solid #ffd700;
}
.panel-tag.purple {
  background: rgba(191, 0, 255, 0.15);
  color: #bf00ff;
  border: 1px solid #bf00ff;
}
.panel-heading {
  font-family: var(--font-title);
  font-size: 1.4rem;
  margin-bottom: 12px;
  color: #fff;
}
.panel-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 25px;
  min-height: 70px;
}
.queue-selector-box {
  width: 100%;
  margin-bottom: 25px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}
.queue-selector-box label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.battle-select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.1);
  color: #fff;
  font-family: var(--font-title);
  font-size: 0.9rem;
  cursor: pointer;
}
.btn-battle-start {
  width: 100%;
  height: 48px;
}

/* Battle Live Progress Panel */
.battle-progress-container {
  width: 100%;
  max-width: 500px;
  padding: 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.battle-progress-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.battle-player-info {
  display: flex;
  flex-direction: column;
  width: 90px;
  min-width: 90px;
}
.battle-player-info .player-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.battle-player-info .player-rating {
  font-size: 0.65rem;
  color: var(--text-secondary);
}
.progress-bar-track {
  flex: 1;
  height: 10px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.07);
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 20px;
  transition: width 0.3s cubic-bezier(0.1, 0.8, 0.2, 1);
}
.progress-fill.p1 {
  background: linear-gradient(90deg, #00f3ff, #0099ff);
  box-shadow: 0 0 10px rgba(0, 243, 255, 0.5);
}
.progress-fill.p2 {
  background: linear-gradient(90deg, #ff00f3, #bf00ff);
  box-shadow: 0 0 10px rgba(255, 0, 243, 0.5);
}
.percent-val {
  font-family: var(--font-title);
  font-size: 0.8rem;
  font-weight: bold;
  width: 32px;
  text-align: right;
}
.battle-vs-node {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--primary-color);
  text-align: center;
  letter-spacing: 1px;
  opacity: 0.65;
  line-height: 1;
}

/* Radar Matchmaking Overlay */
.radar-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(4, 4, 8, 0.85);
  backdrop-filter: blur(12px);
  z-index: 160;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.radar-panel {
  max-width: 340px;
  width: 100%;
  padding: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}
.radar-scanner {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(0, 243, 255, 0.03);
  border: 1.5px solid rgba(0, 243, 255, 0.2);
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 20px rgba(0, 243, 255, 0.1);
  margin-bottom: 10px;
}
.radar-sweep {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, rgba(0, 243, 255, 0.35) 0%, rgba(0, 243, 255, 0) 50%);
  transform-origin: top left;
  border-radius: 0 0 100% 0;
  animation: sweep 2.5s linear infinite;
}
.radar-blip {
  width: 6px;
  height: 6px;
  background: #00f3ff;
  border-radius: 50%;
  position: absolute;
  top: 30%;
  left: 65%;
  box-shadow: 0 0 8px #00f3ff, 0 0 16px #00f3ff;
  animation: blip 2s ease-out infinite;
}
.radar-title {
  font-family: var(--font-title);
  font-size: 1.3rem;
  color: #fff;
}
.radar-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.radar-timer {
  font-family: monospace;
  font-size: 0.95rem;
  color: var(--primary-color);
  margin-bottom: 10px;
}

@keyframes sweep {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
@keyframes blip {
  0% { opacity: 0; transform: scale(0.5); }
  25% { opacity: 1; transform: scale(1.2); }
  75% { opacity: 0.3; }
  100% { opacity: 0; }
}

/* Battle Countdown Overlay */
.countdown-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(4, 4, 8, 0.9);
  backdrop-filter: blur(16px);
  z-index: 180;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}
.countdown-circle {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  border: 4px solid var(--primary-color);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 30px var(--primary-glow);
  animation: pulseCountdown 1s infinite alternate;
}
.countdown-num {
  font-family: var(--font-title);
  font-size: 4rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 20px var(--primary-color);
}
.countdown-msg {
  font-family: var(--font-title);
  font-size: 1.2rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-secondary);
}

@keyframes pulseCountdown {
  from { transform: scale(0.95); border-color: var(--primary-color); box-shadow: 0 0 20px var(--primary-glow); }
  to { transform: scale(1.05); border-color: #ffd700; box-shadow: 0 0 35px rgba(255, 215, 0, 0.6); }
}

/* Battle End Screen Overlay */
.battle-end-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(4, 4, 8, 0.9);
  backdrop-filter: blur(16px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.battle-end-panel {
  max-width: 440px;
  width: 100%;
  padding: 35px 25px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 20px;
  animation: popPanel 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.25) forwards;
}
.battle-end-title {
  font-family: var(--font-title);
  font-size: 2.5rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  line-height: 1;
}
.battle-end-title.success {
  color: #00ff64;
  text-shadow: 0 0 20px rgba(0, 255, 100, 0.5);
  animation: shineWin 1.5s infinite alternate;
}
.battle-end-title.fail {
  color: #ff0055;
  text-shadow: 0 0 20px rgba(255, 0, 85, 0.5);
  animation: glitchDefeat 0.5s infinite alternate;
}
.battle-end-subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
}
.battle-end-comparison {
  width: 100%;
  display: flex;
  align-items: center;
  padding: 15px;
  background: rgba(0,0,0,0.3);
}
.compare-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.compare-card .role-lbl {
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.compare-card .player-name {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 1.05rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.compare-card .solve-time {
  font-family: monospace;
  font-size: 0.9rem;
  color: var(--primary-color);
}
.compare-vs {
  font-family: var(--font-title);
  font-weight: 800;
  font-style: italic;
  font-size: 1.1rem;
  color: rgba(255,255,255,0.25);
  padding: 0 10px;
}
.elo-adjust-box {
  width: 100%;
  background: rgba(255, 215, 0, 0.03);
  border: 1px dashed rgba(255, 215, 0, 0.15);
  border-radius: 12px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.elo-adjust-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}
.elo-adjust-row .player-lbl {
  color: var(--text-secondary);
}
.elo-adjust-row .elo-val {
  font-weight: bold;
  color: #ffd700;
  text-shadow: 0 0 5px rgba(255, 215, 0, 0.3);
}

@keyframes shineWin {
  from { filter: brightness(1.0); }
  to { filter: brightness(1.3); }
}
@keyframes glitchDefeat {
  0% { transform: skew(0deg); }
  20% { transform: skew(1.5deg); }
  40% { transform: skew(-1deg); }
  60% { transform: skew(0.5deg); }
  80% { transform: skew(-0.5deg); }
  100% { transform: skew(0deg); }
}

@media (max-width: 768px) {
  .battle-lobby-container {
    flex-direction: column;
    gap: 15px;
  }
  .lobby-panel {
    padding: 20px 15px;
  }
  .panel-desc {
    min-height: auto;
    margin-bottom: 15px;
  }
}

/* Dynamic Game Version Display */
.game-version {
  position: absolute;
  bottom: 25px;
  font-family: var(--font-title);
  font-size: 0.8rem;
  color: var(--text-secondary);
  opacity: 0.55;
  letter-spacing: 2px;
  font-weight: 600;
  text-transform: uppercase;
  pointer-events: none;
  animation: pulseVersion 2s infinite alternate;
}

@keyframes pulseVersion {
  from { opacity: 0.45; }
  to { opacity: 0.7; }
}

/* Responsive Mobile-First Layout — under 480px: scale down icons and tighten header */
@media (max-width: 480px) {
  /* Scale down global navigation icons so they don't eat into page real estate */
  .sound-toggle, .qr-toggle {
    width: 36px !important;
    height: 36px !important;
  }
  .sound-toggle svg, .qr-toggle svg {
    width: 17px !important;
    height: 17px !important;
  }
  .global-header-toggles {
    gap: 8px !important;
    top: calc(12px + env(safe-area-inset-top)) !important;
    right: calc(12px + env(safe-area-inset-right)) !important;
  }

  /* Shrink page title and wrap header-row items cleanly into two lines to prevent vertical page-title squeezing */
  .header-row {
    flex-wrap: wrap !important;
    padding-right: 0 !important;
    gap: 10px 8px !important;
    margin-bottom: 20px !important;
  }
  .header-row .btn-back {
    order: 1 !important;
  }
  .header-row #level-select-user-badge,
  .header-row #battle-lobby-user-badge {
    order: 2 !important;
    margin-left: auto !important;
    margin-right: calc(85px + env(safe-area-inset-right)) !important;
  }
  .header-row .page-title {
    order: 3 !important;
    flex: 1 1 100% !important;
    text-align: center !important;
    font-size: 1.6rem !important;
    margin: 5px 0 0 0 !important;
    padding-right: 0 !important;
    background: linear-gradient(135deg, #fff 40%, var(--primary-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }

  .game-header {
    padding-right: calc(90px + env(safe-area-inset-right)) !important;
  }
}


