@font-face {
  font-family: 'Gilroy Heavy';
  src: url('fonts/Gilroy-Heavy.woff') format('woff2');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* ── TOKENS ────────────────────────────────────────────────────────────────── */
:root {
  --bg:        #0c0b14;
  --bg:        #40403f;
  --surface:   #171626;
  --surface2:  #201e33;
  --surface3:  #2a2845;
  --border:    rgba(255,255,255,0.07);
  --border-hi: rgba(255,255,255,0.14);

  --accent:    #ff6b6b;
  --accent2:   #feca57;
  --accent3:   #48dbfb;
  --accent4:   #ff9ff3;

  --text:      #f5f4ff;
  --text-muted:#8b8aaa;
  --text-dim:  #5c5b78;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-xl: 32px;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 8px 32px rgba(0,0,0,0.4);
  --shadow-lg: 0 24px 64px rgba(0,0,0,0.55);

  --font-display: 'Gilroy Heavy', system-ui, sans-serif;
  --font-body:    'Gilroy Heavy', system-ui, sans-serif;

  /* Board / canvas (matches btn-sound-circle + locked gray) */
  --board-shell-bg:     #575757;
  --board-shell-border: rgba(242, 242, 242, 0.28);
  --board-base:         #4a4a4a;
  --board-cell:         #575757;
  --board-accent:       #f3526b;

  /* Seamless tile (light pattern); tinted with overlay for dark UI */
  --bg-tile: url('images/tiledbackground.png');
  --bg-tile-overlay: linear-gradient(rgba(64, 64, 63, 0.88), rgba(64, 64, 63, 0.88));
  --bg-tile-overlay-modal: linear-gradient(rgba(64, 64, 63, 0.94), rgba(64, 64, 63, 0.94));
}

/* ── RESET ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
  overflow: hidden;
  position: fixed;
  width: 100%;
}

body {
  background-color: var(--bg);
  background-image: var(--bg-tile-overlay), var(--bg-tile);
  background-repeat: repeat, repeat;
  color: var(--text);
  font-family: var(--font-body);
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  padding-top:    env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left:   env(safe-area-inset-left);
  padding-right:  env(safe-area-inset-right);
}

/* ── BACKGROUND BLOBS ───────────────────────────────────────────────────────── */
/* .bg-blobs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.12;
  animation: blobDrift 18s ease-in-out infinite alternate;
}

.blob-1 {
  width: 500px; height: 500px;
  background: var(--accent);
  top: -120px; left: -120px;
  animation-duration: 20s;
}

.blob-2 {
  width: 400px; height: 400px;
  background: var(--accent3);
  bottom: -100px; right: -80px;
  animation-duration: 15s;
  animation-delay: -7s;
}

.blob-3 {
  width: 300px; height: 300px;
  background: var(--accent4);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  animation-duration: 25s;
  animation-delay: -12s;
}

@keyframes blobDrift {
  0%   { transform: translate(0, 0) scale(1); }
  100% { transform: translate(40px, 30px) scale(1.1); }
} */

/* ── APP SHELL ──────────────────────────────────────────────────────────────── */
.app-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 600px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 20px;
}

/* ── HEADER ─────────────────────────────────────────────────────────────────── */
.site-header {
  width: 100%;
  padding: 16px 20px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.logo {
  font-family: var(--font-display);
  font-size: 1.65rem;
  color: var(--text);
  letter-spacing: 0.5px;
  line-height: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.logo span {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo em {
  font-style: normal;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 3px;
  font-family: var(--font-body);
  font-weight: 800;
  background: linear-gradient(90deg, var(--accent3), var(--accent4));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  opacity: 0.9;
}

.header-stats {
  display: flex;
  gap: 10px;
}

.stat-pill {
  background: var(--board-shell-bg);
  border: 2px solid var(--board-shell-border);
  border-radius: var(--radius-md);
  padding: 6px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 58px;
}

.stat-label {
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: rgba(242, 242, 242, 0.62);
  font-weight: 700;
}

.stat-value {
  font-size: 1.05rem;
  font-weight: 900;
  color: #f2f2f2;
  line-height: 1;
}

@keyframes bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.4); color: var(--board-accent); }
  100% { transform: scale(1); }
}

