/* ═══════════════════════════════════════════════════════════════════
   zenPuzzle — Zen Garden Theme
   ═══════════════════════════════════════════════════════════════════ */

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

  --pipe-disconnected: #A0ADB8;
  --pipe-connected: #4CAF82;
  --pipe-source: #4CAF82;

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

  --text-primary: #2C3E50;
  --text-secondary: #6B7C8D;
  --text-muted: #9BAAB7;

  --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;

  --pipe-width: 14;
  --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;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

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: hidden;
}

/* ═══════════════════════════════════════════════════════════════════
   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.72rem;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

/* 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: 24px;
}

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

.size-options {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.size-btn {
  width: 80px;
  height: 80px;
  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);
}

/* ═══════════════════════════════════════════════════════════════════
   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-timer {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  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: 8px;
  width: 100%;
}

.game-board {
  display: grid;
  gap: 0;
  max-width: 100%;
  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;
}

.tile .pipe-path {
  stroke: var(--pipe-disconnected);
  stroke-width: var(--pipe-width);
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  transition: stroke 0.3s ease;
}

.tile.connected .pipe-path {
  stroke: var(--pipe-connected);
}

.tile .pipe-dot {
  fill: var(--pipe-disconnected);
  transition: fill 0.3s ease;
}

.tile.connected .pipe-dot {
  fill: var(--pipe-connected);
}

/* 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(240, 243, 245, 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-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);
}

/* ═══════════════════════════════════════════════════════════════════
   PAUSE OVERLAY
   ═══════════════════════════════════════════════════════════════════ */
.pause-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(240, 243, 245, 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(240, 243, 245, 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-connected);
  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(--pipe-connected);
}

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

.sand-glass {
  stroke: var(--pipe-disconnected);
  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 particle animation */
.sand-particle {
  position: fixed;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 200;
  will-change: transform, opacity;
}

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

/* ═══════════════════════════════════════════════════════════════════
   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); }
}

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

/* ═══════════════════════════════════════════════════════════════════
   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 {
    width: 72px;
    height: 72px;
  }

  .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: 16px;
  }
}
