/* ==========================================================================
   Flugel 2048 - Modern Responsive Dark Theme & Animation Stylesheet
   Zero dependencies, 100% static CSS3
   ========================================================================== */

:root {
  --bg-primary: #0b0f17;
  --bg-card: rgba(26, 32, 44, 0.85);
  --bg-board: #151c28;
  --bg-cell: #1e293b;
  --border-color: rgba(255, 255, 255, 0.08);
  --text-primary: #f8fafc;
  --text-muted: #94a3b8;
  --accent-gold: #f59e0b;
  --accent-purple: #8b5cf6;
  --accent-emerald: #10b981;
  --accent-rose: #f43f5e;

  /* Board sizing (responsive calculation) */
  --board-max-size: 460px;
  --board-size: min(90vw, var(--board-max-size));
  --grid-gap: clamp(8px, 2.2vw, 14px);
  --tile-size: calc((var(--board-size) - (var(--grid-gap) * 5)) / 4);
  --border-radius-board: 16px;
  --border-radius-tile: 10px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(at 0% 0%, rgba(139, 92, 246, 0.12) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(59, 130, 246, 0.1) 0px, transparent 50%);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 16px 12px 32px;
  overflow-x: hidden;
}

/* App Container */
.app-container {
  width: 100%;
  max-width: var(--board-max-size);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* Header Section */
.game-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.title-group {
  display: flex;
  flex-direction: column;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tutorial-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(139, 92, 246, 0.16);
  border: 1px solid rgba(139, 92, 246, 0.35);
  color: #c4b5fd;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1;
}

.tutorial-btn:hover {
  background: rgba(139, 92, 246, 0.3);
  border-color: rgba(139, 92, 246, 0.6);
  color: #ffffff;
  transform: translateY(-1px);
}

.game-title {
  font-size: clamp(34px, 8vw, 48px);
  font-weight: 900;
  letter-spacing: -1.5px;
  background: linear-gradient(135deg, #ffd700 0%, #f59e0b 50%, #ec4899 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1;
}

.title-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(139, 92, 246, 0.25);
  border: 1px solid rgba(139, 92, 246, 0.4);
  color: #c4b5fd;
  -webkit-text-fill-color: #c4b5fd;
  text-transform: uppercase;
}

.game-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Score Boxes */
.score-board {
  display: flex;
  gap: 8px;
}

.score-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 8px 12px;
  border-radius: 10px;
  min-width: 72px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.score-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.score-value {
  font-size: clamp(16px, 4vw, 20px);
  font-weight: 800;
  color: #ffffff;
  margin-top: 2px;
}

/* Floating score increment popup */
.score-addition {
  position: absolute;
  top: -6px;
  right: 8px;
  font-size: 14px;
  font-weight: 800;
  color: var(--accent-gold);
  opacity: 0;
  pointer-events: none;
}

.score-addition.active {
  animation: floatUpFade 600ms ease-out forwards;
}

@keyframes floatUpFade {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-24px) scale(1.15);
  }
}

/* Action Control Bar */
.control-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.control-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  transition: all 0.15s ease;
}

.control-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.control-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.control-btn:disabled,
.control-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-undo {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.25), rgba(59, 130, 246, 0.25));
  border-color: rgba(139, 92, 246, 0.4);
}

.btn-undo .ad-tag {
  font-size: 9px;
  font-weight: 800;
  padding: 2px 4px;
  background: #f59e0b;
  color: #000;
  border-radius: 4px;
  margin-left: 2px;
}

.btn-primary {
  background: #2563eb;
  border-color: #3b82f6;
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: #1d4ed8;
}

.sound-toggle.muted {
  color: var(--text-muted);
}

/* Game Board Wrapper & Grid */
.game-wrapper {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  background: var(--bg-board);
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius-board);
  box-shadow: 
    0 12px 30px rgba(0, 0, 0, 0.45),
    inset 0 1px 1px rgba(255, 255, 255, 0.08);
  touch-action: none; /* Prevent page scrolling on mobile swipe gestures */
  overflow: hidden;
}

.grid-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--grid-gap);
  padding: var(--grid-gap);
  width: 100%;
  height: 100%;
}

