:root {
  --bg-void: #050816;
  --bg-deep: #0a0f25;
  --bg-mid: #141b3a;
  --surface: #1a2148;
  --surface-2: #232a55;
  --text-cream: #f5f0e1;
  --text-muted: #c5bea3;
  --text-dim: #8a8470;
  --star-light: #fef8e7;
  --gold-glow: #f5d28a;
  --gold-rich: #d4af37;
  --gold-deep: #8b6914;
  --accent: #7dd3fc;
  --accent-deep: #38bdf8;
  --accent-glow: rgba(125, 211, 252, 0.5);
  --success: #86efac;
  --danger: #fca5a5;
  --line-faint: rgba(245, 240, 225, 0.06);
  --line-soft: rgba(245, 240, 225, 0.12);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --display: 'Cormorant Garamond', 'Playfair Display', Georgia, serif;
  --serif: 'Playfair Display', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg-void);
  color: var(--text-cream);
  font-family: var(--serif);
  overflow-x: hidden;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(125, 211, 252, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse 70% 50% at 80% 90%, rgba(212, 175, 55, 0.04) 0%, transparent 50%),
    linear-gradient(180deg, var(--bg-void) 0%, var(--bg-deep) 60%, var(--bg-void) 100%);
  background-attachment: fixed;
  position: relative;
}

/* ============ BACKGROUND STARFIELD ============ */
#bg-stars {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

#bg-stars .twinkle {
  position: absolute;
  width: 2px; height: 2px;
  background: var(--star-light);
  border-radius: 50%;
  opacity: 0.5;
  animation: twinkle var(--dur, 4s) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

@keyframes twinkle {
  0%, 100% { opacity: 0.15; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* film grain overlay */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.04;
  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;
}

/* ============ TOP BAR ============ */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line-faint);
  position: sticky;
  top: 0;
  background: rgba(5, 8, 22, 0.85);
  backdrop-filter: blur(12px);
  z-index: 10;
}

.brand {
  font-family: var(--display);
  font-style: italic;
  font-size: 22px;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.brand b { color: var(--gold-glow); font-weight: 600; }

.top-meta {
  display: flex;
  gap: 18px;
  align-items: center;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.top-meta .dot { width: 4px; height: 4px; background: var(--gold-rich); border-radius: 50%; display: inline-block; margin: 0 6px; vertical-align: middle; }

/* ============ MAIN LAYOUT ============ */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 20px 60px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

/* ============ HERO / INTRO ============ */
.hero {
  text-align: center;
  padding: 40px 0 32px;
}
.hero .eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.3em;
  color: var(--gold-rich);
  text-transform: uppercase;
  margin-bottom: 18px;
}
.hero h1 {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(48px, 9vw, 84px);
  line-height: 0.95;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
  color: var(--text-cream);
}
.hero h1 .italic { font-style: italic; color: var(--gold-glow); }
.hero .sub {
  font-family: var(--serif);
  font-style: italic;
  color: var(--text-muted);
  font-size: 17px;
  max-width: 460px;
  margin: 8px auto 0;
  line-height: 1.5;
}

/* ornate divider */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 28px 0;
  color: var(--gold-deep);
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-deep), transparent);
}
.divider .mark {
  font-family: var(--display);
  font-size: 16px;
  color: var(--gold-rich);
  letter-spacing: 0.3em;
}

/* ============ INTRO CARD ============ */
.intro-card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-mid) 100%);
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  padding: 28px 28px 32px;
  width: 100%;
  max-width: 480px;
  position: relative;
}
.intro-card::before, .intro-card::after,
.intro-card .corner-tl, .intro-card .corner-br {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  border: 1px solid var(--gold-rich);
}
.intro-card::before { top: 8px; left: 8px; border-right: none; border-bottom: none; }
.intro-card::after { bottom: 8px; right: 8px; border-left: none; border-top: none; }

.intro-card h2 {
  font-family: var(--display);
  font-weight: 500;
  font-size: 28px;
  margin-bottom: 12px;
  letter-spacing: -0.01em;
}
.intro-card p {
  color: var(--text-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-faint);
  border-bottom: 1px solid var(--line-faint);
}
.intro-rules li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 6px 0;
  font-size: 14px;
  color: var(--text-muted);
}
.intro-rules li .num {
  font-family: var(--mono);
  color: var(--gold-rich);
  font-size: 11px;
  letter-spacing: 0.1em;
  flex-shrink: 0;
  width: 18px;
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 28px;
  background: var(--gold-rich);
  color: var(--bg-void);
  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-out);
  width: 100%;
  position: relative;
  overflow: hidden;
}
.btn:hover:not(:disabled) {
  background: var(--gold-glow);
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(212, 175, 55, 0.25);
}
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--line-soft);
}
.btn.ghost:hover:not(:disabled) {
  background: var(--surface);
  border-color: var(--gold-rich);
  color: var(--text-cream);
  box-shadow: none;
}

