/* ---------------------------------------------------------------
   Pipe Flow - game-specific styles.

   Loaded after /assets/base.css, which supplies the design tokens,
   the top bar, the buttons, the footer, the modals, the cookie
   banner and the legal-page layout shared by every Lynxy game.
   Only the board, the pipes and the water live here.
---------------------------------------------------------------- */

/* ------------------------------- tokens -------------------------------- */

/* The board is a dark slate panel in both themes - pipes and water read
   best against it - a little deeper in the dark theme. */
:root {
  --board-1: #1b2a4a;
  --board-2: #101a33;
  --board-edge: #0b1226;
  --tile: rgba(255, 255, 255, .045);
  --tile-line: rgba(255, 255, 255, .07);
  --pipe: #5a6e9c;
  --pipe-hi: #7d92c4;
  --pipe-wet: #2f8fc4;
  --channel: #0d1530;
  --water: #4fdcff;
  --glow: rgba(79, 220, 255, .55);
  --hint: #ffd23f;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --board-1: #141f3a;
    --board-2: #0a1126;
    --board-edge: #070c1c;
  }
}

:root[data-theme="dark"] {
  --board-1: #141f3a;
  --board-2: #0a1126;
  --board-edge: #070c1c;
}

/* --------------------------- header extras ----------------------------- */

.topbar__inner { max-width: 640px; }

.brand__mark svg { width: 20px; height: 20px; display: block; }

.stats {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 10px;
  text-align: center;
  min-width: 58px;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.stat__value {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-dim);
}

@media (max-width: 520px) {
  .stats { gap: 6px; }
  .stat { min-width: 44px; padding: 4px 6px; }
  .stat__value { font-size: 15px; }
  .stat__label { font-size: 9px; letter-spacing: .04em; }
  .brand__name { display: none; }
}

.topbar__hint {
  max-width: 640px;
  margin: 6px auto 0;
  padding: 0 16px;
  font-size: 12px;
  color: var(--text-dim);
}

/* -------------------------------- page --------------------------------- */

.page {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel {
  display: flex;
  gap: 10px;
  align-items: center;
}

.levels {
  flex: 1;
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
}

.level {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 7px 4px;
  border-radius: 9px;
  cursor: pointer;
  display: grid;
  gap: 1px;
  line-height: 1.15;
}

.level small { font-size: 10px; font-weight: 600; opacity: .75; }

.level.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.meta {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 13px;
  color: var(--text-dim);
  flex-wrap: wrap;
}

.meta__item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.meta__item strong { color: var(--text); font-weight: 700; }

.meta__item--deal {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.meta__item--deal strong { color: var(--accent); }
.meta__item--time { margin-left: auto; }

/* ------------------------------- stage --------------------------------- */

.stage {
  position: relative;
  border-radius: var(--radius-lg);
  padding: 12px 12px 14px;
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(120, 160, 255, .16), transparent 60%),
    linear-gradient(170deg, var(--board-1), var(--board-2));
  box-shadow: inset 0 0 0 1px var(--board-edge), inset 0 2px 20px rgba(0, 0, 0, .25), var(--shadow);
}

.gauge {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .09);
  overflow: hidden;
}

.gauge__fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2f8fc4, var(--water));
  box-shadow: 0 0 10px var(--glow);
  transition: width .45s cubic-bezier(.3, .7, .3, 1);
}

.gauge__text {
  margin: 6px 2px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: rgba(214, 226, 255, .62);
  font-variant-numeric: tabular-nums;
}

/* The board is as wide as the stage allows, but never taller than the
   screen: --cols and --rows come from app.js, and the cells are square. */
.board {
  --cols: 5;
  --rows: 6;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  width: min(100%, calc((100vh - 330px) * var(--cols) / var(--rows)), 520px);
  min-width: min(100%, 220px);
  margin: 0 auto;
  aspect-ratio: var(--cols) / var(--rows);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* -------------------------------- cells -------------------------------- */

.cell {
  --dl: 0ms;
  position: relative;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  min-width: 0;
  min-height: 0;
}

/* the soft tile behind each piece */
.cell::before {
  content: "";
  position: absolute;
  inset: 2%;
  border-radius: 14%;
  background: var(--tile);
  box-shadow: inset 0 0 0 1px var(--tile-line);
  transition: background .3s ease;
}

.cell--empty { cursor: default; }
.cell--empty::before { opacity: .45; }

.cell:not(.cell--empty):active::before { background: rgba(255, 255, 255, .1); }
.cell:focus-visible::before { box-shadow: inset 0 0 0 2px var(--water); }

.cell__pipe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  transition: transform .2s cubic-bezier(.3, .8, .35, 1.2);
  overflow: visible;
}

.cell__pipe .wall,
.cell__pipe .cap {
  fill: none;
  stroke: var(--pipe);
  stroke-width: 36;
  transition: stroke .3s ease;
}

.cell__pipe .cap { fill: var(--pipe); stroke: none; }

.cell__pipe .chan,
.cell__pipe .chan-cap {
  fill: none;
  stroke: var(--channel);
  stroke-width: 22;
}

.cell__pipe .chan-cap { fill: var(--channel); stroke: none; }

