:root {
  color-scheme: dark;
  --bg: #0c1024;
  --panel: rgba(22, 30, 64, 0.78);
  --panel-strong: rgba(33, 45, 91, 0.9);
  --line: rgba(177, 209, 255, 0.2);
  --text: #f7f4df;
  --muted: #b8c4e8;
  --gold: #ffd76a;
  --mint: #78ffe0;
  --rose: #ff7da7;
  --shadow: 0 22px 80px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 10%, rgba(120,255,224,.18), transparent 25rem),
    radial-gradient(circle at 80% 0%, rgba(255,125,167,.16), transparent 24rem),
    linear-gradient(160deg, #070918 0%, var(--bg) 55%, #171036 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(circle, rgba(255,255,255,.7) 0 1px, transparent 1.4px);
  background-size: 72px 72px;
  opacity: .16;
}

.shell { width: min(1100px, calc(100% - 28px)); margin: 0 auto; padding: 18px 0 34px; position: relative; }
.topnav { display: flex; gap: 10px; align-items: center; justify-content: center; margin-bottom: 14px; color: var(--muted); }
a { color: var(--mint); font-weight: 800; text-decoration: none; }
a:hover { text-decoration: underline; }
.panel { border: 1px solid var(--line); border-radius: 24px; background: var(--panel); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.hero { padding: clamp(20px, 4vw, 36px); text-align: center; overflow: hidden; }
.eyebrow { margin: 0 0 8px; color: var(--mint); letter-spacing: .12em; text-transform: uppercase; font-size: .75rem; font-weight: 900; }
h1 { margin: 0; font-size: clamp(2.3rem, 7vw, 5rem); line-height: .92; letter-spacing: -.05em; }
h2 { margin: 0 0 8px; font-size: clamp(1.35rem, 3vw, 2rem); }
.subtitle, .hint, .bonus, .message { color: var(--muted); line-height: 1.45; }
.subtitle { margin: 16px auto 0; max-width: 680px; font-size: 1.05rem; }
.hud { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 16px 0 10px; }
.stat { padding: 14px; text-align: center; }
.stat span { display: block; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 800; }
.stat strong { display: block; margin-top: 4px; font-size: 1.7rem; }
.patience { height: 16px; padding: 3px; overflow: hidden; }
#patienceBar { height: 100%; width: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--rose), var(--gold), var(--mint)); transition: width .18s linear; }
.play-area { display: grid; grid-template-columns: minmax(260px, 360px) 1fr; gap: 16px; margin-top: 16px; align-items: stretch; }
.order, .board-card, .rules { padding: 18px; }
.mini-sky, .sky-board { position: relative; display: grid; grid-template-columns: repeat(4, 1fr); gap: clamp(10px, 2vw, 14px); aspect-ratio: 1; border-radius: 22px; padding: 14px; background: radial-gradient(circle at 50% 42%, rgba(120,255,224,.08), rgba(5,8,25,.72)); border: 1px solid rgba(255,255,255,.12); }
.mini-sky { max-width: 250px; margin: 16px auto; }
.sky-board { width: min(100%, 520px); margin: 0 auto 18px; gap: clamp(10px, 2vw, 16px); padding: clamp(14px, 3vw, 22px); }
.cell, .star-btn { border-radius: 999px; display: grid; place-items: center; position: relative; }
.cell::before, .star-btn::before { content: ""; width: 22%; aspect-ratio: 1; border-radius: 50%; background: rgba(183, 199, 237, .34); box-shadow: 0 0 8px rgba(183, 199, 237, .18); transition: .16s ease; }
.cell.lit::before, .star-btn.lit::before { width: 38%; background: #fff6a9; box-shadow: 0 0 6px #fff, 0 0 16px var(--gold), 0 0 26px rgba(120,255,224,.34); }
.star-btn { appearance: none; border: 1px solid rgba(255,255,255,.08); background: rgba(255,255,255,.025); cursor: pointer; min-height: 56px; }
.star-btn:hover, .star-btn:focus-visible { outline: 3px solid rgba(120,255,224,.45); outline-offset: 2px; background: rgba(120,255,224,.08); }
.connectors { position: absolute; inset: 14px; width: calc(100% - 28px); height: calc(100% - 28px); pointer-events: none; overflow: visible; z-index: 0; }
.connectors path { fill: none; stroke: rgba(255, 215, 106, .56); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 5px rgba(255,215,106,.5)); }
.mini-sky .cell, .sky-board .star-btn { z-index: 1; }
.preview-controls, .actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
button { min-height: 44px; border: 0; border-radius: 999px; padding: 10px 15px; color: var(--text); background: var(--panel-strong); font-weight: 900; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(255,255,255,.12); }
button:hover, button:focus-visible { transform: translateY(-1px); outline: 3px solid rgba(255,215,106,.35); }
button.primary { background: linear-gradient(135deg, #fff08c, #ff9f6f); color: #241209; box-shadow: 0 10px 28px rgba(255, 159, 111, .28); }
.message { text-align: center; min-height: 2.6em; margin: 4px auto 0; max-width: 620px; }
.rules { margin-top: 16px; }
.rules ul { margin: 10px 0 0; padding-left: 1.2rem; color: var(--muted); line-height: 1.55; }
.shake { animation: shake .28s ease; }
.flash { animation: flash .5s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes flash { 50% { filter: brightness(1.35); } }

@media (max-width: 760px) {
  .hud { grid-template-columns: repeat(2, 1fr); }
  .play-area { grid-template-columns: 1fr; }
  .order { order: -1; }
  h1 { font-size: clamp(2.4rem, 13vw, 4.4rem); }
}
