/* ---------------------------------------------------------
   Drift — a calm lofi audio visualizer
   Tokens
   Base    #17121e / #241a2c
   Rose    #d98a94
   Amber   #e2ac6f
   Lilac   #a596c7
   Cream   #f2e9e1
--------------------------------------------------------- */

:root {
  --base-1: #150f1c;
  --base-2: #241a2e;
  --rose: #d98a94;
  --amber: #e2ac6f;
  --lilac: #a596c7;
  --cream: #f2e9e1;
  --cream-dim: rgba(242, 233, 225, 0.55);
  --panel: rgba(36, 26, 46, 0.55);
  --panel-border: rgba(242, 233, 225, 0.1);
}

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

html, body {
  height: 100%;
}

body {
  font-family: "Work Sans", system-ui, -apple-system, sans-serif;
  background: var(--base-1);
  color: var(--cream);
  overflow: hidden;
  height: 100vh;
  position: relative;
}

/* ---------------- Scene / canvas layer ---------------- */

#scene {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 15%, rgba(217, 138, 148, 0.10), transparent 55%),
    radial-gradient(ellipse at 80% 85%, rgba(165, 150, 199, 0.12), transparent 55%),
    linear-gradient(160deg, var(--base-1) 0%, var(--base-2) 100%);
}

#visualizer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(10, 7, 14, 0.55) 100%);
}

.grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.06;
  /* no mix-blend-mode: blending a full-screen layer over an animating
     canvas forces the browser to re-composite it every frame */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-size: 180px 180px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------- Header ---------------- */

#brand {
  position: fixed;
  top: 28px;
  left: 32px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 5;
  pointer-events: none;
}

.brand-mark {
  font-family: "Fraunces", serif;
  font-weight: 450;
  font-style: italic;
  font-size: 22px;
  letter-spacing: 0.3px;
  color: var(--cream);
}

.brand-sub {
  font-size: 11px;
  letter-spacing: 0.2px;
  color: var(--cream-dim);
}

/* ---------------- Help button ---------------- */

.help-btn {
  position: fixed;
  top: 28px;
  right: 32px;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  font-family: "Fraunces", serif;
  font-style: italic;
  font-size: 15px;
  color: var(--cream-dim);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  cursor: pointer;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  transition: color 0.25s ease, border-color 0.25s ease, background 0.25s ease, transform 0.15s ease;
}

.help-btn:hover {
  color: var(--cream);
  border-color: rgba(242, 233, 225, 0.3);
  background: rgba(242, 233, 225, 0.1);
}

.help-btn:active {
  transform: scale(0.94);
}

.help-btn:focus-visible,
.library-btn:focus-visible,
.upload-btn:focus-visible,
.mode-btn:focus-visible,
.modal-close:focus-visible,
.library-item:focus-visible {
  outline: 1px solid var(--cream-dim);
  outline-offset: 2px;
}

/* ---------------- Help modal ---------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(10, 7, 14, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: overlayIn 0.35s ease both;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-box {
  position: relative;
  width: min(420px, 100%);
  padding: 32px 30px 26px;
  background: linear-gradient(165deg, rgba(36, 26, 46, 0.92), rgba(21, 15, 28, 0.94));
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  max-height: min(600px, 86vh);
  overflow-y: auto;
  animation: modalIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.modal-box::-webkit-scrollbar {
  width: 6px;
}

.modal-box::-webkit-scrollbar-thumb {
  background: rgba(242, 233, 225, 0.2);
  border-radius: 999px;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  color: var(--cream-dim);
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
}

.modal-close:hover {
  color: var(--cream);
  background: rgba(242, 233, 225, 0.08);
}

.modal-eyebrow {
  display: block;
  font-size: 11px;
  letter-spacing: 0.4px;
  color: var(--rose);
  margin-bottom: 6px;
}

.modal-title {
  font-family: "Fraunces", serif;
  font-weight: 450;
  font-style: italic;
  font-size: 24px;
  color: var(--cream);
  margin-bottom: 14px;
}

.modal-intro {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--cream-dim);
  margin-bottom: 22px;
}

.modal-steps {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}

.modal-steps li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--cream-dim);
}

.modal-steps strong {
  display: block;
  font-weight: 500;
  color: var(--cream);
  margin-bottom: 2px;
}

.modal-steps em {
  font-style: italic;
  color: var(--cream);
}

.step-glyph {
  flex: none;
  width: 7px;
  height: 7px;
  margin-top: 6px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--rose), var(--lilac));
}

.modal-note {
  padding-top: 16px;
  border-top: 1px solid var(--panel-border);
  font-size: 12px;
  color: var(--cream-dim);
}

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

@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .modal-overlay, .modal-box {
    animation: none;
  }
}

#hint {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: "Fraunces", serif;
  font-weight: 300;
  font-style: italic;
  font-size: clamp(16px, 2.4vw, 22px);
  color: var(--cream-dim);
  text-align: center;
  z-index: 4;
  transition: opacity 0.8s ease;
  pointer-events: none;
}

#hint.hidden {
  opacity: 0;
}

/* ---------------- Credit ---------------- */

