:root {
  --night: #170c2e;
  --plum: #2b1650;
  --butter: #ffe9b0;
  --peach: #ffb48a;
  --rose: #ff7fa8;
  --lilac: #c9a0ff;
  --mint: #8fe3d0;
  --ink: #fbeee6;
  --ink-soft: rgba(251, 238, 230, 0.62);
  --line: rgba(255, 233, 176, 0.16);
  --track: var(--peach);
  --display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --ui: 'Instrument Sans', 'Avenir Next', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--night);
  color: var(--ink);
  font: 500 14px/1.3 var(--ui);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#scene, #sparks { position: fixed; inset: 0; width: 100%; height: 100%; }
#sparks { pointer-events: none; }

.grain {
  position: fixed; inset: 0; pointer-events: none; opacity: 0.11; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

body { display: flex; flex-direction: column; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.about-text { -webkit-user-select: text; user-select: text; }

/* ---- top ---- */
.top {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: 16px 28px; flex-wrap: wrap;
  padding: 18px 26px 0;
}
h1 {
  margin: 0;
  font: italic 400 clamp(30px, 4vw, 46px)/1 var(--display);
  font-variation-settings: 'SOFT' 100, 'WONK' 1;
  letter-spacing: -0.02em;
  color: var(--butter);
  text-shadow: 0 0 28px rgba(255, 127, 168, 0.55);
}
.song { display: flex; align-items: center; gap: 10px 20px; flex-wrap: wrap; }
.field { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); }
.field output { color: var(--ink); min-width: 3.2em; font-variant-numeric: tabular-nums; }

.hint {
  position: relative;
  flex: 1; min-height: 0;
  display: flex; align-items: flex-end; justify-content: center;
  margin: 0; padding: 0 24px 16px;
  text-align: center;
  font: italic 300 clamp(15px, 1.7vw, 20px)/1.35 var(--display);
  font-variation-settings: 'SOFT' 100, 'WONK' 0;
  color: var(--ink);
  text-shadow: 0 1px 14px rgba(23, 12, 46, 0.9);
  pointer-events: none;
}

/* ---- controls shared ---- */
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--butter); outline-offset: 2px; }

.btn {
  height: 34px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.icon { width: 34px; padding: 0; font-size: 18px; line-height: 1; }
.btn.quiet { border-color: transparent; background: none; color: var(--ink-soft); }
.btn.solid { background: var(--butter); border-color: var(--butter); color: var(--night); font-weight: 600; min-width: 68px; }
.btn.solid:hover { background: #fff3cf; }
.btn.rec::before {
  content: ''; display: inline-block; width: 9px; height: 9px; margin-right: 8px;
  border-radius: 50%; background: var(--rose); vertical-align: 0;
}
.btn.rec[aria-pressed='true'] { background: var(--rose); border-color: var(--rose); color: var(--night); font-weight: 600; }
.btn.rec[aria-pressed='true']::before { background: var(--night); animation: blink 1s steps(2) infinite; }
#loop { min-width: 126px; }
.btn.toggle[aria-pressed='true'] { border-color: var(--mint); color: var(--mint); background: rgba(143, 227, 208, 0.1); }
.btn.glow { border-color: rgba(201, 160, 255, 0.55); background: linear-gradient(120deg, rgba(201, 160, 255, 0.24), rgba(143, 227, 208, 0.2)); }
.btn.glow:hover { background: linear-gradient(120deg, rgba(201, 160, 255, 0.4), rgba(143, 227, 208, 0.34)); }
@keyframes blink { 50% { opacity: 0.25; } }

.seg, .moods { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; background: rgba(23, 12, 46, 0.35); }
.seg button, .moods button {
  height: 28px; min-width: 30px; padding: 0 12px; border: 0; border-radius: 999px; background: none; color: var(--ink-soft);
}
.seg button[aria-pressed='true'], .moods button[aria-pressed='true'] { background: var(--ink); color: var(--night); font-weight: 600; }

select {
  height: 30px; padding: 0 26px 0 12px; border: 1px solid var(--line); border-radius: 999px; appearance: none;
  background: rgba(23, 12, 46, 0.35) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23fbeee6' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center;
}
select option { color: #170c2e; }

input[type='range'] { touch-action: pan-y; appearance: none; width: 96px; height: 18px; background: none; cursor: pointer; }
input[type='range']::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: rgba(251, 238, 230, 0.28); }
input[type='range']::-moz-range-track { height: 3px; border-radius: 3px; background: rgba(251, 238, 230, 0.28); }
input[type='range']::-webkit-slider-thumb { appearance: none; width: 14px; height: 14px; margin-top: -5.5px; border-radius: 50%; background: var(--butter); box-shadow: 0 0 10px rgba(255, 233, 176, 0.6); }
input[type='range']::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--butter); }

