:root {
  --text: #e9eef6;
  --muted: #8fa1b8;
  --tile: rgba(255, 255, 255, 0.045);
  --tile-lit: rgba(255, 214, 140, 0.075);
  --pipe: #43616a;
  --lit: #ffe1a0;
  --glow: rgba(255, 200, 110, 0.55);
  --pin: #9cc4ff;
  --gold: #ffd27a;
  --tile-size: 56px;
  --gap: 4px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: radial-gradient(ellipse 120% 70% at 50% 0%, #1f3d55 0%, #10202f 55%, #0a1320 100%) fixed;
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Night sky */
#sky {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.star {
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.25;
  animation: twinkle var(--t) ease-in-out infinite;
  animation-delay: var(--delay);
}
.firefly {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff1b8;
  box-shadow: 0 0 10px 3px rgba(255, 214, 120, 0.55);
  opacity: 0;
  animation: drift var(--t) ease-in-out infinite alternate, blink var(--b) ease-in-out infinite;
  animation-delay: var(--delay);
}
@keyframes twinkle { 50% { opacity: 0.7; } }
@keyframes drift { to { transform: translate(var(--dx), var(--dy)); } }
@keyframes blink { 0%, 100% { opacity: 0; } 50% { opacity: 0.85; } }

/* Layout */
.app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px 4px;
}
.title {
  margin: 0;
  font: italic 400 22px/1.1 "Iowan Old Style", Georgia, "Times New Roman", serif;
  letter-spacing: 0.2px;
}
.level {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.bloom {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px 7px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  transition: background 0.4s, box-shadow 0.4s;
}
.bloom svg { width: 20px; height: 20px; }
.bloom.pop { animation: pop 0.45s ease; }
.bloom.full { background: rgba(255, 214, 140, 0.16); box-shadow: 0 0 22px rgba(255, 210, 130, 0.25); }
@keyframes pop { 40% { transform: scale(1.12); } }

main {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px 12px;
}

/* Board */
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--tile-size));
  grid-auto-rows: var(--tile-size);
  gap: var(--gap);
  padding: 10px;
  border-radius: 24px;
  background: #0f1c2a;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05), 0 20px 50px rgba(0, 0, 0, 0.25);
  transition: box-shadow 1.2s ease, filter 0.3s;
  touch-action: manipulation;
}
.board.solved {
  box-shadow: inset 0 0 0 1px rgba(255, 220, 150, 0.2), 0 0 70px rgba(255, 205, 120, 0.22);
}
body.paused .board { filter: blur(6px) saturate(0.6); }

.tile {
  position: relative;
  border-radius: 22%;
  background: var(--tile);
  overflow: hidden;
  cursor: pointer;
  transition: background 0.4s, transform 0.12s ease, box-shadow 0.25s;
}
.tile.lit { background: var(--tile-lit); }
.tile.pressing { transform: scale(0.94); }
.tile.stone { background: transparent; cursor: default; }

.spin {
  width: 100%;
  height: 100%;
  transition: transform 0.24s cubic-bezier(0.3, 1.45, 0.55, 1);
}
.no-anim .spin, .no-anim .tile, .no-anim .tile * { transition: none !important; }

.tile svg { display: block; width: 100%; height: 100%; overflow: visible; }

