@font-face {
  font-family: 'Orbitron';
  src: url('../assets/fonts/orbitron-latin-800-normal.woff2') format('woff2');
  font-weight: 800;
  font-display: swap;
}
@font-face {
  font-family: 'Orbitron';
  src: url('../assets/fonts/orbitron-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('../assets/fonts/inter-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('../assets/fonts/inter-latin-500-normal.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('../assets/fonts/inter-latin-600-normal.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('../assets/fonts/inter-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #07111f;
  --bg-2: #0b1a2e;
  --panel: rgba(18, 34, 56, 0.65);
  --panel-border: rgba(120, 200, 255, 0.14);
  --cyan: #00e5ff;
  --cyan-soft: #66f2ff;
  --purple: #b06bff;
  --green: #33ffb0;
  --danger: #ff5470;
  --text: #eaf6ff;
  --text-dim: #8fa7c4;
  --font-display: 'Orbitron', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(ellipse at top, var(--bg-2), var(--bg) 70%);
  color: var(--text);
  font-family: var(--font-body);
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button { font-family: inherit; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  padding: 14px 22px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
  min-height: 44px;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(0, 229, 255, 0.12); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.btn--primary {
  background: linear-gradient(135deg, var(--cyan), #0aa2c9);
  color: #03131c;
  border: none;
  box-shadow: 0 8px 24px rgba(0, 229, 255, 0.28);
}
.btn--accent {
  background: linear-gradient(135deg, var(--purple), #7a3fe0);
  color: #fff;
  border: none;
}
.btn--ghost { background: transparent; }
.btn--link { background: none; border: none; color: var(--text-dim); text-decoration: underline; padding: 6px; min-height: auto; }
.btn--small { padding: 10px 16px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.icon-row { display: flex; gap: 8px; }
.icon-btn {
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--cyan-soft);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(10px);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ── Screens ─────────────────────────────────────────────────────────── */
.screen { width: 100%; flex: 1; display: flex; flex-direction: column; }
[hidden] { display: none !important; }

.start-screen {
  align-items: center;
  justify-content: flex-start;
  padding: 32px 20px 60px;
  text-align: center;
  gap: 4px;
  overflow-y: auto;
}
.brand-row { margin-bottom: 6px; }
.brand-tag {
  font-family: var(--font-display);
  font-size: 0.75rem;
  letter-spacing: 0.25em;
  color: var(--text-dim);
}
.logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.2rem, 9vw, 3.4rem);
  margin: 4px 0 0;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(0, 229, 255, 0.25);
  letter-spacing: 0.04em;
}
.tagline {
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.12em;
  font-size: 0.85rem;
  margin: 6px 0 22px;
}
.stat-pill {
  display: flex; flex-direction: column; align-items: center;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 10px 22px;
  margin-bottom: 10px;
  min-width: 150px;
}
.stat-pill__label { font-size: 0.7rem; color: var(--text-dim); letter-spacing: 0.08em; }
.stat-pill__value { font-family: var(--font-display); font-size: 1.3rem; color: var(--cyan-soft); }
.stat-pill--streak .stat-pill__value { color: #ffb020; }

.menu-buttons { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 320px; margin-top: 18px; }
.icon-row--menu { margin-top: 22px; }

.seo-content {
  max-width: 560px;
  margin-top: 44px;
  text-align: left;
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.6;
  padding: 0 4px;
}
.seo-content h2 { color: var(--text); font-size: 1rem; font-family: var(--font-display); letter-spacing: 0.03em; }
.seo-content ul { padding-left: 20px; }

/* ── Game screen / HUD ───────────────────────────────────────────────── */
.game-screen { padding: 14px 14px 20px; align-items: center; justify-content: center; }
.hud {
  position: relative;
  width: 100%; max-width: 640px;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.hud-left { display: flex; flex-direction: column; gap: 2px; }
.hud-badge { font-family: var(--font-display); font-weight: 700; font-size: 0.95rem; letter-spacing: 0.05em; }
.hud-tier { font-size: 0.72rem; color: var(--text-dim); }
.hud-center { position: absolute; left: 50%; transform: translateX(-50%); top: 50%; margin-top: -0.6em; }
.hud-timer { font-family: var(--font-display); font-size: 1.15rem; color: var(--cyan-soft); text-shadow: 0 0 12px rgba(0,229,255,0.4); }
.hud-right { }

.board-wrap { position: relative; width: min(100%, 560px, 60vh); aspect-ratio: 1 / 1; margin: 8px auto; }
.fx-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
.board {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  gap: 3px;
  background: rgba(4, 10, 20, 0.5);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 6px;
}
.combo-banner {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  font-family: var(--font-display); font-weight: 700;
  color: #ffcf4d;
  text-shadow: 0 0 16px rgba(255, 180, 40, 0.6);
  z-index: 4;
  animation: combo-pop 0.35s ease;
  pointer-events: none;
}
@keyframes combo-pop { from { transform: translateX(-50%) scale(0.6); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

.pipe-tile {
  position: relative;
  appearance: none;
  border: none;
  border-radius: 8px;
  background: rgba(10, 22, 38, 0.75);
  padding: 0;
  cursor: pointer;
  overflow: hidden;
}
.pipe-tile--fixed {
  cursor: default;
  background: repeating-linear-gradient(135deg, rgba(255,255,255,0.03) 0 6px, transparent 6px 13px);
}
.pipe-tile--fixed::after {
  content: '📌';
  position: absolute;
  top: 3px; right: 4px;
  font-size: 10px;
  line-height: 1;
  opacity: 0.55;
  pointer-events: none;
}
.pipe-tile:focus-visible { outline: 2px solid var(--cyan); outline-offset: -2px; }
.pipe-svg { width: 100%; height: 100%; display: block; }
.pipe-rotor { transform-origin: 50% 50%; transition: transform 0.15s cubic-bezier(.2,.9,.3,1); will-change: transform; }
.reduced-motion .pipe-rotor { transition: none; }

.pipe-stroke-bg { fill: none; stroke: #1c3350; stroke-width: 20; stroke-linecap: round; }
.pipe-stroke { fill: none; stroke: #2a4a70; stroke-width: 13; stroke-linecap: round; transition: stroke 0.25s ease, filter 0.25s ease; }
.pipe-hub { fill: #1c3350; transition: fill 0.25s ease; }
.pipe-anchor-source { fill: rgba(179, 107, 255, 0.25); }
.pipe-anchor-target { fill: rgba(51, 255, 176, 0.25); }

/* :where() zeroes the specificity of the generic "any lit tile" rule so
   the source/target overrides below always win regardless of source
   order — without :where(), both sides can tie at equal specificity and
   the winner becomes a fragile function of file order (this was a real
   bug: the source tile's hub was always rendered cyan by the generic
   rule, never its intended purple, because both rules matched at equal
   specificity (0,3,0) and the generic one happened to come first). */
:where(.pipe-tile.is-lit) .pipe-stroke { stroke: var(--cyan); filter: drop-shadow(0 0 6px rgba(0,229,255,0.85)); }
:where(.pipe-tile.is-lit) .pipe-hub { fill: var(--cyan-soft); }
.pipe-tile--source .pipe-stroke { stroke: var(--purple); filter: drop-shadow(0 0 8px rgba(176,107,255,0.9)); }
.pipe-tile--source .pipe-hub { fill: rgba(176,107,255,0.65); }
.pipe-tile--target .pipe-hub { fill: rgba(51,255,176,0.4); }
.pipe-tile--target.is-lit .pipe-stroke { stroke: var(--green); filter: drop-shadow(0 0 8px rgba(51,255,176,0.9)); }
.pipe-tile--target.is-lit .pipe-hub { fill: var(--green); }

.hint-pulse { animation: hint-pulse 1.3s ease-in-out 2; }
@keyframes hint-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 207, 77, 0.6); }
  50% { box-shadow: 0 0 0 8px rgba(255, 207, 77, 0); }
}
.reduced-motion .hint-pulse { animation: none; outline: 2px solid #ffcf4d; }

.hud-bottom {
  width: 100%; max-width: 560px;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  margin-top: 10px; flex-wrap: wrap;
}
.hud-stat { display: flex; flex-direction: column; align-items: center; min-width: 64px; }
.hud-stat__label { font-size: 0.62rem; color: var(--text-dim); letter-spacing: 0.08em; }
.hud-stat__value { font-family: var(--font-display); font-size: 1.05rem; }

/* ── Overlays / modals ───────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(3, 8, 16, 0.72);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  background: linear-gradient(160deg, rgba(20, 38, 62, 0.92), rgba(9, 18, 32, 0.95));
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 28px 26px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
}
.modal h2 { font-family: var(--font-display); letter-spacing: 0.04em; margin-top: 0; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }

.modal--tutorial .tutorial-steps { list-style: none; padding: 0; text-align: left; display: flex; flex-direction: column; gap: 14px; }
.tutorial-steps li { display: flex; align-items: center; gap: 12px; font-weight: 600; letter-spacing: 0.03em; }
.tutorial-num {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--cyan); color: #04141c; font-family: var(--font-display);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.tutorial-note { color: var(--text-dim); font-size: 0.8rem; margin: 14px 0 0; text-align: left; }
.tutorial-footer { color: var(--cyan-soft); font-weight: 700; margin: 18px 0; }

.modal--result .perfect-banner {
  font-weight: 800; color: #ffcf4d; margin-bottom: 6px;
  text-shadow: 0 0 20px rgba(255,207,77,0.6);
  animation: pulse-scale 1s ease-in-out infinite;
}
.reduced-motion .perfect-banner { animation: none; }
@keyframes pulse-scale { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.result-time { font-family: var(--font-display); font-size: 2.2rem; color: var(--cyan-soft); margin: 6px 0 14px; text-shadow: 0 0 20px rgba(0,229,255,0.4); }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.result-stat { background: rgba(255,255,255,0.03); border: 1px solid var(--panel-border); border-radius: 12px; padding: 10px; }
.result-stat span { display: block; font-size: 0.65rem; color: var(--text-dim); letter-spacing: 0.08em; }
.result-stat strong { font-family: var(--font-display); font-size: 1.2rem; }
.pb-banner { color: #ff8a4d; font-weight: 700; margin: 8px 0; }
.rank-banner { color: var(--text-dim); font-size: 0.85rem; margin: 8px 0; }
.rank-banner strong { color: var(--cyan-soft); }

.nickname-row { display: flex; gap: 8px; margin-top: 14px; }
.nickname-row input {
  flex: 1; border-radius: 10px; border: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.04); color: var(--text); padding: 10px 12px; font-size: 0.9rem;
}
.nickname-hint { color: var(--danger); font-size: 0.78rem; min-height: 1.2em; margin: 6px 0 0; }
.nickname-saved { color: var(--green); font-weight: 600; margin: 8px 0 0; }
.modal-actions--result { margin-top: 16px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(20, 10, 14, 0.92); border: 1px solid rgba(255,84,112,0.4);
  color: #ffb3c0; padding: 12px 20px; border-radius: 999px; font-size: 0.85rem;
  z-index: 60;
}

.modal--leaderboard { max-width: 420px; }
.lb-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.lb-tab {
  flex: 1; padding: 9px 6px; border-radius: 999px; border: 1px solid var(--panel-border);
  background: transparent; color: var(--text-dim); font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.04em; cursor: pointer;
}
.lb-tab.is-active { background: var(--cyan); color: #04141c; border-color: transparent; }
.lb-list { min-height: 220px; max-height: 340px; overflow-y: auto; margin-bottom: 14px; }
.lb-row { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.lb-rank { width: 34px; font-family: var(--font-display); color: var(--text-dim); text-align: center; }
.lb-name { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-family: var(--font-display); color: var(--cyan-soft); }
.lb-empty, .lb-loading { color: var(--text-dim); padding: 40px 0; }

.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
.settings-row input { width: 20px; height: 20px; }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (min-width: 720px) {
  .game-screen { padding-top: 30px; }
}
@media (max-width: 380px) {
  .logo { font-size: 2rem; }
  .hud-timer { font-size: 1rem; }
}

/* ── Accessibility ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .pipe-rotor, .perfect-banner, .hint-pulse { animation: none !important; transition: none !important; }
}