#credit {
  position: fixed;
  right: 14px;
  bottom: 8px;
  z-index: 3;
  font-size: 10.5px;
  letter-spacing: 0.2px;
  color: var(--cream-dim);
  opacity: 0.55;
  pointer-events: none;
  white-space: nowrap;
}

@media only screen and (max-width: 680px) {
  #credit {
    right: 50%;
    transform: translateX(50%);
    bottom: 96px;
    font-size: 9.5px;
  }
}

/* ---------------- Control deck ---------------- */

#deck {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: min(92vw, 780px);
  padding: 14px 20px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

#fileInput {
  display: none;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  font-size: 13px;
  color: var(--cream);
  background: linear-gradient(135deg, rgba(217, 138, 148, 0.28), rgba(165, 150, 199, 0.28));
  border: 1px solid rgba(242, 233, 225, 0.18);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.25s ease, transform 0.15s ease;
  white-space: nowrap;
}

.upload-btn:hover {
  background: linear-gradient(135deg, rgba(217, 138, 148, 0.4), rgba(165, 150, 199, 0.4));
}

.upload-btn:active {
  transform: scale(0.97);
}

/* #deck is already `position: fixed` above, so it's the positioning
   context the .library-panel below anchors to. */

.library-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  font-family: "Work Sans", sans-serif;
  font-size: 13px;
  color: var(--cream);
  background: transparent;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.25s ease, border-color 0.25s ease, transform 0.15s ease;
  white-space: nowrap;
}

.library-btn:hover {
  border-color: rgba(242, 233, 225, 0.3);
  background: rgba(242, 233, 225, 0.06);
}

.library-btn:active {
  transform: scale(0.97);
}

.library-btn[aria-expanded="true"] {
  color: var(--base-1);
  background: linear-gradient(135deg, var(--amber), var(--lilac));
  border-color: transparent;
}

.library-panel {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 12px);
  transform: translateX(-50%);
  width: min(320px, 82vw);
  max-height: 260px;
  overflow-y: auto;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.library-panel[hidden] {
  display: none;
}

.library-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.library-item {
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  font-family: "Work Sans", sans-serif;
  font-size: 13px;
  color: var(--cream-dim);
  background: transparent;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.library-item:hover {
  color: var(--cream);
  background: rgba(242, 233, 225, 0.08);
}

.library-item.active {
  color: var(--base-1);
  background: linear-gradient(135deg, var(--rose), var(--lilac));
  font-weight: 500;
}

.library-item:disabled {
  cursor: default;
  opacity: 0.6;
}

.library-empty {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--cream-dim);
  list-style: none;
}

.library-panel::-webkit-scrollbar {
  width: 6px;
}

.library-panel::-webkit-scrollbar-thumb {
  background: rgba(242, 233, 225, 0.2);
  border-radius: 999px;
}

.track-name {
  font-size: 12px;
  color: var(--cream-dim);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#audio {
  height: 34px;
  width: 240px;
  max-width: 40vw;
  border-radius: 999px;
  filter: sepia(0.15) saturate(0.7) hue-rotate(300deg) brightness(1.05);
  accent-color: var(--rose);
}

.modes {
  display: flex;
  gap: 8px;
}

.mode-btn {
  padding: 8px 14px;
  font-family: "Work Sans", sans-serif;
  font-size: 12px;
  letter-spacing: 0.2px;
  color: var(--cream-dim);
  background: transparent;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.25s ease;
}

.mode-btn:hover {
  color: var(--cream);
  border-color: rgba(242, 233, 225, 0.3);
}

.mode-btn.active {
  color: var(--base-1);
  background: linear-gradient(135deg, var(--rose), var(--lilac));
  border-color: transparent;
  font-weight: 500;
}

/* ---------------- Responsive ---------------- */

@media only screen and (max-width: 680px) {
  #brand {
    top: 18px;
    left: 18px;
  }

  .brand-sub {
    display: none;
  }

  .help-btn {
    top: 18px;
    right: 18px;
  }

  .modal-box {
    padding: 28px 22px 22px;
  }

  #deck {
    bottom: 14px;
    padding: 12px 14px;
    gap: 10px;
    border-radius: 16px;
  }

  #audio {
    width: 100%;
    max-width: 100%;
    order: 4;
  }

  .track-name {
    display: none;
  }

  .modes {
    order: 5;
    width: 100%;
    justify-content: center;
  }

  .library-panel {
    width: min(280px, 88vw);
  }

  #hint {
    padding: 0 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .upload-btn, .mode-btn {
    transition: none;
  }
}
