/* ==========================================================================
   DryScout.org — Find the Leak (V1)
   Builds on ../styles.css (tokens, header, buttons, type). Game-only rules here.
   Pipe cells are CSS; the pipes are the approved sprites (dry + wet layered,
   rotated in code). find-the-leak.js sets --cols / --rows on the board.
   ========================================================================== */

.fl-body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse 60% 42% at 12% 6%, rgba(23, 163, 218, 0.10), transparent 70%),
    radial-gradient(ellipse 52% 36% at 88% 10%, rgba(15, 27, 61, 0.08), transparent 70%),
    linear-gradient(180deg, #EEF5FC 0%, #FFFFFF 460px);
}
.fl-body .site-header { background: rgba(255, 255, 255, 0.86); backdrop-filter: blur(6px); }

.fl-back { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; color: var(--navy); min-height: 44px; white-space: nowrap; flex: none; }
.fl-back:hover { color: var(--blue); }

.fl-main { padding: 0 0 56px; }
.fl-screen[hidden] { display: none; }
.fl-body button:focus-visible, .fl-body a:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }
.fl-body button, .fl-body a { -webkit-tap-highlight-color: transparent; }

/* ---------- SCREEN 1: START ---------- */
.fl-start-inner {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  align-items: center; column-gap: 40px;
  min-height: calc(100vh - 76px - 56px);
  padding-top: 24px; padding-bottom: 24px;
}
.fl-title { font-family: var(--font-display); font-weight: 800; font-size: clamp(38px, 4vw, 56px); line-height: 1.1; letter-spacing: -0.02em; color: var(--navy); margin-top: 22px; }
.fl-btn-start { font-size: 20px; padding: 18px 30px; margin-top: 34px; border-radius: 14px; min-height: 56px; }
.fl-start-art { border-radius: 24px; overflow: hidden; box-shadow: 0 16px 48px rgba(15, 27, 61, 0.12); pointer-events: none; }
.fl-start-art img { display: block; width: 100%; height: auto; }