.cell__pipe .water,
.cell__pipe .water-cap {
  fill: none;
  stroke: var(--water);
  stroke-width: 22;
  opacity: 0;
  transition: opacity .2s ease;
}

.cell__pipe .water-cap { fill: var(--water); stroke: none; }

/* the lip of each opening, so adjoining pipes read as joined */
.cell__pipe .lip {
  fill: none;
  stroke: var(--pipe-hi);
  stroke-width: 40;
  transition: stroke .3s ease;
}

.cell.is-wet .wall,
.cell.is-wet .cap { stroke: var(--pipe-wet); }
.cell.is-wet .cap { fill: var(--pipe-wet); stroke: none; }
.cell.is-wet .lip { stroke: var(--pipe-wet); }
.cell.is-wet .water,
.cell.is-wet .water-cap { opacity: 1; }

.cell.is-wet .wall,
.cell.is-wet .cap,
.cell.is-wet .lip,
.cell.is-wet .water,
.cell.is-wet .water-cap { transition-delay: var(--dl); }

.cell.is-wet::before { background: rgba(79, 220, 255, .09); transition-delay: var(--dl); }

.cell.is-hint::before { box-shadow: inset 0 0 0 2px var(--hint), 0 0 16px var(--hint); animation: hint 1s ease-in-out infinite; }

@keyframes hint {
  50% { background: rgba(255, 210, 63, .22); }
}

/* a cap that is a drain: it lights up when the water arrives */
.cell__pipe .cap-ring { fill: none; stroke: var(--pipe-hi); stroke-width: 4; opacity: .5; }

/* a locked piece: amber tile and a small padlock */
.cell.is-locked::before {
  background: rgba(255, 190, 70, .16);
  box-shadow: inset 0 0 0 1.5px rgba(255, 196, 80, .75);
}

.cell.is-locked.is-wet::before { background: rgba(255, 190, 70, .2); }

.cell__lock {
  position: absolute;
  top: 6%;
  right: 6%;
  width: 28%;
  height: 28%;
  display: none;
  place-items: center;
  pointer-events: none;
  z-index: 2;
}

.cell.is-locked .cell__lock { display: grid; }

.cell__lock svg {
  width: 100%;
  height: 100%;
  fill: #ffc450;
  stroke: #ffc450;
  stroke-width: 2.4;
  stroke-linecap: round;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .6));
}

.cell.is-shake { animation: shake .3s ease; }

@keyframes shake {
  25% { transform: translateX(-5%); }
  75% { transform: translateX(5%); }
}

/* while the Lock tool is on, taps lock rather than turn */
.board.is-locking .cell:not(.cell--empty):hover::before { box-shadow: inset 0 0 0 1.5px rgba(255, 196, 80, .6); }
.board.is-locking { cursor: cell; }

/* the tap */
.cell__src {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.cell__src svg {
  width: 62%;
  height: 62%;
  filter: drop-shadow(0 0 8px rgba(91, 123, 255, .7));
}

.board.is-won .cell:not(.cell--empty)::before { animation: won 1.2s ease-in-out 2; }

@keyframes won {
  50% { background: rgba(79, 220, 255, .24); }
}

@media (prefers-reduced-motion: reduce) {
  .cell__pipe { transition: none; }
  .cell.is-hint::before, .board.is-won .cell::before { animation: none; }
}

/* ------------------------------- tools --------------------------------- */

.tools {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-dim);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 8px 2px 6px;
  display: grid;
  justify-items: center;
  gap: 3px;
  cursor: pointer;
}

.tool:active { transform: scale(.97); }
.tool[disabled] { opacity: .45; cursor: default; }
.tool .icon { width: 18px; height: 18px; }

.tool.is-on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.icon__mute { display: none; }
.is-off .icon__waves { display: none; }
.is-off .icon__mute { display: block; }

/* ------------------------------- confetti ------------------------------ */

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

/* ------------------------------ win dialog ----------------------------- */

.stars {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 12px;
  font-size: 34px;
  line-height: 1;
}

.stars span { color: var(--border-strong); }
.stars span.is-on { color: #ffc93c; text-shadow: 0 0 14px rgba(255, 201, 60, .5); }

.score-row {
  display: flex;
  gap: 8px;
  margin: 18px 0;
}

.score-row__item {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 4px;
  display: grid;
  gap: 2px;
}

.score-row__value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-row__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-dim);
}

.modal__home { flex: 0 0 auto; padding-left: 12px; padding-right: 12px; }

/* ------------------------------- about --------------------------------- */

.about { margin-top: 12px; color: var(--text); }
.about h1 { font-size: 22px; letter-spacing: -.02em; margin: 0 0 8px; }
.about h2 { font-size: 16px; margin: 22px 0 6px; }
.about p { font-size: 14px; color: var(--text-dim); margin: 0 0 10px; }
.about strong { color: var(--text); }
.about a { color: var(--accent); }

.about table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 8px 0 12px;
}

.about th, .about td {
  text-align: left;
  padding: 8px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.about th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); }

/* ?shot=og: the board alone, for the share picture */
.is-shot body > *:not(main) { display: none !important; }
.is-shot .panel, .is-shot .about, .is-shot .tools, .is-shot .meta { display: none !important; }