/* ---- deck ---- */
.deck {
  position: relative;
  margin: 0 14px 14px; padding: 14px 16px 16px;
  display: grid; gap: 12px;
  border: 1px solid var(--line); border-radius: 26px;
  background: linear-gradient(180deg, rgba(43, 22, 80, 0.42), rgba(23, 12, 46, 0.72));
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  box-shadow: 0 20px 60px rgba(10, 4, 30, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.reel { display: flex; align-items: center; gap: 14px; color: var(--ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
#overview { flex: 1; min-width: 0; height: 26px; cursor: pointer; border-radius: 8px; }
#where { color: var(--ink); }

.tape { display: grid; grid-template-columns: minmax(400px, auto) 1fr; gap: 10px; }
.tracks { display: grid; grid-template-rows: repeat(7, 34px); gap: 4px; }
#lanes { width: 100%; height: 262px; border-radius: 14px; background: rgba(12, 5, 30, 0.45); }

.track {
  display: flex; align-items: center; gap: 6px; padding: 0 6px 0 4px;
  border: 1px solid transparent; border-radius: 12px;
}
.track.on { border-color: color-mix(in srgb, var(--c) 55%, transparent); background: color-mix(in srgb, var(--c) 13%, transparent); }
.track span.pick { cursor: default; }
.track .pick {
  flex: none; display: flex; align-items: center; gap: 9px; height: 100%; padding: 0 6px;
  border: 0; background: none; text-align: left; border-radius: 10px;
}
.track .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: 0 0 10px var(--c); flex: none; }
.track.muted .dot { background: none; box-shadow: inset 0 0 0 1.5px var(--c); }
.track.muted .pick { color: var(--ink-soft); }
.track select { height: 26px; font-size: 13px; }
.track select.sound { flex: 1; min-width: 0; border-color: transparent; background-color: transparent; font-size: 14px; }
.track select.chord { width: 118px; }
.track.muted select.sound { color: var(--ink-soft); }
.track input[type='range'] { width: 64px; flex: none; margin: 0 2px; }
.track .mini {
  height: 26px; padding: 0 9px; border: 1px solid var(--line); border-radius: 999px; background: none; color: var(--ink-soft); font-size: 12.5px;
}
.track .mini[aria-pressed='true'] { color: var(--night); background: var(--c); border-color: var(--c); font-weight: 600; }

.controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }
.tabs, .chips, #songSlot { display: none; } /* phone layout only */
.group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.deck > *, .tape > *, .play > * { min-width: 0; }
.group.end { margin-left: auto; }

.play { display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: center; }
.octave { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); }
#octOut { min-width: 4.6em; text-align: center; }

.pads { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 7px; }
/* Pads: soft rubber squares with a light inside. --hit is how hard the last
   strike was (0.45–1) and sets how bright the light gets. */
.pad {
  position: relative; height: 72px; padding: 0 4px; overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--track) 34%, rgba(0, 0, 0, 0.5)); border-radius: 15px;
  background:
    radial-gradient(120% 90% at 50% 0%, color-mix(in srgb, var(--track) 20%, transparent), transparent 70%),
    linear-gradient(180deg, #3a2658, #20123a);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), inset 0 -4px 8px rgba(0, 0, 0, 0.35), 0 3px 0 rgba(8, 3, 20, 0.6);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  touch-action: none; user-select: none; -webkit-user-select: none;
  transition: transform 0.09s, box-shadow 0.3s;
}
.pad::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 42%, color-mix(in srgb, var(--track) 55%, #fff) 0%, var(--track) 38%, transparent 78%);
  transition: opacity 0.4s ease-out;
}
.pad .name, .pad .key { position: relative; }
.pad .name { font: 600 15px/1 var(--ui); white-space: nowrap; text-shadow: 0 1px 4px rgba(8, 3, 20, 0.6); }
.pad .key { font-size: 11px; color: var(--ink-soft); }
.pads.off { opacity: 0.3; pointer-events: none; }
.pad.down {
  transform: translateY(3px) scale(0.975);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4), 0 0 calc(34px * var(--hit, 0.8)) color-mix(in srgb, var(--track) 75%, transparent);
  transition-duration: 0s;
}
.pad.down::before { opacity: calc(0.25 + 0.75 * var(--hit, 0.8)); transition-duration: 0s; }
.pad.down .name { color: var(--night); text-shadow: none; }
.pad.down .key { color: rgba(23, 12, 46, 0.6); }
.pad.lit::before { animation: padlight 0.55s ease-out; }
@keyframes padlight { from { opacity: calc(0.2 + 0.6 * var(--hit, 0.8)); } to { opacity: 0; } }

