/* Space look taken from the user's own game URANUS: Blue Current: same palette, type and button style. */
:root {
  --bg: #060a1a;
  --panel: rgba(12, 20, 48, .84);
  --panel2: rgba(20, 32, 72, .7);
  --line: rgba(96, 165, 250, .28);
  --blue: #3b82f6;
  --cyan: #22d3ee;
  --elec: #7dd3fc;
  --gold: #fbbf24;
  --green: #34d399;
  --red: #f43f5e;
  --violet: #a78bfa;
  --text: #e8f0ff;
  --dim: #9fb0d4;
  --dead: #33466f;
  --font: 'Kanit', 'Leelawadee UI', Tahoma, sans-serif;
  --display: 'Orbitron', 'Kanit', 'Leelawadee UI', Tahoma, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(ellipse at 50% -10%, #18286a 0%, #070b1d 55%, #03050d 100%) fixed;
  color: var(--text);
  font: 400 16px/1.5 var(--font);
  overscroll-behavior: none; touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}
#stars { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
#app { min-height: 100dvh; position: relative; overflow: hidden; z-index: 1; }
h1, h2 { font-family: var(--font); font-weight: 800; margin: 0; line-height: 1.2; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
button:disabled { cursor: default; }
input { user-select: text; -webkit-user-select: text; }

.note { color: var(--dim); margin: 0; min-height: 1.5em; }
.lede { color: var(--dim); margin: 0; }

.big-go, .power {
  display: block; width: 100%; min-height: 58px; padding: 12px;
  font: 600 21px var(--font); color: #04101e; border: 0; border-radius: 14px;
  background: linear-gradient(180deg, #67e8f9, #22d3ee 55%, #0ea5e9);
  box-shadow: 0 5px 0 #0369a1, 0 10px 24px rgba(34, 211, 238, .35);
}
.big-go:active, .power:not(:disabled):active { transform: translateY(4px); box-shadow: 0 1px 0 #0369a1, 0 4px 10px rgba(34, 211, 238, .3); }
.big-go:disabled { opacity: .5; }

.ghost {
  min-height: 40px; padding: 4px 12px; background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line); border-radius: 12px; color: var(--text); font-size: 14px;
}
.mute { width: 44px; height: 44px; flex: none; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; font-size: 18px; }

/* ---------- the planet ---------- */
.planet {
  width: 150px; aspect-ratio: 1; border-radius: 50%; position: relative; flex: none; align-self: center;
  background: radial-gradient(circle at 35% 35%, #d6fbff, #7fd8e0 35%, #3a93a8 65%, #123e5a 100%);
  box-shadow: 0 0 60px rgba(103, 232, 249, .45);
}
.planet::after {
  content: ''; position: absolute; left: 28%; top: -32%; width: 42%; height: 164%;
  border: 2px solid rgba(190, 230, 255, .75); border-radius: 50%; transform: rotate(14deg);
  box-shadow: 0 0 10px rgba(190, 230, 255, .4);
}

.game-title { font-family: var(--display); text-align: center; display: flex; flex-direction: column; gap: 6px; }
.game-title span {
  font-size: clamp(32px, 10.4vw, 52px); font-weight: 900; letter-spacing: 2px; line-height: 1; white-space: nowrap;
  background: linear-gradient(180deg, #fff, #a5f3fc 50%, #38bdf8);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(56, 189, 248, .6));
}
.game-title em { font: 600 clamp(19px, 5.6vw, 25px)/1.2 var(--font); color: var(--gold); text-shadow: 0 0 16px rgba(251, 191, 36, .6); }

/* ---------- join / lobby / results share a single centred column ---------- */
.join, .lobby, .result, .all-done, .countdown {
  min-height: 100dvh; max-width: 460px; margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 22px 28px;
  display: flex; flex-direction: column; gap: 14px;
}
.join { justify-content: center; text-align: center; gap: 12px; }
.join .planet { width: 118px; margin: 46px 0 44px; }
.join .logo { height: 36px; width: auto; align-self: center; background: rgba(255, 255, 255, .92); padding: 3px 8px; border-radius: 10px; }
.join-form {
  display: flex; flex-direction: column; gap: 10px; margin-top: 6px; padding: 16px; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
}
.join-form label { font-weight: 600; }
.join-form input {
  height: 54px; padding: 0 14px; font: 600 20px var(--font); width: 100%;
  background: rgba(3, 8, 22, .75); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
}
.join-form .big-go { margin-bottom: 5px; }

.lobby-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.lobby h1 { font-size: 26px; color: var(--elec); flex: 1; min-width: 0; overflow-wrap: anywhere; }
.lobby .big-go { flex: none; margin-bottom: 5px; }
.lobby h2 { font-size: 18px; margin-top: 6px; }
.wait { display: flex; gap: 10px; align-items: center; margin: 0; font-weight: 600; }
.led { width: 14px; height: 14px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); flex: none; }
.blink { animation: blink 1.1s steps(2, jump-none) infinite; }
@keyframes blink { 50% { opacity: .25; } }
.cheat { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.cheat li { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); padding: 6px 12px; border-radius: 14px; font-size: 14.5px; }
.cheat .gate-icon { width: 46px; height: 40px; flex: none; }

.countdown { align-items: center; justify-content: center; text-align: center; font-size: 20px; font-weight: 600; }
.count-num { font: 900 42vw/1 var(--display); color: var(--elec); text-shadow: 0 0 40px rgba(56, 189, 248, .8); }
.count-num.hit { animation: hit .5s ease-out; }
@keyframes hit { from { transform: scale(1.5); opacity: .3; } }

.result { justify-content: center; text-align: center; }
.result-kicker { margin: 0; color: var(--dim); font-size: 18px; font-weight: 600; }
.result h1 { font-size: 34px; }
.rank-big { font: 800 60px/1.1 var(--font); color: var(--elec); margin: 0; text-shadow: 0 0 24px rgba(56, 189, 248, .6); }
.rank-big small { display: block; font-size: 18px; color: var(--dim); font-weight: 400; text-shadow: none; }
.result.top .rank-big { color: var(--gold); text-shadow: 0 0 26px rgba(251, 191, 36, .7); }
.big-score { font: 600 26px var(--font); margin: 0; }
.all-done { justify-content: center; text-align: center; align-items: center; }
.all-done h1 { font-size: 34px; color: var(--gold); text-shadow: 0 0 18px rgba(251, 191, 36, .6); }

/* ---------- game layout: everything fits one screen, the board absorbs spare height ---------- */
.game {
  height: 100dvh; display: flex; flex-direction: column; gap: 6px;
  padding: max(8px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  max-width: 520px; margin: 0 auto;
}
.hud { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: none; min-height: 44px; }
.hud-mid { flex: 1; min-width: 0; text-align: center; }
.hud-right { text-align: right; line-height: 1.15; }
.hud-score { display: block; font: 800 20px var(--display); color: var(--gold); }
.hud-rank { font-size: 12px; color: var(--dim); white-space: nowrap; }
.hud-combo { font-size: 13px; font-weight: 600; color: #fb923c; display: block; min-height: 1.2em; }
.hud-count { display: block; font-size: 11.5px; line-height: 1.2; color: var(--dim); white-space: nowrap; }
.hud-bar { height: 6px; margin: 2px 0; border-radius: 3px; overflow: hidden; background: rgba(3, 8, 22, .75); border: 1px solid var(--line); }
.hud-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #3b82f6, #22d3ee); transition: width .3s; }
.manual-btn { width: 42px; height: 42px; flex: none; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; font-size: 19px; }

/* ---------- symbol guide ---------- */
.manual { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; background: #060a1a; }
.m-top { flex: none; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: max(10px, env(safe-area-inset-top)) 14px 6px; }
.m-top h2 { font-size: 22px; color: var(--elec); }
.m-warn { flex: none; margin: 0; padding: 0 14px 8px; color: var(--gold); font-size: 13px; }
.m-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: 0 14px 28px; }
.m-section { font-size: 18px; font-weight: 800; color: var(--cyan); margin: 16px 0 8px; }
.m-note { margin: -4px 0 8px; font-size: 13.5px; color: var(--dim); }
.m-steps { margin: 0; padding-left: 22px; display: grid; gap: 4px; font-size: 14.5px; }
.m-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 8px; }
.m-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.m-card h3 { margin: 0; font-size: 15.5px; font-weight: 600; }
.m-card p { margin: 1px 0 0; font-size: 13.5px; line-height: 1.35; color: var(--dim); }
.m-head, .m-row { display: flex; align-items: center; gap: 12px; }
.m-card .gate-icon { width: 56px; height: 48px; flex: none; }
.m-emoji { width: 56px; flex: none; text-align: center; font: 800 26px var(--display); color: var(--gold); }
.m-rail { width: 56px; height: 40px; flex: none; position: relative; }
.m-rail::before, .m-rail::after { content: ''; position: absolute; top: 0; bottom: 0; width: 5px; }
.m-rail::before { left: 8px; background: var(--cyan); box-shadow: 0 0 6px var(--cyan); }
.m-rail::after { right: 8px; background: var(--dead); }
.m-wire { width: 56px; height: 5px; flex: none; background: var(--dead); border-radius: 3px; }
.m-wire.live { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.truth { width: 100%; margin-top: 8px; border-collapse: collapse; font-size: 13.5px; text-align: center; }
.truth th { font-weight: 400; color: var(--dim); padding: 2px; border-bottom: 1px solid var(--line); }
.truth td { padding: 2px; color: var(--dim); }
.truth td:last-child { font-weight: 600; color: var(--text); }
.truth td.on { color: var(--gold); }

.clock {
  font: 800 21px/1 var(--display); color: var(--elec); text-shadow: 0 0 10px rgba(125, 211, 252, .7);
  padding: 9px 10px; min-width: 76px; text-align: center; flex: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
}
.all-done .clock { font-size: 34px; }
.clock.urgent { color: #fda4af; text-shadow: 0 0 12px var(--red); border-color: var(--red); animation: blink .5s steps(2, jump-none) infinite; }

.mission { flex: none; background: var(--panel); border: 1px solid var(--line); padding: 7px 12px 8px; border-radius: 16px; }
.mission h1 { font-size: 15px; font-weight: 600; color: var(--cyan); }
.mission p { margin: 1px 0 0; font-size: 14.5px; line-height: 1.32; }

.stage { flex: 1 1 0; min-height: 0; display: flex; align-items: center; justify-content: center; }
.board { width: 100%; height: 100%; display: block; }

.msg { flex: none; margin: 0; font-size: 13.5px; line-height: 1.3; font-weight: 600; text-align: center; color: var(--dim); }
.msg:empty { display: none; }
.msg.bad { color: #fb7185; }
.msg.good { color: var(--green); }
.rule { flex: none; margin: 0; min-height: 1.3em; font-size: 13px; line-height: 1.3; color: var(--dim); text-align: center; }
.rule.is-hint { color: var(--gold); font-weight: 600; }

.palette { flex: none; display: flex; gap: 6px; }
.chip {
  flex: 1 1 0; min-width: 0; min-height: 58px; padding: 3px 2px;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  background: var(--panel); border: 2px solid var(--line); border-radius: 14px;
  font: 800 13px/1.15 var(--display);
}
.chip small { display: block; font: 400 11px var(--font); color: var(--dim); }
.palette.many .chip { flex-direction: column; gap: 1px; font-size: 11.5px; text-align: center; }
.palette.many .chip .gate-icon { width: 34px; height: 24px; }
.chip .gate-icon { width: 38px; height: 32px; flex: none; }
.chip.active { border-color: var(--cyan); background: rgba(34, 211, 238, .15); box-shadow: 0 0 14px rgba(34, 211, 238, .4); }
.chip:disabled { opacity: .3; }
.chip:not(:disabled):active { transform: translateY(2px); }

.actions { flex: none; display: flex; flex-direction: column; gap: 6px; }
.help { display: flex; gap: 6px; }
.help:empty { display: none; }
.help .ghost { flex: 1; }
.power { min-height: 54px; margin-bottom: 5px; }
.power:disabled { background: var(--panel2); color: var(--dim); box-shadow: 0 5px 0 rgba(0, 0, 0, .35); }

/* ---------- ladder extras ---------- */
.hold-row { flex: none; display: flex; gap: 8px; }
.hold {
  flex: 1; height: 54px; border: 0; border-radius: 27px;
  font: 800 14px var(--display); color: #fff; touch-action: none;
}
.hold.go { background: linear-gradient(180deg, #6ee7b7, #10b981); box-shadow: 0 5px 0 #047857; color: #04101e; }
.hold.stop { background: linear-gradient(180deg, #fb7185, #e11d48); box-shadow: 0 5px 0 #9f1239; }
.hold.sense { background: linear-gradient(180deg, #c4b5fd, #8b5cf6); box-shadow: 0 5px 0 #5b21b6; }
.hold.down { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0, 0, 0, .5); filter: brightness(1.25); }

.plant { flex: none; height: 14px; position: relative; overflow: hidden; border-radius: 7px; background: rgba(3, 8, 22, .75); }
.plant.has-box { height: 30px; }
.belt {
  position: absolute; left: 0; right: 0; bottom: 0; height: 10px;
  background: repeating-linear-gradient(90deg, #1b2c55 0 10px, #3b5a9a 10px 20px);
}
.plant.running .belt { animation: belt .35s linear infinite; }
@keyframes belt { to { background-position: 20px 0; } }
.plant .box { position: absolute; bottom: 6px; left: 44%; font-size: 18px; line-height: 1; }
.plant.running .box { animation: box-move 1.2s linear infinite; }
@keyframes box-move { from { left: -8%; } to { left: 100%; } }

/* ---------- board drawing ---------- */
.plate rect { fill: var(--panel2); stroke: var(--line); }
.plate text { fill: var(--text); font: 400 12.5px var(--font); }

.wire path { fill: none; stroke-linejoin: round; }
.wire-base { stroke: var(--dead); stroke-width: 4; }
.wire.live .wire-base { stroke: var(--cyan); stroke-width: 5; filter: drop-shadow(0 0 5px rgba(34, 211, 238, .9)); }
.wire-flow { stroke: #ecfeff; stroke-width: 2; stroke-dasharray: 5 15; animation: flow .5s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -20; } }

.switch, .gate[role='button'], .is-slot { cursor: pointer; outline: none; }
.switch-body { fill: rgba(3, 8, 22, .85); stroke: var(--line); stroke-width: 2; }
.switch-knob { fill: var(--dim); transition: x .08s; }
.switch.on .switch-body { stroke: var(--cyan); }
.switch.on .switch-knob { fill: var(--cyan); filter: drop-shadow(0 0 5px var(--cyan)); }

.gate-body { fill: #101c44; stroke: var(--elec); stroke-width: 2.5; }
.gate-extra { fill: none; stroke: var(--elec); stroke-width: 2.5; }
.gate-icon .gate-body { fill: none; stroke-width: 4; }
.gate-icon .gate-extra { stroke-width: 4; }
.gate.live .gate-body, .gate.live .gate-extra { stroke: var(--cyan); filter: drop-shadow(0 0 6px var(--cyan)); }
.gate-text { fill: var(--text); font: 800 12px var(--display); pointer-events: none; }
.slot-box { fill: rgba(251, 191, 36, .07); stroke: var(--gold); stroke-width: 2; stroke-dasharray: 6 5; }
.slot-q { fill: var(--gold); font: 800 24px var(--display); pointer-events: none; }
.selected .slot-box { fill: rgba(251, 191, 36, .22); stroke-dasharray: none; animation: pulse 1s ease-in-out infinite; }
.gate.selected .gate-body { stroke: var(--gold); stroke-width: 4; }
.rung-item.selected .contact path { stroke: var(--gold); }
@keyframes pulse { 50% { stroke-width: 4; } }

.pilot-ring { fill: rgba(3, 8, 22, .85); stroke: var(--elec); stroke-width: 2; }
.pilot-lens { fill: #0d1838; stroke: var(--line); stroke-width: 1; }
.pilot-icon { font-size: 26px; opacity: .3; pointer-events: none; }
.pilot-icon.small { font-size: 20px; }
.pilot.on .pilot-lens { fill: var(--gold); filter: drop-shadow(0 0 14px var(--gold)); }
.pilot.on .pilot-icon { opacity: 1; }

.rail { stroke: var(--cyan); stroke-width: 5; fill: none; filter: drop-shadow(0 0 4px rgba(34, 211, 238, .7)); }
.rail.neutral { stroke: var(--dead); filter: none; }
.contact path { fill: none; stroke: var(--elec); stroke-width: 4; }
.contact .contact-bars { stroke-width: 4.5; }
.contact .contact-slash { stroke: var(--red); stroke-width: 3.5; }
.contact.live path:not(.contact-slash) { stroke: var(--cyan); }
.gate-icon .contact path, .gate-icon .contact circle { stroke: var(--text); stroke-width: 4; }
.gate-icon .contact .contact-slash { stroke: var(--red); }
.live-stub { stroke: var(--cyan); fill: none; stroke-width: 5; }
.contact-name { fill: var(--text); font: 800 10px var(--display); pointer-events: none; }
.coil-name { fill: var(--text); font: 400 11.5px var(--font); pointer-events: none; }
.hit { pointer-events: all; }

/* ---------- feedback overlays ---------- */
.flash { position: fixed; inset: 0; pointer-events: none; z-index: 20; animation: flash .45s ease-out forwards; }
.flash.win { background: var(--cyan); }
.flash.lose { background: var(--red); }
@keyframes flash { from { opacity: .7; } to { opacity: 0; } }
.stamp {
  position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 30;
  padding: 12px 26px; text-align: center; white-space: nowrap;
  background: var(--panel); border: 2px solid var(--gold); border-radius: 20px;
  box-shadow: 0 0 40px rgba(251, 191, 36, .5); animation: stamp .24s cubic-bezier(.2, 1.6, .4, 1);
}
.stamp b { display: block; font: 900 42px/1.1 var(--display); color: var(--gold); text-shadow: 0 0 18px rgba(251, 191, 36, .7); }
.stamp span { font-weight: 600; }
@keyframes stamp { from { transform: translate(-50%, -50%) scale(2); opacity: 0; } }

@media (max-height: 640px) {
  .mission p { font-size: 13.5px; }
  .chip { min-height: 48px; }
  .power { min-height: 48px; font-size: 19px; }
  .hold { height: 46px; }
  .join { gap: 8px; padding-top: 12px; padding-bottom: 12px; }
  .join .planet { width: 70px; margin: 26px 0 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .wire-flow, .plant.running .belt, .plant.running .box, .blink, .selected .slot-box, .clock.urgent, .count-num.hit { animation: none; }
  .flash { animation-duration: .01s; }
}