.btn.accent {
  background: var(--accent);
  color: var(--bg-void);
}
.btn.accent:hover:not(:disabled) {
  background: var(--accent-deep);
  box-shadow: 0 8px 24px var(--accent-glow);
}

/* ============ GAME 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(--text-dim);
  text-transform: uppercase;
}
.board-header .mode-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--gold-glow);
}
.board-header .mode-tag::before {
  content: '';
  width: 6px; height: 6px;
  background: var(--gold-rich);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--gold-glow);
}
.board-header .timer {
  font-family: var(--mono);
  color: var(--text-cream);
  font-size: 14px;
  letter-spacing: 0.1em;
}

/* the actual board */
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(125, 211, 252, 0.04), transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(212, 175, 55, 0.03), transparent 60%),
    linear-gradient(180deg, #060a1f 0%, #0c1230 100%);
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  overflow: hidden;
  touch-action: manipulation;
}

.board::before, .board::after,
.board .corner-bl, .board .corner-tr {
  content: '';
  position: absolute;
  width: 22px; height: 22px;
  pointer-events: none;
  z-index: 5;
}
.board::before { top: 10px; left: 10px; border-top: 1px solid var(--gold-rich); border-left: 1px solid var(--gold-rich); }
.board::after { bottom: 10px; right: 10px; border-bottom: 1px solid var(--gold-rich); border-right: 1px solid var(--gold-rich); }
.board .corner-tr { top: 10px; right: 10px; border-top: 1px solid var(--gold-rich); border-right: 1px solid var(--gold-rich); }
.board .corner-bl { bottom: 10px; left: 10px; border-bottom: 1px solid var(--gold-rich); border-left: 1px solid var(--gold-rich); }

/* tiny grid texture */
.board .grid-bg {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(245, 240, 225, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(245, 240, 225, 0.025) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}

.board .field-stars {
  position: absolute;
  inset: 0;
}
.board .field-stars .field-twinkle {
  position: absolute;
  width: 1.5px; height: 1.5px;
  background: var(--star-light);
  border-radius: 50%;
  opacity: 0.4;
  animation: twinkle var(--dur, 5s) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

/* stars (clickable) */
.star {
  position: absolute;
  transform-origin: center;
  cursor: pointer;
  z-index: 2;
}
.star-inner {
  position: absolute;
  left: 50%; top: 50%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--star-light) 0%, var(--gold-glow) 40%, transparent 70%);
  transform: translate(-50%, -50%);
  transition: all 0.4s var(--spring);
}
.star.selected .star-inner {
  background: radial-gradient(circle, #fff 0%, var(--accent) 35%, transparent 70%);
  filter: drop-shadow(0 0 14px var(--accent-glow));
}
.star.wrong .star-inner {
  background: radial-gradient(circle, #fff 0%, var(--danger) 35%, transparent 70%);
  animation: shake 0.4s var(--ease-in-out);
}
.star.victory .star-inner {
  background: radial-gradient(circle, #fff 0%, var(--gold-glow) 30%, var(--gold-rich) 60%, transparent 75%);
  filter: drop-shadow(0 0 20px var(--gold-glow));
}
.star.faded .star-inner {
  opacity: 0.15;
}

@keyframes shake {
  0%, 100% { transform: translate(-50%, -50%) translateX(0); }
  20% { transform: translate(-50%, -50%) translateX(-4px); }
  40% { transform: translate(-50%, -50%) translateX(4px); }
  60% { transform: translate(-50%, -50%) translateX(-3px); }
  80% { transform: translate(-50%, -50%) translateX(3px); }
}

/* SVG line layer */
.board .lines-svg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}
.line-segment {
  fill: none;
  stroke: var(--gold-rich);
  stroke-width: 1.2;
  stroke-linecap: round;
  opacity: 0.85;
  filter: drop-shadow(0 0 3px var(--gold-glow));
}

/* ============ REFERENCE MEDALLION ============ */
.reference {
  position: relative;
  margin: 18px auto 0;
  width: 200px;
  max-width: 80%;
}
.reference-label {
  text-align: center;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.25em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.medallion {
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, var(--bg-deep), var(--bg-void));
  border: 1px solid var(--gold-deep);
  position: relative;
  overflow: hidden;
}
.medallion::before {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 1px dashed rgba(212, 175, 55, 0.25);
}

.medallion svg {
  width: 100%; height: 100%;
}
.medallion .ref-star {
  fill: var(--gold-glow);
  filter: drop-shadow(0 0 3px var(--gold-glow));
}
.medallion .ref-line {
  stroke: var(--gold-rich);
  stroke-width: 0.8;
  fill: none;
  opacity: 0.7;
}

/* hidden state for Sky mode after timeout */
.reference.hidden .medallion {
  filter: blur(8px) brightness(0.3);
  transition: filter 1s var(--ease-out);
}
.reference.hidden .medallion::after {
  content: 'memorized';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--gold-glow);
  text-transform: uppercase;
  z-index: 2;
  filter: none;
}

/* ============ CONTROL BAR ============ */
.controls {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}
.controls .selected-count {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  text-transform: uppercase;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  padding: 12px 16px;
}
.controls .selected-count b {
  color: var(--gold-glow);
  font-family: var(--mono);
  margin: 0 4px;
}
.controls .btn { width: auto; min-width: 140px; }

/* ============ VICTORY / RESULT ============ */
.result-card {
  text-align: center;
  padding: 32px 24px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-mid) 100%);
  border: 1px solid var(--gold-deep);
  border-radius: 4px;
  margin: 24px 0;
  position: relative;
}
.result-card .stars-row {
  font-size: 36px;
  letter-spacing: 0.2em;
  margin-bottom: 8px;
}
.result-card .const-name {
  font-family: var(--display);
  font-style: italic;
  font-size: 36px;
  color: var(--gold-glow);
  letter-spacing: 0.02em;
  margin-bottom: 4px;
}
.result-card .aka {
  font-family: var(--serif);
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 18px;
}
.result-stats {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin: 18px 0 24px;
}
.result-stats .stat {
  text-align: center;
}
.result-stats .stat-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.result-stats .stat-value {
  font-family: var(--mono);
  font-size: 22px;
  color: var(--text-cream);
}

