:root {
  --bg-1: #80CCFF;
  --bg-2: #99D9F2;
  --bg-3: #B3E6FF;
  --bg-4: #CCF2FF;
  --text: rgba(0, 0, 0, 0.8);
  --white: #fff;
  --star: #FFCC00;
  --round-button: rgba(140, 92, 56, 0.85);
  --difficulty-card: rgba(0, 122, 255, 0.85);
  --splash-name: rgb(51, 77, 153);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Segoe UI", Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-1);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.app { position: fixed; inset: 0; }

/* ---- Background (port of WoodenBackgroundView) ---- */
.background {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden;
  background: linear-gradient(135deg, var(--bg-1), var(--bg-2) 33%, var(--bg-3) 66%, var(--bg-4));
}
.background__shapes { position: absolute; inset: 0; opacity: 0.25; }
.background__shape { position: absolute; width: 1em; height: 1em; }
.background__glow {
  position: absolute; inset: 0;
  background: radial-gradient(circle at top left, rgba(255,255,255,0.1), transparent 500px);
}

/* ---- Screens ---- */
.screen {
  position: absolute; inset: 0;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  opacity: 1; transition: opacity 250ms ease-in-out;
}
.screen.is-leaving, .screen.is-entering { opacity: 0; pointer-events: none; }

button {
  font: inherit; color: inherit; background: none; border: 0; padding: 0;
  cursor: pointer; touch-action: manipulation;
}
button:disabled { cursor: default; }

.icon { display: inline-block; width: 1em; height: 1em; fill: currentColor; vertical-align: middle; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; color: var(--text); }

.screen__title {
  margin: 0; color: var(--white); font-weight: 700; text-align: center;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* ---- Round brown buttons (reshuffle / back) ---- */
.round-button {
  position: absolute; top: calc(var(--safe-top) + 48px);
  width: 96px; height: 96px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--round-button); color: var(--white); font-size: 56px;
  box-shadow: 0 3px 6px rgba(0,0,0,0.4);
  z-index: 10; /* above the frame, which comes later in tree order */
}
.round-button--restart { right: calc(var(--safe-right) + 16px); }
.round-button--back { left: calc(var(--safe-left) + 16px); }
.round-button:active { transform: scale(0.95); }

.star-row { display: flex; gap: 3px; justify-content: center; font-size: 16px; }
.star-row__on { color: var(--star); }
.star-row__off { color: rgba(255,255,255,0.4); }

/* ---- Splash ---- */
.splash {
  background: linear-gradient(135deg, var(--bg-1), var(--bg-3) 50%, var(--bg-4));
  justify-content: space-between; padding-top: calc(var(--safe-top) + 24px); padding-bottom: calc(var(--safe-bottom) + 12px);
}
.splash__content { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; }
.splash__logo {
  opacity: 0; transform: scale(0.5);
  transition: transform 800ms cubic-bezier(0.34, 1.56, 0.64, 1) 200ms, opacity 800ms ease 200ms;
}
.splash__name {
  font-size: 42px; font-weight: 700; color: var(--splash-name);
  opacity: 0; transition: opacity 600ms ease-in 700ms;
}
.splash__credits {
  font-size: 11px; text-align: center; color: rgba(51, 77, 128, 0.55);
  padding: 0 24px; max-width: 600px; opacity: 0; transition: opacity 600ms ease-in 700ms;
}
.splash.is-animated .splash__logo { opacity: 1; transform: scale(1); }
.splash.is-animated .splash__name, .splash.is-animated .splash__credits { opacity: 1; }

/* ---- Gallery ---- */
.gallery { justify-content: flex-start; gap: 12px; padding-top: calc(var(--safe-top) + 20px); }
.gallery__title { font-size: 42px; }
.gallery__scroll { flex: 1; width: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.gallery__grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px;
  padding: 10px 20px 10px;
}
.gallery__tile {
  position: relative; aspect-ratio: 1 / 1; border-radius: 20px;
  background: rgba(255,255,255,0.9); box-shadow: 0 5px 10px rgba(0,0,0,0.2);
  display: flex; align-items: center; justify-content: center;
}
/* Absolute sizing resolves against the tile's box, not an aspect-ratio-derived height. */
.gallery__image {
  position: absolute; left: 5%; top: 5%; width: 90%; height: 90%;
  object-fit: cover; border-radius: 15px; pointer-events: none;
}
.gallery__tile:active { transform: scale(0.97); }
.gallery__footer {
  flex: none; font-size: 13px; line-height: 1.4; text-align: center; color: rgba(51, 77, 128, 0.85);
  padding: 6px 20px calc(var(--safe-bottom) + 8px);
}
.gallery__footer a { color: inherit; text-decoration: underline; }

/* ---- Difficulty ---- */
.difficulty { gap: 24px; padding: 32px; }
.difficulty__preview {
  width: 260px; height: 260px; border-radius: 24px; padding: 8px;
  background: rgba(255,255,255,0.9); box-shadow: 0 5px 10px rgba(0,0,0,0.2);
}
.difficulty__preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 18px; }
.difficulty__title { font-size: 32px; }
.difficulty__options {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; width: 100%; max-width: 520px; padding: 0 24px;
}
.difficulty__option {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 24px 0;
  border-radius: 20px; background: var(--difficulty-card); color: var(--white);
  box-shadow: 0 3px 6px rgba(0,0,0,0.25);
}
.difficulty__option:active { transform: scale(0.97); }
.difficulty__label { font-size: 30px; font-weight: 800; }

