/* =========================================================
   Pirate Sea Runner - Stylesheet
   ========================================================= */

:root {
  --primary-gold: #f5b041;
  --gold-glow: #f39c12;
  --dark-wood: #2c1b12;
  --light-wood: #5a3825;
  --parchment: #fdf6e2;
  --parchment-border: #d4af37;
  --deep-ocean: #0b2545;
  --ocean-blue: #134074;
  --danger-red: #e74c3c;
  --success-green: #2ecc71;
  --text-dark: #2c1b12;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--deep-ocean);
  font-family: 'Kanit', sans-serif;
  color: #fff;
}

/* =========================================================
   Landscape Orientation Guard Overlay (Mobile Portrait)
   ========================================================= */
.rotate-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  z-index: 99999;
  background: radial-gradient(circle at center, #0f172a 0%, #020617 100%);
  color: #fff;
  padding: 24px;
  justify-content: center;
  align-items: center;
  text-align: center;
}

/* Display overlay whenever held in portrait mode on mobile/tablets */
@media screen and (orientation: portrait) and (max-width: 1024px) {
  .rotate-overlay {
    display: flex;
  }
}

.rotate-content {
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.rotate-anim-box {
  position: relative;
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.phone-anim {
  font-size: 3.5rem;
  animation: rotatePhone 2.2s infinite ease-in-out;
  transform-origin: center center;
}

@keyframes rotatePhone {
  0%, 25% { transform: rotate(0deg) scale(1); }
  60%, 85% { transform: rotate(90deg) scale(1.1); }
  100% { transform: rotate(0deg) scale(1); }
}

.rotate-arrow {
  position: absolute;
  top: -6px;
  right: 6px;
  font-size: 1.8rem;
  color: #ffd166;
  animation: pulseArrow 1.5s infinite alternate ease-in-out;
}

@keyframes pulseArrow {
  0% { transform: scale(0.9) rotate(0deg); opacity: 0.6; }
  100% { transform: scale(1.2) rotate(25deg); opacity: 1; }
}

.rotate-title {
  font-family: 'Press Start 2P', 'Kanit', sans-serif;
  font-size: 1.1rem;
  color: #ffd166;
  text-shadow: 2px 2px 0px #b91c1c;
  margin-bottom: 8px;
  line-height: 1.4;
}

.rotate-subtitle {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.68rem;
  color: #38bdf8;
  letter-spacing: 1px;
  margin-bottom: 14px;
}

.rotate-desc {
  font-size: 0.88rem;
  color: #cbd5e1;
  line-height: 1.5;
  margin-bottom: 20px;
}

.btn-rotate-action {
  font-size: 0.95rem;
  padding: 12px 18px;
  background: linear-gradient(180deg, #ffd166 0%, #e67e22 100%);
  color: #1a1005;
  border: 2px solid #fff;
  border-radius: 6px;
  box-shadow: 0 4px 15px rgba(255, 209, 102, 0.4);
}

#game-wrapper {
  position: relative;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  max-width: 100%;
  max-height: 100%;
  margin: 0 auto;
  overflow: hidden;
  background: #0b2545;
  display: flex;
  justify-content: center;
  align-items: center;
}

canvas#gameCanvas {
  display: block;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  object-fit: contain;
  image-rendering: auto;
}

/* =========================================================
   Touch Control Zones (Mobile)
   ========================================================= */
#touch-controls {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  pointer-events: auto;
  z-index: 25;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-zone {
  flex: 1;
  height: 100%;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 24px;
  background-color: transparent;
  touch-action: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

#touch-left {
  border-right: 1px dashed rgba(255, 255, 255, 0.08);
}

.touch-zone.active {
  background-color: rgba(255, 255, 255, 0.04);
}

.touch-hint {
  background: rgba(15, 32, 39, 0.75);
  border: 1px solid rgba(245, 176, 65, 0.4);
  padding: 5px 12px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.touch-zone.active .touch-hint {
  opacity: 0.8;
}

.touch-icon {
  font-size: 1rem;
}

.touch-text {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary-gold);
  letter-spacing: 0.5px;
}

/* Global Top Action Bar */
.global-actions-bar {
  position: absolute;
  top: 10px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 1000;
}

.global-action-btn {
  background: rgba(15, 23, 42, 0.85);
  border: 1.5px solid rgba(245, 176, 65, 0.5);
  color: #ffffff;
  padding: 5px 12px;
  border-radius: 8px;
  font-family: 'Kanit', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(6px);
  transition: all 0.2s ease;
}

.global-action-btn:hover {
  background: rgba(245, 176, 65, 0.25);
  border-color: #ffd166;
  color: #ffd166;
  transform: translateY(-1px);
}

.global-stage-btn {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.9), rgba(2, 132, 199, 0.9));
  border-color: #7dd3fc;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}

.global-stage-btn:hover {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  border-color: #bae6fd;
  color: #ffffff;
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.6);
}

.global-sound-btn {
  padding: 5px 10px;
  font-size: 1rem;
}

.global-exit-btn {
  background: rgba(220, 38, 38, 0.3);
  border-color: rgba(239, 68, 68, 0.6);
  color: #fca5a5;
}

.global-exit-btn:hover {
  background: #dc2626;
  color: #ffffff;
}

.btn-stage-btn {
  border: 1.5px solid #38bdf8 !important;
  color: #38bdf8 !important;
  background: rgba(14, 165, 233, 0.1) !important;
}

.btn-stage-btn:hover {
  background: rgba(14, 165, 233, 0.3) !important;
  color: #ffffff !important;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.4) !important;
}

.btn-lb-stage {
  border: 1.5px solid #38bdf8 !important;
  color: #38bdf8 !important;
}

/* =========================================================
   Interactive In-Game Live Tutorial (Freeze Screen Callout)
   ========================================================= */
.game-tutorial-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 45;
  background: rgba(10, 20, 30, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeInFast 0.2s ease-out;
}

.game-tutorial-overlay.hidden {
  display: none !important;
}

