/* web-arcade — calm, premium, colourful. One fixed screen, zero scroll,
   iPhone 14 Pro first (393×852, safe-area aware, 44pt targets). */

:root {
  --bg: #f4f1ea;
  --bg-2: #ece7db;
  --panel: #ffffff;
  --ink: #2b2a28;
  --ink-soft: #6f6a61;
  --line: #e0d9cb;
  --cell: #efe9dc;
  --cell-line: #e3dccd;
  --shadow: 0 1px 2px rgba(60, 50, 30, 0.06), 0 8px 24px rgba(60, 50, 30, 0.08);
  --radius: 20px;
  --tap: 46px;
  --accent: #e0a43b;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161a;
    --bg-2: #201e25;
    --panel: #24222a;
    --ink: #f2efe9;
    --ink-soft: #a49fb0;
    --line: #322f3a;
    --cell: #2b2933;
    --cell-line: #35323d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 50% -10%, var(--bg-2), transparent 60%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#app {
  position: fixed;
  inset: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    calc(var(--safe-t) + 8px)
    calc(var(--safe-r) + 16px)
    calc(var(--safe-b) + 12px)
    calc(var(--safe-l) + 16px);
}

.screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: fade-in 0.28s ease;
}
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---- home ------------------------------------------------------------- */

.home__head { padding: 12px 4px 2px; }
.home__title {
  margin: 0;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.home__sub { margin: 6px 0 0; color: var(--ink-soft); font-size: 15px; line-height: 1.35; }

.tiles {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-content: start;
  padding-top: 4px;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 14px;
  min-height: 148px;
  border: none;
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: left;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  overflow: hidden;
}
.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 16%, transparent), transparent 55%);
  pointer-events: none;
}
.tile:active { transform: scale(0.97); }
.tile--soon { opacity: 0.72; cursor: default; }
.tile--soon:active { transform: none; }

.tile__icon {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 12px;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 45%, transparent);
}
.tile__icon svg { width: 24px; height: 24px; }
.tile__title { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.tile__tagline { font-size: 13px; color: var(--ink-soft); line-height: 1.3; flex: 1; }
.tile__badge {
  align-self: flex-start;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  background: color-mix(in srgb, var(--ink) 7%, transparent);
  padding: 3px 9px;
  border-radius: 999px;
}
.tile__badge--live { color: #fff; background: var(--accent); }

/* ---- top bar / hud ---------------------------------------------------- */

.hud {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
}
.hud__level {
  flex: 1;
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.hud__spacer { width: var(--tap); }

.ibtn {
  width: var(--tap);
  height: var(--tap);
  flex: 0 0 var(--tap);
  display: grid;
  place-items: center;
  border: none;
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.ibtn svg { width: 22px; height: 22px; }
.ibtn:active { transform: scale(0.92); }
.ibtn.is-disabled { opacity: 0.35; }

/* ---- level select ----------------------------------------------------- */

.lvl-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  align-content: start;
  overflow: hidden;
}
.lvl {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 16px;
  background: var(--panel);
  color: var(--ink);
  font-size: 20px;
  font-weight: 700;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.lvl:active { transform: scale(0.94); }
.lvl--done { background: var(--accent); color: #fff; }
.lvl--locked { opacity: 0.5; cursor: default; box-shadow: none; background: color-mix(in srgb, var(--ink) 6%, transparent); }
.lvl--locked:active { transform: none; }
.lvl__num { position: relative; }
.lvl--done .lvl__num { opacity: 0.9; font-size: 15px; }
.lvl__mark { position: absolute; top: 5px; right: 6px; opacity: 0.9; }
.lvl__mark svg { width: 15px; height: 15px; }
.lvl--done .lvl__mark { opacity: 1; }

/* ---- game board ------------------------------------------------------- */

/* Arrows is drawn to match Cristina's app pixel-for-pixel: a fine dot grid on
   a near-white screen, thin near-black arrow-pipes, blue when tapped. Palette
   and geometry (cols/rows, stroke, dot pitch) sampled from her frames. */
.screen--game {
  justify-content: flex-start;
  position: relative;
  gap: 8px;
  background: #ffffff;   /* her Arrows screen is white, not the arcade cream */
}
@media (prefers-color-scheme: dark) { .screen--game { background: #ffffff; color: #22242f; } }

.board-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: start center;   /* board sits just under the progress bar */
  touch-action: none;
  width: 100%;
}

.board-frame { width: 100%; display: flex; justify-content: center; }

.board {
  --cols: 20;
  --rows: 30;
  --pipe: #0E1028;         /* near-black deep indigo */
  --pipe-active: #5163F5;  /* saturated blue when tapped/sliding */
  --pipe-blocked: #E0524A;
  --dot: #9B9BAC;
  position: relative;
  aspect-ratio: var(--cols) / var(--rows);
  width: 100%;
  max-width: min(100%, calc((100dvh - 200px) * (var(--cols) / var(--rows))));
  max-height: 100%;
  background: #FAFDFE;     /* barely-there cool white board panel */
  border-radius: 14px;
}

.board-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
}
.cell { position: relative; }
/* a faint dot at every cell (the grid shows through the maze) */
.cell::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22%;
  height: 22%;
  max-width: 4px;
  max-height: 4px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--dot);
  opacity: 0.75;
}

.board-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;   /* taps fall through to the cell grid beneath */
  overflow: visible;
}
.pipe-body,
.pipe-head {
  stroke: var(--pipe);
  transition: stroke 0.12s ease;
}
.piece.is-active .pipe-body,
.piece.is-active .pipe-head { stroke: var(--pipe-active); }
.piece.is-blocked .pipe-body,
.piece.is-blocked .pipe-head { stroke: var(--pipe-blocked); }

.piece { will-change: transform, opacity; }
.piece.sliding {
  transition: transform 0.36s cubic-bezier(0.4, 0, 0.7, 0.2), opacity 0.34s ease-in;
}
.piece.wiggle { animation: pipe-wiggle 0.42s ease; }
@keyframes pipe-wiggle {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-2.5px); }
  80% { transform: translateX(2.5px); }
}

