/* KodKod Run — game styles. Brand system per user stories. */

:root {
  --void: #080c14;
  --surface: #161d2e;
  --gold: #c8a050;
  --text: #e8e4dc;
  --text-dim: rgba(232, 228, 220, 0.5);
  --text-dimmer: rgba(232, 228, 220, 0.35);
  --text-faint: rgba(232, 228, 220, 0.25);
  --teal: #2dd4bf;
  --blue: #2080e0;
  --purple: #9060a8;
  --pink: #e04080;
  --orange: #e08040;
  --accent: #c8a050;                 /* set per level by JS */
  --border-soft: 1px solid rgba(255, 255, 255, 0.06);
  --border-gold: 1px solid rgba(200, 160, 80, 0.2);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body { width: 100%; height: 100%; }

body {
  background: var(--void);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: var(--surface);
  overflow: hidden;
  will-change: transform;
}

@media (min-width: 920px) {
  #game-container {
    width: min(900px, 96vw);
    height: min(500px, 90vh);
    border-radius: 16px;
    border: var(--border-soft);
    box-shadow: 0 0 60px rgba(200, 160, 80, 0.12), 0 20px 60px rgba(0, 0, 0, 0.5);
  }
}

#gameCanvas { display: block; width: 100%; height: 100%; touch-action: none; }

#ui-layer { position: absolute; inset: 0; pointer-events: none; }
#ui-layer button,
#ui-layer a.btn,
#ui-layer .link-danger,
#ui-layer .link-plain,
#ui-layer .level-card { pointer-events: auto; }

