/* ===========================================================================
   Keymix — liquid-glass UI
   Palette = the Camelot spectrum over deep ink. Glassmorphism panels float
   above slow-morphing liquid blobs. One interactive accent: indigo.
   =========================================================================== */

:root {
  --bg:        #0a0c12;
  --bg-2:      #0e111b;
  --ink:       #e9edf6;
  --muted:     #97a2ba;
  --faint:     #6b748c;

  --accent:    #7c7cf0;   /* indigo anchor */
  --accent-2:  #4fc9d6;   /* teal */
  --accent-3:  #d866c6;   /* magenta */

  /* glass */
  --glass:        rgba(20, 26, 40, 0.55);
  --glass-strong: rgba(22, 29, 46, 0.72);
  --glass-brd:    rgba(255, 255, 255, 0.10);
  --glass-hi:     rgba(255, 255, 255, 0.16);
  --glass-shadow: 0 18px 50px -18px rgba(0, 0, 0, 0.7);

  --radius:    22px;
  --radius-sm: 13px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo,
          Consolas, monospace;

  --maxw: 1200px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

h1, h2, h3 { line-height: 1.08; letter-spacing: -0.02em; margin: 0; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }

code, pre, .mono { font-family: var(--mono); }
.inline {
  font-family: var(--mono);
  font-size: 0.86em;
  background: rgba(124, 124, 240, 0.14);
  color: #c8c8ff;
  padding: 0.12em 0.42em;
  border-radius: 6px;
  white-space: nowrap;
}

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

/* ---------------------------------------------------------------------------
   Liquid background
   --------------------------------------------------------------------------- */
.liquid-bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% -10%, #141a2e 0%, var(--bg) 55%),
    var(--bg);
}
.blob {
  position: absolute;
  width: 46vw;
  height: 46vw;
  min-width: 380px;
  min-height: 380px;
  border-radius: 42% 58% 63% 37% / 41% 44% 56% 59%;
  filter: blur(72px);
  opacity: 0.55;
  mix-blend-mode: screen;
  will-change: transform, border-radius;
}
.blob-1 {
  top: -14vw; left: -8vw;
  background: radial-gradient(circle at 30% 30%, #7c7cf0, transparent 70%);
  animation: drift1 26s ease-in-out infinite, morph 16s ease-in-out infinite;
}
.blob-2 {
  top: -6vw; right: -12vw;
  background: radial-gradient(circle at 60% 40%, #4fc9d6, transparent 70%);
  animation: drift2 30s ease-in-out infinite, morph 19s ease-in-out infinite reverse;
}
.blob-3 {
  bottom: -18vw; left: 18vw;
  background: radial-gradient(circle at 50% 50%, #d866c6, transparent 70%);
  animation: drift3 34s ease-in-out infinite, morph 22s ease-in-out infinite;
}
.blob-4 {
  bottom: -10vw; right: 6vw;
  width: 36vw; height: 36vw;
  background: radial-gradient(circle at 40% 60%, #ed8a4f, transparent 72%);
  opacity: 0.4;
  animation: drift1 38s ease-in-out infinite reverse, morph 18s ease-in-out infinite;
}
.liquid-grain {
  position: absolute;
  inset: 0;
  background: radial-gradient(130% 130% at 50% 0%, transparent 55%, rgba(0,0,0,0.45) 100%);
  pointer-events: none;
}

@keyframes morph {
  0%,100% { border-radius: 42% 58% 63% 37% / 41% 44% 56% 59%; }
  33%     { border-radius: 66% 34% 38% 62% / 63% 35% 65% 37%; }
  66%     { border-radius: 38% 62% 56% 44% / 49% 60% 40% 51%; }
}
@keyframes drift1 {
  0%,100% { transform: translate(0,0) scale(1); }
  50%     { transform: translate(8vw, 6vw) scale(1.12); }
}
@keyframes drift2 {
  0%,100% { transform: translate(0,0) scale(1.05); }
  50%     { transform: translate(-7vw, 8vw) scale(0.92); }
}
@keyframes drift3 {
  0%,100% { transform: translate(0,0) scale(1); }
  50%     { transform: translate(6vw, -7vw) scale(1.1); }
}

/* ---------------------------------------------------------------------------
   Glass primitive
   --------------------------------------------------------------------------- */
.glass, .dropzone, .wheel-frame, .toolbar, .table-wrap, .cli-tabs,
.cli-panel, .about-grid > div, .select, .code {
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
  backdrop-filter: blur(22px) saturate(150%);
  border: 1px solid var(--glass-brd);
}

/* ---------------------------------------------------------------------------
   Header / nav
   --------------------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 4vw, 2.4rem);
  background: rgba(10, 12, 18, 0.55);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-mark { width: 30px; height: 30px; filter: drop-shadow(0 2px 8px rgba(124,124,240,0.5)); }
.bm-ring { fill: none; }
.bm-hub { fill: var(--bg); stroke: rgba(255,255,255,0.4); stroke-width: 1; }
.bm-seg { stroke: var(--bg); stroke-width: 0.8; }
.bm-a { fill: #4fc9d6; } .bm-b { fill: #d866c6; }
.bm-c { fill: #ed8a4f; } .bm-d { fill: #7c7cf0; }
.brand-name {
  font-weight: 800; font-size: 1.22rem; letter-spacing: -0.03em;
}
.site-nav { display: flex; gap: 1.4rem; font-size: 0.92rem; }
.site-nav a { color: var(--muted); transition: color 0.18s; }
.site-nav a:hover { color: var(--ink); }

/* ---------------------------------------------------------------------------
   Hero
   --------------------------------------------------------------------------- */
.hero {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(2.4rem, 6vw, 5rem) clamp(1rem, 4vw, 2.4rem) 2rem;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: clamp(1.5rem, 4vw, 3.5rem);
  align-items: center;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-2);
  margin-bottom: 1rem;
}
.hero h1 {
  font-size: clamp(2.4rem, 6vw, 4.1rem);
  font-weight: 850;
}
.lede {
  margin-top: 1.1rem;
  color: var(--muted);
  font-size: clamp(1rem, 1.4vw, 1.12rem);
  max-width: 34ch;
}
.lede strong { color: var(--ink); font-weight: 650; }

/* dropzone */
.dropzone {
  position: relative;
  margin-top: 1.8rem;
  border-radius: var(--radius);
  border-style: dashed;
  border-color: rgba(124, 124, 240, 0.35);
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}
.dropzone::before {  /* liquid sheen sweep */
  content: "";
  position: absolute;
  inset: -50%;
  background: conic-gradient(from 0deg,
    transparent 0deg, rgba(124,124,240,0.18) 60deg,
    rgba(79,201,214,0.16) 140deg, transparent 220deg);
  opacity: 0;
  animation: spin 9s linear infinite;
  transition: opacity 0.3s;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); transform: translateY(-2px); }
.dropzone:hover::before, .dropzone.dragover::before { opacity: 1; }
.dropzone.dragover {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(79, 201, 214, 0.18), var(--glass-shadow);
}
.dz-icon {
  width: 38px; height: 38px; fill: none; stroke: var(--accent);
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
  position: relative;
}
.dz-title { position: relative; font-weight: 650; margin-top: 0.55rem; font-size: 1.05rem; }
.dz-sub { position: relative; color: var(--faint); font-size: 0.85rem; margin-top: 0.25rem; }
.dz-link { color: var(--accent-2); text-decoration: underline; text-underline-offset: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* hero controls */
.hero-controls { margin-top: 1.4rem; display: flex; flex-direction: column; gap: 0.4rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field-inline { flex-direction: row; align-items: center; gap: 0.5rem; }
.field-label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--faint); font-weight: 600;
}
.profile-hint { color: var(--faint); font-size: 0.8rem; min-height: 1.1em; }

.select {
  appearance: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  padding: 0.6rem 2.2rem 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 1rem center, right 0.72rem center;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.select:hover { border-color: var(--glass-hi); }
.select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,124,240,0.3); }
.select-sm { padding-top: 0.4rem; padding-bottom: 0.4rem; font-size: 0.86rem; }
.select option { background: #11151f; color: var(--ink); }

/* ---------------------------------------------------------------------------
   Wheel
   --------------------------------------------------------------------------- */
.hero-wheel { display: flex; justify-content: center; }
.wheel-frame {
  margin: 0;
  border-radius: 28px;
  padding: 1.4rem;
  box-shadow: var(--glass-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  position: relative;
}
.wheel-frame::before {  /* glossy top highlight */
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255,255,255,0.10), transparent 40%);
  pointer-events: none;
}
.wheel { width: clamp(260px, 32vw, 380px); aspect-ratio: 1; position: relative; }
.wheel svg { width: 100%; height: 100%; overflow: visible; }
.wheel .seg {
  cursor: pointer;
  transition: opacity 0.25s, transform 0.25s, filter 0.25s;
  transform-box: fill-box;
  transform-origin: center;
}
.wheel.has-detected .seg:not(.detected) { opacity: 0.26; }
.wheel .seg:hover { filter: brightness(1.18); }
.wheel .seg.active { filter: brightness(1.25) saturate(1.2); }
.wheel .seg.pulse { animation: segpulse 0.7s ease-out; }
.wheel .seg-label {
  font-family: var(--mono); font-size: 8px; font-weight: 600;
  fill: rgba(10,12,18,0.82); pointer-events: none; user-select: none;
}
.wheel .hub-label {
  font-family: var(--mono); fill: var(--ink); text-anchor: middle;
}
@keyframes segpulse {
  0% { filter: brightness(2) saturate(1.5); }
  100% { filter: brightness(1); }
}
.wheel-caption { text-align: center; display: flex; flex-direction: column; gap: 0.15rem; }
.wc-count { font-weight: 650; font-size: 0.98rem; }
.wc-sub { color: var(--faint); font-size: 0.78rem; }

/* ---------------------------------------------------------------------------
   Results
   --------------------------------------------------------------------------- */
.results {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1rem clamp(1rem, 4vw, 2.4rem) 3rem;
}
.toolbar {
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  box-shadow: var(--glass-shadow);
}
.toolbar-status { display: flex; flex-direction: column; gap: 0.4rem; min-width: 180px; flex: 1; }
.progress-text { font-size: 0.9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.progressbar {
  height: 5px; border-radius: 99px; overflow: hidden;
  background: rgba(255,255,255,0.07);
}
.progressbar span {
  display: block; height: 100%; width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.3s ease;
}
.toolbar-actions { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; }

/* buttons */
.btn {
  font: inherit; font-weight: 600; font-size: 0.88rem;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.55rem 1.15rem;
  cursor: pointer;
  transition: transform 0.16s, box-shadow 0.16s, background 0.18s, opacity 0.18s;
  color: var(--ink);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
  position: relative;
  overflow: hidden;
  background: linear-gradient(120deg, var(--accent), var(--accent-3));
  box-shadow: 0 8px 22px -8px rgba(124,124,240,0.8);
}
.btn-primary::after {  /* liquid sheen */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,0.35) 50%, transparent 70%);
  background-size: 250% 100%;
  background-position: 120% 0;
  transition: background-position 0.6s;
}
.btn-primary:not(:disabled):hover { transform: translateY(-2px); box-shadow: 0 12px 28px -8px rgba(124,124,240,0.9); }
.btn-primary:not(:disabled):hover::after { background-position: -40% 0; }
.btn-ghost {
  background: rgba(255,255,255,0.05);
  border-color: var(--glass-brd);
}
.btn-ghost:hover { background: rgba(255,255,255,0.10); }