.stat-value.bumping { animation: bump 0.25s ease; }

/* ── LEVEL BAR ──────────────────────────────────────────────────────────────── */
.level-bar {
  display: none;
  width: 100%;
  padding: 2px 20px 6px;
  align-items: center;
  gap: 12px;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}
.level-bar::-webkit-scrollbar { display: none; }

.level-bar-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-dim);
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.level-btns {
  display: flex;
  gap: 7px;
  flex-shrink: 0;
}

.lvl-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.18s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  outline: none;
}

/* Locked state */
.lvl-btn.locked {
  opacity: 0.35;
  cursor: not-allowed;
}

.lvl-btn.locked::before {
  content: '🔒';
  position: absolute;
  font-size: 0.6rem;
  top: -5px;
  right: -5px;
}

/* Completed state */
.lvl-btn.completed {
  border-color: rgba(78, 205, 196, 0.45);
  background: rgba(78, 205, 196, 0.08);
  color: #4ecdc4;
}

.lvl-btn.completed::after {
  content: '✓';
  position: absolute;
  top: -5px;
  right: -5px;
  width: 14px;
  height: 14px;
  background: #4ecdc4;
  border-radius: 50%;
  font-size: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0c0b14;
  font-weight: 900;
}

/* Active state */
.lvl-btn.active {
  border-color: var(--accent);
  background: rgba(255, 107, 107, 0.15);
  color: var(--accent);
  box-shadow: 0 0 18px rgba(255, 107, 107, 0.35);
}

.lvl-btn:hover:not(.locked):not(.active) {
  border-color: var(--border-hi);
  color: var(--text);
  transform: translateY(-2px);
}

/* ── INFO ROW ───────────────────────────────────────────────────────────────── */
.info-row {
  width: 100%;
  padding: 4px 20px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-shrink: 0;
}

.level-identity {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.level-name {
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: var(--text);
  line-height: 1;
}

.level-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.progress-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: min(130px, 100%);
  width: min(100%, 220px);
  max-width: 220px;
  margin-left: auto;
  margin-right: auto;
  background: var(--board-shell-bg);
  border: 2px solid var(--board-shell-border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
}

.progress-label {
  font-size: 0.65rem;
  color: rgba(242, 242, 242, 0.62);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  width: 100%;
  text-align: center;
}

.progress-track {
  width: 100%;
  height: 8px;
  background: var(--board-base);
  border-radius: 100px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.2);
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--board-accent), #ff6b8a);
  border-radius: 100px;
  transition: width 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 0 12px rgba(243, 82, 107, 0.35);
}

/* ── GAME AREA ──────────────────────────────────────────────────────────────── */
.game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
  gap: 14px;
  padding: 0 16px;
  width: 100%;
  flex: 1;
}

.canvas-shell {
  background: var(--board-shell-bg);
  border: 2px solid var(--board-shell-border);
  border-radius: var(--radius-lg);
  padding: 12px;
  /* box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.04); */
  position: relative;
  /* Prevent shell from growing beyond viewport */
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 240px);
  display: flex;
  align-items: center;
  justify-content: center;
}

#grid-canvas {
  display: block;
  border-radius: var(--radius-sm);
  touch-action: none;
  /* Canvas scales down if container constrains it */
  max-width: 100%;
  max-height: 100%;
}

/* ── CONTROLS ───────────────────────────────────────────────────────────────── */
.controls {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  border: none;
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  cursor: pointer;
  transition: all 0.18s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-ghost {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--border-hi);
  transform: translateY(-2px);
  background: var(--surface3);
}

