/* ── SPELLSPOKE — Styles ────────────────────────────────────────── */
/* "If words weren't magic, they wouldn't call it Spelling!" */
/* Dark background, deep violet accents, witchy-spellcaster theme */

@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700;900&family=Crimson+Text:ital,wght@0,400;0,600;1,400&family=Share+Tech+Mono&display=swap');

:root {
  --bg-dark: #0a0812;
  --bg-panel: #110e1c;
  --bg-hover: #1a1530;
  --text-primary: #e0dce8;
  --text-secondary: #9088a8;
  --text-dim: #504868;
  --accent: #7b2ff2;
  --accent-glow: #9d5cfa;
  --accent-rgb: 123, 47, 242;
  --accent-deep: #5a1db8;
  --violet-mist: rgba(123, 47, 242, 0.08);
  --violet-border: rgba(123, 47, 242, 0.2);
  --violet-glow: rgba(157, 92, 250, 0.3);
  --gold: #c9a84c;
  --gold-dim: rgba(201, 168, 76, 0.55);
  --gold-glow: rgba(201, 168, 76, 0.3);
  --revealed: #9d5cfa;
  --revealed-text: #ffffff;
  --unrevealed: #1a1530;
  --unrevealed-border: #2a2344;
  --center-hex: #c9a84c;
  --success: #4ade80;
  --danger: #e04040;
  --cooldown: #7b2ff2;
  --border-radius: 8px;
  --transition: 0.2s ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Share Tech Mono', 'Courier New', monospace;
  background: var(--bg-dark);
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(123, 47, 242, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 20% 80%, rgba(90, 29, 184, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 60%, rgba(201, 168, 76, 0.02) 0%, transparent 40%);
  color: var(--text-primary);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  user-select: none;
  -webkit-user-select: none;
}

/* Subtle mystical overlay — faint starfield effect */
body::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(1px 1px at 10% 20%, rgba(157, 92, 250, 0.3), transparent),
    radial-gradient(1px 1px at 30% 70%, rgba(201, 168, 76, 0.2), transparent),
    radial-gradient(1px 1px at 60% 15%, rgba(157, 92, 250, 0.25), transparent),
    radial-gradient(1px 1px at 80% 50%, rgba(201, 168, 76, 0.15), transparent),
    radial-gradient(1px 1px at 50% 90%, rgba(157, 92, 250, 0.2), transparent),
    radial-gradient(1px 1px at 90% 85%, rgba(201, 168, 76, 0.2), transparent),
    radial-gradient(1px 1px at 15% 45%, rgba(157, 92, 250, 0.15), transparent),
    radial-gradient(1px 1px at 70% 35%, rgba(201, 168, 76, 0.2), transparent);
  pointer-events: none;
  z-index: 9999;
}

/* ── Screens ──────────────────────────────────────────────────── */

