/* ============ Pipe Dream: Neon Flow ============ */
:root {
  --hue: 190;
  --bg0: #05070f;
  --bg1: #0a1120;
  --ink: #dbe7ff;
  --dim: #8fa3c7;
  --panel: rgba(13, 20, 35, 0.78);
  --panel-line: rgba(130, 180, 255, 0.16);
  --accent: hsl(var(--hue) 95% 62%);
  --accent-soft: hsl(var(--hue) 90% 62% / 0.25);
  --bad: #ff5470;
  --good: #59f0b0;
  --gold: #ffcf5e;
  --font-display: "Orbitron", "Segoe UI", "Helvetica Neue", sans-serif;
  --font-body: "Chakra Petch", "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg0);
  color: var(--ink);
  font-family: var(--font-body);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}
button { font-family: inherit; color: inherit; }
input, select { font-family: inherit; }

#app { position: fixed; inset: 0; overflow: hidden; }

#game-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; touch-action: none; outline: none;
}

/* ============ Screens ============ */
.screen {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .35s ease;
  z-index: 10;
}
.screen.active { opacity: 1; pointer-events: auto; }
.screen.active .menu-inner, .screen.active .panel-page { transform: translateY(0); }

/* ============ Menu ============ */
.menu-inner {
  display: flex; flex-direction: column; align-items: center; gap: 34px;
  transform: translateY(10px); transition: transform .45s cubic-bezier(.2,.9,.25,1.2);
  padding: 24px; max-width: 100%;
}
.logo { text-align: center; }
.logo-kicker {
  font-size: clamp(10px, 1.6vw, 13px); letter-spacing: .42em; text-transform: uppercase;
  color: var(--dim); margin-bottom: 14px;
}
.logo-title {
  font-family: var(--font-display); font-weight: 900;
  font-size: clamp(44px, 11vw, 108px);
  line-height: .95; letter-spacing: .04em; white-space: nowrap;
  background: linear-gradient(100deg, #6ee7ff 0%, #7aa8ff 34%, #b691ff 62%, #6ee7ff 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 26px hsl(200 100% 60% / .38)) drop-shadow(0 3px 0 rgba(0,0,0,.55));
  animation: shimmer 7s linear infinite;
}
.logo-gap { display: inline-block; width: .35em; }
@keyframes shimmer { to { background-position: -220% 0; } }
.logo-sub {
  margin-top: 14px; display: flex; align-items: center; justify-content: center; gap: 16px;
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(13px, 2.4vw, 20px); letter-spacing: .58em; text-indent: .58em;
  color: hsl(160 90% 66%);
  text-shadow: 0 0 18px hsl(160 90% 55% / .55);
}
.logo-sub .rule { height: 1px; width: clamp(30px, 6vw, 70px); background: linear-gradient(90deg, transparent, hsl(160 80% 60% / .6)); }
.logo-sub .rule:last-child { transform: scaleX(-1); }

.menu-buttons { display: flex; flex-direction: column; gap: 14px; width: min(340px, 82vw); }
.menu-foot { color: var(--dim); font-size: 13px; letter-spacing: .12em; }

/* ============ Buttons ============ */
.btn {
  position: relative;
  font-family: var(--font-display); font-weight: 700;
  font-size: 15px; letter-spacing: .18em; text-transform: uppercase;
  padding: 15px 26px; border-radius: 14px; cursor: pointer;
  background: linear-gradient(180deg, rgba(30,42,66,.9), rgba(16,24,40,.9));
  border: 1px solid var(--panel-line);
  color: var(--ink);
  transition: transform .15s ease, box-shadow .2s ease, border-color .2s ease, background .2s;
  box-shadow: 0 4px 18px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.06);
}
.btn:hover { transform: translateY(-2px); border-color: hsl(var(--hue) 80% 60% / .55); box-shadow: 0 8px 26px rgba(0,0,0,.45), 0 0 22px var(--accent-soft), inset 0 1px 0 rgba(255,255,255,.08); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.btn-primary {
  background: linear-gradient(180deg, hsl(var(--hue) 85% 55%), hsl(var(--hue) 90% 40%));
  border-color: hsl(var(--hue) 90% 70% / .8);
  color: #04121c; text-shadow: 0 1px 0 rgba(255,255,255,.25);
  box-shadow: 0 6px 26px hsl(var(--hue) 95% 55% / .4), inset 0 1px 0 rgba(255,255,255,.35);
}
.btn-primary:hover { box-shadow: 0 10px 34px hsl(var(--hue) 95% 55% / .55), inset 0 1px 0 rgba(255,255,255,.4); }
.btn-big { font-size: 17px; padding: 17px 34px; }
.btn-back { margin-top: 22px; }
.btn-danger:hover { border-color: var(--bad); box-shadow: 0 8px 26px rgba(0,0,0,.45), 0 0 22px rgba(255,84,112,.35); }
.btn small { font-size: 10px; letter-spacing: .1em; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; cursor: pointer;
  display: grid; place-items: center;
  background: linear-gradient(180deg, rgba(30,42,66,.9), rgba(16,24,40,.9));
  border: 1px solid var(--panel-line); color: var(--dim);
  transition: color .2s, border-color .2s, transform .15s;
}
.icon-btn:hover { color: var(--ink); border-color: hsl(var(--hue) 80% 60% / .55); transform: translateY(-1px); }
.icon-btn svg { width: 20px; height: 20px; }

/* ============ Pages (help/scores/settings) ============ */
.panel-page {
  width: min(980px, 94vw); max-height: 94dvh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 22px;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  padding: clamp(20px, 4vw, 40px);
  display: flex; flex-direction: column; align-items: center;
  transform: translateY(10px); transition: transform .45s cubic-bezier(.2,.9,.25,1.2);
  box-shadow: 0 30px 80px rgba(0,0,0,.5);
  scrollbar-width: thin; scrollbar-color: #2a3954 transparent;
}
.page-title {
  font-family: var(--font-display); font-weight: 900; letter-spacing: .12em; text-transform: uppercase;
  font-size: clamp(22px, 4vw, 34px); margin-bottom: 24px;
  background: linear-gradient(100deg, #6ee7ff, #b691ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 16px hsl(210 100% 60% / .3));
}
.help-grid, .settings-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px; width: 100%;
}
.help-card {
  background: rgba(8, 13, 24, .6); border: 1px solid var(--panel-line);
  border-radius: 16px; padding: 20px;
}
.help-card h3 {
  font-family: var(--font-display); font-size: 13px; letter-spacing: .22em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 12px;
}
.help-card p { font-size: 14px; line-height: 1.55; color: var(--dim); margin-bottom: 8px; }
.help-card p b { color: var(--ink); }
.flooz-word { color: var(--good); }
.drain-word { color: var(--good); }
.dim { color: var(--dim); }
.kv { width: 100%; border-collapse: collapse; font-size: 14px; }
.kv td { padding: 6px 4px; border-bottom: 1px dashed rgba(130,180,255,.12); color: var(--dim); }
.kv td:first-child { color: var(--ink); font-weight: 600; white-space: nowrap; padding-right: 14px; }
.score-kv td:last-child { text-align: right; color: var(--gold); font-weight: 600; }

.piece-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.piece-legend figure { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.piece-legend svg { width: 52px; height: 52px; background: rgba(5,9,17,.8); border: 1px solid var(--panel-line); border-radius: 10px; }
.piece-legend figcaption { font-size: 11.5px; color: var(--dim); line-height: 1.35; }
.piece-legend .pc { stroke: #1c2740; stroke-width: 19; fill: none; }
.piece-legend .pi { stroke: #7e93b8; stroke-width: 11; fill: none; }

/* ============ Scores ============ */
.scores-summary { color: var(--dim); font-size: 14px; letter-spacing: .06em; margin-bottom: 18px; }
.scores-summary b { color: var(--gold); }
.scores-list { list-style: none; width: min(560px, 100%); display: flex; flex-direction: column; gap: 8px; }
.scores-list li {
  display: grid; grid-template-columns: 44px 1fr auto auto; gap: 14px; align-items: baseline;
  background: rgba(8, 13, 24, .6); border: 1px solid var(--panel-line);
  border-radius: 12px; padding: 12px 18px; font-size: 15px;
}
.scores-list li .rank { font-family: var(--font-display); font-weight: 700; color: var(--dim); }
.scores-list li:nth-child(1) .rank { color: var(--gold); text-shadow: 0 0 12px rgba(255,207,94,.6); }
.scores-list li:nth-child(2) .rank { color: #cdd9ee; }
.scores-list li:nth-child(3) .rank { color: #d9a05b; }
.scores-list li .name { font-weight: 600; letter-spacing: .04em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scores-list li .pts { font-family: var(--font-display); font-weight: 700; color: var(--accent); }
.scores-list li .lvl { color: var(--dim); font-size: 12.5px; }
.scores-empty { color: var(--dim); text-align: center; padding: 30px 10px; font-size: 15px; }

/* ============ Settings ============ */
.field { display: flex; align-items: center; gap: 12px; margin: 10px 0; font-size: 14px; }
.field > span { min-width: 74px; color: var(--dim); }
.field input[type="text"], .field input:not([type]), #go-name {
  flex: 1; min-width: 0; background: rgba(5,9,17,.85); border: 1px solid var(--panel-line);
  color: var(--ink); border-radius: 10px; padding: 10px 14px; font-size: 15px; letter-spacing: .08em;
}
.field input:focus-visible, #go-name:focus-visible, .field select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field select {
  background: rgba(5,9,17,.85); border: 1px solid var(--panel-line); color: var(--ink);
  border-radius: 10px; padding: 9px 12px; font-size: 14px;
}
.field.slider b { min-width: 38px; text-align: right; font-family: var(--font-display); font-size: 13px; color: var(--accent); }
input[type="range"] { flex: 1; accent-color: var(--accent); height: 26px; cursor: pointer; }
.check { display: flex; align-items: center; gap: 12px; margin: 12px 0; font-size: 14px; color: var(--ink); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }
.diff-cards { display: flex; flex-direction: column; gap: 8px; }
.diff-card {
  text-align: left; padding: 12px 16px; border-radius: 12px; cursor: pointer;
  background: rgba(5,9,17,.6); border: 1px solid var(--panel-line);
  display: flex; flex-direction: column; gap: 3px; transition: border-color .2s, box-shadow .2s;
}
.diff-card b { font-family: var(--font-display); letter-spacing: .14em; text-transform: uppercase; font-size: 13px; }
.diff-card span { font-size: 12.5px; color: var(--dim); }
.diff-card.sel { border-color: var(--accent); box-shadow: 0 0 18px var(--accent-soft), inset 0 0 12px hsl(var(--hue) 90% 60% / .08); }
.diff-card.sel b { color: var(--accent); }
.row-buttons { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; justify-content: center; }
.col-buttons { display: flex; flex-direction: column; gap: 12px; min-width: min(300px, 70vw); }

/* ============ HUD ============ */
#screen-game { pointer-events: none; align-items: flex-start; justify-content: stretch; }
#screen-game.active { pointer-events: none; }
#hud {
  pointer-events: auto;
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(5,8,16,.88), rgba(5,8,16,.55) 78%, transparent);
  z-index: 12;
}
.hud-chip {
  display: flex; align-items: center; gap: 9px;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 12px;
  padding: 8px 13px; min-height: 42px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.hud-label { font-size: 10px; letter-spacing: .22em; text-transform: uppercase; color: var(--dim); white-space: nowrap; }
.hud-chip b { font-family: var(--font-display); font-weight: 700; font-size: 17px; letter-spacing: .04em; font-variant-numeric: tabular-nums; }
.hud-level b { color: var(--accent); }
.hud-level-name { font-size: 11.5px; color: var(--dim); letter-spacing: .1em; text-transform: uppercase; white-space: nowrap; }
.hud-score b { color: var(--ink); min-width: 86px; text-align: right; }
.hud-hi b { color: var(--gold); }
.hud-flooz, .hud-goal { flex: 1 1 120px; max-width: 240px; }
.bar { flex: 1; height: 10px; border-radius: 6px; background: rgba(5,9,17,.9); border: 1px solid rgba(130,180,255,.14); overflow: hidden; min-width: 60px; }
.bar > div { height: 100%; width: 100%; border-radius: 6px; transition: width .12s linear; }
#hud-flooz-bar { background: linear-gradient(90deg, #59f0b0, #ffcf5e 70%, #ff5470); box-shadow: 0 0 12px rgba(89,240,176,.5); }
#hud-flooz-bar.flowing { background: hsl(var(--hue) 90% 60%); animation: pulse-bar 1s ease-in-out infinite; }
@keyframes pulse-bar { 50% { opacity: .55; } }
#hud-goal-bar { background: linear-gradient(90deg, hsl(var(--hue) 90% 55%), hsl(var(--hue) 90% 70%)); box-shadow: 0 0 12px var(--accent-soft); }
#hud-goal-bar.done { background: linear-gradient(90deg, var(--gold), #fff0c0); box-shadow: 0 0 14px rgba(255,207,94,.6); }
#hud-goal-text { font-size: 13px; color: var(--dim); }
#hud-goal-text.done { color: var(--gold); }
.hud-lives { gap: 5px; }
.hud-lives svg { width: 15px; height: 20px; filter: drop-shadow(0 0 6px rgba(110,231,255,.6)); }
.hud-lives svg.dead { opacity: .18; filter: none; }

.ff-btn {
  pointer-events: auto;
  position: absolute; right: 18px; bottom: 18px; z-index: 12;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 74px; height: 74px; border-radius: 50%;
  background: linear-gradient(180deg, hsl(var(--hue) 85% 52%), hsl(var(--hue) 90% 36%));
  border: 1px solid hsl(var(--hue) 90% 70% / .8);
  color: #04121c; cursor: pointer;
  font-family: var(--font-display); font-weight: 700; font-size: 10px; letter-spacing: .18em;
  box-shadow: 0 8px 30px hsl(var(--hue) 95% 55% / .45), inset 0 1px 0 rgba(255,255,255,.35);
  transition: transform .15s, box-shadow .2s, filter .2s;
}
.ff-btn svg { width: 26px; height: 26px; }
.ff-btn:hover { transform: scale(1.06); }
.ff-btn:active { transform: scale(.96); }
.ff-btn.on { filter: saturate(1.4); animation: ff-throb .5s ease-in-out infinite; pointer-events: none; }
@keyframes ff-throb { 50% { transform: scale(1.08); box-shadow: 0 8px 40px hsl(var(--hue) 95% 60% / .7), inset 0 1px 0 rgba(255,255,255,.4); } }

/* ============ Overlays ============ */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: rgba(4, 6, 12, .62);
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  opacity: 0; pointer-events: none; transition: opacity .3s ease;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.overlay .card {
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 24px;
  padding: clamp(26px, 5vw, 44px); width: min(480px, 92vw); max-height: 92dvh; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center;
  box-shadow: 0 40px 100px rgba(0,0,0,.6), 0 0 60px hsl(var(--hue) 90% 55% / .12);
  transform: scale(.92) translateY(12px); transition: transform .35s cubic-bezier(.2,.9,.3,1.4);
}
.overlay.show .card { transform: scale(1) translateY(0); }
.card-kicker { font-size: 11px; letter-spacing: .4em; text-transform: uppercase; color: var(--dim); }
.card-title {
  font-family: var(--font-display); font-weight: 900; letter-spacing: .06em; text-transform: uppercase;
  font-size: clamp(22px, 5vw, 32px); line-height: 1.15;
}
.glow-good { color: var(--good); text-shadow: 0 0 24px rgba(89,240,176,.5); }
.glow-bad { color: var(--bad); text-shadow: 0 0 24px rgba(255,84,112,.5); }
.card-tag { color: var(--dim); font-size: 14.5px; line-height: 1.5; }
.card-hint { font-size: 12px; color: var(--dim); letter-spacing: .08em; opacity: .8; }
.intro-objectives { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.intro-objectives .obj {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: rgba(8,13,24,.6); border: 1px solid var(--panel-line); border-radius: 12px;
  padding: 11px 16px; font-size: 14px;
}
.intro-objectives .obj .ico { font-size: 18px; filter: drop-shadow(0 0 8px var(--accent-soft)); }
.intro-objectives .obj b { color: var(--accent); }
.sum-table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.sum-table td { padding: 8px 4px; border-bottom: 1px dashed rgba(130,180,255,.12); text-align: left; color: var(--dim); }
.sum-table td:last-child { text-align: right; font-family: var(--font-display); font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.sum-table td.neg:last-child { color: var(--bad); }
.sum-table td.pos:last-child { color: var(--good); }
.sum-total { display: flex; justify-content: space-between; align-items: baseline; width: 100%; padding-top: 6px; }
.sum-total span { font-size: 11px; letter-spacing: .3em; text-transform: uppercase; color: var(--dim); }
.sum-total b { font-family: var(--font-display); font-weight: 900; font-size: 30px; color: var(--gold); text-shadow: 0 0 22px rgba(255,207,94,.4); font-variant-numeric: tabular-nums; }
.final-score { display: flex; flex-direction: column; gap: 4px; }
.final-score span { font-size: 11px; letter-spacing: .3em; text-transform: uppercase; color: var(--dim); }
.final-score b { font-family: var(--font-display); font-weight: 900; font-size: clamp(36px, 9vw, 54px); color: var(--gold); text-shadow: 0 0 30px rgba(255,207,94,.45); font-variant-numeric: tabular-nums; }
.lost-lives { display: flex; gap: 8px; }
.lost-lives svg { width: 20px; height: 26px; }
.lost-lives svg.dead { opacity: .18; }
.go-entry { display: none; flex-direction: column; gap: 10px; width: 100%; align-items: center; }
.go-entry.show { display: flex; }
.go-entry-label { font-size: 13px; color: var(--gold); letter-spacing: .08em; }
#go-name { width: min(260px, 80%); text-align: center; font-family: var(--font-display); font-weight: 700; letter-spacing: .2em; text-transform: uppercase; }

/* ============ Toast ============ */
#toast {
  position: absolute; left: 50%; bottom: 30px; transform: translate(-50%, 80px);
  background: var(--panel); border: 1px solid var(--gold); color: var(--gold);
  font-family: var(--font-display); font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  padding: 13px 26px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5), 0 0 26px rgba(255,207,94,.3);
  opacity: 0; transition: transform .4s cubic-bezier(.2,.9,.3,1.3), opacity .4s;
  z-index: 30; pointer-events: none; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============ Reduced motion ============ */
body.reduce-motion * { animation-duration: .001s !important; }
body.reduce-motion .logo-title { animation: none; }
body.reduce-motion .screen, body.reduce-motion .overlay, body.reduce-motion .overlay .card { transition-duration: .05s; }

/* ============ Responsive ============ */
@media (max-width: 880px) {
  .hud-level-name, .hud-hi { display: none; }
  #hud { gap: 6px; padding: 8px; }
  .hud-chip { padding: 6px 10px; min-height: 38px; gap: 6px; }
  .hud-chip b { font-size: 14px; }
  .hud-score b { min-width: 60px; }
  .hud-flooz, .hud-goal { flex-basis: 90px; }
  .ff-btn { width: 64px; height: 64px; }
}
@media (max-width: 560px) {
  .hud-label { display: none; }
  .menu-buttons { gap: 10px; }
  .btn { padding: 13px 20px; }
}
