/* ═══════════════════════════════════════════════════════════════════
   zenPuzzles — Zen Garden Theme
   ═══════════════════════════════════════════════════════════════════ */

/* ─── Variables ──────────────────────────────────────────────────── */
:root {
  --bg: #F5F0E8;
  --card-bg: #FAF8F5;
  --card-shadow: rgba(0, 0, 0, 0.06);
  --card-shadow-hover: rgba(0, 0, 0, 0.1);

  --pipe-wall: #3D4152;
  --pipe-empty: #FFFFFF;
  --pipe-water: #5B8DEF;

  --btn-primary: #5B8DEF;
  --btn-primary-hover: #4A7CE0;
  --btn-secondary: #E8ECF0;
  --btn-secondary-hover: #DDE2E8;

  --text-primary: #2C3E50;
  --text-secondary: #3D5364;
  --text-muted: #486070;

  --tile-bg: transparent;
  --tile-hover: rgba(91, 141, 239, 0.06);

  --win-bg: rgba(76, 175, 130, 0.12);
  --win-accent: #4CAF82;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;

  --font: 'Proxima Nova', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --rotate-speed: 0.2s;
}

/* ─── Fonts ──────────────────────────────────────────────────────── */
@font-face {
  font-family: 'Proxima Nova';
  src: url('../fonts/Proxima-Nova-Thin.otf') format('opentype');
  font-weight: 300;
  font-style: normal;
}
@font-face {
  font-family: 'Proxima Nova';
  src: url('../fonts/Proxima-Nova-Regular.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
}
@font-face {
  font-family: 'Proxima Nova';
  src: url('../fonts/Proxima-Nova-Semibold.otf') format('opentype');
  font-weight: 600;
  font-style: normal;
}

/* ─── Dynamic Text Scaling (PWA readability) ────────────────────── */
html {
  font-size: clamp(16px, 5vw, 22px);
}

/* ─── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
}

html, body {
  height: 100%;
  overflow: auto;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font-family: var(--font);
  cursor: pointer;
  border: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

/* ─── Screens ────────────────────────────────────────────────────── */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  overflow-y: auto;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#screen-game.active {
  overflow-y: auto;
}

/* ═══════════════════════════════════════════════════════════════════
   HOME SCREEN
   ═══════════════════════════════════════════════════════════════════ */