.screen {
  display: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-screen.active {
  display: flex;
  flex-direction: column;
}

/* ── Menu ──────────────────────────────────────────────────────── */

.menu-container {
  text-align: center;
  max-width: 440px;
  width: 90%;
  padding: 2rem 2.5rem;
  background: linear-gradient(135deg, rgba(17, 14, 28, 0.95), rgba(14, 10, 24, 0.95));
  border: 1px solid var(--violet-border);
  border-radius: var(--border-radius);
  box-shadow: 0 0 60px rgba(123, 47, 242, 0.06), inset 0 0 60px rgba(0, 0, 0, 0.3);
  position: relative;
}

/* Corner arcane accents */
.menu-container::before, .menu-container::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: rgba(201, 168, 76, 0.35);
  border-style: solid;
}
.menu-container::before { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
.menu-container::after { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }

.menu-sigil {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  filter: drop-shadow(0 0 12px rgba(123, 47, 242, 0.5));
}

.title {
  font-family: 'Cinzel', serif;
  font-size: 3.2rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1;
  margin-bottom: 0.3rem;
  color: var(--text-primary);
}

.spell-accent {
  background: linear-gradient(135deg, #7b2ff2, #c9a84c);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 10px rgba(123, 47, 242, 0.4));
}

.tagline {
  font-family: 'Crimson Text', serif;
  font-style: italic;
  color: var(--gold);
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
  opacity: 0.8;
}

.subtitle {
  color: rgba(123, 47, 242, 0.5);
  font-size: 0.7rem;
  margin-bottom: 1.5rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* Word length selector */
.word-length-select {
  margin-bottom: 1.5rem;
}

.select-label {
  display: block;
  font-family: 'Crimson Text', serif;
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

.length-buttons {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
}

.btn-length {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 60px;
  padding: 0.5rem 0.3rem;
  background: var(--bg-panel);
  border: 1px solid var(--unrevealed-border);
  border-radius: var(--border-radius);
  color: var(--text-secondary);
  font-family: 'Cinzel', serif;
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-length span {
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.55rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.15rem;
  opacity: 0.6;
}

.btn-length:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.btn-length.active {
  background: rgba(123, 47, 242, 0.15);
  border-color: var(--accent);
  color: var(--accent-glow);
  box-shadow: 0 0 15px rgba(123, 47, 242, 0.2);
}

.btn-length.active span {
  opacity: 1;
  color: var(--accent-glow);
}

/* ── Buttons ──────────────────────────────────────────────────── */

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--border-radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: 0.02em;
  font-family: 'Share Tech Mono', monospace;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover {
  background: var(--accent-glow);
  box-shadow: 0 0 25px rgba(var(--accent-rgb), 0.35);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--unrevealed-border);
}
.btn-outline:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.btn-small {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}

.btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ── Tutorial ──────────────────────────────────────────────────── */

.tutorial-container {
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
}

.tutorial-container h2 {
  font-family: 'Cinzel', serif;
  color: var(--accent-glow);
  margin-bottom: 1.5rem;
  text-align: center;
  font-size: 1.6rem;
}

.tutorial-step {
  margin-bottom: 1.2rem;
  padding: 1rem;
  background: var(--bg-panel);
  border-radius: var(--border-radius);
  border-left: 3px solid var(--accent);
}

.tutorial-step h3 {
  color: var(--gold);
  margin-bottom: 0.4rem;
  font-size: 1rem;
}

.tutorial-step p {
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.55;
}

.tutorial-step strong {
  color: var(--text-primary);
}

/* ── Game HUD ──────────────────────────────────────────────────── */

.hud {
  position: relative;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 0.5rem 1rem;
  background: rgba(10, 8, 18, 0.92);
  backdrop-filter: blur(10px);
  border-color: var(--violet-border);
  border-style: solid;
  border-width: 0;
  flex-shrink: 0;
}

#hud-top {
  border-bottom-width: 1px;
}

.hud-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 1.2rem;
  padding-right: 140px;   /* room for music + back buttons */
}

.stat-group {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.stat-icon {
  font-size: 0.9rem;
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
}

/* ── Hex Grid ──────────────────────────────────────────────────── */

#hex-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

#hex-grid {
  width: 100%;
  height: 100%;
}

/* SVG hex cell styles */
.hex-cell {
  cursor: default;
}

.hex-bg {
  transition: fill 0.3s ease, stroke 0.3s ease;
}

.hex-bg.unrevealed {
  fill: var(--unrevealed);
  stroke: var(--unrevealed-border);
  stroke-width: 1.5;
}

.hex-bg.revealed {
  fill: rgba(123, 47, 242, 0.25);
  stroke: var(--accent);
  stroke-width: 1.5;
}

.hex-bg.center {
  fill: rgba(201, 168, 76, 0.2);
  stroke: var(--gold);
  stroke-width: 2;
}

.hex-letter {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  fill: var(--text-primary);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.hex-letter.hidden-letter {
  fill: var(--text-dim);
}

.hex-letter.revealed-letter {
  fill: #ffffff;
  filter: drop-shadow(0 0 4px rgba(157, 92, 250, 0.6));
}

.hex-letter.center-letter {
  fill: var(--gold);
  filter: drop-shadow(0 0 6px rgba(201, 168, 76, 0.5));
}

/* Reveal glow animation */
@keyframes hexRevealGlow {
  0% { filter: drop-shadow(0 0 0px rgba(157, 92, 250, 0)); }
  50% { filter: drop-shadow(0 0 12px rgba(157, 92, 250, 0.8)); }
  100% { filter: drop-shadow(0 0 4px rgba(157, 92, 250, 0.3)); }
}

.hex-reveal-anim {
  animation: hexRevealGlow 0.6s ease-out;
}

/* Spoke label text */
.spoke-label {
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  fill: var(--text-dim);
  text-anchor: middle;
  dominant-baseline: central;
  opacity: 0.4;
}

/* ── Letter Picker ─────────────────────────────────────────────── */

#letter-picker {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  padding: 0.6rem 0.8rem;
  background: rgba(10, 8, 18, 0.92);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--violet-border);
  flex-shrink: 0;
}

.letter-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-panel);
  border: 1px solid var(--unrevealed-border);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.letter-btn:hover:not(.used):not(.disabled) {
  background: rgba(123, 47, 242, 0.2);
  border-color: var(--accent);
  color: var(--accent-glow);
  box-shadow: 0 0 10px rgba(123, 47, 242, 0.2);
}