.fx { display: grid; grid-template-columns: auto auto auto; gap: 6px 14px; }
.fx label { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--ink-soft); }
.fx input { width: 68px; }
.fx select { height: 24px; width: 86px; font-size: 12.5px; padding: 0 20px 0 8px; background-position: right 7px center; }
#dice svg { display: block; margin: auto; }

@media (max-width: 1080px) {
  .play { grid-template-columns: 1fr; }
  .octave { order: 2; }
  .fx { order: 3; grid-template-columns: repeat(6, auto); justify-content: start; }
  .group.end { margin-left: 0; }
}
@media (max-height: 760px) and (min-width: 761px) {
  .tracks { grid-template-rows: repeat(7, 26px); }
  #lanes { height: 206px; }
  .pad { height: 56px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- credit and about ---- */
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.credit {
  padding: 0; border: 0; background: none; color: var(--ink-soft);
  font-size: 12.5px; text-shadow: 0 1px 10px rgba(23, 12, 46, 0.9);
}
.credit:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }

.about {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; overflow: auto;
  border: 1px solid var(--line); border-radius: 24px;
  background: var(--plum); color: var(--ink);
  box-shadow: 0 30px 90px rgba(10, 4, 30, 0.7);
}
.about::backdrop { background: rgba(12, 5, 30, 0.6); backdrop-filter: blur(6px); }
.about img { display: block; width: 100%; height: auto; }
.about-text { padding: 20px 26px 26px; }
.about h2 {
  margin: 0 0 10px; color: var(--butter);
  font: italic 400 30px/1.1 var(--display); font-variation-settings: 'SOFT' 100, 'WONK' 1;
}
.about p { margin: 0 0 10px; font-size: 15px; line-height: 1.5; color: var(--ink-soft); max-width: 60ch; }
.about .made { margin: 16px 0 18px; color: var(--ink); font-size: 16px; }
.about .made a { color: var(--butter); text-decoration: underline; text-underline-offset: 3px; }
.about .made a:hover { color: #fff3cf; }

/* ---- phones ----
   The deck becomes a bottom sheet with three tabs. Play: pick a track and tap
   the pads. Tracks: sounds, volumes and the tape. Sound: mood, tempo, effects.
   Play / Record / Loop stay in reach on every tab. */
@media (max-width: 760px), (max-height: 520px) and (pointer: coarse) {
  html, body { overflow: hidden; height: 100dvh; overscroll-behavior: none; }
  .top { padding: calc(8px + env(safe-area-inset-top)) 14px 0; }
  h1 { font-size: 30px; }
  .hint { padding: 0 16px 8px; font-size: 15px; }

  .deck {
    display: flex; flex-direction: column; gap: 10px;
    margin: 0 6px calc(6px + env(safe-area-inset-bottom)); padding: 10px; border-radius: 20px;
    max-height: 70dvh; overflow-y: auto; overscroll-behavior: contain;
    touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  }
  .deck[data-tab='play'] [data-tab]:not([data-tab='play']) { display: none !important; }
  .deck[data-tab='tracks'] [data-tab]:not([data-tab='tracks']) { display: none !important; }
  .deck[data-tab='sound'] [data-tab]:not([data-tab='sound']) { display: none !important; }
  #songSlot { display: block; }

  .tabs {
    display: grid; grid-template-columns: repeat(3, 1fr); flex: none;
    padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: #24133f;
    position: sticky; top: 0; z-index: 3; box-shadow: 0 -12px 0 12px #2a174a;
  }
  .tabs button { height: 40px; border: 0; border-radius: 999px; background: none; color: var(--ink-soft); }
  .tabs button[aria-pressed='true'] { background: var(--ink); color: var(--night); font-weight: 600; }

  .chips { display: flex; flex-wrap: wrap; gap: 6px; flex: none; }
  .chip {
    flex: 1 1 auto; justify-content: center; display: flex; align-items: center; gap: 7px; height: 38px; padding: 0 12px;
    border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 255, 255, 0.05); white-space: nowrap;
  }
  .chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
  .chip[aria-pressed='true'] { border-color: var(--c); background: color-mix(in srgb, var(--c) 22%, transparent); }

  .btn { height: 42px; padding: 0 15px; }
  .btn.icon { width: 42px; }
  .seg button, .moods button { height: 36px; min-width: 40px; }
  select { height: 38px; }
  input[type='range'] { height: 30px; }
  input[type='range']::-webkit-slider-thumb { width: 22px; height: 22px; margin-top: -9.5px; }
  input[type='range']::-moz-range-thumb { width: 22px; height: 22px; }

  /* order within the sheet: tabs, the tab's content, then the transport */
  .controls { display: contents; } /* its groups take their own places in the sheet */
  .tabs { order: 0; }
  .controls .group:first-child { order: 1; }
  .chips, #songSlot, .reel { order: 2; }
  .play, .tape { order: 3; }
  .controls .group { order: 4; }
  .group { gap: 6px; flex: none; }
  .group.end { margin-left: 0; }
  /* Play, Record and Loop stay pinned under the tabs while the sheet scrolls */
  .controls .group:first-child {
    display: grid; grid-template-columns: 1fr 1fr 1.5fr auto;
    position: sticky; top: 48px; z-index: 2; background: #2a174a; box-shadow: 0 0 0 6px #2a174a; border-radius: 12px;
  }
  .controls .group:first-child .btn { padding: 0 8px; min-width: 0; }
  .group[data-tab='play'] { display: grid; grid-template-columns: repeat(3, 1fr); }
  .group[data-tab='play'] .btn { padding: 0 6px; font-size: 13px; }

  .play { grid-template-columns: 1fr; gap: 10px; }
  .pads { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
  .pad { height: 70px; border-radius: 14px; }
  .pad .key { display: none; }
  .pad .name { font-size: 14px; }
  .octave { justify-content: center; }

  .tape { grid-template-columns: minmax(0, 1fr); }
  .tracks { grid-template-rows: repeat(7, 44px); min-width: 0; }
  .track { min-width: 0; padding: 0 2px; gap: 4px; }
  .track .pick { padding: 0 4px; }
  .track select { height: 34px; }
  .track select { padding: 0 20px 0 8px; background-position: right 7px center; }
  .track select.chord { width: 88px; }
  .track input[type='range'] { width: 54px; }
  .track .mini { height: 32px; }
  #lanes { height: 150px; }
  #overview { height: 30px; touch-action: none; }
  #length { display: none; }

  #songSlot .song { display: grid; grid-template-columns: 1fr; gap: 10px; }
  #songSlot .moods { display: grid; grid-template-columns: repeat(4, 1fr); }
  #songSlot .field { justify-content: space-between; }
  #songSlot .field input[type='range'] { flex: 1; width: auto; max-width: 220px; }
  .fx { grid-template-columns: 1fr; gap: 4px; }
  .fx input { width: auto; flex: 1; max-width: 220px; }
  .fx select { height: 36px; width: auto; min-width: 150px; font-size: 14px; }

  .about { max-height: calc(100dvh - 24px); }
}

/* ---- handpan page ---- */
.top .panlink { margin-right: auto; }
.panview {
  position: fixed; inset: 0; z-index: 20; display: grid; grid-template-rows: auto 1fr auto;
  background: #0d0a1c; touch-action: none; overscroll-behavior: none;
}
.panview[hidden] { display: none; }
.pan-scene {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  transition: opacity 0.5s; opacity: 1;
}
.pan-scene.swap { opacity: 0.25; }
.pan-shade {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 70% 55% at 50% 52%, rgba(10, 6, 24, 0.28), transparent 75%),
    linear-gradient(rgba(10, 6, 24, 0.5), transparent 16%, transparent 66%, rgba(10, 6, 24, 0.72));
}
.pan-top, .pan-stage, .pan-bottom { position: relative; }
.pan-top {
  display: flex; justify-content: space-between; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 14px 0;
}
.pan-top .btn:not(.solid) { background: rgba(23, 12, 46, 0.55); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.pan-stage { display: grid; place-items: center; min-height: 0; padding: 8px; }
.pan-body {
  position: relative; aspect-ratio: 1; touch-action: none; cursor: pointer;
  width: min(96vw, 760px, 100%); max-height: 100%;
  -webkit-tap-highlight-color: transparent;
}
@supports (height: 1dvh) { .pan-body { width: min(96vw, 760px, calc(100dvh - 250px)); } }
.pan-body > img {
  display: block; width: 100%; height: 100%; pointer-events: none; -webkit-user-drag: none;
  filter: drop-shadow(0 26px 30px rgba(0, 0, 0, 0.55)) drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
}
.pan-fx { position: absolute; inset: 0; pointer-events: none; border-radius: 50%; overflow: hidden; }
.pan-ring {
  position: absolute; width: var(--size); aspect-ratio: 1; border-radius: 50%; translate: -50% -50%;
  border: 2px solid rgba(255, 244, 214, 0.75); opacity: 0;
  animation: panring 0.9s ease-out;
}
.pan-ring.strong {
  background: radial-gradient(circle, rgba(255, 244, 214, 0.5), rgba(255, 244, 214, 0.12) 55%, transparent 72%);
  animation-duration: 1.3s;
}
@keyframes panring {
  from { opacity: 0.95; scale: 0.55; }
  to { opacity: 0; scale: 1.5; }
}
.pan-bottom {
  display: grid; gap: 8px; padding: 0 12px calc(12px + env(safe-area-inset-bottom));
}
.pan-info {
  margin: 0; text-align: center; color: var(--ink);
  font: italic 300 15px/1.35 var(--display); font-variation-settings: 'SOFT' 100, 'WONK' 0;
  text-shadow: 0 1px 10px rgba(10, 6, 24, 0.9);
}
.pan-row { display: flex; gap: 8px; justify-content: center; overflow-x: auto; scrollbar-width: none; }
.pan-row::-webkit-scrollbar { display: none; }
.pan-choice {
  flex: none; display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 14px 0 4px;
  border: 1px solid var(--line); border-radius: 999px; white-space: nowrap;
  background: rgba(23, 12, 46, 0.55); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.pan-choice img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.pan-choice[aria-pressed='true'] { border-color: var(--butter); background: rgba(255, 233, 176, 0.2); }
@media (max-width: 760px), (max-height: 520px) and (pointer: coarse) {
  .top { display: flex; align-items: flex-start; justify-content: space-between; }
  .top .panlink { margin-right: 0; }
  .pan-info { font-size: 13.5px; }
  /* on a phone only the chosen one spells out its name, so every choice fits on screen */
  .pan-choice { height: 48px; padding: 0 4px; }
  .pan-choice span { display: none; }
  .pan-choice[aria-pressed='true'] { padding-right: 14px; }
  .pan-choice[aria-pressed='true'] span { display: inline; }
}
@media (max-height: 520px) {
  .pan-info { display: none; }
  .pan-bottom { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) { .pan-ring { animation-duration: 0.01s !important; } }
