/* ===== CSS VARIABLES ===== */
:root {
  /* Base colors */
  --bg: #0b0a14;
  --p: rgba(255, 255, 255, 0.05);
  --p2: rgba(255, 255, 255, 0.09);
  --bd: rgba(255, 255, 255, 0.1);
  --tx: #f3f2ff;
  --mu: #9896b5;

  /* Christmas Theme */
  --ac: #d42426;
  --ac2: #2e7d32;

  /* Status colors */
  --ok: #34d399;
  --no: #fb7185;
  --warn: #fbbf24;

  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    /* Base colors */
    --bg: #f4f2ff;
    --p: rgba(255, 255, 255, 0.75);
    --p2: rgba(255, 255, 255, 0.95);
    --bd: rgba(40, 30, 100, 0.12);
    --tx: #1a1640;
    --mu: #6c6a8e;

    /* Later override with Christmas colors
    --ac: #6244f0;
    --ac2: #e8408c;
    */

    /* Status colors */
    --ok: #0f9f6e;
    --no: #d63a50;
    --warn: #b77a00;

    color-scheme: light;
  }
}

/* ===== GLOBAL STYLES ===== */
* {
  box-sizing: border-box;
}

/* Prevent default display behavior */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--tx);
  font: 16px/1.4 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(700px 450px at 10% -10%, color-mix(in srgb, var(--ac) 30%, transparent), transparent),
    radial-gradient(600px 400px at 100% 0, color-mix(in srgb, var(--ac2) 22%, transparent), transparent);
  background-size: contain;
  background-attachment: scroll;
  max-height: 100dvh;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ===== MAIN LAYOUT ===== */
.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: clamp(280px, 23vw, 380px) 1fr clamp(250px, 20vw, 340px);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  max-width: 1800px;
  margin: 0 auto;
}

/* ===== HEADER ===== */
header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 20px;
  justify-content: space-between;
}

.logo {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--tx);
  text-decoration: none;
}

.logo span {
  background: linear-gradient(90deg, var(--ac), var(--ac2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ===== STATS ===== */
.stats {
  display: flex;
  gap: 22px;
  cursor: pointer;
}

.stats div {
  text-align: center;
  transition: opacity 0.2s;
}

.stats div:hover {
  opacity: 0.8;
}

.stats b {
  display: block;
  font-size: 20px;
  line-height: 1.1;
}

.stats small {
  color: var(--mu);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

/* ===== AUDIO CONTROLS ===== */
.vol {
  display: flex;
  gap: 8px;
  align-items: center;
}

.vol input {
  width: 110px;
  accent-color: var(--ac);
}

/* ===== ACCOUNT ===== */
.account {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.updates-button {
  border: 1px solid var(--bd);
  border-radius: 999px;
  padding: 8px 13px;
  background: var(--p);
  color: var(--mu);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.updates-button:hover {
  border-color: var(--ac);
  color: var(--tx);
}

/* ===== WAVEFORM EQ ===== */
.eq {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 150px;
  width: 100%;
}

#waveform {
  width: 100%;
  height: 100%;
  background: transparent;
}
#waveform.stage {
  max-width: 600px;
}

/* ===== PANELS & CARDS ===== */
.panel,
.card {
  background: var(--p);
  border: 1px solid var(--bd);
  border-radius: 20px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.panel {
  padding: 18px;
  overflow: auto;
  min-height: 0;
  scrollbar-gutter: stable;
  scrollbar-color: var(--mu) transparent;
  scrollbar-width: thin;
}

/* Custom scrollbar Webkit */
.panel::-webkit-scrollbar {
  width: 10px;
}

.panel::-webkit-scrollbar-track {
  margin: 12px 0;
  background: transparent;
}

.panel::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: var(--mu);
  background-clip: padding-box;
}

/* ===== HEADINGS ===== */
h3 {
  margin: 18px 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mu);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h3:first-child {
  margin-top: 0;
}

/* ===== HEADINGS SUBELEMENTS ===== */
.mini button {
  border: 0;
  background: none;
  color: var(--ac);
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
  padding: 0 0 0 10px;
}

.clear-history {
  border: 0;
  background: none;
  color: var(--ac);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  padding: 2px 0;
}

.clear-history:hover {
  color: var(--tx);
  text-decoration: underline;
}

/* ===== STATISTICS ===== */
.period-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-bottom: 10px;
  font-size: 11px;
  color: var(--mu);
}

.period-stats div {
  background: var(--p);
  padding: 4px;
  border-radius: 6px;
  text-align: center;
}

.period-stats b {
  display: block;
  color: var(--tx);
  font-size: 13px;
}

/* ===== YEARS ===== */
.yr {
  display: flex;
  align-items: baseline;
  gap: 10px;
  justify-content: center;
  margin-bottom: 6px;
}

.yr b {
  font-size: 30px;
  letter-spacing: -0.02em;
}

.yr span {
  color: var(--mu);
}

/* ===== RANGE SLIDER ===== */
.range {
  position: relative;
  height: 30px;
}

.rail {
  position: absolute;
  top: 13px;
  left: 0;
  right: 0;
  height: 5px;
  border-radius: 5px;
  background: var(--bd);
}

.sel {
  position: absolute;
  top: 13px;
  height: 5px;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--ac), var(--ac2));
}

.range input {
  position: absolute;
  left: 0;
  top: 5px;
  width: 100%;
  height: 20px;
  margin: 0;
  background: none;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}

.range input::-webkit-slider-runnable-track {
  background: none;
}

.range input::-moz-range-track {
  background: none;
}

.range input::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--ac);
  cursor: grab;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.range input::-moz-range-thumb {
  pointer-events: auto;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--ac);
  cursor: grab;
}

