:root {
  --void: #07070e;
  --bg-1: #0c0c16;
  --bg-2: #12121e;
  --surface: #16161f;
  --surface-2: #1e1e2c;
  --text: #f1eff7;
  --muted: #b4b1c6;
  --dim: #6e6c82;
  --line: rgba(241, 239, 247, 0.08);
  --line-2: rgba(241, 239, 247, 0.16);
  --violet: #a78bfa;
  --cyan: #38bdf8;
  --amber: #fbbf24;
  --green: #4ade80;
  --danger: #fb7185;
  --spectral: linear-gradient(90deg, #a78bfa 0%, #38bdf8 40%, #4ade80 60%, #fbbf24 80%, #fb7185 100%);
  --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 20% 0%, rgba(56, 189, 248, 0.07), transparent 55%),
    radial-gradient(ellipse 55% 45% at 85% 100%, rgba(167, 139, 250, 0.06), 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.7; } }
.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 */
.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(7,7,14,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: transparent; background: var(--spectral); -webkit-background-clip: text; background-clip: text; 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(--cyan); 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 */
.hero { text-align: center; padding: 36px 0 26px; }
.hero .eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: 0.3em; color: var(--cyan); 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 { color: transparent; background: var(--spectral); -webkit-background-clip: text; background-clip: text; font-style: italic; }
.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: var(--spectral); opacity: 0.5; }
.divider .mark { font-size: 14px; color: var(--cyan); }

.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-demo { margin: 18px 0; }
.intro-demo canvas { width: 100%; height: 56px; border-radius: 4px; display: block; border: 1px solid var(--line); }
.intro-demo .cap { font-family: var(--mono); font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--dim); margin-top: 8px; text-align: center; }
.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(--cyan); font-size: 11px; flex-shrink: 0; width: 18px; }

/* buttons */
.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: #0a0a14; background: var(--spectral); }
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 12px 32px rgba(56, 189, 248, 0.25); filter: brightness(1.05); }
.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(--cyan); color: var(--text); box-shadow: none; filter: none; }

/* board */
.board-frame { width: 100%; max-width: 560px; 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(--cyan); }
.board-header .mode-tag::before { content: ''; width: 6px; height: 6px; background: var(--cyan); border-radius: 50%; box-shadow: 0 0 8px var(--cyan); }
.board-header .timer { color: var(--text); font-size: 14px; letter-spacing: 0.1em; }

.mystery { position: relative; margin-bottom: 8px; }
.mystery-label { font-family: var(--mono); font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--dim); margin-bottom: 8px; text-align: center; }
.mystery canvas { width: 100%; height: 96px; display: block; border-radius: 6px; border: 1px solid var(--line-2); box-shadow: 0 8px 40px rgba(0,0,0,0.5); }
.scale-row { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 9px; color: var(--dim); letter-spacing: 0.1em; margin-top: 5px; padding: 0 2px; }

.prompt-line { text-align: center; font-family: var(--display); font-style: italic; font-size: 19px; color: var(--text); margin: 20px 0 14px; }
.prompt-line b { color: var(--cyan); font-style: normal; }

/* options */
.options { display: flex; flex-direction: column; gap: 10px; }
.spec-option { display: flex; align-items: center; gap: 14px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; transition: all 0.25s var(--ease); text-align: left; width: 100%; }
.spec-option:hover { border-color: var(--line-2); background: var(--surface-2); transform: translateX(2px); }
.spec-option .el-name { flex-shrink: 0; width: 96px; }
.spec-option .el-name .sym { font-family: var(--display); font-size: 26px; line-height: 1; color: var(--text); }
.spec-option .el-name .nm { font-family: var(--mono); font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); margin-top: 2px; }
.spec-option .ref { flex: 1; min-width: 0; }
.spec-option .ref canvas { width: 100%; height: 38px; display: block; border-radius: 3px; transition: filter 0.6s ease; }
.spec-option.selected { border-color: var(--cyan); background: rgba(56, 189, 248, 0.08); }
.spec-option.correct { border-color: var(--green); background: rgba(74, 222, 128, 0.1); animation: pop 0.5s var(--spring); }
.spec-option.wrong { border-color: var(--danger); animation: shake 0.4s ease; }
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.03); } 100% { transform: scale(1); } }
@keyframes shake { 0%,100%{transform:translateX(0);} 25%{transform:translateX(-5px);} 75%{transform:translateX(5px);} }
.options.memory.hide .ref canvas { filter: blur(7px) brightness(0.4); }

.peek-btn { display: block; margin: 14px auto 0; font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--dim); background: none; border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; cursor: pointer; transition: all 0.25s; }
.peek-btn:hover { color: var(--cyan); border-color: var(--cyan); }

.confirm-row { margin-top: 14px; }

/* result */
.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: transparent; background: var(--spectral); -webkit-background-clip: text; background-clip: text; 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(--cyan); 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(--cyan); 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 */
.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(56,189,248,0.08), transparent); border-left: 2px solid var(--cyan); padding-left: 12px; }
.lb-rank { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.lb-rank.top1 { color: var(--amber); 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-acc { font-size: 12px; letter-spacing: 0.08em; }
.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(--cyan); 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; }
  .spec-option .el-name { width: 72px; }
  .spec-option .el-name .sym { font-size: 22px; }
  .result-stats { gap: 18px; }
}
@media (prefers-reduced-motion: reduce) { #bg-dust .d { animation: none !important; } }