.btn-primary {
  background: linear-gradient(135deg, #ff6b6b, #ee5a24);
  color: #fff;
  box-shadow: 0 4px 20px rgba(255, 107, 107, 0.4);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(255, 107, 107, 0.55);
}

.btn-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn:active:not(:disabled) { transform: scale(0.96); }

/* ── HINT TEXT ──────────────────────────────────────────────────────────────── */
.hint-text {
  display: none;
  font-size: 0.72rem;
  color: var(--text-dim);
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.5px;
}

/* ── WIN OVERLAY ────────────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 11, 20, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay.show { display: flex; }

#win-overlay.overlay {
  background-color: transparent;
  background-image: var(--bg-tile-overlay-modal), var(--bg-tile);
  background-repeat: repeat, repeat;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.win-card {
  background: var(--board-shell-bg);
  border: 2px solid var(--board-shell-border);
  border-radius: var(--radius-lg);
  padding: 28px 28px;
  text-align: center;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  animation: cardBounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  flex-shrink: 0;
  margin: auto;
}

@keyframes cardBounce {
  from { transform: scale(0.5) translateY(40px); opacity: 0; }
  to   { transform: scale(1) translateY(0);      opacity: 1; }
}

.win-burst {
  font-size: 3.5rem;
  margin-bottom: 12px;
  display: block;
  animation: burstSpin 0.6s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes burstSpin {
  from { transform: rotate(-20deg) scale(0); }
  to   { transform: rotate(0) scale(1); }
}

.win-title {
  font-family: var(--font-display);
  font-size: 2.4rem;
  color: #f2f2f2;
  line-height: 1;
  margin-bottom: 6px;
}

.win-subtitle {
  color: rgba(242, 242, 242, 0.65);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 20px;
}

/* Stars */
.stars {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 24px;
}

.star {
  font-size: 2.2rem;
  filter: grayscale(1) opacity(0.25);
  transition: filter 0.2s;
}

.star.lit {
  filter: none;
  animation: starPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes starPop {
  from { transform: scale(0) rotate(-30deg); }
  to   { transform: scale(1) rotate(0); }
}

/* Win stats */
.win-stats {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0;
  background: var(--board-base);
  border: 2px solid var(--board-shell-border);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  margin-bottom: 28px;
}

.win-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.win-stat-divider {
  width: 1px;
  height: 36px;
  background: rgba(242, 242, 242, 0.15);
  flex-shrink: 0;
}

.win-stat-val {
  font-family: var(--font-display);
  font-size: 1.9rem;
  color: #f2f2f2;
  line-height: 1;
}

.win-stat-lbl {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: rgba(242, 242, 242, 0.55);
  font-weight: 700;
}

.win-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

#win-overlay .win-actions .btn-ghost {
  background: var(--board-base);
  color: rgba(242, 242, 242, 0.85);
  border: 2px solid var(--board-shell-border);
}

#win-overlay .win-actions .btn-ghost:hover {
  color: #fff;
  filter: brightness(1.1);
  transform: translateY(-1px);
}

#win-overlay .win-actions .btn-primary {
  background: linear-gradient(90deg, var(--board-accent), #ff6b8a);
  border: 2px solid rgba(242, 242, 242, 0.28);
  color: #fff;
  box-shadow: 0 0 16px rgba(243, 82, 107, 0.35);
}

#win-overlay .win-actions .btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
  box-shadow: 0 0 22px rgba(243, 82, 107, 0.45);
}

/* ── PARTICLES ──────────────────────────────────────────────────────────────── */
.particle {
  position: fixed;
  pointer-events: none;
  z-index: 300;
  border-radius: 50%;
  animation: particleFly var(--dur) ease-out forwards;
}

