@font-face { font-family: "Fraunces"; src: url("fonts/fraunces.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Hanken Grotesk"; src: url("fonts/hanken-grotesk.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("fonts/jetbrains-mono.woff2") format("woff2"); font-weight: 100 800; font-display: swap; }

:root {
  --paper: #F4F0E8;
  --ink: #1A1815;
  --ground: #100F0D;
  --ox: #7C2B22;
  --ox-lit: #A63E30;
  --ox-deep: #571C16;
  --coral: #C9776A;
  --stone: #8A7F6E;
  --stone-lit: #B5AA97;
  --line: rgba(244, 240, 232, 0.10);
  --line-2: rgba(244, 240, 232, 0.18);
  --well: rgba(8, 7, 6, 0.42);
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --cut: 18px;
  --gap: clamp(10px, 1.7vh, 18px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--ground);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ground */
.stage {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background:
    radial-gradient(55% 48% at 14% 8%, rgba(124, 43, 34, 0.42), transparent 72%),
    radial-gradient(45% 40% at 92% 96%, rgba(201, 119, 106, 0.13), transparent 70%),
    linear-gradient(180deg, #1C1A16 0%, #0E0D0B 100%);
}
.stage::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(244, 240, 232, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(244, 240, 232, 0.035) 1px, transparent 1px);
  background-size: 34px 34px;
  -webkit-mask-image: radial-gradient(ellipse 70% 65% at 50% 50%, #000 25%, transparent 80%);
  mask-image: radial-gradient(ellipse 70% 65% at 50% 50%, #000 25%, transparent 80%);
}
.stage::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0.07; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* card */
.shell {
  position: relative; z-index: 1;
  width: min(880px, 100%);
  max-height: 100%;
  display: flex;
  filter: drop-shadow(0 28px 50px rgba(0, 0, 0, 0.55)) drop-shadow(0 0 1px rgba(0, 0, 0, 0.6));
}
.frame, .card {
  clip-path: polygon(var(--cut) 0, 100% 0, 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, 0 100%, 0 var(--cut));
}
.frame {
  flex: 1; display: flex; min-height: 0;
  padding: 1px;
  background: linear-gradient(158deg, rgba(244, 240, 232, 0.42) 0%, rgba(244, 240, 232, 0.10) 28%, rgba(244, 240, 232, 0.05) 62%, rgba(201, 119, 106, 0.6) 100%);
}
.card {
  position: relative; flex: 1; min-width: 0; min-height: 0;
  display: flex; flex-direction: column; gap: var(--gap);
  padding: clamp(14px, 2.4vh, 26px) clamp(14px, 3vw, 28px);
  background:
    linear-gradient(165deg, rgba(42, 38, 33, 0.97) 0%, rgba(24, 22, 19, 0.98) 55%, rgba(19, 17, 15, 0.99) 100%);
  overflow: hidden;
}
.card::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 42%; pointer-events: none;
  background: linear-gradient(180deg, rgba(244, 240, 232, 0.075), rgba(244, 240, 232, 0) 100%);
}
.card::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(112deg, transparent 38%, rgba(244, 240, 232, 0.045) 46%, transparent 54%);
}
.card > * { position: relative; z-index: 1; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  font-family: var(--serif); font-weight: 700; font-size: 17px; color: var(--paper);
  background: linear-gradient(180deg, var(--ox-lit) 0%, var(--ox) 52%, var(--ox-deep) 100%);
  clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.mark svg { width: 60%; height: 60%; fill: none; stroke: var(--paper); stroke-width: 2.4; stroke-linecap: square; }
.titles { display: flex; flex-direction: column; min-width: 0; }
h1 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: clamp(18px, 2.4vw, 24px); letter-spacing: -0.01em; line-height: 1.1; font-variation-settings: "SOFT" 50; }
.by { font-family: var(--mono); font-size: 11px; color: var(--stone-lit); margin-top: 2px; }
.status {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  font-family: var(--mono); font-size: 11.5px; color: var(--stone-lit);
  padding: 6px 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.18);
}
.led { width: 7px; height: 7px; border-radius: 50%; background: var(--stone); box-shadow: 0 0 0 2px rgba(138, 127, 110, 0.15); }
.card[data-state="ready"] .led, .card[data-state="playing"] .led { background: var(--coral); box-shadow: 0 0 10px rgba(201, 119, 106, 0.8); }
.card[data-state="playing"] .led { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* deck */
.deck { display: flex; flex-direction: column; gap: 10px; min-height: 0; flex: 1 1 auto; }
.fileRow { display: flex; align-items: center; gap: 12px; min-width: 0; min-height: 28px; }
.fname { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.card[data-state="empty"] .fname { color: var(--stone-lit); font-weight: 500; }
.fmeta { font-family: var(--mono); font-size: 11.5px; color: var(--stone-lit); white-space: nowrap; }
#replaceBtn { margin-left: auto; }

.wave {
  position: relative; flex: 1 1 auto;
  min-height: 74px; height: clamp(96px, 20vh, 190px); max-height: 190px;
  background:
    linear-gradient(180deg, transparent calc(50% - 0.5px), rgba(244, 240, 232, 0.07) calc(50% - 0.5px), rgba(244, 240, 232, 0.07) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    var(--well);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 10px rgba(0, 0, 0, 0.45);
  outline: none;
  touch-action: none;
}
.card:not([data-state="empty"]) .wave { cursor: pointer; }
.card[data-state="empty"] .wave { background: var(--well); }
.wave:focus-visible { border-color: var(--coral); }
#waveCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.corner { position: absolute; width: 12px; height: 12px; pointer-events: none; }
.corner.tl { top: -1px; left: -1px; border-top: 2px solid var(--coral); border-left: 2px solid var(--coral); }
.corner.br { bottom: -1px; right: -1px; border-bottom: 2px solid var(--coral); border-right: 2px solid var(--coral); }

.drop { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 10px; }
.card:not([data-state="empty"]) .drop { display: none; }
.dropInner { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.dropIcon { width: 30px; height: 30px; fill: none; stroke: var(--coral); stroke-width: 2.4; stroke-linecap: square; }
.dropTitle { margin: 0; font-weight: 600; font-size: 15px; }
.dropSub { margin: 0 0 4px; font-size: 12.5px; color: var(--stone-lit); }
.dropErr { margin: 0; font-size: 12.5px; color: #E59A8B; min-height: 0; }
.dropErr:empty { display: none; }
.wave.over { border-color: var(--coral); box-shadow: inset 0 0 0 1px var(--coral), inset 0 0 40px rgba(201, 119, 106, 0.15); }

.loading { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--mono); font-size: 12px; color: var(--stone-lit); background: rgba(10, 9, 8, 0.6); }
.loading span { display: block; width: 120px; height: 2px; margin: 0 auto 10px; background: linear-gradient(90deg, transparent, var(--coral), transparent); background-size: 200% 100%; animation: scan 1s linear infinite; }
@keyframes scan { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.transport { display: flex; align-items: center; gap: 14px; }
.play {
  width: 50px; height: 50px; flex: none; border: 0; cursor: pointer; padding: 0;
  display: grid; place-items: center;
  background: linear-gradient(180deg, var(--ox-lit) 0%, var(--ox) 50%, var(--ox-deep) 100%);
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), inset 0 -10px 18px rgba(0, 0, 0, 0.25);
  transition: filter 0.15s ease;
}
.play svg { width: 22px; height: 22px; fill: var(--paper); }
.play .iPause { display: none; }
.card[data-state="playing"] .play .iPlay { display: none; }
.card[data-state="playing"] .play .iPause { display: block; }
.play:hover:not(:disabled) { filter: brightness(1.12); }
.play:disabled { background: linear-gradient(180deg, #3A352F, #2A2622); cursor: default; }
.play:disabled svg { fill: var(--stone); }
.clock { font-family: var(--mono); font-size: clamp(18px, 2.4vw, 22px); font-weight: 500; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.clock .sep { color: var(--stone); margin: 0 8px; }
#tEnd { color: var(--stone-lit); }
#restartBtn { margin-left: auto; }

/* panels */
.panels { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); flex: none; }
.panel {
  display: flex; flex-direction: column; gap: 10px;
  padding: clamp(12px, 1.8vh, 16px) clamp(12px, 1.8vw, 18px);
  background: linear-gradient(180deg, rgba(244, 240, 232, 0.035), rgba(244, 240, 232, 0.012));
  border: 1px solid var(--line);
  min-width: 0;
}
.card[data-state="empty"] .panel, .card[data-state="empty"] .foot .lens { opacity: 0.45; }
.pHead { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.pHead label { font-family: var(--mono); font-size: 12px; color: var(--stone-lit); }
.pHead output { font-family: var(--mono); font-weight: 500; font-size: clamp(28px, 4.2vh, 38px); line-height: 1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.pHead output small { font-size: 0.48em; color: var(--coral); margin-left: 4px; letter-spacing: 0; font-weight: 500; }

.range { position: relative; height: 30px; }
.ticks { position: absolute; left: 7px; right: 7px; top: 22px; height: 6px; pointer-events: none; }
#speedPanel .ticks {
  background: repeating-linear-gradient(90deg, rgba(244, 240, 232, 0.28) 0 1px, transparent 1px calc(100% / 6));
  border-right: 1px solid rgba(244, 240, 232, 0.28);
}
#pitchPanel .ticks {
  background:
    linear-gradient(90deg, transparent calc(50% - 1px), var(--coral) calc(50% - 1px), var(--coral) calc(50% + 1px), transparent calc(50% + 1px)),
    repeating-linear-gradient(90deg, rgba(244, 240, 232, 0.24) 0 1px, transparent 1px calc(100% / 12));
  border-right: 1px solid rgba(244, 240, 232, 0.24);
}
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  position: relative; z-index: 1;
  width: 100%; height: 22px; margin: 0; background: transparent; cursor: pointer;
  --lo: 0%; --hi: 33%;
}
input[type="range"]:disabled { cursor: default; }
input[type="range"]:focus { outline: none; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 0;
  background: linear-gradient(90deg, rgba(244, 240, 232, 0.13) 0 var(--lo), var(--coral) var(--lo) var(--hi), rgba(244, 240, 232, 0.13) var(--hi) 100%);
}
input[type="range"]::-moz-range-track {
  height: 4px; border-radius: 0;
  background: linear-gradient(90deg, rgba(244, 240, 232, 0.13) 0 var(--lo), var(--coral) var(--lo) var(--hi), rgba(244, 240, 232, 0.13) var(--hi) 100%);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 22px; margin-top: -9px; border: 0; border-radius: 2px;
  background:
    linear-gradient(90deg, transparent 6px, var(--ox) 6px 8px, transparent 8px),
    linear-gradient(180deg, #FFFFFF 0%, #EDE6D9 48%, #CDC3B2 100%);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 4px 10px rgba(0, 0, 0, 0.55), 0 0 16px rgba(201, 119, 106, 0.35);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 22px; border: 0; border-radius: 2px;
  background:
    linear-gradient(90deg, transparent 6px, var(--ox) 6px 8px, transparent 8px),
    linear-gradient(180deg, #FFFFFF 0%, #EDE6D9 48%, #CDC3B2 100%);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 4px 10px rgba(0, 0, 0, 0.55), 0 0 16px rgba(201, 119, 106, 0.35);
}
input[type="range"]:disabled::-webkit-slider-thumb { background: #6E6658; box-shadow: none; }
input[type="range"]:disabled::-moz-range-thumb { background: #6E6658; box-shadow: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 2px var(--coral), 0 4px 10px rgba(0, 0, 0, 0.55); }
input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 2px var(--coral), 0 4px 10px rgba(0, 0, 0, 0.55); }

.chips { display: flex; gap: 6px; }
.chip {
  flex: 1; min-width: 0; height: 30px; padding: 0 4px; cursor: pointer;
  font-family: var(--mono); font-size: 12px; color: var(--stone-lit);
  background: rgba(0, 0, 0, 0.2); border: 1px solid var(--line);
}
.chip:hover:not(:disabled) { color: var(--paper); border-color: var(--line-2); }
.chip.on { color: var(--paper); border-color: var(--coral); background: rgba(124, 43, 34, 0.35); }
.chip:disabled { cursor: default; }

.seg {
  position: relative; display: grid; grid-template-columns: 1fr 1fr;
  height: 36px; padding: 3px; background: var(--well); border: 1px solid var(--line);
}
.seg button { position: relative; z-index: 1; border: 0; background: none; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--stone-lit); transition: color 0.2s ease; }
.seg button[aria-checked="true"] { color: var(--paper); }
.seg button:disabled { cursor: default; }
.seg button:focus-visible { outline: 1px solid var(--coral); outline-offset: -2px; }
.segThumb {
  position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px);
  background: linear-gradient(180deg, var(--ox-lit) 0%, var(--ox) 55%, var(--ox-deep) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
  transition: transform 0.22s cubic-bezier(0.3, 0.7, 0.2, 1);
}
.seg[data-mode="shift"] .segThumb { transform: translateX(100%); }
.card[data-state="empty"] .segThumb { background: #3A352F; }

.hint { margin: -2px 0 0; font-size: 12.5px; color: var(--stone-lit); }
.scale { display: flex; justify-content: space-between; margin: -4px 1px 0; font-family: var(--mono); font-size: 10.5px; color: var(--stone); }
.steppers { display: flex; align-items: center; gap: 6px; }
.step {
  width: 44px; height: 30px; cursor: pointer;
  font-family: var(--mono); font-size: 12.5px; color: var(--paper);
  background: rgba(0, 0, 0, 0.2); border: 1px solid var(--line);
}
.step:hover:not(:disabled) { border-color: var(--line-2); }
.step:disabled { color: var(--stone); cursor: default; }
.total { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--stone-lit); white-space: nowrap; }
.total b { color: var(--paper); font-weight: 600; }

/* footer */
.foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex: none; padding-top: 2px; }
.lens { display: flex; gap: 22px; }
.lens div { display: flex; flex-direction: column; }
.lens span { font-family: var(--mono); font-size: 11px; color: var(--stone-lit); white-space: nowrap; }
.lens b { font-family: var(--mono); font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 8px; }

.btn, .ghost {
  height: 44px; padding: 0 18px; cursor: pointer; white-space: nowrap;
  font-weight: 600; font-size: 14px;
}
.btn.small, .ghost.small { height: 30px; padding: 0 12px; font-size: 12.5px; }
.ghost { background: rgba(0, 0, 0, 0.18); border: 1px solid var(--line-2); color: var(--paper); }
.ghost:hover:not(:disabled) { border-color: rgba(244, 240, 232, 0.35); }
.ghost:disabled { color: var(--stone); border-color: var(--line); cursor: default; }
.btn {
  position: relative; border: 0; color: var(--paper); overflow: hidden;
  background: linear-gradient(180deg, var(--ox-lit) 0%, var(--ox) 52%, var(--ox-deep) 100%);
  clip-path: polygon(9px 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%, 0 9px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.26);
  transition: filter 0.15s ease;
}
.btn.small { clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px); }
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:disabled { background: linear-gradient(180deg, #3A352F, #2A2622); color: var(--stone); cursor: default; }
.btn.primary { min-width: 168px; }
.dlFill { position: absolute; left: 0; top: 0; bottom: 0; width: var(--p, 0%); background: rgba(244, 240, 232, 0.16); }
.dlText { position: relative; }
.btn.busy { cursor: progress; }

:focus-visible { outline: 2px solid var(--coral); outline-offset: 2px; }

.dragVeil {
  position: fixed; inset: 0; z-index: 5; display: none; place-items: center; pointer-events: none;
  background: rgba(16, 15, 13, 0.6);
  font-family: var(--mono); font-size: 14px; color: var(--paper);
}
.dragVeil div { padding: 14px 22px; border: 1px solid var(--coral); background: rgba(124, 43, 34, 0.35); }
body.dragging .dragVeil { display: grid; }

/* phone and narrow */
@media (max-width: 760px) {
  :root { --cut: 14px; }
  .stage { padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); place-items: stretch; }
  .shell { width: 100%; height: 100%; }
  .panels { grid-template-columns: 1fr; }
  .wave { height: auto; max-height: none; }
  .panel { gap: 8px; }
  .lens { gap: 14px; }
  .lens b { font-size: 14px; }
  .btn.primary { min-width: 0; }
  .fmeta { display: none; }
  #pitchPanel .hint { display: none; }
}
@media (max-width: 380px) {
  .actions .ghost { padding: 0 12px; }
  .btn { padding: 0 14px; }
  .status { padding: 5px 8px; }
}
@media (max-width: 760px) and (max-height: 760px) {
  .card { gap: 9px; padding: 12px 13px; }
  .panel { padding: 10px 12px; gap: 7px; }
  .hint { display: none; }
  .pHead output { font-size: 26px; }
  .chips .chip, .step { height: 28px; }
  .seg { height: 34px; }
  .play { width: 44px; height: 44px; }
  .btn, .ghost { height: 40px; }
  .mark { width: 30px; height: 30px; font-size: 15px; }
}
@media (max-width: 760px) and (max-height: 640px) {
  .scale { display: none; }
  .wave { min-height: 56px; }
  .by { display: none; }
}
@media (min-width: 761px) and (max-height: 700px) {
  .hint { display: none; }
  .wave { height: clamp(70px, 16vh, 140px); }
}

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