.result-fact {
  background: var(--bg-deep);
  border-left: 2px solid var(--gold-rich);
  padding: 14px 16px;
  margin: 18px 0;
  text-align: left;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-muted);
  font-style: italic;
}
.result-fact b {
  color: var(--gold-glow);
  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; }

/* ============ MYTH MODE ============ */
.myth-question {
  font-family: var(--display);
  font-size: 22px;
  text-align: center;
  margin: 16px 0 24px;
  color: var(--text-cream);
  line-height: 1.4;
  font-style: italic;
}
.myth-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.myth-option {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  color: var(--text-cream);
  padding: 16px 20px;
  border-radius: 2px;
  text-align: left;
  font-family: var(--serif);
  font-size: 15px;
  cursor: pointer;
  transition: all 0.25s var(--ease-out);
  position: relative;
}
.myth-option:hover {
  border-color: var(--gold-rich);
  background: var(--surface-2);
  transform: translateX(2px);
}
.myth-option.correct {
  border-color: var(--success);
  background: rgba(134, 239, 172, 0.08);
}
.myth-option.wrong {
  border-color: var(--danger);
  background: rgba(252, 165, 165, 0.08);
}

/* ============ LEADERBOARD ============ */
.leaderboard {
  margin: 32px 0 0;
  padding: 24px 0 0;
  border-top: 1px solid var(--line-faint);
}
.leaderboard h3 {
  font-family: var(--display);
  font-style: italic;
  font-size: 22px;
  text-align: center;
  margin-bottom: 4px;
  color: var(--text-cream);
}
.leaderboard .lb-sub {
  text-align: center;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.25em;
  color: var(--text-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-faint);
  font-size: 14px;
}
.lb-row.self {
  background: linear-gradient(90deg, rgba(212, 175, 55, 0.06), transparent);
  border-left: 2px solid var(--gold-rich);
  padding-left: 12px;
}
.lb-rank {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
}
.lb-rank.top1 { color: var(--gold-glow); font-size: 14px; }
.lb-rank.top2 { color: #d4d4d4; }
.lb-rank.top3 { color: #b87333; }
.lb-name {
  font-family: var(--serif);
  color: var(--text-cream);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lb-medals {
  font-size: 14px;
  letter-spacing: 0.15em;
  opacity: 0.85;
}
.lb-time {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.lb-empty {
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
  font-style: italic;
  font-size: 14px;
}

.signin-prompt {
  text-align: center;
  padding: 18px;
  background: var(--surface);
  border: 1px dashed var(--line-soft);
  border-radius: 4px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-muted);
}
.signin-prompt button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  background: var(--text-cream);
  color: var(--bg-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: all 0.25s;
}
.signin-prompt button:hover { transform: translateY(-1px); }

/* ============ TOAST ============ */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--gold-rich);
  color: var(--text-cream);
  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);
}

/* mobile tweaks */
@media (max-width: 540px) {
  .stage { padding: 20px 14px 40px; }
  .hero { padding: 24px 0 18px; }
  .topbar { padding: 14px 16px; }
  .top-meta { font-size: 10px; }
  .controls { flex-direction: column; }
  .controls .btn { width: 100%; }
  .result-stats { gap: 20px; }
}

/* footer */
.footer-tip {
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 28px;
  padding: 12px;
}