/* ---------- Screens ---------- */
.screen[hidden] { display: none; }
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 400ms ease;
}
.screen.is-visible { opacity: 1; }
.overlay {
  background: rgba(8, 12, 20, 0.88);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.dim-overlay {
  background: rgba(8, 12, 20, 0.7);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.screen-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px;
  max-width: 380px;
  max-height: 100%;
  overflow-y: auto;
}
.screen-inner.wide { max-width: 620px; width: 100%; }

/* ---------- Preloader ---------- */
#preloader { background: var(--void); z-index: 5; }
.preloader-inner { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.preloader-title {
  font-family: 'Space Grotesk', sans-serif;
  color: var(--gold);
  font-size: 16px; font-weight: 600; letter-spacing: 0.02em;
}
.progress-track {
  width: 220px; height: 6px;
  background: var(--surface); border-radius: 999px; overflow: hidden;
}
.progress-fill { width: 0%; height: 100%; background: var(--gold); border-radius: 999px; transition: width 160ms ease; }

/* ---------- Level badge ---------- */
.level-badge {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 12px;
  border: 1px solid rgba(200, 160, 80, 0.25);
  border-radius: 999px;
  color: var(--teal);
  text-transform: uppercase; letter-spacing: 0.08em;
  font-size: 11px; font-weight: 600;
  margin-bottom: 16px;
}
.badge-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(200, 160, 80, 0.5);
  animation: pulse-dot 1.8s ease-out infinite;
}
@keyframes pulse-dot {
  0% { box-shadow: 0 0 0 0 rgba(200, 160, 80, 0.5); }
  70% { box-shadow: 0 0 0 8px rgba(200, 160, 80, 0); }
  100% { box-shadow: 0 0 0 0 rgba(200, 160, 80, 0); }
}

/* ---------- Start screen ---------- */
.game-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 36px; font-weight: 700;
  color: var(--gold); letter-spacing: -0.02em;
  margin-bottom: 8px;
}
.game-title.small { font-size: 28px; }
.menu-track { font-family: 'Space Grotesk', sans-serif; font-size: 18px; font-weight: 600; color: #fff; margin-bottom: 4px; }
.menu-duration { font-size: 13px; color: var(--text-dim); margin-bottom: 14px; }
.menu-duration .clock { color: var(--gold); }
.game-subtitle {
  font-size: 14px; color: var(--text-dim);
  max-width: 320px; line-height: 1.5; margin-bottom: 16px;
}
.section-dots { display: flex; gap: 8px; margin-bottom: 20px; }
.section-dots .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: rgba(232, 228, 220, 0.2);
}
.section-dots .dot.on { background: var(--accent); }
.hint-text { margin-top: 16px; font-size: 12px; color: var(--text-faint); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  border: none; cursor: pointer; text-decoration: none;
  transition: transform 120ms ease, background 120ms ease, opacity 120ms ease;
}
.btn:hover { transform: scale(1.03); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
.btn-primary {
  background: var(--gold); color: var(--void);
  font-size: 15px; font-weight: 600;
  padding: 13px 34px; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(200, 160, 80, 0.25);
}
.btn-spotify {
  background: #1db954; color: #fff;
  font-size: 13px; font-weight: 600;
  padding: 10px 24px; border-radius: 20px;
}
.btn-ghost {
  background: transparent; color: var(--gold);
  border: 1.5px solid rgba(200, 160, 80, 0.4);
  font-size: 13px; font-weight: 600;
  padding: 9px 22px; border-radius: 10px;
  margin-top: 10px;
}
.btn-ghost.dim { color: var(--text-dim); border-color: rgba(255, 255, 255, 0.14); }
.link-plain {
  margin-top: 12px; font-size: 12px; color: var(--text-dim);
  text-decoration: none;
}
.link-plain:hover { color: var(--text); }
.link-danger {
  margin-top: 14px; font-size: 11px; color: #d05a5a;
  background: none; border: none; cursor: pointer;
  text-transform: uppercase; letter-spacing: 0.08em;
}

/* ---------- Level Select ---------- */
.level-list {
  display: flex; flex-direction: column; gap: 12px;
  width: 100%; margin: 16px 0; overflow-y: auto;
}
@media (min-width: 600px) {
  .level-list { display: grid; grid-template-columns: 1fr 1fr; }
}
.level-card {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: var(--surface);
  border: var(--border-soft);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 120ms ease;
}
.level-card:hover:not(.locked) {
  border-color: rgba(200, 160, 80, 0.45);
  box-shadow: 0 0 20px rgba(200, 160, 80, 0.15);
}
.level-card:active:not(.locked) { transform: scale(0.98); }
.level-card.locked { opacity: 0.4; cursor: not-allowed; }
.level-num {
  flex-shrink: 0;
  width: 30px; height: 30px; border-radius: 50%;
  border: 1.5px solid var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 13px;
  color: var(--gold);
}
.level-card.completed .level-num { border-color: var(--gold); background: rgba(200, 160, 80, 0.15); }
.level-card-body { flex: 1; min-width: 0; }
.level-card-track { font-family: 'Space Grotesk', sans-serif; font-size: 15px; font-weight: 600; color: #fff; }
.level-card-env { font-size: 12px; color: var(--text-dim); }
.level-card-meta { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.pill {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 2px 8px; border-radius: 999px;
  border: var(--border-gold); color: var(--text-dim);
}
.pill.status-play { color: var(--teal); border-color: rgba(45, 212, 191, 0.3); }
.pill.status-done { color: var(--gold); border-color: rgba(200, 160, 80, 0.4); }
.pill.status-locked { color: var(--text-dimmer); }

/* ---------- HUD ---------- */
#hud[hidden] { display: none; }
#hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 14px; gap: 12px;
}
.hud-left { min-width: 0; }
.hud-right { display: flex; align-items: flex-start; gap: 8px; }
.score-box {
  display: flex; flex-direction: column; gap: 2px;
  background: rgba(8, 12, 20, 0.7);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: var(--border-gold); border-radius: 10px;
  padding: 8px 14px; min-width: 150px;
}
.score-label { font-size: 10px; text-transform: uppercase; color: var(--text-dim); letter-spacing: 0.12em; font-weight: 600; }
.score-value { font-family: 'Space Grotesk', sans-serif; font-size: 22px; font-weight: 700; color: var(--gold); }
.track-progress { margin-top: 6px; }
.track-progress-bar {
  width: 100%; height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px; overflow: hidden;
}
.track-progress-fill {
  width: 0%; height: 100%;
  background: linear-gradient(90deg, var(--accent), #f0d090);
  border-radius: 2px; transition: width 0.3s ease;
}
.track-progress-time { font-size: 10px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.hud-btn {
  width: 32px; height: 32px; flex-shrink: 0;
  background: rgba(8, 12, 20, 0.7);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: var(--border-gold); border-radius: 8px;
  color: var(--gold); font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 120ms ease;
}
.hud-btn:hover { transform: scale(1.08); }
.hud-btn:active { transform: scale(0.94); }
.hud-btn.off { color: var(--text-dimmer); }
.track-box {
  display: flex; align-items: center; gap: 8px; max-width: 200px;
  background: rgba(8, 12, 20, 0.7);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: var(--border-soft); border-radius: 10px; padding: 7px 10px;
}
.track-cover {
  width: 34px; height: 34px; border-radius: 6px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent) 0%, var(--blue) 100%);
}
.track-meta { display: flex; flex-direction: column; min-width: 0; }
.track-name { font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-artist { font-size: 10px; color: var(--text-dim); }

/* ---------- Section notification ---------- */
.section-note {
  position: absolute; top: 78px; left: 0; right: 0;
  text-align: center;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--accent);
  opacity: 0;
  transition: opacity 400ms ease;
}
.section-note[hidden] { display: none; }
.section-note.show { opacity: 1; }

/* ---------- Game over ---------- */
.over-title { font-size: 20px; color: rgba(232, 228, 220, 0.6); margin-bottom: 4px; }
.over-subtrack { font-size: 14px; color: #fff; margin-bottom: 8px; }
.over-score { font-family: 'Space Grotesk', sans-serif; font-size: 52px; font-weight: 700; color: var(--gold); line-height: 1; }
.over-best { font-size: 12px; text-transform: uppercase; color: var(--text-dim); letter-spacing: 0.1em; margin-top: 6px; }
.over-reached { font-size: 12px; color: var(--text-dim); margin-top: 8px; }
.mini-progress {
  width: 200px; height: 2px; margin: 6px auto 0;
  background: rgba(255, 255, 255, 0.08); border-radius: 2px; overflow: hidden;
}
.mini-progress-fill { width: 0%; height: 100%; background: var(--accent); }
.over-soclose { color: var(--teal); font-size: 12px; margin-top: 6px; font-weight: 600; }
.over-soclose[hidden] { display: none; }
.stats-row { display: flex; justify-content: center; gap: 24px; margin: 18px 0; }
.stat { display: flex; flex-direction: column; gap: 3px; }
.stat-value { font-family: 'Space Grotesk', sans-serif; font-size: 22px; font-weight: 700; color: #fff; }
.stat-label { font-size: 10px; text-transform: uppercase; color: var(--text-dimmer); letter-spacing: 0.08em; }
.over-buttons { display: flex; flex-direction: column; align-items: center; gap: 4px; }

/* ---------- Level complete ---------- */
.lc-track { font-family: 'Space Grotesk', sans-serif; font-size: 24px; font-weight: 700; color: #fff; }
.lc-headline { font-family: 'Space Grotesk', sans-serif; font-size: 34px; font-weight: 700; color: var(--gold); margin: 6px 0 4px; }
.perfect-badge {
  display: inline-block; margin: 6px 0 2px;
  padding: 5px 14px; border-radius: 999px;
  border: 1px solid rgba(200, 160, 80, 0.5); color: var(--gold);
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  animation: perfect-glow 1.8s ease-in-out infinite;
}
.perfect-badge[hidden] { display: none; }
@keyframes perfect-glow {
  0%, 100% { box-shadow: 0 0 6px rgba(200, 160, 80, 0.2); }
  50% { box-shadow: 0 0 18px rgba(200, 160, 80, 0.45); }
}

/* ---------- Pause ---------- */
.pause-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 24px; font-weight: 700; color: var(--gold);
  letter-spacing: 0.06em; margin-bottom: 18px;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .score-value { font-size: 18px; }
  .score-box { min-width: 130px; }
  .track-box { max-width: 150px; }
  .game-title { font-size: 28px; }
  .over-score { font-size: 44px; }
  .lc-headline { font-size: 28px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .badge-dot, .perfect-badge { animation: none; }
  .btn { transition: none; }
  .screen { transition: opacity 1ms; }
}