/* ===== PRESETS & TILES ===== */
.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.presets button,
.hints button {
  border: 1px solid var(--bd);
  background: var(--p);
  border-radius: 99px;
  padding: 5px 12px;
  font-size: 13px;
  color: var(--mu);
  transition: 0.15s;
}

.presets button:hover,
.hints button:hover:not(:disabled) {
  border-color: var(--ac);
  color: var(--tx);
}

.presets button.on {
  background: var(--ac);
  border-color: var(--ac);
  color: #fff;
}

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tile {
  border: 1px solid var(--bd);
  background: var(--p);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
  font-size: 13.5px;
  font-weight: 600;
  transition: 0.15s;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.tile small {
  color: var(--mu);
  font-weight: 400;
  font-size: 11.5px;
}

.tile.on {
  background: linear-gradient(135deg, color-mix(in srgb, var(--ac) 70%, transparent), color-mix(in srgb, var(--ac2) 60%, transparent));
  border-color: transparent;
  color: #fff;
}

.tile.on small {
  color: rgba(255, 255, 255, 0.8);
}

.tile.z {
  opacity: 0.4;
}

/* ===== DIFFICULTY SELECTION ===== */
.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--p);
  border: 1px solid var(--bd);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

.seg button {
  border: 0;
  background: none;
  padding: 9px;
  border-radius: 9px;
  font-weight: 600;
  color: var(--mu);
}

.seg button.on {
  background: var(--ac);
  color: #fff;
}

/* ===== NOTE SELECTION ===== */
.note {
  color: var(--mu);
  font-size: 13px;
  margin: 10px 0;
}

kbd {
  background: var(--p2);
  border: 1px solid var(--bd);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 12px;
}

.updates-link {
  color: #b9a8ff;
  text-decoration: none;
}

.updates-link:hover {
  text-decoration: underline;
  color: var(--tx);
}

/* ========================================
   GAME AREA
   ======================================== */

.game {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: auto;
}

/* ===== CARDS ===== */
.card {
  padding: 20px;
}

.stage {
  flex: 1 1 auto;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
}

/* ===== TRACK INFO ===== */
.track {
  position: relative;
  height: 12px;
  background: var(--bd);
  border-radius: 8px;
  overflow: hidden;
}

.fill {
  position: absolute;
  inset: 0;
  width: 0;
  background: linear-gradient(90deg, var(--ac), var(--ac2));
}

#marks {
  position: relative;
}

#marks u {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--bg);
}

/* ===== METADATA ===== */
.meta {
  display: flex;
  justify-content: space-between;
  color: var(--mu);
  font-size: 13px;
  margin-top: 8px;
}

/* ===== STATUS & HINTS ===== */
.status {
  text-align: center;
  color: var(--mu);
  margin: 10px 0 0;
  min-height: 22px;
}

.hints {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  justify-content: center;
}

.hints > span {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--mu);
}

.hints button:disabled {
  opacity: 0.4;
  cursor: default;
}

#hchips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  width: 100%;
  justify-content: center;
}

#hchips em {
  font-style: normal;
  background: var(--p2);
  border: 1px solid var(--warn);
  color: var(--warn);
  border-radius: 99px;
  padding: 3px 11px;
  font-size: 13px;
}

/* ===== GUESS INPUTS ===== */
#guesses {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.guess {
  display: flex;
  gap: 10px;
  align-items: center;
  height: 44px;
  padding: 0 14px;
  border: 1px dashed var(--bd);
  border-radius: 12px;
  font-size: 14px;
  color: var(--mu);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.guess.f {
  border-style: solid;
  background: var(--p);
  color: var(--tx);
}