@keyframes particleFly {
  0%   { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

/* ── RESPONSIVE: PORTRAIT SMALL ─────────────────────────────────────────────── */
@media (max-width: 400px) {
  .site-header   { padding: 12px 14px 8px; }
  .logo          { font-size: 1.35rem; }
  .level-bar     { padding: 2px 14px 4px; }
  .lvl-btn       { width: 30px; height: 30px; font-size: 0.72rem; }
  .info-row      { padding: 2px 14px 6px; }
  .level-name    { font-size: 1.1rem; }
  .game-area     { padding: 0 10px; gap: 10px; }
  .canvas-shell  { padding: 8px; border-radius: var(--radius-md); }
  .controls      { gap: 7px; }
  .btn           { padding: 8px 14px; font-size: 0.75rem; }
  .hint-text     { font-size: 0.65rem; }
}

/* ── RESPONSIVE: LANDSCAPE (any height under 500px) ─────────────────────────── */
@media (orientation: landscape) and (max-height: 500px) {
  .app-shell {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    max-width: 100%;
    padding-bottom: 8px;
  }

  /* Left column: header + level bar + info stacked */
  .site-header {
    width: 200px;
    flex-direction: column;
    align-items: flex-start;
    padding: 10px 12px 6px;
    gap: 8px;
    flex-shrink: 0;
  }

  .header-stats {
    flex-direction: row;
    gap: 8px;
  }

  .stat-pill {
    padding: 4px 10px;
    min-width: 48px;
  }

  .level-bar {
    width: 200px;
    padding: 2px 12px 4px;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 5px;
  }

  .level-bar-label { display: none; }

  .lvl-btn { width: 28px; height: 28px; font-size: 0.68rem; }

  .info-row {
    width: 200px;
    flex-direction: column;
    align-items: center;
    padding: 2px 12px 6px;
    gap: 6px;
    flex-shrink: 0;
  }

  .progress-wrap {
    align-items: center;
    min-width: unset;
    width: min(100%, 220px);
  }

  .progress-track { width: 100%; }

  /* Right column: canvas + controls */
  .game-area {
    flex: 1;
    padding: 6px 12px 6px 8px;
    gap: 8px;
    min-width: 0;
    justify-content: center;
  }

  .canvas-shell {
    padding: 8px;
    border-radius: var(--radius-md);
    max-height: calc(100vh - 24px);
  }

  .controls { gap: 8px; }

  .btn {
    padding: 7px 12px;
    font-size: 0.72rem;
    gap: 5px;
  }

  .btn svg { width: 13px; height: 13px; }

  .hint-text { display: none; }

  /* Win card compact in landscape */
  .win-card {
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    max-width: 520px;
  }

  .win-burst    { font-size: 2rem; margin-bottom: 0; flex-shrink: 0; }
  .win-title    { font-size: 1.6rem; }
  .win-subtitle { font-size: 0.78rem; margin-bottom: 8px; }
  .stars        { margin-bottom: 8px; }
  .star         { font-size: 1.6rem; }
  .win-stats    { padding: 10px 14px; margin-bottom: 12px; }
  .win-stat-val { font-size: 1.4rem; }
  .win-burst, .win-title, .win-subtitle, .stars, .win-stats, .win-actions {
    width: 100%;
  }
}

/* ── RESPONSIVE: LANDSCAPE MEDIUM (500–700px height) ────────────────────────── */
@media (orientation: landscape) and (min-height: 500px) and (max-height: 700px) {
  .site-header  { padding: 10px 20px 8px; }
  .level-bar    { padding: 2px 20px 4px; }
  .lvl-btn      { width: 32px; height: 32px; }
  .info-row     { padding: 2px 20px 6px; }
  .game-area    { gap: 10px; }
  .canvas-shell { max-height: calc(100vh - 220px); }
  .win-card     { padding: 20px 24px; }
  .win-burst    { font-size: 2.4rem; }
  .win-title    { font-size: 1.8rem; }
  .stars        { margin-bottom: 14px; }
  .win-stats    { margin-bottom: 16px; }
}

/* ══════════════════════════════════════════════════════════════════════════════
   LEVEL SELECT (after splash)
   ══════════════════════════════════════════════════════════════════════════════ */

.level-select-screen {
  position: fixed;
  inset: 0;
  z-index: 1001;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  background-color: var(--bg);
  background-image: var(--bg-tile-overlay), var(--bg-tile);
  background-repeat: repeat, repeat;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.level-select-screen.is-visible {
  display: flex;
}

.level-select-title {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 5vw, 2rem);
  color: var(--text);
  text-align: center;
  letter-spacing: 0.02em;
}

.level-select-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  max-width: 440px;
}

.level-select-screen .level-select-item.btn-sound-circle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
}

.level-select-screen .level-select-item svg {
  grid-area: unset;
  display: block;
}