/* ---- Game ---- */
.game { padding: 0; }
.frame {
  position: relative; padding: 15px; border-radius: 20px; background: var(--white);
  box-shadow: 0 5px 10px rgba(0,0,0,0.3);
}
.board { position: relative; overflow: hidden; }
.board__reference { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; pointer-events: none; }
.board__tiles { position: absolute; inset: 0; }
.board__lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; stroke: rgba(255,255,255,0.8); }

/* game.js writes the full transform (position, plus scale(0.3) while hidden), so
   the reveal grows the tile in and a drop eases it onto its slot. */
.tile {
  position: absolute; left: 0; top: 0; touch-action: none; cursor: grab;
  background-repeat: no-repeat; will-change: transform;
  opacity: 1; filter: brightness(0.9);
  transition-property: transform, opacity, filter; transition-timing-function: ease-in-out;
  transition-duration: var(--tile-reveal-ms, 400ms);
}
.tile__shade { position: absolute; inset: 0; background: rgba(0,0,0,0.25); pointer-events: none; }
.tile.is-locked { filter: none; pointer-events: none; }
.tile.is-locked .tile__shade { display: none; }
.tile.is-hidden { opacity: 0; pointer-events: none; }
/* A dragged tile follows the finger with no easing. */
.tile.is-dragging { cursor: grabbing; transition: none; }
.board__tiles.is-reshuffling .tile:not(.is-dragging) { transition-property: transform, opacity, filter; transition-duration: 300ms; }
.game.is-won .tile { pointer-events: none; }

/* ---- Celebration ---- */
.celebration { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; z-index: 5; }
.celebration__snake-star, .celebration__burst-star { position: absolute; left: 0; top: 0; width: 1em; height: 1em; }
.celebration__snake-star { filter: drop-shadow(0 0 6px #FFCC00) drop-shadow(0 0 3px #fff); }
.celebration__burst-star { filter: drop-shadow(0 0 3px rgba(255,204,0,0.5)); }
.celebration__message {
  position: absolute; left: 50%; top: 50%; width: 90%; text-align: center;
  font-weight: 900; color: var(--white);
  text-shadow: 0 0 4px #000, 0 0 10px #FFCC00;
  transform: translate(-50%, -50%) scale(0.1); opacity: 0;
  transition: transform 600ms cubic-bezier(0.34, 1.56, 0.64, 1), opacity 200ms ease;
}
.celebration__message.is-shown { transform: translate(-50%, -50%) scale(1); opacity: 1; }