.grid-cell {
  background: var(--bg-cell);
  border-radius: var(--border-radius-tile);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Dynamic Tile Container & Tiles */
.tile-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.tile {
  position: absolute;
  width: var(--tile-size);
  height: var(--tile-size);
  border-radius: var(--border-radius-tile);
  display: flex;
  align-items: center;
  justify-content: center;
  /* Fluid sliding coordinate translation */
  transform: translate(
    calc(var(--tile-col) * (var(--tile-size) + var(--grid-gap)) + var(--grid-gap)),
    calc(var(--tile-row) * (var(--tile-size) + var(--grid-gap)) + var(--grid-gap))
  );
  transition: transform 110ms cubic-bezier(0.2, 0.9, 0.3, 1);
  will-change: transform;
}

.tile-inner {
  width: 100%;
  height: 100%;
  border-radius: var(--border-radius-tile);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: clamp(22px, 5.5vw, 32px);
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

/* Font scale adjustments for large digits */
.font-medium {
  font-size: clamp(18px, 4.5vw, 26px);
}

.font-small {
  font-size: clamp(15px, 3.8vw, 22px);
}

.font-tiny {
  font-size: clamp(12px, 3.2vw, 17px);
}

/* Tile Appearance & Neon Glows */
.tile-2 .tile-inner {
  background: #334155;
  color: #f1f5f9;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.tile-4 .tile-inner {
  background: #475569;
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.tile-8 .tile-inner {
  background: linear-gradient(135deg, #f97316, #ea580c);
  color: #ffffff;
  box-shadow: 0 0 14px rgba(249, 115, 22, 0.4);
}

.tile-16 .tile-inner {
  background: linear-gradient(135deg, #ff6b35, #e04812);
  color: #ffffff;
  box-shadow: 0 0 16px rgba(255, 107, 53, 0.45);
}

.tile-32 .tile-inner {
  background: linear-gradient(135deg, #f43f5e, #e11d48);
  color: #ffffff;
  box-shadow: 0 0 18px rgba(244, 63, 94, 0.5);
}

.tile-64 .tile-inner {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: #ffffff;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.6);
}

.tile-128 .tile-inner {
  background: linear-gradient(135deg, #fbbf24, #d97706);
  color: #ffffff;
  box-shadow: 0 0 22px rgba(251, 191, 36, 0.65);
}

.tile-256 .tile-inner {
  background: linear-gradient(135deg, #f59e0b, #b45309);
  color: #ffffff;
  box-shadow: 0 0 25px rgba(245, 158, 11, 0.75);
}

.tile-512 .tile-inner {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  box-shadow: 0 0 26px rgba(16, 185, 129, 0.8);
}

.tile-1024 .tile-inner {
  background: linear-gradient(135deg, #06b6d4, #0891b2);
  color: #ffffff;
  box-shadow: 0 0 28px rgba(6, 182, 212, 0.85);
}

.tile-2048 .tile-inner {
  background: linear-gradient(135deg, #a855f7, #7c3aed);
  color: #ffffff;
  box-shadow: 0 0 32px rgba(168, 85, 247, 0.9);
  animation: pulseGlow 2s infinite alternate ease-in-out;
}

.tile-super .tile-inner {
  background: linear-gradient(135deg, #ec4899, #8b5cf6, #3b82f6);
  color: #ffffff;
  box-shadow: 0 0 36px rgba(236, 72, 153, 0.9);
}

@keyframes pulseGlow {
  0% {
    box-shadow: 0 0 22px rgba(168, 85, 247, 0.7);
  }
  100% {
    box-shadow: 0 0 38px rgba(168, 85, 247, 1);
  }
}

/* Tile Animations */
.tile-new .tile-inner {
  animation: spawnPop 150ms cubic-bezier(0.175, 0.885, 0.32, 1.275) backwards;
}

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

.tile-merged .tile-inner {
  animation: mergePulse 180ms ease-in-out;
}

@keyframes mergePulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.18);
    filter: brightness(1.25);
  }
  100% {
    transform: scale(1);
  }
}

/* Vaporize animation when destroying 2s and 4s */
.tile-vaporize {
  animation: vaporizeDisintegrate 350ms forwards ease-out !important;
}

@keyframes vaporizeDisintegrate {
  0% {
    transform: translate(
      calc(var(--tile-col) * (var(--tile-size) + var(--grid-gap)) + var(--grid-gap)),
      calc(var(--tile-row) * (var(--tile-size) + var(--grid-gap)) + var(--grid-gap))
    ) scale(1);
    opacity: 1;
    filter: blur(0);
  }
  40% {
    filter: brightness(2) blur(1px);
    transform: translate(
      calc(var(--tile-col) * (var(--tile-size) + var(--grid-gap)) + var(--grid-gap)),
      calc(var(--tile-row) * (var(--tile-size) + var(--grid-gap)) + var(--grid-gap))
    ) scale(1.15);
  }
  100% {
    opacity: 0;
    transform: translate(
      calc(var(--tile-col) * (var(--tile-size) + var(--grid-gap)) + var(--grid-gap)),
      calc(var(--tile-row) * (var(--tile-size) + var(--grid-gap)) + var(--grid-gap))
    ) scale(0.2);
    filter: blur(8px);
  }
}

/* Instructions & Footer */
.game-footer {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.hint-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  text-align: center;
}

.hint-box strong {
  color: var(--text-primary);
}

.hint-keys {
  display: inline-flex;
  gap: 4px;
  vertical-align: middle;
}

.key-pill {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-color);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 11px;
  color: #ffffff;
}

/* ==========================================================================
   Modals & Overlays
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(8, 12, 20, 0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: #161f30;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.6);
  border-radius: 20px;
  width: 100%;
  max-width: 380px;
  padding: 24px;
  text-align: center;
  transform: scale(0.92);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

.modal-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 12px;
  text-transform: uppercase;
}

.badge-warning {
  background: rgba(245, 158, 11, 0.2);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: var(--accent-gold);
}

.badge-win {
  background: rgba(168, 85, 247, 0.2);
  border: 1px solid rgba(168, 85, 247, 0.4);
  color: #c4b5fd;
}

.modal-title {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 10px;
  color: #ffffff;
}

.modal-desc {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 20px;
}

.highlight-text {
  color: var(--accent-rose);
  font-weight: 700;
}

.highlight-revive {
  color: var(--accent-emerald);
  font-weight: 700;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-btn {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
}

.btn-revive-action {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.35);
}

.btn-revive-action:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

/* ==========================================================================
   Simulated Video Ad Overlay
   ========================================================================== */
.ad-player-box {
  width: 100%;
  background: #000000;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
  margin-bottom: 16px;
}

.ad-canvas {
  width: 100%;
  height: 190px;
  display: block;
}

.ad-video-header {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.ad-badge {
  font-size: 10px;
  font-weight: 800;
  padding: 3px 6px;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid;
  border-radius: 4px;
}

.ad-timer {
  font-size: 11px;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.7);
  padding: 3px 8px;
  border-radius: 6px;
  color: #ffffff;
}

.ad-progress-container {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
}

.ad-progress-bar {
  height: 100%;
  width: 0%;
  background: #f59e0b;
}

.ad-sponsor-info {
  margin-bottom: 16px;
}

.ad-sponsor-name {
  font-size: 16px;
  font-weight: 800;
  color: #ffffff;
}

.ad-sponsor-tagline {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.btn-claim-ad {
  background: #475569;
  color: #94a3b8;
  cursor: not-allowed;
}

.btn-claim-ad.active {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #000000;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(245, 158, 11, 0.45);
}

.btn-claim-ad.active:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.ad-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.ad-close-btn:hover {
  color: #ffffff;
}

/* Tutorial Modal & Instructions */
.tutorial-card {
  max-width: 440px;
  max-height: 88vh;
  overflow-y: auto;
  position: relative;
  text-align: left;
}

.modal-close-icon {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.modal-close-icon:hover {
  color: #ffffff;
}

.badge-info {
  background: rgba(6, 182, 212, 0.2);
  border: 1px solid rgba(6, 182, 212, 0.4);
  color: #67e8f9;
}

.tutorial-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.tutorial-step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  padding: 10px 12px;
  border-radius: 10px;
}

.step-icon {
  font-size: 20px;
  line-height: 1.2;
  flex-shrink: 0;
}

.step-text strong {
  font-size: 13px;
  color: var(--text-primary);
  display: block;
  margin-bottom: 2px;
}

.step-text p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
}

/* Footer Navigation & SEO Links */
.footer-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.seo-link {
  color: var(--text-muted);
  font-size: 12px;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s ease;
}

.seo-link:hover {
  color: #c4b5fd;
  text-decoration: underline;
}

.nav-divider {
  color: rgba(255, 255, 255, 0.2);
  font-size: 10px;
}

/* Footer Copyright */
.footer-copyright {
  text-align: center;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.4px;
  margin-top: 4px;
}

.copyright-link {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.15s ease;
}

.copyright-link:hover {
  color: var(--text-primary);
  text-decoration: underline;
}