.level-select-num {
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1;
  color: inherit;
}

.level-select-item--locked .level-select-num {
  display: none;
}

.level-select-key {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: #fff;
}

.level-select-screen .level-select-key svg {
  width: 26px;
  height: 26px;
}

.level-select-screen .level-select-item--locked.btn-sound-circle {
  background: #575757;
  border-color: rgba(242, 242, 242, 0.35);
}

.level-select-item--locked {
  cursor: not-allowed;
}

/* ══════════════════════════════════════════════════════════════════════════════
   SPLASH SCREEN
   ══════════════════════════════════════════════════════════════════════════════ */

/* ── Base ── */
.splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: var(--bg);
  background-image: var(--bg-tile-overlay), var(--bg-tile);
  background-repeat: repeat, repeat;
  overflow: hidden;
  transition: opacity 0.7s ease, visibility 0.7s ease;
}

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

/* ── Animated pipe-grid background canvas ── */
.splash-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.12;
}

#splash-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Center content ── */
.splash-center {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 48px;
}

/* ── Title block ── */
.splash-title-wrap {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.splash-pre {
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 4px;
  color: rgba(242, 242, 242, 0.5);
  opacity: 0;
  animation: splashFadeUp 0.6s ease 0.2s forwards;
}

.splash-title {
  font-family: var(--font-display);
  font-size: clamp(3rem, 12vw, 6rem);
  color: #f2f2f2;
  line-height: 1;
  letter-spacing: -1px;
  opacity: 0;
  animation: splashFadeUp 0.7s cubic-bezier(0.22, 1, 0.36, 1) 0.4s forwards;
  text-shadow: 0 4px 32px rgba(243, 82, 107, 0.28);
}

.splash-title span {
  background: linear-gradient(135deg, var(--board-accent), #ff6b8a);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.splash-subtitle {
  font-family: var(--font-body);
  font-size: clamp(0.75rem, 3vw, 1.1rem);
  font-weight: 900;
  letter-spacing: clamp(4px, 2vw, 10px);
  text-transform: uppercase;
  color: rgba(242, 242, 242, 0.72);
  opacity: 0;
  animation: splashFadeUp 0.7s ease 0.65s forwards;
}

/* ── Loading bar ── */
.splash-loader-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: clamp(220px, 55vw, 380px);
  opacity: 0;
  animation: splashFadeUp 0.5s ease 0.9s forwards;
}

.splash-bar-track {
  width: 100%;
  height: 8px;
  background: var(--board-base);
  border-radius: 100px;
  border: 1px solid rgba(0, 0, 0, 0.22);
  overflow: visible;
  position: relative;
}

.splash-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--board-accent), #ff6b8a);
  border-radius: 100px;
  transition: width 0.08s linear;
  position: relative;
  z-index: 1;
  box-shadow: 0 0 12px rgba(243, 82, 107, 0.35);
}

/* Moving glow at the tip of the bar */
.splash-bar-glow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--board-accent);
  filter: blur(8px);
  opacity: 0.95;
  left: 0%;
  transition: left 0.08s linear;
  pointer-events: none;
}

.splash-pct {
  font-family: var(--font-display);
  font-size: 1rem;
  color: rgba(242, 242, 242, 0.55);
  letter-spacing: 2px;
  min-width: 3.5ch;
  text-align: center;
  transition: color 0.3s;
}

.splash-pct.done {
  color: var(--board-accent);
}

/* ── Y8 logo – bottom right ── */
.splash-y8 {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
  right: max(20px, env(safe-area-inset-right, 20px));
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  opacity: 0;
  animation: splashFadeUp 0.5s ease 1.1s forwards;
}

.splash-y8-label {
  font-family: var(--font-body);
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: rgba(242, 242, 242, 0.45);
}

.splash-y8-logo {
  height: 36px;
  width: auto;
  image-rendering: pixelated; /* keeps the pixel-art logo crisp */
  opacity: 0.9;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.5));
  transition: opacity 0.2s, transform 0.2s;
}

