:root {
  --void: #0a0b10;
  --bg-1: #0f1118;
  --bg-2: #151823;
  --surface: #181b26;
  --surface-2: #1f2330;
  --text: #eef0f6;
  --muted: #aeb4c4;
  --dim: #6a7082;
  --line: rgba(238, 240, 246, 0.08);
  --line-2: rgba(238, 240, 246, 0.16);
  --laser: #ff5e7a;
  --laser-soft: #ff90a6;
  --laser-deep: #c23b56;
  --steel: #9fb0c8;
  --gem: #5eead4;
  --display: 'Cormorant Garamond', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body {
  background:
    radial-gradient(ellipse 60% 50% at 18% 0%, rgba(255, 94, 122, 0.07), transparent 55%),
    radial-gradient(ellipse 55% 45% at 88% 100%, rgba(94, 234, 212, 0.05), transparent 55%),
    linear-gradient(180deg, var(--void) 0%, var(--bg-1) 60%, var(--void) 100%);
  background-attachment: fixed; color: var(--text); font-family: var(--display); min-height: 100vh; -webkit-font-smoothing: antialiased; position: relative; overflow-x: hidden;
}
#bg-dust { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
#bg-dust .d { position: absolute; width: 2px; height: 2px; background: #fff; border-radius: 50%; opacity: 0.3; animation: tw var(--dur,5s) ease-in-out infinite; animation-delay: var(--delay,0s); }
@keyframes tw { 0%,100% { opacity: 0.1; } 50% { opacity: 0.6; } }
.grain { position: fixed; inset: 0; z-index: 1; pointer-events: none; opacity: 0.035; mix-blend-mode: overlay; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }
#root { position: relative; z-index: 2; min-height: 100vh; display: flex; flex-direction: column; }

.topbar { display: flex; justify-content: space-between; align-items: center; padding: 18px 24px; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; background: rgba(10,11,16,0.85); backdrop-filter: blur(12px); }
.brand { font-family: var(--display); font-style: italic; font-size: 22px; letter-spacing: 0.04em; color: var(--muted); }
.brand b { color: var(--laser); font-weight: 600; font-style: normal; }
.top-meta { display: flex; gap: 10px; align-items: center; font-family: var(--mono); font-size: 12px; color: var(--dim); letter-spacing: 0.1em; text-transform: uppercase; }
.top-meta .dot { width: 4px; height: 4px; background: var(--laser); border-radius: 50%; }

.stage { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 32px 20px 60px; max-width: 720px; width: 100%; margin: 0 auto; }

.hero { text-align: center; padding: 36px 0 26px; }
.hero .eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: 0.3em; color: var(--laser); text-transform: uppercase; margin-bottom: 18px; }
.hero h1 { font-family: var(--display); font-weight: 500; font-size: clamp(48px, 9vw, 82px); line-height: 0.95; letter-spacing: -0.02em; margin-bottom: 8px; }
.hero h1 .grad { font-style: italic; color: var(--laser); }
.hero .sub { font-style: italic; color: var(--muted); font-size: 17px; max-width: 450px; margin: 8px auto 0; line-height: 1.5; }
.divider { display: flex; align-items: center; gap: 12px; margin: 26px 0; width: 100%; max-width: 460px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--laser-deep), transparent); }
.divider .mark { font-size: 14px; color: var(--laser); }

