:root {
  --ink: #15120f;
  --ink-2: #1e1a16;
  --ink-3: #2a241e;
  --line: rgba(240, 226, 200, 0.1);
  --ivory: #f3ead9;
  --ivory-dim: #b9ad98;
  --brass: #d8a548;
  --brass-soft: rgba(216, 165, 72, 0.16);
  --error: #e5866d;
  --display: "Fraunces", Georgia, serif;
  --body: "Bricolage Grotesque", "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(216, 165, 72, 0.13), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(150, 70, 40, 0.14), transparent 60%),
    var(--ink);
  color: var(--ivory);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  opacity: 0.06;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

.muted { color: var(--ivory-dim); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 12px; }

/* ---------- header ---------- */
.top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: 24px 40px;
  padding: 28px clamp(16px, 4vw, 56px) 20px;
  animation: rise 0.7s cubic-bezier(.2,.7,.2,1) both;
}

.back {
  color: var(--ivory-dim);
  text-decoration: none;
  font-size: 13px;
  align-self: start;
  padding-top: 6px;
  transition: color .2s;
}
.back:hover { color: var(--brass); }

.eyebrow {
  margin: 0 0 4px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brass);
}

h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 0.95;
  letter-spacing: -0.02em;
}
h1 em { font-style: italic; color: var(--brass); }

.file-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border-radius: 999px;
  font: 500 14px var(--body);
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform .15s, background .2s, border-color .2s, color .2s;
  user-select: none;
}
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn:active { transform: translateY(1px) scale(.98); }
.btn-primary { background: var(--brass); color: var(--ink); }
.btn-primary:hover { background: #e6b65c; }
.btn-ghost { background: transparent; color: var(--ivory); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--brass); color: var(--brass); }
.btn:focus-visible, .icon-btn:focus-visible, .play-btn:focus-visible, .link-btn:focus-visible, .part:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 3px;
}

/* ---------- stage ---------- */
.stage {
  padding: 0 clamp(16px, 4vw, 56px) 40px;
  display: grid;
  gap: 18px;
}

.now-playing {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 2fr;
  gap: 24px;
  align-items: end;
  animation: rise 0.7s .08s cubic-bezier(.2,.7,.2,1) both;
}

.label {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ivory-dim);
}

#song-title {
  margin: 2px 0 2px;
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  font-size: 26px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
#song-info { margin: 0; font-size: 13px; }
.error { margin: 6px 0 0; color: var(--error); font-size: 13px; }

.parts {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.part {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--ink-2);
  color: var(--ivory);
  font: 13px var(--body);
  cursor: pointer;
  transition: opacity .2s, border-color .2s, transform .15s;
  animation: pop .35s cubic-bezier(.2,.7,.2,1) both;
}
.part:hover { border-color: var(--part); }
.part .sw { width: 14px; height: 14px; border-radius: 50%; background: var(--part); box-shadow: 0 0 0 3px color-mix(in srgb, var(--part) 22%, transparent); }
.part .n { font-family: var(--mono); font-size: 11px; color: var(--ivory-dim); }
.part[aria-pressed="false"] { opacity: .42; }
.part[aria-pressed="false"] .sw { background: transparent; box-shadow: inset 0 0 0 2px var(--part); }

/* ---------- instrument ---------- */
.instrument {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: linear-gradient(180deg, #100e0c, #1a1612);
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px -30px rgba(0,0,0,.7), inset 0 1px 0 rgba(255,255,255,.03);
  animation: rise 0.8s .14s cubic-bezier(.2,.7,.2,1) both;
}

.roll-wrap {
  position: relative;
  height: clamp(220px, 42vh, 460px);
}
#roll { display: block; width: 100%; height: 100%; }

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  padding: 24px;
  gap: 4px;
  transition: opacity .4s;
}
.empty-state.hidden { opacity: 0; pointer-events: none; }
.empty-state svg {
  width: 54px; height: 54px; margin-bottom: 10px;
  fill: none; stroke: var(--brass); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
  animation: bob 3s ease-in-out infinite;
}
.empty-state p { margin: 0; max-width: 46ch; }
kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--ink-3);
  color: var(--ivory);
}

.keyboard {
  position: relative;
  height: clamp(110px, 16vw, 170px);
  background: #0c0a09;
  border-top: 3px solid #5a1f1a;
  box-shadow: inset 0 6px 10px -4px rgba(0,0,0,.8);
  touch-action: none;
  user-select: none;
}

