:root {
  --bg-deep: #0a0e1c;
  --bg-panel: #10152b;
  --line-grid: rgba(140, 160, 255, 0.06);
  --text-main: #e9ecff;
  --text-dim: #8890b8;
  --cyan: #5ee7ff;
  --amber: #ffb347;
  --violet: #8b7cf6;
  --danger: #ff5c7a;
  --ok: #6dffb0;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: var(--font-ui);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100vh;
  max-width: 720px;
  margin: 0 auto;
  background:
    radial-gradient(ellipse at 30% 15%, rgba(139,124,246,0.12), transparent 55%),
    radial-gradient(ellipse at 70% 85%, rgba(94,231,255,0.08), transparent 55%),
    linear-gradient(180deg, #0a0e1c 0%, #0c1024 100%);
  overflow: hidden;
}

/* subtle drifting grid, evokes a HUD / radar */
#app::before {
  content: "";
  position: absolute;
  inset: -50% -50%;
  background-image:
    linear-gradient(var(--line-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-grid) 1px, transparent 1px);
  background-size: 42px 42px;
  transform: rotate(6deg);
  animation: driftGrid 60s linear infinite;
  pointer-events: none;
}

@keyframes driftGrid {
  from { background-position: 0 0; }
  to { background-position: -420px 420px; }
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  z-index: 5;
}
.screen.active { display: flex; }

/* ---------- MENU ---------- */
#menu-screen { justify-content: center; gap: 6px; padding: 24px; text-align: center; }

.brand-kicker {
  font-family: var(--font-mono);
  letter-spacing: 0.35em;
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.brand-title {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(48px, 14vw, 84px);
  line-height: 0.95;
  letter-spacing: -0.02em;
  color: var(--text-main);
  margin: 0 0 4px;
  text-shadow: 0 0 32px rgba(94,231,255,0.25);
}
.brand-title .cursor {
  display: inline-block;
  color: var(--cyan);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.brand-sub {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 28px;
}

.nick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}
.nick-row label {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}
#nickname {
  font-family: var(--font-mono);
  background: var(--bg-panel);
  border: 1px solid rgba(140,160,255,0.2);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 15px;
  width: 180px;
  outline: none;
}
#nickname:focus { border-color: var(--cyan); }

.menu-links {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}
.menu-link {
  background: none;
  border: none;
  font-family: var(--font-ui);
  font-size: 18px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px 10px;
  transition: color 0.15s;
}
.menu-link:hover, .menu-link:focus-visible { color: var(--text-main); }
.menu-link.primary { color: var(--amber); font-weight: 600; }
.menu-link.primary:hover { color: #ffc978; }

/* ---------- GAME ---------- */
#game-screen { justify-content: flex-start; }

#hud-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 16px;
  z-index: 6;
  pointer-events: none;
}
#hud-top > * { pointer-events: auto; }

.icon-btn {
  background: rgba(16,21,43,0.7);
  border: 1px solid rgba(140,160,255,0.18);
  color: var(--text-dim);
  width: 36px; height: 36px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { color: var(--text-main); border-color: var(--cyan); }
.hud-left { display: flex; gap: 8px; }

.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.hud-score {
  font-family: var(--font-mono);
  font-size: 22px;
  color: var(--text-main);
}
.hud-level {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--cyan);
  letter-spacing: 0.1em;
}
.hud-lives {
  display: flex;
  gap: 4px;
}
.life-hex {
  width: 20px; height: 22px;
  background: var(--amber);
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}
.life-hex.lost { background: rgba(140,160,255,0.12); }

#field {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.enemy {
  position: absolute;
  top: -40px;
  font-family: var(--font-mono);
  font-size: 18px;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(10, 14, 28, 0.75);
  border: 1px solid rgba(140,160,255,0.15);
  color: var(--text-main);
  transform: translateX(-50%);
  z-index: 2;
  max-width: min(92vw, 640px);
}
.enemy .typed { color: var(--cyan); }
.enemy .mistake { color: var(--danger); background: rgba(255,92,122,0.18); border-radius: 2px; }
.enemy .rest { color: var(--text-main); }
.enemy.active {
  border-color: var(--cyan);
  box-shadow: 0 0 14px rgba(94,231,255,0.35);
}
.enemy.error {
  border-color: var(--danger);
  box-shadow: 0 0 14px rgba(255,92,122,0.45);
  animation: shake 0.12s ease-in-out 0s 2;
}
@keyframes shake {
  0%, 100% { margin-left: 0; }
  50% { margin-left: -3px; }
}
.enemy.dying {
  animation: pop 0.18s ease forwards;
}
@keyframes pop {
  to { transform: translateX(-50%) scale(1.4); opacity: 0; }
}

#ship {
  position: absolute;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 26px;
  filter: drop-shadow(0 0 10px rgba(94,231,255,0.5));
  z-index: 4;
}

#laser-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  pointer-events: none;
  overflow: visible;
}
.laser-line {
  stroke: var(--cyan);
  stroke-width: 2;
  stroke-linecap: round;
  opacity: 0.9;
  filter: drop-shadow(0 0 4px rgba(94,231,255,0.8));
  transition: opacity 0.18s linear;
}
.laser-line.fade { opacity: 0; }
.laser-line.emp {
  stroke: var(--violet);
  filter: drop-shadow(0 0 5px rgba(139,124,246,0.8));
}