.intro-card { background: linear-gradient(180deg, var(--surface), var(--bg-2)); border: 1px solid var(--line-2); border-radius: 6px; padding: 28px; width: 100%; max-width: 500px; }
.intro-card h2 { font-family: var(--display); font-weight: 500; font-size: 28px; margin-bottom: 12px; }
.intro-card p { color: var(--muted); line-height: 1.6; font-size: 15px; margin-bottom: 14px; }
.intro-rules { list-style: none; margin: 16px 0 24px; padding: 16px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.intro-rules li { display: flex; gap: 12px; padding: 6px 0; font-size: 14px; color: var(--muted); }
.intro-rules li .num { font-family: var(--mono); color: var(--laser); font-size: 11px; flex-shrink: 0; width: 18px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; padding: 14px 28px; font-family: var(--mono); font-size: 12px; font-weight: 500; letter-spacing: 0.2em; text-transform: uppercase; border: none; border-radius: 2px; cursor: pointer; transition: all 0.3s var(--ease); width: 100%; color: #1a0a10; background: linear-gradient(135deg, var(--laser-soft), var(--laser)); }
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 12px 32px rgba(255, 94, 122, 0.28); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line-2); }
.btn.ghost:hover:not(:disabled) { background: var(--surface); border-color: var(--laser); color: var(--text); box-shadow: none; }

.board-frame { width: 100%; max-width: 500px; margin: 0 auto; }
.board-header { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 16px; font-family: var(--mono); font-size: 11px; letter-spacing: 0.2em; color: var(--dim); text-transform: uppercase; }
.board-header .mode-tag { display: inline-flex; align-items: center; gap: 8px; color: var(--laser); }
.board-header .mode-tag::before { content: ''; width: 6px; height: 6px; background: var(--laser); border-radius: 50%; box-shadow: 0 0 8px var(--laser); }
.board-header .timer { color: var(--text); font-size: 14px; letter-spacing: 0.1em; }

