/* Synth: Moog Messenger style panel in the Polyrhythm look (black stage, dark glass dock, orange / green / purple).
   Three bands: sigil art pinned on top, controls scroll in the middle, keyboard pinned at the bottom. */
*, *::before, *::after { box-sizing: border-box; }
:root {
  --bg: #000; --text: #f2f2f2; --muted: #6e6e6e; --soft: #aaa;
  --panel: rgba(12, 12, 14, 0.72); --border: rgba(255, 255, 255, 0.1);
  --orange: #ff8a1f; --green: #3ddc84; --purple: #a855f7; --focus: #fff;
  --stage-h: clamp(150px, 30svh, 280px);
  --key-h: clamp(96px, 15svh, 140px);
}
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background: #000; color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; overscroll-behavior: none; }
[hidden] { display: none !important; }
.app {
  height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  padding-top: env(safe-area-inset-top, 0px); background: #000;
}
.site-header { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

/* Top band: the art. */
.stage-wrap { height: var(--stage-h); display: flex; justify-content: center; background: #000; box-shadow: 0 1px 0 var(--border), 0 6px 10px rgba(0, 0, 0, .85); z-index: 2; }
#visual { display: block; width: 100%; max-width: 980px; height: 100%; touch-action: none; cursor: grab; }
#visual.dragging { cursor: grabbing; }

/* Middle band: everything adjustable, scrolls by finger. */
.middle {
  min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 0 10px 8px; background: var(--panel); outline: none;
}
.middle > * { max-width: 1100px; margin-left: auto; margin-right: auto; }

button { font: inherit; font-size: .78rem; color: var(--text); background: rgba(20, 20, 22, .9); border: 1px solid var(--border); border-radius: 8px; padding: 4px 9px; cursor: pointer; min-height: 36px; }
button:hover { border-color: rgba(255, 255, 255, .28); }
button:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button:disabled { cursor: not-allowed; opacity: .45; }

/* Preset dropdown: one pill with previous / next steppers, sticky at the top of the middle band. */
.preset-bar { position: relative; z-index: 5; display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 10px; padding: 12px 10px; border: 1px solid rgba(61, 220, 132, .32); border-radius: 18px;
  background: radial-gradient(120% 140% at 50% 0%, rgba(61, 220, 132, .14), rgba(61, 220, 132, .03) 60%, rgba(11, 10, 13, 0)); }
.picker-label { font-size: .74rem; font-weight: 900; letter-spacing: .16em; text-transform: uppercase; color: #9fe8bd; }
.picker-step { width: 46px; min-height: 46px; border-width: 2px; padding: 0; font-size: 1.3rem; line-height: 1; color: var(--soft); border-radius: 999px; background: #101010; border-color: #3d3347; }
.picker-wrap { position: relative; }
.picker-pill { display: inline-flex; align-items: center; gap: 8px; width: min(360px, 62vw); min-height: 54px; padding: 6px 18px; border-radius: 999px;
  background: linear-gradient(180deg, #17402a, #0f2a1b); border: 2px solid var(--green); box-shadow: 0 0 18px rgba(61, 220, 132, .5), inset 0 0 14px rgba(61, 220, 132, .16); }
.picker-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--green); box-shadow: 0 0 6px var(--green); }
.picker-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.12rem; font-weight: 900; letter-spacing: .02em; color: #fff; text-shadow: 0 0 10px rgba(61, 220, 132, .45); }
.picker-edited { flex: none; font-size: .56rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--orange); }
.picker-kind { flex: none; margin-left: auto; font-size: .6rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: #7fbf98; }
.picker-caret { flex: none; width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 7px solid #e8e8e8; }
.picker-list { position: absolute; z-index: 30; left: 50%; top: calc(100% + 6px); transform: translateX(-50%); width: min(290px, 86vw);
  max-height: 60vh; overflow-y: auto; overscroll-behavior: contain; margin: 0; padding: 6px; list-style: none;
  background: rgba(18, 15, 24, .98); border: 1px solid #3d3347; border-radius: 12px; box-shadow: 0 12px 30px rgba(0, 0, 0, .8); }
.picker-list li[role="option"] { display: flex; align-items: baseline; gap: 8px; padding: 9px 11px; border-radius: 8px; font-size: .84rem; font-weight: 700; color: #d6d6d6; cursor: pointer; }
.picker-list li[role="option"] small { margin-left: auto; font-size: .6rem; font-weight: 600; color: #7d7387; letter-spacing: .04em; }
.picker-list li[role="option"]:hover, .picker-list li.is-focus { background: #1d1726; }
.picker-list li[aria-selected="true"] { background: #12261b; color: #fff; box-shadow: inset 0 0 0 1px var(--green); }
.picker-list .opt-head { padding: 9px 11px 3px; font-size: .58rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: #8b7a9c; }
.picker-list .opt-init { color: var(--soft); }

/* Output row: the Volume knob alone, centred. */
.perf-row { --accent: #d0d0d0; display: flex; justify-content: center; margin: 4px auto 8px; }

/* Record row: Polyrhythm's Record pill and length dropdown, at the very bottom above Support the developer. */
.record-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; margin: 12px auto 0; min-height: 34px; }
.btn-record { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; font-size: .78rem; min-height: 34px;
  padding: 6px 12px; border-radius: 999px; border: 1px solid rgba(255, 80, 80, .55); background: rgba(255, 60, 60, .12); color: var(--text); }
.btn-record .rec-dot { width: 8px; height: 8px; border-radius: 50%; background: #ff3b3b; box-shadow: 0 0 8px rgba(255, 59, 59, .8); }
.btn-record.is-recording { border-color: #ff5a5a; background: rgba(255, 60, 60, .22); animation: recpulse 1.2s ease-in-out infinite; }
@keyframes recpulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 59, 59, 0); } 50% { box-shadow: 0 0 0 4px rgba(255, 59, 59, .18); } }
.record-length-control { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.record-length-control span { font-size: .68rem; font-weight: 600; color: #aaa; }
.record-length-control select { min-width: 54px; min-height: 34px; padding: 5px 6px; font: inherit; font-size: .78rem; color: var(--text); background: #101012; border: 1px solid #38323f; border-radius: 8px; }
.rec-progress { display: inline-flex; align-items: center; gap: 8px; min-width: 140px; }
.rec-left { font-size: .72rem; font-weight: 700; color: #ffb4b4; font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.rec-bar { flex: 1; height: 4px; border-radius: 999px; background: rgba(255, 255, 255, .12); overflow: hidden; min-width: 72px; }
.rec-bar > i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, #ff3b3b, #ff8a1f); border-radius: 999px; }
button:disabled, select:disabled { cursor: not-allowed; opacity: .45; }

/* Clip preview and encoding modals (Polyrhythm). */
body.modal-open { overflow: hidden; }
.clip-modal { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, .72); backdrop-filter: blur(6px); }
.clip-card { width: min(420px, 100%); max-height: min(92dvh, 920px); overflow: auto; background: rgba(16, 16, 18, .96); border: 1px solid rgba(255, 255, 255, .12); border-radius: 16px; padding: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, .55); }
.clip-card video { width: 100%; max-height: 56dvh; aspect-ratio: 1; border-radius: 12px; background: #000; display: block; margin-bottom: 10px; }
.clip-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.clip-btn { font-size: .78rem; font-weight: 700; padding: 8px 12px; min-height: 36px; }
.clip-btn-muted { color: var(--muted); }
.game-modal { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: center; align-items: center; background: rgba(0, 0, 0, .55); padding: 18px; }
.game-card { width: min(350px, 100%); padding: 24px; border: 1px solid #a875ce; border-radius: 16px; background: #17101e; text-align: center; box-shadow: 0 0 35px #7b409666; }
.game-card h2 { margin: 0 0 10px; font-size: 22px; } .game-card p { line-height: 1.5; color: #d4cddd; margin: 0; }
@media (pointer: coarse), (max-width: 480px) { #btn-record, .record-length-control select, .clip-btn { min-height: 44px; } .record-row { gap: 6px; } }

/* Panel sections, named like the Messenger panel. */
.panel-grid { display: grid; grid-template-columns: 1fr; gap: 8px; align-items: start; }
.panel { --accent: var(--orange); margin: 0; min-width: 0; border: 1px solid color-mix(in srgb, var(--accent) 38%, #2a2430); border-radius: 10px; background: rgba(16, 15, 19, .9); padding: 4px 8px 8px; }
.panel legend { padding: 0 6px; font-size: .62rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.panel[data-accent="green"] { --accent: var(--green); }
.panel[data-accent="purple"] { --accent: var(--purple); }
.panel-row { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start; gap: 6px 4px; }
.panel-row + .panel-row { margin-top: 6px; }
/* Oscillator rows: Oscillator 1, 2 and 3 in the art's orange, green and purple. */
.osc-row { --accent: var(--orange); position: relative; padding: 14px 4px 4px; border-radius: 8px; border-left: 3px solid var(--accent);
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 13%, transparent), color-mix(in srgb, var(--accent) 4%, transparent)); }
.osc-row[data-accent="green"], .knob-control[data-accent="green"] { --accent: var(--green); }
.osc-row[data-accent="purple"], .knob-control[data-accent="purple"] { --accent: var(--purple); }
.knob-control[data-accent="orange"] { --accent: var(--orange); }
.osc-row-label { position: absolute; top: 3px; left: 9px; font-size: .58rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.osc-row .seg[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.knob-control[data-accent] .knob-label { color: color-mix(in srgb, var(--accent) 70%, #ddd); }

/* Knob: the Polyrhythm synth knob, swept 7:00 to 5:00 like the Messenger's pots. */
.knob-control { display: grid; justify-items: center; align-content: start; gap: 2px; width: 74px; }
.knob-label { min-height: 2.1em; display: flex; align-items: flex-end; text-align: center; font-size: .56rem; font-weight: 700; letter-spacing: .05em; line-height: 1.05; text-transform: uppercase; color: #a9a2b0; }
.synth-knob { width: 44px; height: 44px; border-radius: 50%; position: relative; border: 2px solid #59535f;
  background: repeating-conic-gradient(#25222a 0deg 8deg, #17151b 8deg 16deg);
  box-shadow: 0 0 0 3px #09090b, 0 0 0 4px #39303f, 0 3px 8px #000; touch-action: none; cursor: ns-resize; user-select: none; -webkit-user-select: none; }
.synth-knob::before { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: linear-gradient(130deg, #36313e, #15131b); box-shadow: inset 0 1px 2px #766985; }
.synth-knob i { position: absolute; inset: 0; transform: rotate(var(--angle, -150deg)); pointer-events: none; }
.synth-knob i::after { content: ""; position: absolute; width: 3px; height: 14px; border-radius: 3px; background: var(--accent); top: 3px; left: calc(50% - 1.5px); box-shadow: 0 0 7px var(--accent); }
.synth-knob:focus-visible { outline: 2px solid #d2b5ff; outline-offset: 5px; }
.synth-knob.dragging { border-color: var(--accent); }
.knob-value { min-width: 44px; min-height: 26px; display: inline-flex; justify-content: center; align-items: center; padding: 1px 5px; border: 1px solid #38323f; border-radius: 6px; background: #121016;
  font-size: .72rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); cursor: text; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.knob-sub { min-height: 1.1em; font-size: .56rem; color: #7f7887; font-variant-numeric: tabular-nums; text-align: center; white-space: nowrap; }
.number-editor { width: 60px; height: 26px; padding: 1px; font: 16px system-ui, sans-serif; text-align: center; color: #fff; background: #21152e; border: 2px solid #ad78d4; border-radius: 6px; }

/* Panel switches and toggles: compact segmented buttons. */
.switch-control { display: grid; justify-items: center; gap: 3px; }
.switch-group { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 3px; }
.seg { min-height: 30px; padding: 2px 8px; font-size: .64rem; font-weight: 700; letter-spacing: .03em; color: #9a9a9a; background: #101010; border-color: #2b2830; border-radius: 6px; }
.seg[aria-checked="true"], .toggle[aria-pressed="true"] { color: #0a0a0a; background: var(--accent); border-color: var(--accent); box-shadow: 0 0 8px color-mix(in srgb, var(--accent) 55%, transparent); }
.toggle { min-height: 30px; padding: 2px 9px; font-size: .62rem; font-weight: 800; letter-spacing: .06em; color: #9a9a9a; background: #101010; border-color: #2b2830; border-radius: 6px; align-self: center; }

.support-footer { text-align: center; padding: 12px 16px 6px; }
.support-footer a { color: #6e6e6e; font-size: 12px; letter-spacing: .03em; text-decoration: none; }
.support-footer a:hover, .support-footer a:focus-visible { color: #bbb; }

/* Bottom band: Hold, centred, and the keyboard, always visible. */
.dock { padding: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px)); background: #060608; border-top: 1px solid var(--border); box-shadow: 0 -6px 12px rgba(0, 0, 0, .8); z-index: 2; }
.dock > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.dock-row { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 6px; }
.transport-switch { display: inline-flex; align-items: center; gap: 7px; border: 0; background: transparent; padding: 0 2px; min-width: 52px; }
.switch-label { color: var(--soft); font-size: .62rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.switch-track { position: relative; width: 42px; height: 24px; border: 1px solid #38323f; border-radius: 999px; background: #121016; transition: background 160ms, border-color 160ms; }
.switch-knob { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #6e6e6e; transition: transform 160ms, background 160ms; }
.transport-switch.playing .switch-track { background: rgba(61, 220, 132, .18); border-color: var(--green); }
.transport-switch.playing .switch-knob { transform: translateX(18px); background: var(--green); }
.transport-switch.playing .switch-label { color: var(--green); }
.dock-row { position: relative; }
.hold-hint { position: absolute; left: calc(50% + 62px); top: 50%; transform: translateY(-50%); font-size: .66rem; font-weight: 700; color: #ffd2a6; white-space: nowrap; animation: pendtext 1.6s ease-in-out infinite; }
@keyframes pendtext { 50% { opacity: .55; } }
.transport-switch.pending .switch-track { border: 1px dashed var(--orange); background: rgba(255, 138, 31, .14); }
.transport-switch.pending .switch-knob { background: var(--orange); }
.transport-switch.pending .switch-label { color: #ffd2a6; }
.keyboard { position: relative; height: var(--key-h); display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; user-select: none; -webkit-user-select: none; touch-action: none; }
.key { min-height: 0; padding: 0; border-radius: 0 0 6px 6px; cursor: pointer; }
.key.white { position: relative; z-index: 1; border: 1px solid #2c2c30; background: linear-gradient(180deg, #cfcfd4 0%, #f2f2f2 82%); box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .12); }
.key.white.active { background: linear-gradient(180deg, #2aa865, var(--green)); box-shadow: 0 0 14px rgba(61, 220, 132, .55); transform: translateY(2px); }
.key.black { position: absolute; z-index: 2; top: 0; width: 8.4%; height: 60%; transform: translateX(-50%); border: 1px solid #000; background: linear-gradient(100deg, #050506, #24232a); box-shadow: 0 6px 10px rgba(0, 0, 0, .55); }
.key.black.active { background: linear-gradient(100deg, #5b2a8c, var(--purple)); box-shadow: 0 0 14px rgba(168, 85, 247, .6); transform: translate(-50%, 2px); }
.key.white.pending { background: linear-gradient(180deg, #e9d2bb 0%, #f6efe8 82%); box-shadow: inset 0 0 0 3px var(--orange), 0 0 10px rgba(255, 138, 31, .35); }
.key.black.pending { box-shadow: inset 0 0 0 2px var(--orange), 0 6px 10px rgba(0, 0, 0, .55); }
.key[data-note="61"] { left: 12.5%; } .key[data-note="63"] { left: 25%; } .key[data-note="66"] { left: 50%; }
.key[data-note="68"] { left: 62.5%; } .key[data-note="70"] { left: 75%; } .key[data-note="73"] { left: calc(100% - 4.2%); }

/* Short phones: shrink the pinned art and keys so the middle keeps room. */
@media (max-height: 700px) { :root { --stage-h: clamp(120px, 24svh, 200px); --key-h: clamp(84px, 14svh, 110px); } .dock-row { margin-bottom: 4px; } }
@media (max-height: 700px) { .preset-bar { margin-top: 6px; padding: 8px 6px; } .picker-pill { min-height: 48px; } .picker-step { width: 42px; min-height: 42px; } .picker-name { font-size: 1.02rem; } }
@media (max-height: 600px) { :root { --stage-h: 110px; --key-h: 80px; } }
@media (max-width: 480px) { .preset-bar { gap: 6px; margin-top: 8px; padding: 10px 6px; } .picker-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .picker-pill { width: calc(100vw - 140px); gap: 6px; padding: 6px 14px; } .picker-kind { display: none; } }
@media (max-width: 380px) { .knob-control { width: 68px; } .picker-kind { display: none; } }
/* Desktop: same three bands, sections side by side. */
@media (min-width: 900px) {
  :root { --stage-h: clamp(200px, 34vh, 330px); --key-h: clamp(110px, 17vh, 150px); }
  .middle { padding: 0 20px 10px; }
  .panel-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .panel.wide { grid-column: span 2; }
  /* Oscillators spans two rows so Mixer and Filter envelope stack beside it: every panel fits its contents, no holes. */
  .panel-grid { grid-auto-flow: row dense; }
  .panel-grid > .panel:first-child { grid-row: span 2; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: .01ms !important; animation: none !important; } }