@keyframes fadeInFast {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.tutorial-callout-card {
  width: 100%;
  max-width: 540px;
  background: #fffdf5;
  border: 4px solid var(--dark-wood);
  border-radius: 8px;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.85), 6px 6px 0px #000;
  padding: 20px 22px;
  text-align: center;
  position: relative;
  animation: popCard 0.25s ease-out;
}

@keyframes popCard {
  0% { transform: translateY(20px) scale(0.92); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

.callout-header {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  border-bottom: 2px dashed #d4a373;
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.callout-icon {
  font-size: 2.2rem;
  background: #2c1b12;
  color: #ffd166;
  border: 2px solid #ffd166;
  border-radius: 50%;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.callout-tag {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.6rem;
  background: #b91c1c;
  color: #fff;
  padding: 3px 8px;
  border-radius: 3px;
  display: inline-block;
  margin-bottom: 4px;
}

.callout-title {
  font-family: 'Press Start 2P', 'Kanit', sans-serif;
  font-size: 1rem;
  color: #2c1b12;
  margin: 0;
}

.callout-desc {
  font-size: 0.92rem;
  color: #2c1b12;
  line-height: 1.5;
  margin-bottom: 14px;
  text-align: left;
}

.callout-desc strong {
  color: #b91c1c;
}

.callout-highlight-zone {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.tut-zone-guide {
  flex: 1;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  border: 2px solid #cbd5e1;
  background: rgba(0, 0, 0, 0.04);
  color: #64748b;
  transition: all 0.2s ease;
}

.tut-zone-guide.active-target {
  background: #fef08a;
  border-color: #ca8a04;
  color: #854d0e;
  box-shadow: 0 0 12px rgba(234, 179, 8, 0.6);
  animation: pulseGlow 1.2s infinite alternate;
}

@keyframes pulseGlow {
  0% { transform: scale(0.98); }
  100% { transform: scale(1.02); }
}

.callout-footer {
  display: flex;
  gap: 10px;
}

.btn-tut-action {
  flex: 2;
  font-size: 0.95rem;
  padding: 12px;
  background: linear-gradient(180deg, #ffd166 0%, #e67e22 100%);
  color: #1a1005;
}

.btn-tut-skip {
  flex: 1;
  font-size: 0.78rem;
  padding: 8px;
  border: 1.5px solid #888;
  color: #666;
}

/* =========================================================
   HUD Overlay
   ========================================================= */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: 6px 10px;
  pointer-events: none;
  z-index: 20;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  background: transparent;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

#hud.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.hud-top {
  display: flex;
  gap: 5px;
  flex-wrap: nowrap;
  align-items: center;
}

.hud-item {
  background: rgba(15, 32, 39, 0.92);
  border: 1.5px solid var(--primary-gold);
  border-radius: 4px;
  box-shadow: 1px 1px 0px #000;
  padding: 2px 7px;
  display: flex;
  flex-direction: column;
}

.hud-label {
  font-size: 0.58rem;
  color: #c5d1de;
  text-transform: uppercase;
  font-weight: 600;
  line-height: 1.1;
}

.hud-value {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--primary-gold);
  font-family: 'Press Start 2P', 'Kanit', sans-serif;
  line-height: 1.2;
}

.stamp-progress-box {
  min-width: 110px;
}

.progress-bar-bg {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 2px;
}

.progress-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #f39c12, #2ecc71);
  transition: width 0.3s ease;
}

.global-actions-bar {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.global-action-btn {
  background: rgba(15, 23, 42, 0.92);
  border: 2px solid var(--primary-gold);
  color: #ffd166;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6), 0 0 10px rgba(255, 209, 102, 0.25);
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.global-action-btn:hover {
  transform: scale(1.05);
  background: #1e293b;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.8), 0 0 15px rgba(255, 209, 102, 0.5);
}

.global-action-btn:active {
  transform: scale(0.95);
}

.global-sound-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 1.2rem;
  padding: 0;
}

.global-exit-btn {
  padding: 0 12px;
  height: 38px;
  font-size: 0.82rem;
  font-weight: 700;
  font-family: 'Kanit', sans-serif;
  background: rgba(136, 19, 19, 0.9);
  border: 2px solid #f87171;
  color: #fee2e2;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6), 0 0 10px rgba(239, 68, 68, 0.3);
}

.global-exit-btn:hover {
  background: #991b1b;
  border-color: #fca5a5;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.8), 0 0 15px rgba(239, 68, 68, 0.6);
}

/* =========================================================
   UI Layers & Modals
   ========================================================= */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 50;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  background: rgba(10, 20, 25, 0.65);
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.modal-card {
  width: 100%;
  max-width: 490px;
  background: var(--parchment);
  color: var(--text-dark);
  border: 4px solid #2c1b12;
  border-radius: 4px;
  box-shadow: 6px 6px 0px #000, inset 0 0 10px rgba(90, 56, 37, 0.2);
  padding: 22px 18px;
  text-align: center;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

/* =========================================================
   Grand Title Screen (Cover Artwork & Action Panel)
   ========================================================= */
.title-screen-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 35;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.title-screen-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.title-screen-backdrop {
  position: absolute;
  top: -5%;
  left: -5%;
  width: 110%;
  height: 110%;
  background: url('../assets/images/title_bg.jpg') center center/cover no-repeat;
  filter: brightness(0.9);
  transform-origin: 50% 80%;
  animation: shipOceanRocking 8.5s infinite ease-in-out;
  will-change: transform;
}

/* Realistic ship swaying on ocean waves */
@keyframes shipOceanRocking {
  0% {
    transform: scale(1.06) translate(0px, 0px) rotate(0deg);
  }
  20% {
    transform: scale(1.07) translate(8px, -12px) rotate(1.4deg);
  }
  40% {
    transform: scale(1.06) translate(14px, 6px) rotate(0.6deg);
  }
  55% {
    transform: scale(1.075) translate(2px, -8px) rotate(-1.2deg);
  }
  75% {
    transform: scale(1.06) translate(-10px, 8px) rotate(-1.6deg);
  }
  90% {
    transform: scale(1.065) translate(-4px, -4px) rotate(-0.4deg);
  }
  100% {
    transform: scale(1.06) translate(0px, 0px) rotate(0deg);
  }
}

/* Subtle moving ocean ripple / shimmer overlay */
.ocean-ripple-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 200%;
  height: 45%;
  background: radial-gradient(ellipse at center bottom, rgba(56, 189, 248, 0.12) 0%, rgba(14, 116, 144, 0.05) 50%, transparent 80%);
  pointer-events: none;
  z-index: 1;
  animation: oceanDrift 12s infinite alternate ease-in-out;
}

@keyframes oceanDrift {
  0% { transform: translateX(0) scaleY(1); opacity: 0.7; }
  50% { transform: translateX(-15%) scaleY(1.15); opacity: 0.9; }
  100% { transform: translateX(-30%) scaleY(1.05); opacity: 0.6; }
}

/* Atmospheric sea fog / foam at the bottom */
.ocean-fog-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 25%;
  background: linear-gradient(to top, rgba(10, 25, 47, 0.75) 0%, rgba(15, 32, 39, 0.3) 60%, transparent 100%);
  pointer-events: none;
  z-index: 1;
  animation: fogPulse 6s infinite ease-in-out alternate;
}

@keyframes fogPulse {
  0% { opacity: 0.6; }
  100% { opacity: 0.85; }
}

.title-screen-container {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  max-width: 1200px;
  padding: 24px 36px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  box-sizing: border-box;
  background: transparent;
}

.title-brand-panel {
  flex: 1;
  max-width: 520px;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-start;
  margin-bottom: 6px;
}

.stamp-badge-preview {
  display: inline-block;
  background: rgba(15, 23, 42, 0.85);
  border: 1.5px solid var(--primary-gold);
  color: #ffd166;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  margin-bottom: 6px;
}

.main-game-title {
  font-family: 'Press Start 2P', cursive;
  font-size: 1.85rem;
  color: #ffd166;
  text-shadow: 3px 3px 0px #b91c1c, 5px 5px 0px #000, 0 0 16px rgba(255, 209, 102, 0.5);
  line-height: 1.25;
  margin: 4px 0 2px 0;
  letter-spacing: -0.5px;
}

.sub-game-title {
  font-family: 'Press Start 2P', cursive;
  font-size: 1.25rem;
  color: #06d6a0;
  text-shadow: 2.5px 2.5px 0px #000, 0 0 14px rgba(6, 214, 160, 0.5);
  line-height: 1.2;
  margin-bottom: 6px;
  letter-spacing: 0px;
}

.game-tagline {
  font-size: 0.95rem;
  color: #f1faee;
  font-weight: 500;
  margin-bottom: 0px;
  text-shadow: 2px 2px 4px #000, 0 0 10px rgba(0, 0, 0, 0.9);
}

/* Right Action Panel */
.title-action-panel {
  width: 100%;
  max-width: 350px;
  margin-bottom: 6px;
}

.title-card-box {
  background: rgba(44, 27, 18, 0.92);
  border: 4px solid var(--primary-gold);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8), 6px 6px 0px #000;
  padding: 24px 20px;
  backdrop-filter: blur(8px);
}

.title-card-box .input-group label {
  color: #ffd166;
  font-weight: 700;
  font-size: 0.9rem;
}

.title-card-box .input-group input {
  background: #fff8eb;
  border: 2px solid #b7791f;
  font-weight: 700;
  color: #2c1b12;
}

.title-btn-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.btn-touch-play {
  font-size: 1.15rem;
  padding: 14px 16px;
  background: linear-gradient(180deg, #ffd166 0%, #e67e22 100%);
  color: #1a1005;
  border: 3px solid #fff;
  box-shadow: 0 6px 0 #000, 0 0 20px rgba(255, 209, 102, 0.6);
  animation: pulseTouch 1.8s infinite ease-in-out;
}

@keyframes pulseTouch {
  0%, 100% { transform: scale(1); box-shadow: 0 6px 0 #000, 0 0 20px rgba(255, 209, 102, 0.6); }
  50% { transform: scale(1.03); box-shadow: 0 6px 0 #000, 0 0 30px rgba(255, 209, 102, 0.9); }
}

.btn-tutorial {
  background: #2b5876;
  color: #fff;
  border: 2px solid #4e4376;
  font-size: 0.9rem;
  padding: 10px;
}

.btn-tutorial:hover {
  background: #356b8e;
}

.btn-lb {
  background: rgba(15, 23, 42, 0.9);
  color: #ffffff !important;
  border: 2px solid #ffd166;
  font-size: 0.92rem;
  padding: 10px 14px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
  transition: all 0.15s ease;
}

.btn-lb:hover {
  background: #1e293b;
  color: #ffffff !important;
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(255, 209, 102, 0.4);
}

.btn-certificate {
  background: linear-gradient(180deg, #059669 0%, #047857 100%);
  color: #ffffff !important;
  border: 2px solid #6ee7b7;
  font-size: 0.9rem;
  padding: 10px 14px;
  font-weight: 800;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s ease;
}

.btn-certificate:hover {
  background: #10b981;
  color: #ffffff !important;
  box-shadow: 0 6px 15px rgba(16, 185, 129, 0.4);
}

.btn-certificate.cert-unlocked {
  background: linear-gradient(180deg, #f59e0b 0%, #d97706 100%);
  border: 2px solid #fef08a;
  animation: pulseTouch 2s infinite ease-in-out;
}

/* =========================================================
   How To Play Modal
   ========================================================= */
.how-to-play-card {
  max-width: 640px;
  text-align: left;
  max-height: 88vh;
  overflow-y: auto;
}

.guide-subtitle {
  font-size: 0.85rem;
  color: #795548;
  margin-top: -6px;
  margin-bottom: 14px;
  font-weight: 600;
  text-align: center;
}

.tutorial-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.tutorial-card {
  display: flex;
  gap: 12px;
  background: rgba(255, 255, 255, 0.8);
  border: 2px solid #8d5524;
  border-radius: 6px;
  padding: 10px 12px;
  box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.15);
}

.tutorial-card.special-card {
  background: linear-gradient(135deg, #fff9e6 0%, #fff2cc 100%);
  border: 2px solid #d35400;
}

.tut-icon {
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
}

.tut-content h4 {
  font-size: 0.85rem;
  color: #872110;
  margin: 0 0 4px 0;
  font-weight: 700;
}

.tut-content p {
  font-size: 0.75rem;
  color: #2c1b12;
  margin: 0;
  line-height: 1.35;
}

.stamp-badge-preview {
  display: inline-block;
  background: #2c1b12;
  color: #ffd166;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.65rem;
  padding: 6px 12px;
  border: 2px solid #ffd166;
  border-radius: 2px;
  margin-bottom: 10px;
  letter-spacing: 1px;
}

.game-title {
  font-family: 'Press Start 2P', cursive;
  font-size: 1.4rem;
  color: #b91c1c;
  text-shadow: 3px 3px 0px #ffd166, 4px 4px 0px #000;
  line-height: 1.3;
  margin-bottom: 8px;
  letter-spacing: -1px;
}

.game-subtitle {
  font-size: 0.85rem;
  color: #554;
  margin-bottom: 14px;
  font-weight: 600;
}

.modal-title {
  font-family: 'Press Start 2P', cursive;
  font-size: 1.15rem;
  color: #b91c1c;
  text-shadow: 2px 2px 0px #ffd166;
  margin-bottom: 8px;
  text-align: center;
  line-height: 1.3;
}

.input-group {
  margin-bottom: 14px;
  text-align: left;
}

.input-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.input-group input {
  width: 100%;
  padding: 8px 12px;
  border: 3px solid #2c1b12;
  border-radius: 4px;
  font-size: 0.95rem;
  font-family: 'Kanit', sans-serif;
  background: #fff;
  color: #2c1b12;
  outline: none;
  box-shadow: 2px 2px 0px #000;
}

.input-group input:focus {
  border-color: #d35400;
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  width: 100%;
  padding: 11px 14px;
  border-radius: 4px;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: 'Kanit', 'Press Start 2P', sans-serif;
  cursor: pointer;
  border: 2px solid #000;
  box-shadow: 0 4px 0 #000;
  transition: transform 0.08s ease;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #000;
}

.btn-primary {
  background: linear-gradient(180deg, #ffd166, #e67e22);
  color: #1a1005;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}

.btn-secondary {
  background: #34495e;
  color: #fff;
}

.btn-outline {
  background: transparent;
  border: 2px solid #555;
  color: #444;
  font-size: 0.85rem;
  padding: 6px;
}

.btn-bounce {
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

/* =========================================================
   Game Over & Stamp Screen (Compact Screen-Fit Design)
   ========================================================= */
.gameover-card {
  max-width: 460px;
  padding: 12px 16px;
  max-height: 94vh;
  overflow-y: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.gameover-card .modal-title {
  font-size: 1.15rem;
  margin-bottom: 2px;
}

.gameover-card .tier-rank-badge {
  font-size: 0.78rem;
  padding: 2px 8px;
  margin-bottom: 6px;
}

.stamp-banner {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  font-weight: 800;
  padding: 4px 10px;
  border: 2px solid #000;
  border-radius: 5px;
  margin-bottom: 6px;
  box-shadow: 2px 2px 0px #000;
  animation: bounce 0.6s ease;
  text-align: center;
}

.stamp-banner-main {
  font-size: 0.88rem;
  font-weight: 800;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.stamp-banner-sub {
  font-size: 0.72rem;
  font-weight: 600;
  color: #fef08a;
  margin-top: 1px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.6);
}

.gameover-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}

.stat-pill {
  background: rgba(90, 56, 37, 0.1);
  border-radius: 6px;
  padding: 4px 6px;
}

.stat-title {
  display: block;
  font-size: 0.68rem;
  color: #777;
  line-height: 1.1;
}

.stat-num {
  font-size: 1.05rem;
  font-weight: 800;
  color: #a02c18;
  line-height: 1.2;
}

.gameover-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 2px;
}

.btn-gameover-primary {
  grid-column: 1 / -1;
  font-size: 1.05rem;
  padding: 9px 12px;
  background: linear-gradient(180deg, #ffd166 0%, #e67e22 100%);
  color: #1a1005;
  border: 2px solid #fff;
  box-shadow: 0 3px 0 #000;
  animation: pulseTouch 2s infinite ease-in-out;
}

.btn-gameover-sub {
  font-size: 0.8rem !important;
  padding: 7px 8px !important;
  border-radius: 4px;
  box-shadow: 0 2px 0 #000;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: #ffffff !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.btn-gameover-sub.btn-secondary {
  background: #334155;
  border: 1.5px solid #64748b;
}

.btn-gameover-sub.btn-outline {
  background: #1e293b;
  border: 1.5px solid #f59e0b;
  color: #ffffff !important;
}

.btn-gameover-sub.btn-gameover-exit {
  background: #7f1d1d;
  border: 1.5px solid #ef4444;
  color: #ffffff !important;
}

.btn-gameover-sub.btn-certificate {
  background: #047857;
  border: 1.5px solid #34d399;
  color: #ffffff !important;
}

.stamp-icon-large {
  font-size: 2.4rem;
  color: #27ae60;
}

.stamp-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: #27ae60;
}

.stamp-code {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: #2c3e50;
  font-family: monospace;
}

/* Modal Close Icon */
.modal-close-icon {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  background: rgba(44, 27, 18, 0.85);
  border: 2px solid var(--primary-gold);
  border-radius: 50%;
  color: var(--primary-gold);
  font-size: 1rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: transform 0.15s ease, background 0.15s ease;
}

.modal-close-icon:hover {
  transform: scale(1.1);
  background: #b91c1c;
  color: #fff;
}

/* =========================================================
   Grand Leaderboard Modal (Large Screen & Hall of Fame)
   ========================================================= */
.leaderboard-card {
  width: 95%;
  max-width: 820px;
  padding: 24px 22px;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.leaderboard-desc {
  font-size: 0.92rem;
  color: #5d4037;
  margin-top: -4px;
  margin-bottom: 12px;
  font-weight: 500;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

/* Player Personal Rank Status Banner */
.lb-player-status-banner {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 2px solid var(--primary-gold);
  border-radius: 6px;
  padding: 10px 16px;
  margin-bottom: 12px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
  color: #f1f5f9;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.lb-status-content {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
}

.lb-status-icon {
  font-size: 1.6rem;
}

.lb-status-text {
  font-size: 0.95rem;
  line-height: 1.4;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.lb-status-sub {
  font-size: 0.82rem;
  color: #94a3b8;
  margin-top: 2px;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.leaderboard-list-container {
  max-height: 350px;
  overflow-y: auto;
  border: 2px solid #8d5524;
  border-radius: 6px;
  background: #ffffff;
  margin-bottom: 12px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.12);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.leaderboard-table th {
  background: #2c1b12;
  color: var(--primary-gold);
  padding: 10px 10px;
  text-align: center;
  font-size: 0.82rem;
  font-family: 'Press Start 2P', 'Noto Sans Thai', 'Kanit', sans-serif;
  letter-spacing: 0.5px;
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 2px solid var(--primary-gold);
}

.leaderboard-table td {
  padding: 10px 10px;
  border-bottom: 1px solid #f0e6d2;
  text-align: center;
  vertical-align: middle;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.leaderboard-table tr:nth-child(even) {
  background: #fdfaf3;
}

.leaderboard-table tr:hover {
  background: #fdf3d8;
}

.leaderboard-table tr.current-player {
  background: #fff3c4;
  font-weight: bold;
  border-left: 5px solid #d35400;
}

.you-badge {
  display: inline-block;
  background: #d35400;
  color: #ffffff;
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 800;
  margin-left: 4px;
}

.col-rank {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.72rem;
  color: #555;
  white-space: nowrap;
}

.rank-1 .col-rank, .rank-1 .col-name { color: #b7791f; font-weight: 800; }
.rank-2 .col-rank, .rank-2 .col-name { color: #718096; font-weight: 800; }
.rank-3 .col-rank, .rank-3 .col-name { color: #a0522d; font-weight: 800; }

.lb-tier-pill {
  display: inline-block;
  padding: 3px 8px;
  background: #0f172a;
  border: 1.5px solid #ffd166;
  border-radius: 0;
  font-size: 0.72rem;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
  white-space: nowrap;
}

.lb-score-val {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.82rem;
  color: #b91c1c;
}

.col-dist {
  font-size: 0.8rem;
  color: #4a5568;
}

/* Pagination Controls */
.lb-pagination-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 8px;
}

.btn-page-nav {
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 700;
  border-radius: 4px;
  cursor: pointer;
}

.lb-page-indicator {
  font-size: 0.8rem;
  font-weight: 700;
  color: #4a3424;
  font-family: 'Press Start 2P', 'Kanit', sans-serif;
}

.leaderboard-actions {
  display: flex;
  gap: 12px;
}

.btn-back-title {
  flex: 2;
  font-size: 1.05rem;
  padding: 12px 16px;
}

.btn-reset {
  flex: 1;
  font-size: 0.8rem;
}

.tier-rank-badge {
  display: inline-block;
  margin: 6px auto 12px auto;
  padding: 6px 16px;
  background: #0f172a;
  border: 2px solid var(--primary-gold);
  border-radius: 6px;
  color: #ffd166;
  font-family: 'Press Start 2P', 'Kanit', sans-serif;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* =========================================================
   Certificate Button & Stamp Pass Modal
   ========================================================= */
.btn-certificate {
  background: linear-gradient(135deg, #1b4332 0%, #2d6a4f 50%, #40916c 100%);
  color: #d8f3dc;
  border: 2px solid #74c69d;
  font-size: 0.88rem;
  padding: 10px 12px;
  box-shadow: 0 0 15px rgba(82, 183, 136, 0.4);
  animation: glowGreen 2s infinite alternate;
}

@keyframes glowGreen {
  0% { box-shadow: 0 0 8px rgba(82, 183, 136, 0.3); }
  100% { box-shadow: 0 0 20px rgba(116, 198, 157, 0.8); }
}

.btn-certificate:hover {
  background: #2d6a4f;
  transform: translateY(-2px);
}

.cert-card {
  max-width: 600px;
  background: #fffdf5;
  border: 6px double #8d5524;
  border-radius: 8px;
  padding: 24px 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8), inset 0 0 20px rgba(141, 85, 36, 0.15);
  position: relative;
  text-align: center;
}

.cert-header {
  border-bottom: 2px dashed #caa87b;
  padding-bottom: 12px;
  margin-bottom: 14px;
  position: relative;
}

.cert-seal {
  position: absolute;
  top: -8px;
  right: 10px;
  width: 64px;
  height: 64px;
  background: radial-gradient(circle, #e63946 60%, #b7094c 100%);
  border-radius: 50%;
  border: 2px dashed #ffd166;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotate(12deg);
}

.seal-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.seal-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.seal-text {
  font-size: 0.5rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 1px;
}

.cert-badge-tag {
  display: inline-block;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.6rem;
  background: #2c1b12;
  color: #ffd166;
  padding: 4px 10px;
  border-radius: 3px;
  margin-bottom: 6px;
}

.cert-title {
  font-family: 'Press Start 2P', 'Kanit', cursive;
  font-size: 1.15rem;
  color: #872110;
  margin: 4px 0 2px 0;
  text-shadow: 1px 1px 0px #ffd166;
}

.cert-event-name {
  font-size: 0.8rem;
  color: #6b705c;
  font-weight: 600;
  margin: 0;
}

.cert-intro {
  font-size: 0.82rem;
  color: #555;
  margin: 8px 0 12px 0;
  line-height: 1.4;
}

.cert-player-box {
  background: linear-gradient(180deg, #fff3d6 0%, #ffe8b3 100%);
  border: 2px solid #b7791f;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 12px;
}

.cert-label {
  font-size: 0.72rem;
  color: #8d5524;
  text-transform: uppercase;
  font-weight: 700;
  display: block;
}

.cert-name-val {
  font-size: 1.35rem;
  color: #1a1005;
  margin: 2px 0 0 0;
  font-weight: 800;
}

.cert-metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.cert-metric-pill {
  background: rgba(255, 255, 255, 0.9);
  border: 1.5px solid #d4af37;
  border-radius: 6px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
}

.m-label {
  font-size: 0.65rem;
  color: #7f8c8d;
  font-weight: 600;
}

.m-val {
  font-size: 0.95rem;
  font-weight: 800;
  color: #2c3e50;
  font-family: 'Press Start 2P', 'Kanit', monospace;
  margin: 2px 0;
}

.score-highlight {
  color: #d35400;
}

.rank-highlight {
  color: #27ae60;
}

.m-target {
  font-size: 0.6rem;
  color: #27ae60;
  font-weight: bold;
}

.cert-code-section {
  background: linear-gradient(180deg, #f0fdf4 0%, #dcfce7 100%);
  border: 2.5px dashed #16a34a;
  border-radius: 8px;
  padding: 14px 12px;
  margin-bottom: 10px;
}

.cert-verified-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #15803d;
  color: #ffffff;
  padding: 8px 14px;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(22, 163, 74, 0.35);
  margin-bottom: 6px;
}

.cert-verified-icon {
  font-size: 1.25rem;
}

.cert-verified-text {
  font-size: 0.88rem;
  font-weight: 800;
  font-family: 'Press Start 2P', 'Kanit', sans-serif;
  letter-spacing: 0.5px;
}

.cert-staff-instruction {
  font-size: 0.82rem;
  color: #14532d;
  margin: 8px 0 4px 0;
  font-weight: 500;
}

.cert-date-text {
  font-size: 0.72rem;
  color: #4b5563;
}

/* =========================================================
   Responsive Design (Tablets & Mobile)
   ========================================================= */

/* Tablet Optimizations (iPad, Galaxy Tab, 768px - 1280px) */
@media (min-width: 768px) {
  /* Ergonomic Thumb Touch Controls for Tablet side grip */
  #touch-left {
    justify-content: flex-start;
    padding-left: 28px;
    padding-bottom: 24px;
  }
  #touch-right {
    justify-content: flex-end;
    padding-right: 28px;
    padding-bottom: 24px;
  }
  .touch-hint {
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 0.95rem;
    border-width: 1.5px;
  }
  .touch-icon {
    font-size: 1.4rem;
  }
  .touch-text {
    font-size: 0.9rem;
  }

  /* Tablet Modal Scaling */
  .modal-card {
    max-width: 680px;
    padding: 26px 24px;
  }
  .how-to-play-card {
    max-width: 740px;
  }
  .leaderboard-card {
    max-width: 820px;
  }
  .cert-card {
    max-width: 660px;
  }
  .tutorial-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .btn {
    min-height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* Tablet Landscape Fit (iPad 1024x768 / 1180x820) */
@media (min-width: 769px) and (max-width: 1200px) {
  .title-screen-container {
    padding: 24px 36px;
    max-width: 96%;
    gap: 24px;
  }
  .title-brand-panel {
    max-width: 480px;
  }
  .main-game-title {
    font-size: 1.85rem;
  }
  .sub-game-title {
    font-size: 1.25rem;
  }
  .game-tagline {
    font-size: 0.95rem;
    margin-bottom: 12px;
  }
  .title-action-panel {
    max-width: 330px;
  }
  .title-card-box {
    padding: 18px;
  }
  .btn-touch-play {
    font-size: 1.05rem;
    padding: 12px 14px;
  }
  .hud-top {
    gap: 12px;
  }
  .hud-item {
    padding: 4px 12px;
  }
  .hud-value {
    font-size: 1.25rem;
  }
}

/* Mobile Landscape Adjustments (Height <= 550px or Width <= 768px) */
@media (max-height: 550px) {
  .title-screen-container {
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
    padding: 14px 20px;
    text-align: left;
  }
  .title-brand-panel {
    text-align: left;
    align-items: flex-start;
    max-width: 52%;
    margin-bottom: 2px;
  }
  .main-game-title {
    font-size: 1.25rem;
    line-height: 1.2;
  }
  .sub-game-title {
    font-size: 0.9rem;
    line-height: 1.2;
    margin-bottom: 4px;
  }
  .game-tagline {
    font-size: 0.75rem;
  }
  .stamp-badge-preview {
    font-size: 0.68rem;
    padding: 2px 7px;
    margin-bottom: 3px;
  }
  .title-action-panel {
    max-width: 44%;
    margin-bottom: 0;
  }
  .title-card-box {
    padding: 10px 12px;
  }
  .title-btn-stack .btn {
    padding: 7px 10px;
    font-size: 0.82rem;
    margin-bottom: 4px;
  }
  .input-group {
    margin-bottom: 6px;
  }
  .input-group label {
    font-size: 0.75rem;
    margin-bottom: 2px;
  }
  .input-group input {
    padding: 4px 8px;
    font-size: 0.85rem;
  }
  .gameover-card {
    max-width: 440px;
    padding: 8px 12px;
    max-height: 96vh;
  }
  .gameover-card .modal-title {
    font-size: 1rem;
    margin-bottom: 2px;
  }
  .gameover-card .tier-rank-badge {
    font-size: 0.72rem;
    padding: 1px 6px;
    margin-bottom: 4px;
  }
  .gameover-card .stamp-banner {
    padding: 3px 8px;
    margin-bottom: 4px;
  }
  .gameover-card .gameover-stats {
    gap: 4px;
    margin-bottom: 6px;
  }
  .gameover-card .stat-pill {
    padding: 2px 4px;
  }
  .gameover-card .stat-title {
    font-size: 0.62rem;
  }
  .gameover-card .stat-num {
    font-size: 0.95rem;
  }
  .gameover-actions-grid {
    gap: 4px;
  }
  .btn-gameover-primary {
    font-size: 0.92rem;
    padding: 6px 10px;
  }
  .btn-gameover-sub {
    font-size: 0.74rem !important;
    padding: 5px 6px !important;
  }
}

@media (max-width: 480px) and (min-height: 551px) {
  .title-screen-container {
    flex-direction: column;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px;
    text-align: left;
  }
  .title-brand-panel {
    text-align: left;
    align-items: flex-start;
    max-width: 100%;
  }
  .main-game-title {
    font-size: 1.35rem;
  }
  .sub-game-title {
    font-size: 1rem;
  }
  .title-action-panel {
    max-width: 100%;
  }
}

/* =========================================================
   Exit / Standby Screen Modal & Exit Buttons
   ========================================================= */
.btn-title-exit,
.btn-gameover-exit {
  background: rgba(44, 27, 18, 0.85);
  border: 1.5px solid #ef4444;
  color: #fca5a5;
  transition: all 0.2s ease;
}

.btn-title-exit:hover,
.btn-gameover-exit:hover {
  background: #7f1d1d;
  color: #ffffff;
  border-color: #f87171;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
}

.exit-card {
  max-width: 440px;
  background: #fdfaf0;
  border: 3px solid #7f1d1d;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.85), 4px 4px 0px #000;
  padding: 24px 20px;
  text-align: center;
}

.exit-icon-wrap {
  position: relative;
  width: 70px;
  height: 70px;
  margin: 0 auto 10px auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.exit-big-icon {
  font-size: 3rem;
}

.exit-sub-icon {
  position: absolute;
  top: -4px;
  right: -2px;
  font-size: 1.5rem;
  animation: floatZzz 2s infinite ease-in-out;
}

@keyframes floatZzz {
  0% { transform: translateY(0px) scale(0.9); opacity: 0.7; }
  50% { transform: translateY(-6px) scale(1.1); opacity: 1; }
  100% { transform: translateY(0px) scale(0.9); opacity: 0.7; }
}

.exit-badge-tag {
  display: inline-block;
  background: #fef2f2;
  border: 1.5px solid #f87171;
  color: #991b1b;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 20px;
  margin: 6px 0 12px 0;
}

.exit-desc {
  font-size: 0.88rem;
  color: #475569;
  line-height: 1.5;
  margin-bottom: 20px;
}

.exit-btn-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.exit-btn-stack .btn {
  width: 100%;
  padding: 12px;
  font-size: 0.95rem;
}

/* =========================================================
   BOOTH STAGE DISPLAY SCREEN (Ctrl+9 Fullscreen Mode)
   ========================================================= */

#stage-screen {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  background-color: #06101e;
  overflow: hidden;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
  color: #fff;
}

#stage-screen.hidden {
  display: none !important;
}

.stage-screen-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: url('../assets/images/title_bg.jpg') center center/cover no-repeat;
  filter: none;
  transform: none;
  animation: none;
}

/* --- Main Layout Container (Full Viewport Height) --- */
.stage-layout-container {
  position: relative;
  z-index: 5;
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  padding: 18px 28px;
  box-sizing: border-box;
  width: 100vw;
  height: 100vh;
  gap: 28px;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

/* --- Left Panel (Branding Top-Left, Big QR Bottom-Left) --- */
.stage-left-panel {
  width: 320px;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  flex-shrink: 0;
}

/* --- Brand Box (Top-Left) --- */
.stage-brand-box {
  background: rgba(10, 25, 47, 0.94);
  border-left: 5px solid #f5b041;
  padding: 12px 16px;
  border-radius: 0 14px 14px 0;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.6);
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.stage-stamp-badge {
  display: inline-block;
  background: rgba(245, 176, 65, 0.25);
  border: 1.5px solid #f5b041;
  color: #ffd166;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
  margin-bottom: 6px;
}

.stage-main-title {
  font-size: 1.45rem;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.25;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
  margin: 0;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.stage-sub-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #ffd166;
  line-height: 1.25;
  margin: 2px 0 4px 0;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.stage-tagline {
  font-size: 0.85rem;
  color: #94a3b8;
  margin: 0;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

/* --- Grand QR Card (Bottom-Left, Enlarged) --- */
.stage-qr-card {
  position: relative;
  background: rgba(15, 23, 42, 0.95);
  border: 2px solid #d4af37;
  border-radius: 18px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.75), 0 0 20px rgba(212, 175, 55, 0.25);
  padding: 16px 18px;
  text-align: center;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.stage-qr-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  text-align: left;
}

.stage-qr-icon {
  font-size: 1.8rem;
}

.stage-qr-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: #ffd166;
  margin: 0;
  line-height: 1.2;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.stage-qr-subtitle {
  font-size: 0.82rem;
  color: #94a3b8;
}

.stage-qr-image-wrapper {
  position: relative;
  background: #ffffff;
  padding: 10px;
  border-radius: 14px;
  display: inline-block;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.3), inset 0 0 8px rgba(0, 0, 0, 0.15);
  margin-bottom: 12px;
}

.stage-qr-image {
  display: block;
  width: 240px;
  height: 240px;
  object-fit: contain;
  border-radius: 8px;
}

.stage-qr-footer {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stage-url-link {
  font-size: 1rem;
  font-weight: 700;
  color: #38bdf8;
  letter-spacing: 0.3px;
}

.stage-qr-hint {
  font-size: 0.82rem;
  color: #cbd5e1;
  line-height: 1.35;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

/* --- Right Panel (Expanded 30% Width for Grand High-Visibility Table) --- */
.stage-right-panel {
  width: 63%;
  max-width: 860px;
  min-width: 520px;
  height: 100%;
  display: flex;
  flex-direction: column;
  margin-left: auto;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.stage-leaderboard-card {
  flex: 1;
  background: rgba(15, 23, 42, 0.94);
  border: 2px solid rgba(212, 175, 55, 0.6);
  border-radius: 16px;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.75), 0 0 16px rgba(212, 175, 55, 0.2);
  padding: 14px 20px;
  display: flex;
  flex-direction: column;
  height: 100%;
  box-sizing: border-box;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

/* Header */
.stage-lb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1.5px solid rgba(255, 255, 255, 0.12);
  padding-bottom: 10px;
  margin-bottom: 10px;
}

.stage-lb-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stage-lb-trophy {
  font-size: 2.2rem;
  filter: drop-shadow(0 0 8px #f59e0b);
}

.stage-lb-title {
  font-size: 1.55rem;
  font-weight: 800;
  color: #ffffff;
  margin: 0;
  line-height: 1.15;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.stage-lb-session-info {
  font-size: 0.92rem;
  font-weight: 700;
  color: #ffd166;
  margin-top: 2px;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.stage-refresh-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(56, 189, 248, 0.15);
  border: 1.5px solid rgba(56, 189, 248, 0.45);
  color: #38bdf8;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 18px;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.stage-refresh-spinner {
  display: inline-block;
  animation: spinSlow 8s linear infinite;
}

@keyframes spinSlow {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Single-Column Grand Leaderboard Table (1 Rank per Row, High Visibility) */
.stage-table-wrapper {
  flex: 1;
  overflow-y: auto;
  margin-bottom: 8px;
  border-radius: 10px;
}

.stage-leaderboard-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 5px;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.stage-leaderboard-table th {
  background: rgba(30, 41, 59, 0.9);
  color: #94a3b8;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 8px 12px;
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 2px solid rgba(212, 175, 55, 0.5);
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.stage-table-row {
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  transition: all 0.2s ease;
}

.stage-table-row td {
  padding: 8px 12px;
  font-size: 1.05rem;
  vertical-align: middle;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.stage-table-row.rank-1 {
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.3), rgba(30, 41, 59, 0.9));
  border: 2px solid #ffd700;
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.3);
}

.stage-table-row.rank-2 {
  background: linear-gradient(90deg, rgba(148, 163, 184, 0.25), rgba(30, 41, 59, 0.9));
  border: 2px solid #cbd5e1;
}

.stage-table-row.rank-3 {
  background: linear-gradient(90deg, rgba(217, 119, 6, 0.25), rgba(30, 41, 59, 0.9));
  border: 2px solid #f97316;
}

.col-st-rank {
  text-align: center;
  width: 95px;
  white-space: nowrap;
}

.col-st-name {
  text-align: left;
}

.stage-player-name-text {
  font-size: 1.2rem;
  font-weight: 700;
  color: #ffffff;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.col-st-tier {
  text-align: center;
  width: 140px;
}

.stage-tier-badge {
  display: inline-block;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 0;
  border: 1.5px solid;
  white-space: nowrap;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.col-st-dist {
  text-align: right;
  font-size: 0.98rem;
  font-weight: 600;
  color: #38bdf8;
  width: 100px;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.col-st-stamp {
  text-align: center;
  width: 90px;
}

.stage-stamp-pass {
  color: #34d399;
  font-weight: 800;
  font-size: 0.95rem;
}

.stage-stamp-none {
  color: #64748b;
  font-size: 0.95rem;
}

.col-st-score {
  text-align: right;
  padding-right: 16px !important;
  width: 130px;
}

.stage-score-num {
  font-size: 1.25rem;
  font-weight: 800;
  color: #ffd166;
  font-family: 'Press Start 2P', 'Noto Sans Thai', 'Kanit', sans-serif;
}

.stage-table-row.rank-1 .stage-score-num {
  color: #ffd700;
  font-size: 1.45rem;
}

.stage-rank-pill {
  font-size: 1.05rem;
  font-weight: 800;
  color: #94a3b8;
  display: inline-block;
  min-width: 28px;
  text-align: center;
  white-space: nowrap;
}

.stage-medal {
  font-size: 1.02rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  letter-spacing: 0.5px;
  word-break: keep-all;
  line-height: 1.2;
}

.stage-medal.gold {
  background: #ffd700;
  color: #1e1b4b;
}

.stage-medal.silver {
  background: #e2e8f0;
  color: #0f172a;
}

.stage-medal.bronze {
  background: #f97316;
  color: #ffffff;
}

.stage-table-empty {
  padding: 50px 10px;
  text-align: center;
  color: #94a3b8;
  font-size: 1.15rem;
  line-height: 1.7;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

/* Stage Footer */
.stage-lb-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 10px;
  margin-top: 6px;
  font-size: 0.85rem;
  color: #94a3b8;
  font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
}

.stage-live-badge {
  color: #34d399;
  font-size: 0.85rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.admin-link-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  font-size: 0.75rem;
  color: #64748b;
  text-decoration: none;
  transition: color 0.2s;
}

.admin-link-badge:hover {
  color: #ffd166;
}

/* Refresh Glint Animation */
.stage-grid-wrapper.refresh-glint {
  animation: stageGlintAnim 0.6s ease-out;
}

@keyframes stageGlintAnim {
  0% { opacity: 0.65; transform: scale(0.995); }
  50% { opacity: 1; transform: scale(1.003); filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.4)); }
  100% { opacity: 1; transform: scale(1); filter: none; }
}

/* --- Archive History Modal --- */
.archive-modal-card {
  max-width: 680px;
  width: 90%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.archive-list-container {
  max-height: 50vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px;
}

.archive-card-item {
  background: #ffffff;
  border: 1.5px solid #d4af37;
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.archive-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
}

.archive-session-title {
  font-size: 1rem;
  font-weight: 800;
  color: #2c1b12;
}

.archive-timestamp {
  font-size: 0.78rem;
  color: #64748b;
}

.archive-summary {
  font-size: 0.82rem;
  color: #d97706;
  font-weight: 600;
}

.archive-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.archive-btn-download {
  background: #2563eb;
  color: #ffffff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}

.archive-btn-download:hover {
  background: #1d4ed8;
}

.archive-btn-delete {
  background: #fee2e2;
  color: #dc2626;
  border: 1px solid #f87171;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.82rem;
  cursor: pointer;
}

/* =========================================================
   Build Version Badge on Title Screen
   ========================================================= */
.build-version-tag {
  position: absolute;
  bottom: 8px;
  right: 12px;
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(255, 209, 102, 0.45);
  color: #ffd166;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.58rem;
  padding: 4px 8px;
  border-radius: 4px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.5px;
  backdrop-filter: blur(4px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.version-dot {
  width: 6px;
  height: 6px;
  background-color: #10b981;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 6px #10b981;
}

.archive-btn-delete:hover {
  background: #dc2626;
  color: #ffffff;
}