/* thin level-progress bar under the top bar (soft periwinkle, like her app) */
.progress {
  height: 6px;
  border-radius: 999px;
  background: #E7E9F7;
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: #AEB6EC;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* hearts */
.hearts { display: flex; gap: 5px; align-items: center; flex: 1; justify-content: center; }
.heart {
  width: 22px;
  height: 22px;
  color: #F94353;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.heart svg { width: 100%; height: 100%; }
.heart--spent { opacity: 0.24; transform: scale(0.82); color: #9B9BAC; }

/* the game screen's chrome is the lavender-pill set from her app */
.screen--game .ibtn {
  background: #C8CEF1;
  color: #484B63;
  box-shadow: none;
}
.screen--game .hud .hearts { color: #F94353; }

/* floating levels button (bottom-right) */
.fab-levels {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 16px;
  background: #C8CEF1;
  color: #484B63;
  font-size: 24px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.fab-levels:active { transform: scale(0.92); }

/* ---- win overlay ------------------------------------------------------ */

.win {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 10;
}
.win.is-in { opacity: 1; }
.win__card {
  width: 100%;
  max-width: 320px;
  padding: 28px 24px;
  border-radius: 26px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
  transform: translateY(12px) scale(0.96);
  transition: transform 0.32s cubic-bezier(0.34, 1.4, 0.64, 1);
}
.win.is-in .win__card { transform: none; }
.win__spark {
  width: 64px; height: 64px; margin: 0 auto 12px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: #fff; background: var(--accent);
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 45%, transparent);
}
.win__spark svg { width: 34px; height: 34px; }
.win__spark--soft { background: #e0524a; }
.win__title { margin: 0 0 4px; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.win__sub { margin: 0 0 20px; color: var(--ink-soft); font-size: 15px; }
.win__actions { display: flex; flex-direction: column; gap: 10px; }

.btn {
  min-height: var(--tap);
  padding: 0 22px;
  border: none;
  border-radius: 14px;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.btn:active { transform: scale(0.96); }
.btn--primary { background: var(--accent); color: #fff; box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 40%, transparent); }

.screen--error { justify-content: center; align-items: center; gap: 16px; color: var(--ink-soft); }

/* ---- reduced motion --------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
  .screen, .piece { animation: none !important; }
  .piece.sliding { transition: none !important; }
}