.home-container {
  width: 100%;
  max-width: 480px;
  padding: 60px 24px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.home-logo {
  text-align: center;
  margin-bottom: 48px;
}

.logo-text {
  font-size: 2.8rem;
  font-weight: 300;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.logo-accent {
  font-weight: 600;
}

.logo-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
  letter-spacing: 1px;
}

/* Copyright */
.home-copyright {
  margin-top: 32px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
}

/* Build info footer */
.build-footer {
  position: fixed;
  bottom: 4px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.5;
  pointer-events: none;
  z-index: 1;
}

/* Puzzle cards */
.puzzle-cards {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.puzzle-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: 0 2px 8px var(--card-shadow);
  transition: box-shadow 0.2s ease, transform 0.15s ease;
  cursor: pointer;
}

.puzzle-card:hover {
  box-shadow: 0 4px 16px var(--card-shadow-hover);
  transform: translateY(-1px);
}

.puzzle-card:active {
  transform: scale(0.98);
}

.puzzle-card-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.puzzle-card-icon svg {
  width: 32px;
  height: 32px;
}

.puzzle-card-info {
  flex: 1;
}

.puzzle-card-name {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.puzzle-card-desc {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.puzzle-card-arrow {
  color: var(--text-muted);
  font-size: 1.2rem;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════════
   SETUP SCREEN
   ═══════════════════════════════════════════════════════════════════ */
.setup-container {
  width: 100%;
  max-width: 480px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.back-btn {
  align-self: flex-start;
  background: none;
  color: var(--btn-primary);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 8px 0;
  margin-bottom: 24px;
}

.setup-icon {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-lg);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.setup-icon svg {
  width: 48px;
  height: 48px;
}

.setup-title {
  font-size: 1.6rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.setup-desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.5;
  margin-bottom: 32px;
  max-width: 320px;
}

.size-selector {
  width: 100%;
  margin-bottom: 1.2rem;
}

.size-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: lowercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.6rem;
  text-align: center;
}

.size-options {
  display: flex;
  gap: 2.5vw;
  justify-content: center;
  width: 100%;
}

.size-btn {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 0.3rem;
  border-radius: var(--radius-md);
  background: var(--card-bg);
  box-shadow: 0 2px 8px var(--card-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.size-btn:hover {
  box-shadow: 0 4px 12px var(--card-shadow-hover);
}

.size-btn.selected {
  background: var(--btn-primary);
  box-shadow: 0 4px 16px rgba(91, 141, 239, 0.3);
}

.size-btn-label {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.size-btn.selected .size-btn-label {
  color: white;
}

.size-btn-sub {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.size-btn.selected .size-btn-sub {
  color: rgba(255, 255, 255, 0.7);
}

/* Best stats */
.best-stats {
  width: 100%;
  text-align: center;
  margin-bottom: 24px;
  min-height: 24px;
}

.best-stats-text {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.best-stats-text span {
  font-weight: 600;
  color: var(--text-secondary);
}

/* Play button */
.play-btn {
  width: 100%;
  max-width: 280px;
  padding: 16px;
  background: var(--btn-primary);
  color: white;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: background 0.15s ease, transform 0.1s ease;
}

.play-btn:hover {
  background: var(--btn-primary-hover);
}

.play-btn:active {
  transform: scale(0.97);
}

/* Seed input on setup screen */
.seed-input-wrap {
  width: 100%;
  max-width: 280px;
  margin-top: 12px;
  text-align: center;
}

.seed-input {
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 0.88rem;
  color: var(--text-primary);
  background: var(--card-bg);
  border: 1.5px solid var(--btn-secondary);
  border-radius: var(--radius-sm);
  text-align: center;
  outline: none;
  transition: border-color 0.15s ease;
}

.seed-input:focus {
  border-color: var(--btn-primary);
}

.seed-input::placeholder {
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* How to play link on setup screen */
.how-to-play-btn {
  background: none;
  color: var(--btn-primary);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 12px 0 0;
  transition: color 0.15s ease;
}

.how-to-play-btn:hover {
  color: var(--btn-primary-hover);
}

/* ═══════════════════════════════════════════════════════════════════
   GAME SCREEN
   ═══════════════════════════════════════════════════════════════════ */
.game-header {
  width: 100%;
  max-width: 600px;
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
}

.game-header .back-btn {
  margin-bottom: 0;
  font-size: 1.2rem;
  padding: 8px;
}

.game-title {
  flex: 1;
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
}

.game-seed {
  font-size: 0.72rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background 0.15s ease;
  font-variant-numeric: tabular-nums;
}

.game-seed:hover {
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.04);
}

.game-help-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  flex-shrink: 0;
  transition: color 0.15s;
}

.game-help-btn:hover {
  color: var(--text-primary);
}

.game-timer {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  text-align: right;
}

/* Board */
.game-board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5vw;
  width: 100%;
}

.game-board {
  display: grid;
  gap: 0;
  max-width: 90vw;
  max-height: 100%;
}

.tile {
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.tile:hover {
  background: var(--tile-hover);
}

.tile:active {
  transform: scale(0.92);
}

.tile svg {
  width: 100%;
  height: 100%;
  display: block;
  transition: transform var(--rotate-speed) ease;
}

/* Wall layer — always dark */
.tile .pipe-wall { stroke: var(--pipe-wall); stroke-width: 12; stroke-linecap: butt; fill: none; }
.tile .pipe-wall-dot { fill: var(--pipe-wall); stroke: none; }

/* Channel layer — white by default, blue when connected */
.tile .pipe-channel { stroke: var(--pipe-empty); stroke-width: 5; stroke-linecap: butt; fill: none; transition: stroke 0.3s ease; }
.tile .pipe-channel-dot { fill: var(--pipe-empty); transition: fill 0.3s ease; }

/* Connected — only channel turns blue, walls stay dark */
.tile.connected .pipe-channel { stroke: var(--pipe-water); }
.tile.connected .pipe-channel-dot { fill: var(--pipe-water); }

/* Source indicator */
.pipe-source { fill: #E74C3C; stroke: none; }

/* Faint grid for pipes */
.pipes-grid .tile { border: 1px solid rgba(0, 0, 0, 0.05); }

/* Toolbar */
.game-toolbar {
  width: 100%;
  max-width: 600px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px 16px 24px;
}

.toolbar-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 48px;
}

.toolbar-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.toolbar-value {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.toolbar-btn {
  padding: 10px 20px;
  background: var(--btn-secondary);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.toolbar-btn:hover {
  background: var(--btn-secondary-hover);
}

.toolbar-btn:active {
  transform: scale(0.96);
}

.toolbar-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.toolbar-btn:disabled:hover {
  background: var(--btn-secondary);
}

.toolbar-btn:disabled:active {
  transform: none;
}

/* ═══════════════════════════════════════════════════════════════════
   WIN OVERLAY
   ═══════════════════════════════════════════════════════════════════ */
.win-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(245, 240, 232, 0.92);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.3s ease;
}

.win-overlay.active {
  display: flex;
}

.win-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  max-width: 360px;
  width: 100%;
  animation: slideUp 0.4s ease;
}

.win-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--win-bg);
  color: var(--win-accent);
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.win-title {
  font-size: 1.6rem;
  font-weight: 600;
  margin-bottom: 24px;
}

.win-stats {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-bottom: 16px;
}

.win-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.win-stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.win-stat-value {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.win-best {
  min-height: 24px;
  margin-bottom: 24px;
}

.win-best-text {
  font-size: 0.82rem;
  color: var(--win-accent);
  font-weight: 600;
}

.win-seed {
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  transition: color 0.15s ease, background 0.15s ease;
  font-variant-numeric: tabular-nums;
}

.win-seed:hover {
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.04);
}

.win-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.win-actions .play-btn {
  max-width: 240px;
}

.win-actions .toolbar-btn {
  background: none;
  color: var(--btn-primary);
}

/* Solved banner — sits at bottom of game screen, lets player admire the board */
.solved-banner {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card-bg);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 50;
  animation: slideUpBanner 0.4s ease;
}

.solved-banner span {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--win-accent);
}

@keyframes slideUpBanner {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════════════
   PAUSE OVERLAY
   ═══════════════════════════════════════════════════════════════════ */
.pause-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(245, 240, 232, 0.96);
  z-index: 90;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.pause-overlay.active {
  display: flex;
}

.pause-card {
  text-align: center;
}

.pause-icon {
  font-size: 3rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.pause-title {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* ═══════════════════════════════════════════════════════════════════
   ABOUT / RULES
   ═══════════════════════════════════════════════════════════════════ */
.about-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 32px;
  height: 32px;
  background: none;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease;
}

.about-btn:hover {
  color: var(--text-secondary);
}

.rules-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(245, 240, 232, 0.94);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.3s ease;
  overflow-y: auto;
}

.rules-overlay.active {
  display: flex;
}

.rules-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 36px 28px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  max-width: 400px;
  width: 100%;
  position: relative;
  animation: slideUp 0.4s ease;
}

.rules-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  background: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease;
}

.rules-close:hover {
  color: var(--text-primary);
}

.rules-title {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 24px;
}

.rules-section {
  margin-bottom: 20px;
}

.rules-section:last-child {
  margin-bottom: 0;
}

.rules-heading {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.rules-text {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.rules-tiles {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.rules-tile-example {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.rules-tile-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.rules-tile-icon svg {
  width: 40px;
  height: 40px;
}

.rules-tile-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.rules-list {
  list-style: none;
  padding: 0;
}

.rules-list li {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
  padding-left: 16px;
  position: relative;
}

.rules-list li::before {
  content: '\2022';
  color: var(--pipe-water);
  position: absolute;
  left: 0;
}

/* ═══════════════════════════════════════════════════════════════════
   SAND SORT
   ═══════════════════════════════════════════════════════════════════ */
.sand-tube {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 4px 2px;
  transition: transform 0.2s ease, background 0.15s ease;
}

.sand-tube:active {
  transform: none;
}

.sand-tube.sand-selected {
  transform: translateY(-8px);
}

.sand-tube.sand-selected .sand-glass {
  stroke: var(--btn-primary);
}

.sand-tube.sand-sorted .sand-glass {
  stroke: var(--win-accent);
}

.sand-vessel-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.sand-glass {
  stroke: var(--pipe-wall);
  stroke-width: 3;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 0.3s ease;
}

.sand-drop {
  animation: sandDrop 0.25s ease-out;
}

@keyframes sandDrop {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Pour stream animation */
.sand-stream {
  position: fixed;
  border-radius: 3px;
  pointer-events: none;
  z-index: 200;
  will-change: width, height, opacity;
  opacity: 1;
}

.sand-pouring .sand-glass {
  stroke: var(--btn-primary);
}

.sand-pour-target .sand-glass {
  stroke: var(--btn-primary);
  filter: drop-shadow(0 0 4px rgba(91, 141, 239, 0.3));
}

/* ═══════════════════════════════════════════════════════════════════
   CHROMA PUZZLE
   ═══════════════════════════════════════════════════════════════════ */
.chroma-tile {
  border-radius: 2px;
  aspect-ratio: 1;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.1s ease;
  position: relative;
}

.chroma-tile:active {
  transform: scale(0.95);
}

.chroma-tile.chroma-selected {
  transform: translateY(-4px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  outline: 2px solid white;
  outline-offset: -2px;
  z-index: 5;
}

.chroma-tile.chroma-fixed::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  transform: translate(-50%, -50%) rotate(45deg);
  background: rgba(255, 255, 255, 0.7);
}

/* Dark tiles get a white diamond, light tiles get a dark diamond */
.chroma-tile.chroma-fixed {
  cursor: default;
}

.chroma-shake {
  animation: chromaShake 0.3s ease;
}

@keyframes chromaShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

/* Hint highlight */
.chroma-tile.chroma-hint {
  outline: 3px solid #2196F3;
  outline-offset: -3px;
  z-index: 5;
  animation: chromaHintPulse 1.2s ease infinite;
}

@keyframes chromaHintPulse {
  0%, 100% { outline-color: #2196F3; }
  50% { outline-color: #90CAF9; }
}

/* Board gap for chroma */
.game-board:has(.chroma-tile) {
  gap: 1px;
}

/* ═══════════════════════════════════════════════════════════════════
   LOGIN
   ═══════════════════════════════════════════════════════════════════ */
.login-card {
  max-width: 340px;
}

.login-step {
  text-align: center;
}

.login-status {
  font-size: 0.82rem;
  color: #DC3545;
  margin-top: 10px;
  min-height: 20px;
}

.login-account-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
  align-items: center;
}

/* ═══════════════════════════════════════════════════════════════════
   STATS SCREEN
   ═══════════════════════════════════════════════════════════════════ */
/* User / Login button */
.user-btn {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 32px;
  height: 32px;
  background: none;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease;
}

.user-btn:hover {
  color: var(--text-secondary);
}

.user-initial {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--btn-primary);
  color: white;
  font-size: 0.82rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stats-btn {
  position: absolute;
  top: 20px;
  left: 60px;
  width: 32px;
  height: 32px;
  background: none;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease;
}

.stats-btn:hover {
  color: var(--text-secondary);
}

.stats-container {
  width: 100%;
  max-width: 480px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stats-page-title {
  font-size: 1.6rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.stats-total {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

.stats-grid {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.stats-section {
  width: 100%;
}

.stats-section-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  text-transform: lowercase;
}

.stats-row {
  display: grid;
  grid-template-columns: 100px 1fr 1fr 1fr;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  align-items: center;
}

.stats-row:last-child {
  border-bottom: none;
}

.stats-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

.stats-value {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════════════════ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 400px) {
  .home-container {
    padding: 40px 16px 32px;
  }

  .logo-text {
    font-size: 2.2rem;
  }

  .puzzle-card {
    padding: 20px;
    gap: 16px;
  }

  .size-btn {
    padding: 0.2rem;
  }

  .game-toolbar {
    gap: 12px;
  }

  .toolbar-btn {
    padding: 10px 14px;
    font-size: 0.8rem;
  }
}

/* Tall phones: center board better */
@media (min-height: 700px) {
  .game-board-wrap {
    padding: 5vw;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   GAME-OVER OVERLAY
   ═══════════════════════════════════════════════════════════════════ */
.gameover-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(245, 240, 232, 0.92);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.3s ease;
}

.gameover-overlay.active {
  display: flex;
}

.gameover-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  max-width: 360px;
  width: 100%;
  animation: slideUp 0.4s ease;
}

.gameover-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(220, 53, 69, 0.12);
  color: #DC3545;
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.gameover-title {
  font-size: 1.6rem;
  font-weight: 600;
  margin-bottom: 24px;
}

.gameover-score-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.gameover-score-value {
  font-size: 2rem;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  margin-bottom: 8px;
}

.gameover-best {
  min-height: 24px;
  margin-bottom: 24px;
}

.gameover-best-text {
  font-size: 0.82rem;
  color: var(--win-accent);
  font-weight: 600;
}

.gameover-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.gameover-actions .play-btn {
  max-width: 240px;
}

.gameover-actions .toolbar-btn {
  background: none;
  color: var(--btn-primary);
}

/* ═══════════════════════════════════════════════════════════════════
   NINE PUZZLE
   ═══════════════════════════════════════════════════════════════════ */
.nine-cell {
  border: 0.5px solid rgba(0, 0, 0, 0.08);
  border-radius: 1px;
  transition: background-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.nine-cell:active {
  transform: none;
}

.nine-cell.nine-region-right {
  border-right: 2px solid rgba(0, 0, 0, 0.18);
}

.nine-cell.nine-region-bottom {
  border-bottom: 2px solid rgba(0, 0, 0, 0.18);
}

.nine-cell.nine-filled {
  border-radius: 2px;
}

.nine-cell.nine-ghost {
  background-color: var(--ghost-color, rgba(91, 141, 239, 0.25)) !important;
  opacity: 0.5;
}

.nine-cell.nine-clear {
  animation: nineClearFlash 0.3s ease;
}

@keyframes nineClearFlash {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.5; background-color: var(--win-accent); }
  100% { transform: scale(1); opacity: 1; background-color: transparent; }
}

/* Nine toolbar */
.nine-toolbar {
  flex-wrap: wrap;
  gap: 12px;
}

.nine-score-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 48px;
}

.nine-score-value {
  font-size: 1.4rem;
}

.nine-target-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: -2px;
}

.nine-block-tray {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nine-block-slot {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nine-block {
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 6px var(--card-shadow);
  cursor: pointer;
  padding: 4px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.nine-block:hover {
  box-shadow: 0 3px 10px var(--card-shadow-hover);
}

.nine-block.nine-block-selected {
  transform: translateY(-4px);
  box-shadow: 0 6px 16px rgba(91, 141, 239, 0.3);
  outline: 2px solid var(--btn-primary);
}

.nine-block-used {
  opacity: 0;
}

.nine-block-grid {
  display: grid;
  gap: 1px;
  width: 100%;
  height: 100%;
}

.nine-preview-cell {
  aspect-ratio: 1;
  border-radius: 1px;
}

.nine-preview-filled {
  border-radius: 2px;
}

/* ═══════════════════════════════════════════════════════════════════
   CAIRN PUZZLE
   ═══════════════════════════════════════════════════════════════════ */
.cairn-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
}

.cairn-toolbar {
  flex-direction: column;
  gap: 8px;
}

.cairn-skill-bar {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
}

.cairn-skill-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 6px;
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 4px var(--card-shadow);
  cursor: pointer;
  min-width: 40px;
  transition: all 0.15s ease;
}

.cairn-skill-btn:hover {
  box-shadow: 0 2px 8px var(--card-shadow-hover);
}

.cairn-skill-btn.cairn-skill-selected {
  background: var(--btn-primary);
  box-shadow: 0 3px 10px rgba(91, 141, 239, 0.3);
}

.cairn-skill-btn.cairn-skill-selected .cairn-skill-label,
.cairn-skill-btn.cairn-skill-selected .cairn-skill-count {
  color: white;
}

.cairn-skill-btn.cairn-skill-empty {
  opacity: 0.35;
  cursor: default;
}

.cairn-skill-label {
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.3px;
}

.cairn-skill-count {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.cairn-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* Cairn level select grid */
.cairn-level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  margin-top: 8px;
}

.cairn-level-btn {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 6px var(--card-shadow);
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 4px;
}

.cairn-level-btn:hover {
  box-shadow: 0 3px 10px var(--card-shadow-hover);
}

.cairn-level-btn.selected {
  background: var(--btn-primary);
  box-shadow: 0 4px 16px rgba(91, 141, 239, 0.3);
}

.cairn-level-btn.completed {
  border: 2px solid var(--win-accent);
}

.cairn-level-btn.locked {
  opacity: 0.35;
  cursor: default;
}

.cairn-level-num {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.cairn-level-btn.selected .cairn-level-num {
  color: white;
}

.cairn-level-btn.locked .cairn-level-num {
  color: var(--text-muted);
}

.cairn-level-star {
  font-size: 0.65rem;
  color: var(--win-accent);
}

/* ─── Arrows Puzzle ─────────────────────────────────────────────── */

.arrows-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
}

.arrows-svg line,
.arrows-svg polyline {
  stroke-width: 0.15;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.arrows-svg polygon,
.arrows-svg circle {
  stroke: none;
}

.arrows-svg g {
  transition: opacity 0.2s;
}

.arrows-svg g.arrows-shake {
  animation: arrows-shake 0.4s ease-in-out;
}

@keyframes arrows-shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(0.08, 0); }
  40% { transform: translate(-0.08, 0); }
  60% { transform: translate(0.06, 0); }
  80% { transform: translate(-0.04, 0); }
}

.arrows-tile {
  position: relative;
  z-index: 1;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.arrows-tile:hover {
  background: none;
}

.arrows-tile.arrows-empty {
  cursor: default;
}

.arrows-tile.arrows-escapable {
  cursor: pointer;
}

.arrows-tile.arrows-escapable:hover {
  background: rgba(91, 141, 239, 0.10);
  border-radius: 2px;
}

.arrows-tile:active {
  transform: none;
}

/* ─── Peaks Puzzle ─── */
.peaks-grid .tile {
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.peaks-tile svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.peaks-line {
  stroke: var(--pipe-wall);
  stroke-width: 3;
  stroke-linecap: round;
}

.peaks-clue {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 33px;
  height: 33px;
  border-radius: 50%;
  background: #FFFFFF;
  border: 1.5px solid rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.975rem;
  font-weight: 600;
  color: var(--text-primary);
  pointer-events: none;
  z-index: 10;
  transition: border-color 0.2s, color 0.2s;
}

.peaks-clue.violated {
  border-color: #DC3545;
  color: #DC3545;
}

.peaks-clue.satisfied {
  border-color: var(--pipe-water);
  color: var(--pipe-water);
}

.peaks-tile.peaks-connected .peaks-line {
  stroke: var(--pipe-water);
  transition: stroke 0.15s;
}

.peaks-tile.peaks-loop-error {
  background: rgba(220, 53, 69, 0.12);
}

.peaks-tile.peaks-loop-error .peaks-line {
  stroke: #DC3545;
  transition: stroke 0.15s;
}

.peaks-tile.peaks-empty-highlight {
  box-shadow: inset 0 0 0 3px #28A745;
}

/* ─── Loop Puzzles (Flags + Pearls) ─── */
.loop-grid { position: relative; }
.loop-grid .tile { border: none; background: transparent; }

.loop-svg {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  overflow: visible; pointer-events: none;
}

.loop-edge-ghost { stroke: rgba(0,0,0,0.12); stroke-width: 0.06; stroke-linecap: round; }
.loop-edge { stroke: var(--pipe-wall); stroke-width: 0.12; stroke-linecap: round; }
.loop-edge-last { stroke: #5BC0BE; }
.loop-edge-x { stroke: #DC3545; stroke-width: 0.08; }
.loop-dot { fill: #BFBFBF; }
.loop-clue-white { fill: white; stroke: var(--pipe-wall); stroke-width: 0.04; }
.loop-clue-black { fill: var(--pipe-wall); stroke: var(--pipe-wall); stroke-width: 0.04; }
.loop-clue-text { font-weight: 600; text-anchor: middle; dominant-baseline: central; pointer-events: none; }

.loop-tile:hover { background: rgba(91, 141, 239, 0.06); }

/* Admire bar (shown after dismissing win overlay) */
.admire-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: linear-gradient(transparent, var(--bg) 40%);
}
