/* FrogPipes - tool-specific styles. Chrome, hero, privacy badge, and tokens
   come from the shared shell; this file carries the board, tiles, stats, and controls. */

:root {
  --neon: var(--accent);
  --pipe-core: #3fce5a;
  --pipe-edge: #0f5b25;
  --pipe-glow: rgba(63, 206, 90, 0.55);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.panel {
  background: var(--surface-dark);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
}

/* ─── Top bar ─────────────────────────────────────────────────────────── */

.fdp-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

#modeLabel {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}

/* ─── Stats ───────────────────────────────────────────────────────────── */

.fdp-stats {
  display: flex;
  gap: 1.25rem;
}
.fdp-stat { display: flex; flex-direction: column; align-items: center; text-align: center; }
.fdp-stat__num {
  font-family: var(--mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--pipe-core);
  line-height: 1.1;
}
.fdp-stat__label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-top: 0.15rem;
}

/* ─── Board ───────────────────────────────────────────────────────────── */

#board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  background: var(--bg-deep);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-md);
  padding: 8px;
  margin: 0 auto 1rem;
  width: 100%;
  max-width: 360px;
  box-sizing: border-box;
}

/* ─── Tiles ───────────────────────────────────────────────────────────── */

.loop-tile {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-dark);
  border-radius: 4px;
  background: var(--surface-dark);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  min-width: 44px;
  transition: border-color 120ms ease, background 120ms ease;
  /* Pipes extend into the gutter to meet neighbors - don't clip the overhang. */
  overflow: visible;
}
.loop-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.loop-tile svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  /* Casing + glow on the whole tile GROUP, so the dark edge traces the outer
     silhouette of the union of all arms = one smooth shape per tile, with no
     internal seams where segments meet at the center (T's + crosses included). */
  filter:
    drop-shadow(2px 0 0 var(--pipe-edge)) drop-shadow(-2px 0 0 var(--pipe-edge))
    drop-shadow(0 2px 0 var(--pipe-edge)) drop-shadow(0 -2px 0 var(--pipe-edge))
    drop-shadow(0 0 4px var(--pipe-glow));
  transition: filter 0.3s ease;
}

/* ─── Pipe strokes (svg lines inside tiles) ────────────────────────────── */

.loop-pipe {
  stroke: var(--pipe-core);
  stroke-width: 22;
  /* Always flat - connected ends meet flush (seamless), loose ends get the
     .loop-rim pipe-mouth. No round caps. Casing/glow lives on the tile group
     (.loop-tile svg), not here, so the arms merge into one shape. */
  stroke-linecap: butt;
  fill: none;
}

/* ─── Pipe-mouth rim (Mario-pipe entrance on a LOOSE end; app.js shows it only
       where a pipe does NOT connect to a neighbour, hides it on seamless joins).
       A short perpendicular collar wider than the pipe body = the opening lip. ─ */

.loop-rim {
  stroke: #5fe07a; /* a touch lighter than the body so the lip reads as raised */
  stroke-width: 12;
  stroke-linecap: butt;
  fill: none;
}

/* The dark recessed opening, painted on top of the rim and narrower than it, so
   the green lip shows around a dark hole = the Mario pipe mouth. */
.loop-mouth {
  stroke: #0c2e16; /* deep green-black, the pipe interior */
  stroke-width: 7;
  stroke-linecap: butt;
  fill: none;
}

/* ─── Completion flow reveal: app.js BFS-adds .is-lit to each tile staggered by
       depth on solve, so light surges out through the connected network (like
       FrogPath's path reveal). Filter-only - NEVER transform - because each tile
       carries an inline rotate() that a transform animation would clobber. ───── */