.key {
  position: absolute;
  top: 0;
  --hit: var(--brass);
}
.key.white {
  height: 100%;
  background: linear-gradient(180deg, #e9dfcc 0%, var(--ivory) 70%, #fffaf0 100%);
  border-right: 1px solid #b8aa92;
  border-radius: 0 0 4px 4px;
  z-index: 1;
  transition: background .08s;
}
.key.black {
  height: 62%;
  background: linear-gradient(180deg, #2b2621, #161310 80%, #2f2924);
  border-radius: 0 0 3px 3px;
  box-shadow: 0 3px 4px rgba(0,0,0,.55), inset 0 -4px 0 rgba(255,255,255,.06);
  z-index: 2;
  transition: background .08s, transform .08s;
}
.key.white.on {
  background: linear-gradient(180deg, color-mix(in srgb, var(--hit) 65%, var(--ivory)) 0%, var(--hit) 100%);
}
.key.black.on {
  background: linear-gradient(180deg, color-mix(in srgb, var(--hit) 70%, #1a1612), var(--hit));
  transform: translateY(1px);
}
.key .lbl {
  position: absolute;
  bottom: 6px;
  left: 0; right: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 9px;
  color: #8b7f6c;
  pointer-events: none;
}
.key.on .lbl { color: var(--ink); }
.key.home { box-shadow: inset 0 -3px 0 var(--brass-soft); }

/* ---------- transport ---------- */
.transport {
  display: grid;
  gap: 16px;
  padding: 18px 22px;
  border-radius: var(--radius);
  background: var(--ink-2);
  border: 1px solid var(--line);
  animation: rise 0.8s .2s cubic-bezier(.2,.7,.2,1) both;
}

.timeline {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
}
.time { font-family: var(--mono); font-size: 13px; color: var(--ivory-dim); min-width: 4ch; text-align: center; }

.controls {
  display: grid;
  grid-template-columns: 1fr minmax(180px, 260px) minmax(160px, 220px);
  gap: 28px;
  align-items: center;
}

.buttons { display: flex; align-items: center; gap: 10px; }

.icon-btn, .play-btn {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--ink-3);
  color: var(--ivory);
  cursor: pointer;
  transition: transform .15s, background .2s, border-color .2s, color .2s, opacity .2s;
}
.icon-btn { width: 42px; height: 42px; border-radius: 50%; }
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }
.icon-btn#loop-btn svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover:not(:disabled) { border-color: var(--brass); color: var(--brass); }
.icon-btn.toggle[aria-pressed="true"] { background: var(--brass-soft); border-color: var(--brass); color: var(--brass); }
.icon-btn:active:not(:disabled), .play-btn:active:not(:disabled) { transform: scale(.94); }

.play-btn {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--brass);
  border-color: transparent;
  color: var(--ink);
  box-shadow: 0 10px 30px -10px rgba(216,165,72,.6);
}
.play-btn:hover:not(:disabled) { background: #e6b65c; }
.play-btn svg { width: 24px; height: 24px; fill: currentColor; }
.play-btn .i-pause { display: none; }
.play-btn.playing .i-play { display: none; }
.play-btn.playing .i-pause { display: block; }

button:disabled { opacity: .35; cursor: not-allowed; box-shadow: none; }

.dial label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--ivory-dim);
  margin-bottom: 4px;
}
.dial output { font-family: var(--mono); color: var(--ivory); }
.dial-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; min-height: 20px; }
.link-btn {
  border: 0; background: none; padding: 0;
  color: var(--brass); font: 12px var(--body);
  cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}

/* range inputs */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  --pct: 0%;
}
input[type="range"]:disabled { cursor: not-allowed; opacity: .4; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--brass) var(--pct), var(--ink-3) var(--pct));
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--ink-3); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--brass); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--ivory);
  border: 3px solid var(--brass);
  transition: transform .15s;
}
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--ivory);
  border: 3px solid var(--brass);
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.15); }
input[type="range"]:focus-visible { outline: 2px solid var(--brass); outline-offset: 4px; border-radius: 4px; }

/* drop overlay */
.drop-overlay {
  position: fixed;
  inset: 12px;
  z-index: 40;
  display: grid;
  place-items: center;
  border: 2px dashed var(--brass);
  border-radius: 20px;
  background: rgba(21, 18, 15, .82);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.drop-overlay.show { opacity: 1; }
.drop-overlay p { font-family: var(--display); font-style: italic; font-size: 34px; color: var(--brass); margin: 0; }

/* motion */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: none; } }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* responsive */
@media (max-width: 860px) {
  .top { grid-template-columns: 1fr; align-items: start; }
  .now-playing { grid-template-columns: 1fr; }
  .parts { justify-content: flex-start; }
  .controls { grid-template-columns: 1fr 1fr; }
  .buttons { grid-column: 1 / -1; justify-content: center; }
  .key .lbl { display: none; }
}
@media (max-width: 520px) {
  .controls { grid-template-columns: 1fr; }
}