.optics { width: 100%; aspect-ratio: 1; background: radial-gradient(ellipse at 50% 50%, rgba(255,94,122,0.04), transparent 70%), linear-gradient(160deg, #0c0e16, #11141f); border: 1px solid var(--line-2); border-radius: 6px; display: block; }
.optics .cell-bg { fill: rgba(255,255,255,0.012); stroke: rgba(255,255,255,0.04); stroke-width: 0.01; }
.optics .mirror-hit { fill: transparent; cursor: pointer; }
.optics .mirror { stroke: var(--steel); stroke-width: 0.12; stroke-linecap: round; filter: drop-shadow(0 0 0.04px rgba(159,176,200,0.6)); pointer-events: none; transition: stroke 0.2s; }
.optics .mirror-cell:hover .mirror { stroke: #cfe0f5; }
.optics .beam { stroke: var(--laser); stroke-width: 0.07; fill: none; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 0.12px var(--laser)) drop-shadow(0 0 0.3px var(--laser)); }
.optics .beam.flow { stroke-dasharray: 0.5 0.35; animation: flow 1s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -0.85; } }
.optics .beam.won { stroke: var(--laser-soft); stroke-width: 0.1; filter: drop-shadow(0 0 0.2px var(--laser-soft)) drop-shadow(0 0 0.5px var(--laser)); }
.optics .emitter { fill: var(--laser); filter: drop-shadow(0 0 0.15px var(--laser)); }
.optics .target-ring { fill: none; stroke: var(--steel); stroke-width: 0.06; }
.optics .target-core { fill: rgba(159,176,200,0.15); transition: fill 0.3s; }
.optics .target.lit .target-ring { stroke: var(--laser-soft); }
.optics .target.lit .target-core { fill: var(--laser); filter: drop-shadow(0 0 0.25px var(--laser)); }
.optics .gem { fill: rgba(94,234,212,0.18); stroke: var(--gem); stroke-width: 0.04; transition: all 0.3s; }
.optics .gem.lit { fill: var(--gem); filter: drop-shadow(0 0 0.2px var(--gem)); }

.controls { display: flex; gap: 12px; margin-top: 18px; }
.controls .info-box { flex: 1; display: flex; align-items: center; justify-content: center; gap: 18px; font-family: var(--mono); font-size: 12px; letter-spacing: 0.12em; color: var(--muted); text-transform: uppercase; background: var(--surface); border: 1px solid var(--line-2); border-radius: 2px; padding: 12px 16px; }
.controls .info-box b { color: var(--laser-soft); }
.controls .info-box .gem-stat.ok { color: var(--gem); }

.result-card { text-align: center; padding: 32px 24px; margin: 24px 0; background: linear-gradient(180deg, var(--surface), var(--bg-2)); border: 1px solid var(--line-2); border-radius: 6px; width: 100%; max-width: 520px; }
.result-card .squares { font-size: 30px; letter-spacing: 0.18em; margin-bottom: 10px; }
.result-card h3 { font-family: var(--display); font-style: italic; font-size: 34px; color: var(--laser-soft); margin-bottom: 4px; }
.result-card .aka { color: var(--muted); font-style: italic; margin-bottom: 18px; }
.result-stats { display: flex; justify-content: center; gap: 28px; margin: 18px 0 24px; }
.result-stats .s-label { font-family: var(--mono); font-size: 10px; letter-spacing: 0.2em; color: var(--dim); text-transform: uppercase; margin-bottom: 4px; }
.result-stats .s-value { font-family: var(--mono); font-size: 22px; color: var(--text); }
.result-fact { background: var(--void); border-left: 2px solid var(--laser); padding: 14px 16px; margin: 18px 0; text-align: left; font-size: 14px; line-height: 1.6; color: var(--muted); font-style: italic; }
.result-fact b { color: var(--laser-soft); font-style: normal; font-family: var(--mono); font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase; display: block; margin-bottom: 6px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.leaderboard { margin: 32px 0 0; padding: 24px 0 0; border-top: 1px solid var(--line); width: 100%; max-width: 520px; }
.leaderboard h3 { font-family: var(--display); font-style: italic; font-size: 22px; text-align: center; margin-bottom: 4px; }
.leaderboard .lb-sub { text-align: center; font-family: var(--mono); font-size: 10px; letter-spacing: 0.25em; color: var(--dim); text-transform: uppercase; margin-bottom: 18px; }
.lb-list { list-style: none; }
.lb-row { display: grid; grid-template-columns: 32px 1fr auto auto; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.lb-row.self { background: linear-gradient(90deg, rgba(255,94,122,0.08), transparent); border-left: 2px solid var(--laser); padding-left: 12px; }
.lb-rank { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.lb-rank.top1 { color: var(--laser-soft); font-size: 14px; }
.lb-rank.top2 { color: #d4d4d4; }
.lb-rank.top3 { color: #c79a6b; }
.lb-name { font-family: var(--display); color: var(--text); font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-moves { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.lb-time { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.lb-empty { text-align: center; padding: 20px; color: var(--dim); font-style: italic; }
.signin-prompt { text-align: center; padding: 18px; background: var(--surface); border: 1px dashed var(--line-2); border-radius: 6px; margin-bottom: 16px; font-size: 13px; color: var(--muted); }
.signin-prompt button { display: inline-flex; align-items: center; gap: 8px; margin-top: 10px; background: var(--text); color: var(--void); border: none; padding: 10px 16px; font-family: var(--mono); font-size: 11px; letter-spacing: 0.15em; text-transform: uppercase; cursor: pointer; border-radius: 2px; transition: transform 0.25s; }
.signin-prompt button:hover { transform: translateY(-1px); }

.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--laser); color: var(--text); padding: 12px 20px; border-radius: 2px; font-family: var(--mono); font-size: 12px; letter-spacing: 0.15em; z-index: 100; box-shadow: 0 8px 30px rgba(0,0,0,0.4); opacity: 0; transition: opacity 0.3s; }
.toast.show { opacity: 1; }
.footer-tip { text-align: center; font-style: italic; color: var(--dim); font-size: 12px; margin-top: 28px; padding: 12px; }

@media (max-width: 540px) {
  .stage { padding: 20px 14px 40px; }
  .topbar { padding: 14px 16px; }
  .result-stats { gap: 18px; }
}
@media (prefers-reduced-motion: reduce) { #bg-dust .d { animation: none !important; } .optics .beam.flow { animation: none !important; } }