.guess.f::before {
  content: "✕";
  color: var(--no);
  font-weight: 700;
}

.guess.skip::before {
  content: "→";
  color: var(--mu);
}

.guess.half::before {
  content: "≈";
  color: var(--warn);
}

.guess.win {
  border-color: var(--ok);
}

.guess.win::before {
  content: "✓";
  color: var(--ok);
}

/* ===== SEARCH INPUT ===== */
.in {
  position: relative;
}

#q {
  width: 100%;
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid var(--bd);
  background: var(--p);
  color: var(--tx);
  font: inherit;
  font-size: 17px;
  outline: none;
}

#q:focus {
  border-color: var(--ac);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ac) 25%, transparent);
}

/* ===== SUGGESTIONS ===== */
.sug {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  max-height: min(300px, 40vh);
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--bd);
  border-radius: 14px;
  z-index: 20;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.sug div {
  padding: 11px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--bd);
}

.sug div:last-child {
  border: 0;
}

.sug div.hi,
.sug div:hover {
  background: var(--p2);
}

.sug small {
  color: var(--mu);
  margin-left: 6px;
}

/* ===== ACTIONS ===== */
.actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.big {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 68px;
  border-radius: 16px;
  border: 1px solid var(--bd);
  background: var(--p2);
  font-weight: 700;
  font-size: 16px;
  transition: 0.15s;
}

.big svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
  flex: none;
}

.big small {
  font-weight: 400;
  color: var(--mu);
}

.big:hover:not(:disabled) {
  border-color: var(--ac);
  transform: translateY(-1px);
}

.big:disabled {
  opacity: 0.4;
  cursor: default;
}

.big.pri {
  background: linear-gradient(90deg, var(--ac), var(--ac2));
  border: 0;
  color: #fff;
}

.big.pri small {
  color: rgba(255, 255, 255, 0.8);
}

#pb:not(:disabled) {
  background: linear-gradient(135deg, var(--ac), color-mix(in srgb, var(--ac) 50%, var(--ac2)));
  border: 0;
  color: #fff;
}

/* ===== ERROR MESSAGES ===== */
.err {
  color: var(--no);
  text-align: center;
  font-size: 14px;
  min-height: 20px;
  margin: 0;
}

/* ===== RESULTS ===== */
.result {
  display: flex;
  gap: 18px;
  align-items: center;
}

.result img {
  width: 110px;
  height: 110px;
  border-radius: 16px;
  object-fit: cover;
  background: var(--bd);
}

.result h2 {
  margin: 2px 0;
  font-size: 24px;
  line-height: 1.15;
}

.result p {
  margin: 2px 0;
  color: var(--mu);
}

.result .r {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.result .r button {
  border: 1px solid var(--bd);
  background: var(--p);
  border-radius: 99px;
  padding: 7px 14px;
  font-size: 13.5px;
}

/* ===== HISTORY LIST ===== */
#hl {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#hl li {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--p);
  border: 1px solid var(--bd);
  font-size: 14px;
  display: flex;
  gap: 10px;
}

#hl li b {
  display: block;
  font-weight: 600;
}

#hl li small {
  color: var(--mu);
}

#hl .empty {
  color: var(--mu);
  justify-content: center;
}

#hl .w::before,
#hl .l::before {
  font-weight: 800;
}

#hl .w::before {
  content: "✓";
  color: var(--ok);
}

#hl .l::before {
  content: "✕";
  color: var(--no);
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 940px) {
  .app {
    height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: none;
    padding: 10px;
  }

  header {
    flex-wrap: wrap;
    gap: 10px;
  }

  .stats {
    gap: 16px;
  }

  .vol {
    display: none;
  }

  .game {
    order: 1;
    overflow: visible;
  }

  #filters {
    order: 2;
  }

  #hist {
    order: 3;
  }

  .panel {
    overflow: visible;
  }

  .stage {
    min-height: 260px;
    padding: 14px;
  }

  .eq {
    min-height: 80px;
  }

  .actions {
    grid-template-columns: 1fr 1fr;
  }

  .actions #go {
    grid-column: 1 / -1;
  }

  .big {
    height: 58px;
  }

  #guesses {
    grid-template-columns: 1fr;
  }

  .result {
    flex-direction: column;
    text-align: center;
  }

  .tiles {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

@media (max-width: 520px) {
  .tiles {
    grid-template-columns: 1fr 1fr;
  }
}