@font-face {
  font-family: 'Outfit';
  src: url('assets/fonts/Outfit-VariableFont_wght.ttf') format('truetype-variations');
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  /* Palette-driven colour scheme. JS (game.js) overrides these RGB triplets each
     playthrough by picking one of the cozy palettes ported from the iOS app.
     Defaults below are the "Forest" palette so the very first paint is cozy. */
  --accent-rgb: 74, 222, 128;
  --accent-deep-rgb: 42, 143, 82;
  --secondary-rgb: 140, 230, 180;
  --bg-rgb: 12, 20, 16;
  --panel-rgb: 22, 34, 27;

  --bg-color: rgb(var(--bg-rgb));
  --panel-bg: rgba(var(--panel-rgb), 0.75);
  --border-color: rgba(var(--accent-rgb), 0.15);
  --accent-color: rgb(var(--accent-rgb));
  --accent-deep-color: rgb(var(--accent-deep-rgb));
  --accent-glow: rgba(var(--accent-rgb), 0.4);
  --cyan-color: rgb(var(--secondary-rgb));
  --cyan-glow: rgba(var(--secondary-rgb), 0.4);
  --text-primary: #f5f2ff;
  --text-secondary: #a49cb5;
  --shadow-color: rgba(0, 0, 0, 0.6);
  --card-border: 1px solid rgba(var(--accent-rgb), 0.15);
}

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

html {
  height: 100%;
  background: var(--bg-color);
}

body {
  font-family: 'Outfit', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-height: 100%;
  height: 100dvh;
  overflow: auto;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(var(--accent-rgb), 0.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(var(--secondary-rgb), 0.08) 0%, transparent 50%);
}

.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(448px, calc(100vw - 24px));
  width: clamp(280px, min(calc(100vw - 24px), calc((100dvh - 213px) * 0.6923077)), 448px);
  max-width: 100%;
  padding: max(8px, env(safe-area-inset-top)) 0 max(8px, env(safe-area-inset-bottom));
}

/* Native-matching SlothByte splash. The logo screen is deliberately independent
   of the active game palette. */
.dev-splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #171b24;
  opacity: 1;
  transition: opacity 0.8s ease-out;
  cursor: pointer;
}

.dev-splash.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.dev-logo {
  display: block;
  width: min(300px, 74vw);
  height: min(300px, 74vw);
  object-fit: contain;
  opacity: 0;
  filter: drop-shadow(0 0 30px rgba(224, 214, 185, 0.3));
  animation: dev-logo-in 0.8s ease-out forwards;
}

.skip-hint {
  position: absolute;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 0;
  width: 100%;
  color: #595959;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-align: center;
  animation: skip-pulse 0.9s ease-in-out infinite alternate;
}

@keyframes dev-logo-in {
  to { opacity: 1; }
}

@keyframes skip-pulse {
  from { opacity: 0.35; }
  to { opacity: 0.9; }
}

.game-header {
  width: 100%;
  margin-bottom: 12px;
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: var(--card-border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 32px var(--shadow-color);
}

.logo {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 3px;
  text-align: center;
  margin-bottom: 12px;
  color: var(--text-primary);
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

.logo .highlight {
  color: var(--accent-color);
  text-shadow: 0 0 12px var(--accent-glow);
}

.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr 80px;
  gap: 8px;
}

.stat-box {
  background: rgba(0, 0, 0, 0.35);
  border-radius: 8px;
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(var(--accent-rgb), 0.08);
}

.stat-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 1px;
  margin-bottom: 2px;
}

.stat-value {
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
}

.preview-box {
  padding: 4px;
}