.pipe, .glow {
  fill: none;
  stroke-linecap: round;
  transition: stroke 0.35s, opacity 0.35s;
}
.pipe { stroke: var(--pipe); stroke-width: 13; }
.glow { stroke: var(--glow); stroke-width: 26; opacity: 0; filter: url(#soft); }
.lit .pipe { stroke: var(--lit); }
.lit .glow { opacity: 1; }

/* Flowers: closed buds that open when the light arrives */
.petals {
  transform: scale(0.42);
  transform-origin: 50px 50px;
  transform-box: view-box;
  transition: transform 0.55s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.petals ellipse { fill: #6c7590; transition: fill 0.45s; }
.heart { fill: #8790a8; transition: fill 0.45s; }
.lit .petals { transform: scale(1); }
.lit .petals ellipse { fill: var(--c); }
.lit .heart { fill: #ffe7a3; }
.c0 { --c: #f6a6c1; }
.c1 { --c: #c9a9f6; }
.c2 { --c: #ffb88f; }
.c3 { --c: #9fd6f5; }
.c4 { --c: #f5e08a; }
.c5 { --c: #a9e6bb; }

/* Moon stone */
.halo { fill: rgba(255, 238, 190, 0.16); animation: breathe 4s ease-in-out infinite; transform-origin: 50px 50px; transform-box: view-box; }
.orb { fill: #fff3d2; }
.crater { fill: rgba(170, 140, 90, 0.18); }
@keyframes breathe { 50% { transform: scale(1.13); opacity: 0.7; } }

/* Stones */
.rock { fill: #24323f; stroke: #2e4050; stroke-width: 2; }
.moss { fill: none; stroke: #4d7a5a; stroke-width: 5; stroke-linecap: round; opacity: 0.8; }

/* Pins */
/* Pinned tiles are shaded over the tile's own colour: darker while unlit, brighter once lit. */
.tile.locked, .tile.hinted { background-image: linear-gradient(rgba(4, 9, 16, 0.22), rgba(4, 9, 16, 0.22)); }
.tile.lit.locked, .tile.lit.hinted { background-image: linear-gradient(rgba(255, 222, 160, 0.11), rgba(255, 222, 160, 0.11)); }
.tile.locked::after, .tile.hinted::after {
  content: "";
  position: absolute;
  top: 9%;
  right: 9%;
  width: 11%;
  height: 11%;
  border-radius: 50%;
  background: var(--pin);
  box-shadow: 0 0 6px var(--pin);
}
.tile.hinted::after { background: var(--gold); box-shadow: 0 0 6px var(--gold); }
.board.solved .tile { background-image: none; }
.board.solved .tile::after { opacity: 0; transition: opacity 0.6s; }
.tile.nudge { animation: nudge 0.3s ease; }
@keyframes nudge { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

/* Win wave: ripples outward from the moon along the pipes */
.board.solved .tile:not(.stone) { animation: wave 0.9s ease both; animation-delay: var(--d); }
@keyframes wave {
  40% { transform: scale(1.09); background: rgba(255, 214, 140, 0.2); }
}

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 6px 16px max(18px, env(safe-area-inset-bottom));
}
.toolbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 78px;
  padding: 10px 14px 8px;
  border: 0;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: #c9d5e6;
  transition: background 0.2s, transform 0.12s, opacity 0.2s;
}
.toolbar button:active { transform: scale(0.94); background: rgba(255, 255, 255, 0.11); }
.toolbar button:disabled { opacity: 0.35; cursor: default; }
.toolbar svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(7, 13, 22, 0.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fade 0.35s ease;
}
.overlay[hidden] { display: none; }
#done {
  align-items: flex-end;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent 55%, rgba(7, 13, 22, 0.7));
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
#done .card { padding: 20px 22px 18px; }
#done h2 { font-size: 24px; margin-bottom: 6px; }
#done .poem { margin-bottom: 12px; }
#done .stats { margin-bottom: 14px; }
@keyframes fade { from { opacity: 0; } }

.card {
  width: 100%;
  max-width: 340px;
  padding: 28px 24px 22px;
  border-radius: 26px;
  background: rgba(24, 39, 56, 0.94);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  text-align: center;
  animation: rise 0.45s cubic-bezier(0.2, 1.2, 0.4, 1);
}
@keyframes rise { from { transform: translateY(18px) scale(0.97); opacity: 0; } }
.card h2 {
  margin: 0 0 10px;
  font: italic 400 28px/1.15 "Iowan Old Style", Georgia, serif;
}
.card p { margin: 0 0 16px; line-height: 1.5; }
.lead { color: #d6dfec; }
.muted { color: var(--muted); font-size: 14px; }
.tip {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  color: #c7d3e3;
  font-size: 14px;
  text-align: left;
}
.tip::before { content: "Tip  "; color: var(--gold); font-weight: 600; }
.poem { color: #e8d9b8; font-style: italic; }
.rules {
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
  text-align: left;
  font-size: 15px;
  line-height: 1.45;
  color: #c7d3e3;
}
.rules li { position: relative; padding-left: 20px; margin-bottom: 8px; }
.rules li::before { content: "✿"; position: absolute; left: 0; color: #f6a6c1; }
.rules b { color: var(--text); }
.stats {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin-bottom: 20px;
}
.stats div { display: flex; flex-direction: column; gap: 2px; }
.stats b { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stats span { font-size: 11px; color: var(--muted); letter-spacing: 0.12em; text-transform: uppercase; }

.card button {
  display: block;
  width: 100%;
  padding: 13px 16px;
  border: 0;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.07);
  font-size: 15px;
  transition: transform 0.12s, background 0.2s;
}
.card button:active { transform: scale(0.97); }
.card button.primary {
  background: linear-gradient(180deg, #ffe3a6, #f5c97a);
  color: #3b2a10;
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(255, 200, 110, 0.25);
}
.card .row { display: flex; gap: 10px; margin-top: 10px; }
.card button.spaced { margin-top: 10px; }

/* Garden picker */
.garden-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  max-height: min(50vh, 340px);
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0 -4px 16px;
  padding: 4px;
}
.card .garden-grid button {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.card .garden-grid button.done { background: rgba(255, 214, 140, 0.12); color: var(--lit); }
.card .garden-grid button.done::after {
  content: "✿";
  position: absolute;
  top: 3px;
  right: 6px;
  font-size: 11px;
  color: #f6a6c1;
}
.card .garden-grid button.started::before {
  content: "";
  position: absolute;
  bottom: 6px;
  left: 50%;
  width: 5px;
  height: 5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: var(--pin);
}
.card .garden-grid button.here { box-shadow: inset 0 0 0 2px var(--gold); color: var(--text); }
.card .row button { flex: 1; font-size: 14px; }
#done .row { margin-top: 0; }
.small { font-size: 13px; }
.rank-line { min-height: 1.5em; margin: -6px 0 12px !important; color: var(--gold); font-size: 14px; }

/* Leaderboards */
.leaders-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.leaders-head h2 { margin: 0; }
.card .leaders-head button { width: 40px; height: 40px; padding: 0; border-radius: 50%; font-size: 22px; line-height: 1; }
.card .leaders-head button:disabled { opacity: 0.3; }
.tabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 12px; border-radius: 14px; background: rgba(255, 255, 255, 0.05); }
.card .tabs button { flex: 1; padding: 8px; border-radius: 10px; background: none; color: var(--muted); font-size: 14px; }
.card .tabs button.on { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.leader-list { min-height: 40px; max-height: min(42vh, 380px); overflow-y: auto; margin: 0 0 8px; padding: 0; list-style: none; text-align: left; }
.leader-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; font-size: 15px; }
.leader-list li.you { background: rgba(255, 214, 140, 0.12); color: var(--lit); }
.leader-list li.gap { justify-content: center; padding: 0; color: var(--muted); }
.leader-list .rank { width: 24px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.leader-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leader-list .val { font-variant-numeric: tabular-nums; }

/* Account */
.field { margin: 0 0 14px; text-align: left; }
.field span { display: block; margin: 0 0 6px 4px; font-size: 13px; color: var(--muted); }
.field b {
  display: block;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  font-weight: 500;
  font-size: 16px;
}
.sign-in { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 4px; }
.sign-in p { margin: 0; }
.card button.apple { background: #fff; color: #000; font-weight: 600; border-radius: 999px; max-width: 280px; }
.card button.quiet {
  margin-top: 10px;
  background: none;
  color: var(--muted);
  font-size: 14px;
}

@media (prefers-reduced-motion: reduce) {
  .star, .firefly, .halo { animation: none; }
  .firefly { opacity: 0.4; }
  .board.solved .tile { animation: none; }
}