@keyframes pipe-flow-surge {
  0%   { filter:
           drop-shadow(2px 0 0 var(--pipe-edge)) drop-shadow(-2px 0 0 var(--pipe-edge))
           drop-shadow(0 2px 0 var(--pipe-edge)) drop-shadow(0 -2px 0 var(--pipe-edge))
           brightness(1.6) drop-shadow(0 0 4px var(--pipe-core)); }
  50%  { filter:
           drop-shadow(2px 0 0 var(--pipe-edge)) drop-shadow(-2px 0 0 var(--pipe-edge))
           drop-shadow(0 2px 0 var(--pipe-edge)) drop-shadow(0 -2px 0 var(--pipe-edge))
           brightness(2.2) drop-shadow(0 0 13px var(--pipe-core)); }
  100% { filter:
           drop-shadow(2px 0 0 var(--pipe-edge)) drop-shadow(-2px 0 0 var(--pipe-edge))
           drop-shadow(0 2px 0 var(--pipe-edge)) drop-shadow(0 -2px 0 var(--pipe-edge))
           brightness(1.6) drop-shadow(0 0 7px var(--pipe-core)); }
}
/* Whole-tile brighten+glow when the BFS wave hits it (app.js adds .is-lit to the
   tile group). On the svg group so the tile pulses as one shape, casing kept. */
.loop-tile.is-lit svg {
  filter:
    drop-shadow(2px 0 0 var(--pipe-edge)) drop-shadow(-2px 0 0 var(--pipe-edge))
    drop-shadow(0 2px 0 var(--pipe-edge)) drop-shadow(0 -2px 0 var(--pipe-edge))
    brightness(1.6) drop-shadow(0 0 7px var(--pipe-core));
  animation: pipe-flow-surge 0.55s ease;
}

/* (No hub element anymore - single-stub terminals show a center pipe-mouth,
   multi-connector tiles merge bare at center; nothing renders the old dot.) */

/* ─── Solved state: board lights up ────────────────────────────────────── */

@keyframes neon-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.72; }
}

#board.is-solved .loop-tile svg {
  filter:
    drop-shadow(2px 0 0 var(--pipe-edge)) drop-shadow(-2px 0 0 var(--pipe-edge))
    drop-shadow(0 2px 0 var(--pipe-edge)) drop-shadow(0 -2px 0 var(--pipe-edge))
    drop-shadow(0 0 6px var(--pipe-glow)) drop-shadow(0 0 16px var(--pipe-glow));
  animation: neon-pulse 1.8s ease-in-out infinite;
}
#board.is-solved .loop-tile {
  border-color: rgba(63, 206, 90, 0.35);
  background: rgba(63, 206, 90, 0.06);
}

/* ─── Status ──────────────────────────────────────────────────────────── */

#status {
  min-height: 1.4em;
  margin: 0 0 1rem;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.4;
}

/* ─── Controls ────────────────────────────────────────────────────────── */

.fdp-controls {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

/* ─── Result panel ────────────────────────────────────────────────────── */

#resultPanel {
  background: var(--bg-deep);
  border: 1px solid rgba(25, 195, 125, 0.4);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin-top: 0.5rem;
}
#resultPanel[hidden] { display: none; }

#resultSummary {
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 1rem;
  white-space: pre-wrap;
  line-height: 1.6;
}

/* ─── How to play (popup, opened from the (i) button in the topbar) ─────── */

.fdp-how-to-play {
  margin: 0 0 0.85rem;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}

.fdp-help-wrap { position: relative; display: flex; }
.fdp-info-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(229, 231, 235, 0.4);
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease, background 120ms ease;
}
.fdp-info-btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(25, 195, 125, 0.08); }
.fdp-info-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.fdp-help-popup {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  z-index: 20;
  width: min(20rem, 80vw);
  padding: 1rem 1.1rem;
  background: var(--bg-deep);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.fdp-help-popup[hidden] { display: none; }
.fdp-help-popup p:last-child { margin-bottom: 0; }
.fdp-help-close {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}
.fdp-help-close:hover { color: var(--accent); }
.fdp-help-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ─── Responsive ──────────────────────────────────────────────────────── */

@media (max-width: 560px) {
  .fdp-stats { gap: 1.75rem; }
  .fdp-stat__num { font-size: 1.4rem; }

  #board {
    gap: 4px;
    padding: 6px;
    max-width: 100%;
  }
  .loop-tile { min-width: 40px; }

  .fdp-controls {
    gap: 0.5rem;
    flex-direction: column;
  }
  .fdp-controls .btn {
    padding: 0.65rem 1rem;
    font-size: 0.85rem;
    width: 100%;
    justify-content: center;
  }
}