.next-preview-container {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--accent-color);
  box-shadow: 0 0 12px var(--accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.next-tile-val {
  font-size: 0.9rem;
  font-weight: 800;
  color: white;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 450 / 650;
  background: var(--panel-bg);
  border: var(--card-border);
  border-radius: 20px;
  box-shadow: 0 12px 40px var(--shadow-color);
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}

/* Overlays */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(var(--bg-rgb), 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  transition: opacity 0.3s ease;
}

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

.overlay-content {
  width: 85%;
  text-align: center;
  padding: 30px 20px;
  background: rgba(var(--panel-rgb), 0.95);
  border: 1px solid var(--accent-color);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
  transform: translateY(0);
  transition: transform 0.3s ease;
}

.overlay.hidden .overlay-content {
  transform: translateY(20px);
}

.overlay-content h2 {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 2px;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--cyan-color) 0%, var(--accent-color) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 15px rgba(var(--accent-rgb), 0.3);
}

.overlay-content p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.final-score-container {
  background: rgba(0, 0, 0, 0.4);
  padding: 12px 20px;
  border-radius: 12px;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid rgba(var(--accent-rgb), 0.1);
}

.final-score-container span:first-child {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.final-score-container span:last-child {
  font-size: 1.6rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 10px rgba(var(--accent-rgb), 0.5);
}

.how-to-play {
  text-align: left;
  margin-bottom: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.step {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.02);
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(var(--accent-rgb), 0.05);
}

.step .icon {
  font-size: 1.2rem;
}

.step .desc {
  font-size: 0.85rem;
  color: var(--text-primary);
}

.glow-button {
  width: 100%;
  background: linear-gradient(135deg, var(--accent-color) 0%, var(--accent-deep-color) 100%);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px 24px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 20px var(--accent-glow);
  transition: all 0.2s ease;
  letter-spacing: 1px;
}

.glow-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(var(--accent-rgb), 0.6);
}

.glow-button:focus-visible,
.icon-button:focus-visible,
.menu-button:focus-visible {
  outline: 2px solid var(--cyan-color);
  outline-offset: 3px;
}

.glow-button:active {
  transform: translateY(1px);
}

/* Secondary button (e.g. NEW GAME shown under CONTINUE) */
.glow-button.secondary {
  background: var(--panel-bg);
  color: var(--text-primary);
  border: var(--card-border);
  box-shadow: none;
  margin-top: 12px;
}

.glow-button.secondary:hover {
  background: rgba(var(--accent-rgb), 0.1);
  box-shadow: 0 0 10px var(--accent-glow);
}

.glow-button.hidden {
  display: none;
}

.game-footer {
  width: 100%;
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 8px;
}

.footer-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  background: var(--panel-bg);
  border: var(--card-border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 1.1rem;
  transition: all 0.2s ease;
}

.icon-button:hover {
  background: rgba(var(--accent-rgb), 0.1);
  transform: scale(1.05);
  box-shadow: 0 0 10px var(--accent-glow);
}

.menu-button {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
  background: var(--panel-bg);
  border: var(--card-border);
  border-radius: 999px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.menu-button span:first-child {
  font-family: sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
  transform: translateY(-1px);
}

.menu-button:hover {
  color: var(--text-primary);
  background: rgba(var(--accent-rgb), 0.1);
  box-shadow: 0 0 10px var(--accent-glow);
}

[hidden] {
  display: none !important;
}

.controls-info {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

@media (max-height: 740px), (max-width: 340px) {
  .game-container {
    width: min(448px, calc(100vw - 16px));
    width: clamp(250px, min(calc(100vw - 16px), calc((100dvh - 166px) * 0.6923077)), 448px);
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .game-header {
    margin-bottom: 8px;
    padding: 8px 10px;
  }

  .logo {
    margin-bottom: 6px;
    font-size: 1.05rem;
  }

  .stat-box {
    padding: 3px 6px;
  }

  .game-footer {
    margin-top: 8px;
  }

  .overlay-content {
    width: 90%;
    padding: 18px 14px;
  }

  .overlay-content p {
    margin-bottom: 14px;
  }

  .how-to-play {
    gap: 6px;
    margin-bottom: 16px;
  }

  .step {
    padding: 7px 10px;
  }

  .controls-info {
    font-size: 0.65rem;
    letter-spacing: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