.splash-y8-logo:hover {
  opacity: 1;
  transform: scale(1.05);
}

/* ── Keyframes ── */
@keyframes splashFadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Mobile tweaks for splash ── */
@media (max-width: 400px) {
  .splash-center  { gap: 36px; }
  .splash-y8-logo { height: 28px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .splash-center  { gap: 20px; flex-direction: row; align-items: center; }
  .splash-title-wrap { text-align: left; }
  .splash-title   { font-size: clamp(2rem, 8vh, 3.5rem); }
  .splash-subtitle { font-size: 0.7rem; letter-spacing: 5px; }
  .splash-loader-wrap { width: clamp(160px, 30vw, 280px); }
  .splash-y8-logo { height: 26px; }
  .splash-y8      { bottom: max(12px, env(safe-area-inset-bottom, 12px)); right: max(12px, env(safe-area-inset-right, 12px)); }
}

/* ══════════════════════════════════════════════════════════════════════════════
   NEW FEATURES: Sound toggle, Hint button, Shake, Keyboard hint, Connected glow
   ══════════════════════════════════════════════════════════════════════════════ */

/* ── Sound icon button ── */
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: color 0.18s, background 0.18s;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.btn-icon svg {
  width: 20px;
  height: 20px;
  display: block;
}

.btn-icon:hover {
  color: var(--text);
  background: var(--surface2);
}

.btn-sound-circle {
  width: 50px;
  height: 50px;
  padding: 0;
  border: 2px solid #f2f2f2;
  border-radius: 100%;
  background: #f3526b;
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  transition: filter 0.18s ease, transform 0.15s ease;
}

.btn-sound-circle:hover:not(:disabled):not(.hint-exhausted) {
  filter: brightness(1.08);
}

.btn-sound-circle:active:not(:disabled):not(.hint-exhausted) {
  transform: scale(0.96);
}

.btn-sound-circle svg {
  display: block;
  grid-area: 1 / 1;
}

.btn-sound-circle-lg {
  width: 64px;
  height: 64px;
}

/* Game controls: same circle style; flex + badge so hint count fits */
.controls .btn-sound-circle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.controls .btn-sound-circle svg {
  grid-area: unset;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.controls .btn-sound-circle-lg svg {
  width: 28px;
  height: 28px;
}

.controls .btn-sound-circle .hint-count {
  position: absolute;
  bottom: 3px;
  right: 3px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  font-size: 0.62rem;
  font-weight: 900;
  line-height: 18px;
  text-align: center;
  color: #f3526b;
  background: #fff;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.controls .btn-sound-circle-lg .hint-count {
  bottom: 5px;
  right: 5px;
  min-width: 20px;
  height: 20px;
  line-height: 20px;
  font-size: 0.65rem;
}

.controls .btn-sound-circle:disabled,
.controls .btn-sound-circle.hint-exhausted {
  opacity: 0.35;
  cursor: not-allowed;
  filter: none;
  transform: none;
  box-shadow: none;
}

/* ── Canvas shake animation (invalid move) ── */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  15%      { transform: translateX(-5px); }
  30%      { transform: translateX(5px); }
  45%      { transform: translateX(-4px); }
  60%      { transform: translateX(4px); }
  75%      { transform: translateX(-2px); }
  90%      { transform: translateX(2px); }
}

.canvas-shell.shake {
  animation: shake 0.38s ease;
}

/* ── Keyboard shortcut hint ── */
.kb-hint {
  display: none;
  font-size: 0.65rem;
  color: var(--text-dim);
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.3px;
  opacity: 0.7;
}

/* Hide keyboard hint on touch-primary devices */
@media (hover: none) and (pointer: coarse) {
  .kb-hint { display: none; }
}

/* ── Landscape adjustments for new controls ── */
@media (orientation: landscape) and (max-height: 500px) {
  .kb-hint  { display: none; }
}

/* ══════════════════════════════════════════════════════════════════════════════
   HOW TO PLAY MODAL (matches board: gray shell + pink accent)
   ══════════════════════════════════════════════════════════════════════════════ */

#howto-overlay.overlay {
  background-color: transparent;
  background-image: var(--bg-tile-overlay-modal), var(--bg-tile);
  background-repeat: repeat, repeat;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.howto-card {
  background: var(--board-shell-bg);
  border: 2px solid var(--board-shell-border);
  border-radius: var(--radius-lg);
  padding: 32px 28px 28px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.25) transparent;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  animation: cardBounce 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

.howto-card::-webkit-scrollbar { width: 4px; }
.howto-card::-webkit-scrollbar-track { background: transparent; }
.howto-card::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.25); border-radius: 2px; }