.letter-btn.disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

/* Used letters disappear with a fade-out */
.letter-btn.used {
  opacity: 0;
  transform: scale(0.5);
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Starter letter is pre-used */
.letter-btn.starter {
  opacity: 0;
  pointer-events: none;
}

/* ── Cooldown Bar ──────────────────────────────────────────────── */

#cooldown-bar-container {
  height: 4px;
  background: rgba(10, 8, 18, 0.9);
  flex-shrink: 0;
  overflow: hidden;
}

#cooldown-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transition: width 0.1s linear;
  border-radius: 0 2px 2px 0;
  box-shadow: 0 0 8px rgba(123, 47, 242, 0.4);
}

/* ── Back Button ───────────────────────────────────────────────── */

.hud-back-btn {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 20;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--unrevealed-border);
  border-radius: 50%;
  background: rgba(17, 14, 28, 0.8);
  color: var(--text-dim);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition);
}

.hud-back-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

/* ── Music Toggle ──────────────────────────────────────────────── */

.hud-music-btn {
  position: absolute;
  top: 8px;
  right: 50px;
  z-index: 20;
  padding: 4px 12px;
  border: 1px solid rgba(201, 168, 76, 0.2);
  border-radius: 4px;
  background: rgba(201, 168, 76, 0.06);
  color: rgba(201, 168, 76, 0.5);
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}
.hud-music-btn:hover {
  background: rgba(201, 168, 76, 0.12);
  color: var(--gold);
  border-color: rgba(201, 168, 76, 0.4);
  box-shadow: 0 0 8px rgba(201, 168, 76, 0.08);
}
.hud-music-btn.muted {
  opacity: 0.4;
  color: #556;
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
}

/* ── Timer Warning States ──────────────────────────────────────── */

.timer-warning {
  color: var(--danger) !important;
  animation: timerFlash 0.8s ease-in-out infinite;
}

.timer-overtime {
  color: var(--danger) !important;
  animation: none;
}

@keyframes timerFlash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Overlays ──────────────────────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 4, 10, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-content {
  text-align: center;
  padding: 2rem;
  background: linear-gradient(135deg, rgba(17, 14, 28, 0.97), rgba(14, 10, 24, 0.97));
  border-radius: var(--border-radius);
  border: 1px solid var(--violet-border);
  max-width: 420px;
  width: 90%;
  box-shadow: 0 0 40px rgba(123, 47, 242, 0.1);
}

.results-sigil {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.overlay-content h2 {
  font-family: 'Cinzel', serif;
  font-size: 1.8rem;
  margin-bottom: 0.3rem;
  color: var(--gold);
}

.results-flavor {
  font-family: 'Crimson Text', serif;
  font-style: italic;
  color: var(--text-secondary);
  margin-bottom: 1.2rem;
  font-size: 0.9rem;
}

.results-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 1.5rem;
}

.result-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}

.result-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.result-value {
  font-family: 'Cinzel', serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent-glow);
}

.result-percentile {
  font-size: 0.7rem;
  color: var(--gold);
}

/* Leaderboard name prompt */
.lb-prompt-text {
  color: var(--gold);
  font-family: 'Crimson Text', serif;
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.lb-name-input {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 1rem;
}

.lb-name-input input {
  background: var(--bg-panel);
  border: 1px solid var(--unrevealed-border);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-family: 'Share Tech Mono', monospace;
  font-size: 1rem;
  padding: 0.5rem 0.75rem;
  width: 180px;
  text-align: center;
}

.lb-name-input input:focus {
  outline: none;
  border-color: var(--accent);
}

.results-buttons {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.results-buttons .btn {
  min-width: 120px;
}

/* ── Leaderboard Overlay ───────────────────────────────────────── */

.leaderboard-content {
  max-width: 460px;
}

.lb-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1rem;
  border-radius: var(--border-radius);
  overflow: hidden;
  border: 1px solid var(--unrevealed-border);
}

.lb-tab {
  flex: 1;
  padding: 0.5rem 0.75rem;
  background: var(--bg-panel);
  border: none;
  color: var(--text-dim);
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition);
}