/* ---------- SCREEN 2: GAME PANEL ---------- */
.fl-game .container { padding-top: 22px; }
.fl-panel {
  position: relative; max-width: 1100px; margin: 0 auto;
  background: var(--surface);
  border: 1px solid rgba(15, 27, 61, 0.08);
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(15, 27, 61, 0.07);
  overflow: hidden;
}
.fl-panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 16px 26px;
  background: linear-gradient(100deg, var(--navy) 0%, var(--navy-soft) 100%);
  color: #fff;
}
.fl-game-title { font-family: var(--font-display); font-weight: 800; font-size: 22px; letter-spacing: -0.01em; line-height: 1.1; }
.fl-objective { font-size: 15px; color: rgba(255, 255, 255, 0.82); margin-top: 3px; }
.fl-stats { display: flex; gap: 8px; flex: none; }
.fl-stat {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 92px; padding: 7px 14px;
  border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
}
.fl-stat-label { font-size: 11px; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: rgba(255, 255, 255, 0.72); }
.fl-stat-value { font-family: var(--font-display); font-weight: 800; font-size: 22px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.fl-stat-value.is-low { color: #FFD166; }

/* ---------- BOARD ---------- */
.fl-board-wrap { padding: 22px 26px 26px; }
.fl-board {
  --cols: 9; --rows: 4; --gap: 8px;
  display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: var(--gap);
  width: min(100%, calc((100vh - 330px) * var(--cols) / var(--rows)));
  margin: 0 auto;
  padding: 12px; border-radius: 22px;
  background: linear-gradient(180deg, #E7F1FB 0%, #DCE9F7 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 8px 24px rgba(15, 27, 61, 0.08);
  transition: box-shadow .4s ease;
  user-select: none; -webkit-user-select: none;
}
.fl-board.is-solved { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 0 0 4px rgba(30, 111, 230, 0.35), 0 10px 34px rgba(30, 111, 230, 0.25); }

/* Cells: pale blue rounded tiles, the whole cell is the tap target */
.fl-cell {
  position: relative; aspect-ratio: 1; padding: 0; border: 0; cursor: pointer;
  border-radius: 14%; background: linear-gradient(180deg, #F4F9FE 0%, #E8F1FA 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.9), inset 0 -2px 0 rgba(15, 27, 61, 0.06), 0 2px 6px rgba(15, 27, 61, 0.08);
  transition: box-shadow .15s ease, transform .15s ease;
}
@media (hover: hover) { .fl-cell.fl-pipe:hover { box-shadow: inset 0 0 0 2px rgba(30, 111, 230, 0.35), inset 0 -2px 0 rgba(15, 27, 61, 0.06), 0 4px 12px rgba(15, 27, 61, 0.12); } }
.fl-cell.fl-pipe:active { transform: scale(.97); }
.fl-cell.fl-end { cursor: default; background: linear-gradient(180deg, #2B6FE0 0%, #1A55C0 100%); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 3px 10px rgba(15, 27, 61, 0.22); }
.fl-cell.fl-end.is-wet { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 0 0 3px rgba(30, 111, 230, 0.35), 0 3px 12px rgba(30, 111, 230, 0.3); }

/* Pipe sprites: dry + wet stacked, rotated together; slightly larger than the cell so ends reach the edges */
.fl-pipe-art { position: absolute; inset: 0; pointer-events: none; transform: rotate(var(--deg, 0deg)); transition: transform .16s cubic-bezier(.3, .8, .4, 1); will-change: transform; }
.fl-pipe-art img { position: absolute; left: -15%; top: -15%; width: 130%; height: 130%; }
.fl-pipe-art .wet { opacity: 0; transition: opacity .18s ease; }
.fl-pipe-art .wet.elbow { transform: scale(.87); }   /* the wet elbow art is drawn a touch larger than the dry one */
.fl-cell.is-wet .fl-pipe-art .wet { opacity: 1; }
.fl-cell.is-wet .fl-pipe-art .dry { opacity: 0; transition: opacity .18s ease; }

/* Endpoints: the approved socket tile (mirrored for the source) with a wet stub overlay once connected */
.fl-end .fl-pipe-art { transform: none; }
.fl-end.fl-source .fl-pipe-art { transform: scaleX(-1); }
.fl-end .stub { clip-path: inset(0 44% 0 0); }
.fl-end .stub.wet { opacity: 0; }
.fl-end.is-wet .stub.wet { opacity: 1; }
/* Leak: droplets spraying from the target socket until the flow is connected */
.fl-spray { position: absolute; left: 74%; top: 14%; width: 46%; height: 68%; pointer-events: none; z-index: 3; }
.fl-spray img { width: 100%; height: 100%; object-fit: contain; animation: fl-spray 1.1s ease-in-out infinite; }
.fl-target.is-wet .fl-spray, .fl-board.is-solved .fl-spray { display: none; }
@keyframes fl-spray { 0%, 100% { transform: translate(0, 0) scale(1); opacity: 1; } 50% { transform: translate(6%, 10%) scale(.94); opacity: .78; } }
.fl-drip { position: absolute; left: 88%; top: 62%; width: 12%; height: 12%; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; background: #2B8DFF; opacity: 0; z-index: 3; pointer-events: none; animation: fl-drip 1.4s ease-in infinite; }
.fl-target.is-wet .fl-drip, .fl-board.is-solved .fl-drip { display: none; }
@keyframes fl-drip { 0% { transform: translateY(0) scale(.7); opacity: 0; } 20% { opacity: .9; } 100% { transform: translateY(160%) scale(1); opacity: 0; } }

.fl-cell.is-solved-path { z-index: 1; }
.fl-board.is-locked .fl-cell { cursor: default; }

/* Success beat */
.fl-banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 30;
  padding: 16px 30px; border-radius: 999px;
  background: #fff; color: var(--navy);
  font-family: var(--font-display); font-weight: 800; font-size: clamp(22px, 2.6vw, 32px); letter-spacing: 0.02em; white-space: nowrap;
  box-shadow: 0 14px 40px rgba(15, 27, 61, 0.20);
  animation: fl-banner-in .28s cubic-bezier(.2, .9, .3, 1.3);
}
.fl-banner[hidden] { display: none; }
.fl-banner .tick { color: #1B7F4B; }
@keyframes fl-banner-in { from { opacity: 0; transform: translate(-50%, -50%) scale(.7); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }

/* ---------- SCREEN 3: RESULTS ---------- */
.fl-results-inner {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  min-height: calc(100vh - 76px - 56px); justify-content: center;
  padding-top: 24px; padding-bottom: 24px;
}
.fl-results-title { font-family: var(--font-display); font-weight: 800; font-size: clamp(38px, 4.2vw, 56px); line-height: 1.1; letter-spacing: -0.02em; color: var(--navy); }
.fl-results-sub { font-size: 20px; color: var(--text-soft); margin-top: 8px; }
.fl-results-sub[hidden] { display: none; }
.fl-results-stats { display: flex; gap: 14px; margin-top: 22px; }
.fl-results-stats > div { min-width: 120px; padding: 12px 22px; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
.fl-results-stats > div[hidden] { display: none; }
.fl-results-stats dt { font-size: 12px; font-weight: 700; letter-spacing: 0.22em; text-transform: uppercase; color: var(--text-soft); }
.fl-results-stats dd { font-family: var(--font-display); font-weight: 800; font-size: 34px; color: var(--blue); line-height: 1.1; margin-top: 2px; font-variant-numeric: tabular-nums; }
.fl-results-art { width: clamp(260px, 30vw, 400px); margin-top: 18px; border-radius: 20px; overflow: hidden; box-shadow: 0 12px 36px rgba(15, 27, 61, 0.12); }
.fl-results-art img { display: block; width: 100%; height: auto; }
.fl-btn-again { font-size: 20px; padding: 18px 34px; margin-top: 20px; border-radius: 14px; min-height: 56px; }

/* ---------- Motion preference ---------- */
@media (prefers-reduced-motion: reduce) {
  .fl-pipe-art { transition: none; }
  .fl-spray img, .fl-drip, .fl-banner { animation: none; }
  .fl-drip { display: none; }
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 980px) {
  .fl-start-inner { grid-template-columns: 1fr; justify-items: center; text-align: center; min-height: 0; padding-top: 28px; }
  .fl-start-art { width: min(92vw, 640px); margin-top: 24px; }
  .eyebrow-bar { justify-content: center; }
  .fl-board { width: 100%; }
}

@media (max-width: 640px) {
  .fl-main { padding-bottom: 32px; }
  .fl-back { font-size: 14px; }
  .fl-back-long { display: none; }
  .fl-title { font-size: 36px; }
  .fl-btn-start { width: 100%; max-width: 360px; }

  .fl-game .container { padding: 14px 12px 0; }
  .fl-panel { border-radius: 16px; }
  .fl-panel-head { flex-direction: column; align-items: stretch; gap: 12px; padding: 14px 16px; }
  .fl-game-title { font-size: 20px; }
  .fl-objective { font-size: 14px; }
  .fl-stats { justify-content: space-between; }
  .fl-stat { flex: 1 1 0; min-width: 0; padding: 6px 10px; }
  .fl-stat-value { font-size: 21px; }

  .fl-board-wrap { padding: 12px 6px 14px; }
  .fl-board { --gap: 5px; padding: 6px; border-radius: 16px; }
  .fl-cell { border-radius: 12%; }

  .fl-results-inner { min-height: 0; padding-top: 32px; }
  .fl-results-sub { font-size: 17px; }
  .fl-results-stats { width: 100%; max-width: 360px; gap: 8px; }
  .fl-results-stats > div { flex: 1 1 0; min-width: 0; padding: 10px 8px; }
  .fl-results-stats dd { font-size: 26px; }
  .fl-results-art { width: min(86vw, 340px); }
  .fl-btn-again { width: 100%; max-width: 360px; }
}