/* Close button */
.howto-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--board-base);
  border: 2px solid var(--board-shell-border);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  color: rgba(242, 242, 242, 0.85);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.18s ease, color 0.18s ease;
  outline: none;
  line-height: 1;
}

.howto-close:hover {
  color: #fff;
  filter: brightness(1.12);
}

/* Header */
.howto-header {
  text-align: center;
  margin-bottom: 24px;
}

.howto-icon {
  font-size: 2.4rem;
  margin-bottom: 8px;
  display: block;
  animation: burstSpin 0.5s cubic-bezier(0.34,1.56,0.64,1);
}

.howto-title {
  font-family: var(--font-display);
  font-size: 1.9rem;
  color: #f2f2f2;
  line-height: 1;
  margin-bottom: 4px;
}

.howto-game-name {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 3px;
  color: rgba(242, 242, 242, 0.55);
}

/* Sections */
.howto-sections {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-bottom: 24px;
}

.howto-section {
  background: var(--board-base);
  border: 2px solid var(--board-shell-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.howto-section-label {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: rgba(242, 242, 242, 0.62);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.howto-section-icon {
  font-size: 0.9rem;
}

/* Key rows */
.howto-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.howto-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.howto-keys {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
  min-width: 90px;
}

#howto-overlay kbd {
  background: var(--board-shell-bg);
  border: 2px solid var(--board-shell-border);
  border-bottom-width: 2px;
  border-radius: 6px;
  color: #f2f2f2;
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 4px 8px;
  white-space: nowrap;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.howto-desc {
  font-size: 0.78rem;
  color: rgba(242, 242, 242, 0.72);
  font-weight: 600;
  line-height: 1.4;
}

/* Objective color dots */
.howto-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  border: 2px solid rgba(242, 242, 242, 0.25);
}

.howto-fill-icon {
  font-size: 1rem;
  opacity: 0.65;
}

/* Rules list */
.howto-rules {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.howto-rule {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.78rem;
  color: rgba(242, 242, 242, 0.72);
  font-weight: 600;
  line-height: 1.4;
}

.howto-rule-dot {
  color: var(--board-accent);
  font-size: 1rem;
  line-height: 1.2;
  flex-shrink: 0;
}

/* Play button */
.howto-play-btn {
  width: 100%;
  justify-content: center;
  padding: 14px;
  font-size: 0.95rem;
  background: linear-gradient(90deg, var(--board-accent), #ff6b8a) !important;
  border: 2px solid rgba(242, 242, 242, 0.28) !important;
  color: #fff !important;
  box-shadow: 0 0 16px rgba(243, 82, 107, 0.35);
}

.howto-play-btn:hover:not(:disabled) {
  filter: brightness(1.06);
  box-shadow: 0 0 22px rgba(243, 82, 107, 0.45);
}

/* Mobile */
@media (max-width: 400px) {
  .howto-card     { padding: 24px 18px 20px; }
  .howto-keys     { min-width: 76px; }
  .howto-desc     { font-size: 0.72rem; }
  .howto-rule     { font-size: 0.72rem; }
}

/* Compact landscape */
@media (orientation: landscape) and (max-height: 500px) {
  .howto-card     { padding: 16px 20px 16px; max-height: 95vh; }
  .howto-header   { margin-bottom: 14px; }
  .howto-icon     { font-size: 1.6rem; margin-bottom: 4px; }
  .howto-title    { font-size: 1.4rem; }
  .howto-sections { gap: 10px; }
  .howto-section  { padding: 10px 12px; }
}