#hud-bottom {
  position: absolute;
  bottom: 20px;
  left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 13px;
  z-index: 6;
}

.emp-bar-track {
  width: 160px;
  height: 5px;
  background: rgba(140,160,255,0.12);
  border-radius: 3px;
  overflow: hidden;
}
.emp-bar-fill {
  height: 100%;
  background: var(--violet);
  width: 0%;
  transition: width 0.2s;
}
.emp-bar-fill.ready { background: var(--amber); }

/* ---------- OVERLAY (pause / game over / records / settings) ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(6,8,18,0.88);
  backdrop-filter: blur(3px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 10;
  padding: 24px;
  text-align: center;
}
.overlay.active { display: flex; }
.overlay h2 {
  font-family: var(--font-mono);
  font-size: 28px;
  margin: 0;
  color: var(--text-main);
}
.overlay .stat-row {
  font-family: var(--font-mono);
  color: var(--text-dim);
  font-size: 14px;
}
.overlay .stat-row b { color: var(--cyan); font-size: 16px; }
#go-rank {
  max-width: 260px;
  font-size: 12px;
  line-height: 1.5;
}

.btn {
  font-family: var(--font-ui);
  font-weight: 600;
  background: var(--amber);
  color: #1a1206;
  border: none;
  padding: 10px 22px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
}
.btn:hover { background: #ffc978; }
.btn.ghost {
  background: none;
  border: 1px solid rgba(140,160,255,0.25);
  color: var(--text-dim);
}
.btn.ghost:hover { color: var(--text-main); border-color: var(--cyan); }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ---------- Settings ---------- */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 260px;
  text-align: left;
}
.settings-form label {
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.settings-form select, .settings-form input[type=range] {
  font-family: var(--font-ui);
  background: var(--bg-panel);
  border: 1px solid rgba(140,160,255,0.2);
  color: var(--text-main);
  padding: 7px;
  border-radius: 6px;
}
.tier-checks { display: flex; gap: 12px; flex-wrap: wrap; }
.tier-checks label { flex-direction: row; align-items: center; gap: 6px; font-size: 12px; }
.settings-hint {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-dim);
}

/* ---------- Records table ---------- */
.records-table {
  font-family: var(--font-mono);
  font-size: 14px;
  width: 280px;
  border-collapse: collapse;
}
.records-table th {
  color: var(--text-dim);
  font-weight: 400;
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.08em;
  padding-bottom: 8px;
}
.records-table td { padding: 4px 0; color: var(--text-main); }
.records-table td.rank { color: var(--cyan); width: 24px; }
.records-table td.score { text-align: right; color: var(--amber); }
.records-table tr.record-row { cursor: pointer; }
.records-table tr.record-row:hover td { color: var(--cyan); }
.records-table tr.record-row:hover td.score { color: var(--amber); }
.records-empty { color: var(--text-dim); font-size: 13px; }

.records-lang-switch {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 6px;
}
.records-lang-switch button,
.records-period-switch button {
  font-family: var(--font-ui);
  font-size: 12px;
  background: none;
  border: 1px solid rgba(140,160,255,0.2);
  color: var(--text-dim);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.records-lang-switch button:hover,
.records-period-switch button:hover { color: var(--text-main); border-color: var(--cyan); }
.records-lang-switch button.active {
  color: #0a0e1c;
  background: var(--cyan);
  border-color: var(--cyan);
  font-weight: 600;
}
.records-period-switch {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 10px;
}
.records-period-switch button.active {
  color: #1a1206;
  background: var(--amber);
  border-color: var(--amber);
  font-weight: 600;
}
.records-note {
  max-width: 280px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-dim);
  text-align: center;
}
.records-source {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
  letter-spacing: 0.03em;
}
.records-loading td {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 10px 0;
}

/* ---------- Record detail must sit above the records list overlay ---------- */
#record-detail-overlay { z-index: 11; }

/* ---------- Letter mistake map ---------- */
.letter-map {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 220px;
  margin-top: 4px;
}
.letter-map .lm-title {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 2px;
}
.lm-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
}
.lm-letter {
  width: 16px;
  color: var(--text-main);
  text-transform: uppercase;
}
.lm-bar-track {
  flex: 1;
  height: 6px;
  background: rgba(140,160,255,0.1);
  border-radius: 3px;
  overflow: hidden;
}
.lm-bar-fill {
  height: 100%;
  background: var(--danger);
  border-radius: 3px;
}
.lm-count { color: var(--text-dim); width: 20px; text-align: right; }

/* ---------- Custom text ---------- */
.custom-textarea {
  width: 300px;
  height: 140px;
  font-family: var(--font-ui);
  background: var(--bg-panel);
  border: 1px solid rgba(140,160,255,0.2);
  color: var(--text-main);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  resize: vertical;
  outline: none;
}
.custom-textarea:focus { border-color: var(--cyan); }

@media (max-width: 420px) {
  .brand-title { font-size: 15vw; }
  .enemy { font-size: 16px; }
}