/* table */
.table-wrap { border-radius: var(--radius); overflow: hidden; box-shadow: var(--glass-shadow); }
.tracks { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.tracks thead th {
  text-align: left;
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--faint); font-weight: 600;
  padding: 0.85rem 0.9rem;
  border-bottom: 1px solid var(--glass-brd);
  background: rgba(255,255,255,0.025);
  position: sticky; top: 0;
}
.tracks th.sortable { cursor: pointer; user-select: none; }
.tracks th.sortable:hover { color: var(--ink); }
.tracks th.sortable[data-dir]::after { content: " ▴"; color: var(--accent); }
.tracks th.sortable[data-dir="desc"]::after { content: " ▾"; }
.tracks tbody tr {
  border-bottom: 1px solid rgba(255,255,255,0.045);
  transition: background 0.15s;
}
.tracks tbody tr:hover { background: rgba(255,255,255,0.04); }
.tracks tbody tr.row-enter { animation: rowin 0.45s ease both; }
@keyframes rowin { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.tracks td { padding: 0.6rem 0.9rem; vertical-align: middle; }
.col-cover { width: 52px; }
.col-bpm, .col-key { width: 84px; }
.col-status { width: 96px; }
.col-dl { width: 48px; text-align: center; }

.cover {
  width: 40px; height: 40px; border-radius: 9px; object-fit: cover;
  background: linear-gradient(135deg, #1a2030, #232b40);
  display: grid; place-items: center;
}
.cover.placeholder::after { content: "♪"; color: var(--faint); font-size: 1rem; }
.t-artist { color: var(--muted); }
.t-title { font-weight: 600; }
.bpm-cell { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 600; }
.newname { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); word-break: break-all; }

.key-badge {
  display: inline-block;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.82rem;
  padding: 0.22rem 0.55rem;
  border-radius: 8px;
  min-width: 38px;
  text-align: center;
  box-shadow: 0 2px 8px -2px rgba(0,0,0,0.5);
}

.status { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.status.pending { color: var(--muted); }
.status.pending .dot { background: var(--accent-2); animation: blink 1s ease-in-out infinite; }
.status.done    { color: #6fe0a8; }
.status.done .dot { background: #6fe0a8; }
.status.error   { color: #f0726b; }
.status.error .dot { background: #f0726b; }
@keyframes blink { 50% { opacity: 0.25; } }

.dl-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--glass-brd);
  color: var(--ink);
  width: 32px; height: 32px; border-radius: 9px;
  display: inline-grid; place-items: center;
  cursor: pointer; transition: background 0.15s, transform 0.15s;
  text-decoration: none;
}
.dl-btn:hover { background: rgba(124,124,240,0.25); transform: translateY(-1px); }
.dl-btn[aria-disabled="true"] { opacity: 0.3; pointer-events: none; }

.empty-row { padding: 2rem; text-align: center; color: var(--faint); }

/* ---------------------------------------------------------------------------
   CLI section
   --------------------------------------------------------------------------- */
.cli, .about {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(2.5rem, 6vw, 5rem) clamp(1rem, 4vw, 2.4rem);
}
.cli-head { max-width: 56ch; }
.cli-head h2, .about h2 { font-size: clamp(1.7rem, 3.4vw, 2.5rem); font-weight: 800; margin-top: 0.6rem; }
.cli-tabs {
  display: inline-flex;
  gap: 0.25rem;
  margin: 1.8rem 0 1rem;
  padding: 0.3rem;
  border-radius: 999px;
}
.cli-tab {
  font: inherit; font-weight: 600; font-size: 0.88rem;
  color: var(--muted);
  background: transparent; border: 0;
  padding: 0.45rem 1.1rem; border-radius: 999px;
  cursor: pointer; transition: color 0.18s, background 0.18s;
}
.cli-tab:hover { color: var(--ink); }
.cli-tab.is-active { color: var(--ink); background: linear-gradient(120deg, var(--accent), var(--accent-3)); }
.cli-panel { border-radius: var(--radius); padding: 1.4rem clamp(1rem, 3vw, 1.8rem); box-shadow: var(--glass-shadow); }
.cli-panel[hidden] { display: none; }
.cli-note { color: var(--muted); font-size: 0.92rem; margin-bottom: 1.1rem; }
.cli-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1.2rem; counter-reset: step; }
.cli-steps li { display: flex; flex-direction: column; gap: 0.5rem; }
.step-label {
  font-size: 0.8rem; color: var(--accent-2); font-weight: 600;
  counter-increment: step;
}
.step-label::before {
  content: counter(step);
  display: inline-grid; place-items: center;
  width: 1.4rem; height: 1.4rem; margin-right: 0.5rem;
  border-radius: 50%; background: rgba(79,201,214,0.18);
  font-family: var(--mono); font-size: 0.72rem;
}
.code {
  position: relative;
  border-radius: var(--radius-sm);
  padding: 0.95rem 1.1rem;
  overflow-x: auto;
  font-size: 0.84rem;
  line-height: 1.6;
}
.code code { color: #d7def0; white-space: pre; display: block; }
.copy {
  position: absolute; top: 0.55rem; right: 0.55rem;
  font: inherit; font-size: 0.72rem; font-weight: 600;
  color: var(--muted);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--glass-brd);
  border-radius: 7px; padding: 0.25rem 0.55rem; cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.copy:hover { color: var(--ink); background: rgba(124,124,240,0.25); }
.copy.copied { color: #6fe0a8; }

.flags-title { font-size: 1.1rem; margin: 2.2rem 0 1rem; font-weight: 700; }
.flags { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.flags th, .flags td { text-align: left; padding: 0.7rem 0.9rem; border-bottom: 1px solid rgba(255,255,255,0.06); }
.flags th { color: var(--faint); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; }
.flags td code { color: #c8c8ff; font-size: 0.84rem; }
.flags td:last-child { color: var(--muted); }

/* ---------------------------------------------------------------------------
   About / footer
   --------------------------------------------------------------------------- */
.about-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.about-grid > div { border-radius: var(--radius); padding: 1.6rem; box-shadow: var(--glass-shadow); }
.about-grid h2 { font-size: 1.3rem; margin-bottom: 0.7rem; }
.about-grid p { color: var(--muted); font-size: 0.95rem; }

.site-footer {
  max-width: var(--maxw); margin: 0 auto;
  padding: 2rem clamp(1rem, 4vw, 2.4rem) 3rem;
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  color: var(--muted); font-size: 0.85rem;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.footer-muted { color: var(--faint); }
.footer-link { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.footer-link:hover { color: var(--ink); }

/* ---------------------------------------------------------------------------
   Focus + responsive + reduced motion
   --------------------------------------------------------------------------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

@media (max-width: 880px) {
  .hero { grid-template-columns: 1fr; }
  .hero-wheel { order: -1; }
  .about-grid { grid-template-columns: 1fr; }
  .col-newname { display: none; }
  .site-nav { gap: 0.9rem; }
}
@media (max-width: 560px) {
  .col-artist { display: none; }
  .toolbar { flex-direction: column; align-items: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto; }
  .blob { transform: none; }
}