.lb-tab:not(:last-child) {
  border-right: 1px solid var(--unrevealed-border);
}

.lb-tab:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.lb-tab.active {
  background: rgba(123, 47, 242, 0.15);
  color: var(--accent-glow);
}

.lb-table-wrap {
  margin-bottom: 1.2rem;
  max-height: 320px;
  overflow-y: auto;
}

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.lb-table thead th {
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--unrevealed-border);
  text-align: left;
}

.lb-table thead th:first-child {
  text-align: center;
  width: 30px;
}

.lb-table tbody td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid rgba(42, 35, 68, 0.4);
  color: var(--text-secondary);
}

.lb-table tbody td:first-child {
  text-align: center;
  color: var(--gold);
  font-weight: 700;
}

.lb-table tbody tr:nth-child(-n+3) td:first-child {
  font-size: 0.95rem;
}

.lb-table tbody tr.lb-highlight td {
  color: var(--accent-glow);
  background: rgba(123, 47, 242, 0.08);
}

.lb-empty {
  color: var(--text-dim);
  font-family: 'Crimson Text', serif;
  font-style: italic;
  font-size: 0.9rem;
  padding: 1rem;
}

/* ── Footer Brand ──────────────────────────────────────────────── */

.footer-brand {
  display: block;
  margin-top: 1.8rem;
  font-size: 0.7rem;
  color: var(--gold-dim);
  letter-spacing: 0.03em;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.footer-brand a {
  color: var(--gold);
  text-decoration: none;
  transition: color var(--transition);
}

.footer-brand a:hover {
  color: #f1d27a;
  text-decoration: underline;
}

.footer-cross {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.6rem;
  color: var(--text-dim);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.footer-cross a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition);
}

.footer-cross a:hover {
  color: var(--accent-glow);
  text-decoration: underline;
}

/* ── Share ─────────────────────────────────────────────────────── */

.menu-share-section {
  margin-top: 1rem;
  margin-bottom: 0;
}

.btn-menu-share {
  padding: 0.45rem 1.2rem;
  background: transparent;
  border: 1px solid var(--violet-border);
  border-radius: var(--border-radius);
  color: var(--text-secondary);
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-menu-share:hover {
  border-color: var(--accent);
  color: var(--accent-glow);
  background: rgba(123, 47, 242, 0.08);
}

.share-section {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--violet-border);
}

.share-label {
  font-family: 'Crimson Text', serif;
  font-style: italic;
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-bottom: 0.5rem;
}

.share-buttons {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.btn-share {
  padding: 0.35rem 0.75rem;
  background: var(--bg-panel);
  border: 1px solid var(--unrevealed-border);
  border-radius: var(--border-radius);
  color: var(--text-secondary);
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.7rem;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-share:hover {
  border-color: var(--accent);
  color: var(--accent-glow);
  background: rgba(123, 47, 242, 0.12);
}

.btn-share.copied {
  border-color: var(--success);
  color: var(--success);
}

/* ── Responsive ────────────────────────────────────────────────── */

@media (max-width: 420px) {
  .title { font-size: 2.6rem; }
  .menu-container { padding: 1.5rem 1.2rem; }
  .btn { padding: 0.6rem 1.2rem; font-size: 0.9rem; }
  .btn-length { width: 50px; font-size: 1.2rem; }
  .btn-length span { font-size: 0.5rem; }
  .letter-btn { width: 34px; height: 34px; font-size: 0.9rem; }
  .results-stats { gap: 1rem; }
  .result-value { font-size: 1.4rem; }
}

@media (max-width: 360px) {
  .title { font-size: 2.2rem; }
  .letter-btn { width: 30px; height: 30px; font-size: 0.8rem; }
  #letter-picker { gap: 3px; padding: 0.4rem; }
}

@media (min-width: 768px) {
  .letter-btn { width: 44px; height: 44px; font-size: 1.1rem; }
}
