/* Shared look for the Spark 2 touch views (webapp/views). Same design language as the
   OpenAcoustic views in ../Helicon/tools/views: one colour per block type, flat dark surfaces,
   line-art pictures, one top bar with tone selector + view switcher. */
:root {
  --bg: #0e1115; --surface: #161a20; --surface-2: #1d222a; --surface-3: #262c35;
  --ink: #e9edf1; --muted: #8b96a3; --faint: #5b6572; --rule: #2a313b;
  --accent: #6cb6cf; --on: #43d17a; --warn: #f0b04a; --danger: #ff6b5b;
  --lcd: #c9d8c2; --lcd-ink: #1c2a1a;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  /* one colour per block type */
  --c-gate: #7d8794; --c-comp: #3f7fe2; --c-drive: #d4a72c; --c-amp: #e2583f;
  --c-mod: #8c5ed8; --c-eq: #36a77f; --c-delay: #2aa8bb; --c-reverb: #b9c2cc;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.4 var(--sans); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
.mono { font-family: var(--mono); }
html { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
input, textarea, select { -webkit-user-select: text; user-select: text; }

/* ── top bar: connection · tone · views ── */
:root { --barh: 58px; }
.pbar { position: sticky; top: 0; z-index: 60; min-height: var(--barh); display: flex; align-items: center; gap: 12px;
  padding: max(0px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  background: #0a0c0ff0; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-bottom: 1px solid var(--rule); }
.pbar .sp { flex: 1; }
.psel { position: relative; display: flex; align-items: center; gap: 6px; min-width: 0; }
.pstep { width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--rule); background: var(--surface-2); color: var(--ink); font-size: 15px; cursor: pointer; flex: none; }
.pstep:active { background: var(--surface-3); }
.pname { display: flex; align-items: baseline; gap: 10px; height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid transparent; background: none; cursor: pointer; min-width: 0; touch-action: pan-y; }
.pname:hover, .pname[aria-expanded=true] { border-color: var(--rule); background: var(--surface); }
.pnum { font: 700 20px var(--mono); color: var(--accent); }
.pnm { font: 700 19px var(--sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
.pnm i { font-style: normal; color: var(--warn); font-size: 14px; margin-left: 4px; }
.car { color: var(--muted); font-size: 12px; }
.pinfo { font: 600 14px var(--mono); color: var(--muted); white-space: nowrap; }
.plist { position: absolute; top: calc(100% + 8px); left: 48px; width: 340px; max-height: 64vh; display: grid; grid-template-rows: auto 1fr auto; background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; box-shadow: 0 16px 40px #000c; overflow: hidden; z-index: 70; }
.plist[hidden] { display: none; }
.plist input { margin: 10px; background: var(--bg); border: 1px solid var(--rule); border-radius: 8px; color: var(--ink); padding: 9px 10px; font: inherit; }
.pitems { overflow: auto; padding: 0 6px 8px; }
.pitems button { display: flex; gap: 12px; width: 100%; text-align: left; background: none; border: 0; border-radius: 8px; padding: 10px; cursor: pointer; font-size: 15px; align-items: center; }
.pitems button span { font: 600 14px var(--mono); color: var(--muted); width: 26px; }
.pitems button small { margin-left: auto; display: flex; gap: 3px; }
.pitems button small i { width: 6px; height: 6px; border-radius: 50%; background: var(--surface-3); }
.pitems button small i.on { background: var(--c); }
.pitems button:hover { background: var(--surface-2); }
.pitems button.sel { background: var(--surface-3); } .pitems button.sel span { color: var(--accent); }
.pitems .none { padding: 12px; color: var(--muted); font-size: 13px; }
.pfoot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--rule); }
.views { display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 3px; flex: none; }
.views a { display: grid; justify-items: center; min-width: 56px; padding: 4px 8px; border-radius: 9px; color: var(--muted); text-decoration: none; font: 600 10px var(--sans); letter-spacing: .04em; }
.views a b { font-size: 16px; line-height: 1.1; font-weight: 400; }
.views a:hover { color: var(--ink); }
.views a.on { background: var(--surface-3); color: var(--ink); }
.pbar.big .pstep { width: 84px; height: 84px; border-radius: 18px; font-size: 32px; }
.pbar.big .pname { height: 84px; }
.pbar.big .pnum { font-size: 24px; } .pbar.big .pnm { font-size: 40px; font-weight: 800; max-width: 46vw; }
.pbar.big .plist { left: 92px; width: 380px; }
.pbar.big .pitems button { padding: 14px 10px; font-size: 18px; }
html.bigbar { --barh: 104px; }
@media (max-width: 760px) {
  :root { --barh: 104px; } html.bigbar { --barh: 128px; }
  .pbar { flex-wrap: wrap; align-content: center; row-gap: 6px; gap: 6px; padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 6px; }
  .pinfo, .pbar .sp { display: none; } .conn span { display: none; }
  .psel { flex: 1; } .pname { flex: 1; } .pnm { max-width: none; min-width: 0; flex: 1 1 0; font-size: 17px; } .pbar { max-width: 100vw; } .pbar > * { min-width: 0; } .pbar.big .pnm { font-size: 24px; }
  .pbar.big .pstep { width: 60px; height: 60px; font-size: 24px; } .pbar.big .pname { height: 60px; }
  .views { width: 100%; } .views a { flex: 1; min-width: 0; grid-auto-flow: column; gap: 6px; align-items: center; justify-content: center; padding: 6px 4px; }
  .plist, .pbar.big .plist { left: 0; width: min(340px, calc(100vw - 20px)); }
}
@media (max-width: 480px) {
  .views { overflow: hidden; } .views a { grid-auto-flow: row; gap: 0; padding: 4px 2px; font-size: 9px; letter-spacing: 0; overflow: hidden; }
  .views a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ── connection chip + popover ── */
.cwrap { position: relative; flex: none; }
.conn { display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--rule); background: var(--surface); cursor: pointer; font: 700 11px var(--mono); letter-spacing: .06em; color: var(--muted); text-transform: uppercase; }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.conn[data-s=ready] { color: var(--ink); } .conn[data-s=ready] i { background: var(--on); box-shadow: 0 0 8px var(--on); }
.conn[data-s=connecting] i { background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.cpop { position: absolute; top: calc(100% + 10px); left: 0; width: 320px; z-index: 75; background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; box-shadow: 0 16px 40px #000c; padding: 14px; display: grid; gap: 10px; }
.cpop[hidden] { display: none; }
.cmsg { font: 600 13px var(--sans); }
.crow { display: flex; gap: 8px; flex-wrap: wrap; }
.crow button, .pfoot button { background: var(--surface-2); border: 1px solid var(--rule); border-radius: 8px; padding: 8px 12px; cursor: pointer; font-size: 13px; }
.crow button.pri { background: var(--accent); color: #06212b; border-color: var(--accent); font-weight: 700; }
.crow button:disabled { opacity: .4; cursor: not-allowed; }
.offbar { position: sticky; top: var(--barh); z-index: 58; display: flex; align-items: center; justify-content: center; gap: 12px; padding: 6px 12px; background: #2a210d; color: var(--warn); font: 600 13px var(--sans); }
.offbar[hidden] { display: none; }
.offbar button { background: var(--warn); color: #241800; border: 0; border-radius: 6px; padding: 5px 10px; font: 700 12px var(--sans); cursor: pointer; }

/* Block pictures: inline line-art SVG in currentColor (92x48) */
.art { display: block; aspect-ratio: 92 / 48; width: 92px; }
.art * { vector-effect: non-scaling-stroke; }

/* Knob */
.knob { display: inline-grid; justify-items: center; gap: 2px; touch-action: none; user-select: none; cursor: ns-resize; --kc: var(--accent); }
.knob svg { display: block; overflow: visible; }
.knob .kv { font: 600 12px var(--mono); color: var(--ink); white-space: nowrap; }
.knob .kl { font: 600 10px var(--sans); letter-spacing: .06em; color: var(--muted); text-transform: uppercase; white-space: nowrap; }
.knob .kl i { font-style: normal; color: var(--warn); }
.knob:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 8px; }
.knob.active svg, .knob.fine svg { filter: drop-shadow(0 0 6px var(--kc)); }
.knob.fine .kv::after { content: " · fine"; color: var(--warn); }

/* State chip OFF / ON */
.st { font: 700 10px var(--mono); letter-spacing: .08em; padding: 2px 6px; border-radius: 4px; background: var(--surface-3); color: var(--faint); }
.st.on { background: #43d17a22; color: var(--on); }
.note { font-size: 12px; color: var(--muted); }
.note b { color: var(--ink); font-weight: 600; }
.q { color: var(--warn); }

/* ── fader: horizontal bar; drag anywhere (relative), double-tap = default, tap value = type ── */
.fader { display: grid; grid-template-columns: 1fr 52px; align-items: center; gap: 10px; min-height: 30px; cursor: ew-resize; touch-action: none; }
.ftrack { position: relative; height: 24px; border-radius: 7px; background: var(--bg); border: 1px solid var(--rule); overflow: hidden; }
.ffill { position: absolute; top: 0; bottom: 0; left: 0; background: var(--fc, var(--accent)); opacity: .75; }
.fader.active .ftrack { border-color: var(--fc, var(--accent)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--fc, var(--accent)) 25%, transparent); }
.fval, .ftype { font: 600 12px var(--mono); text-align: right; color: var(--ink); }
.ftype { width: 100%; background: var(--bg); border: 1px solid var(--accent); border-radius: 5px; padding: 3px 6px; }

/* toast */
.svtoast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100; background: var(--surface-3); color: var(--ink); font: 600 14px var(--mono); padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px #000a; opacity: 0; pointer-events: none; transition: opacity .3s; white-space: nowrap; max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis; }
.svtoast.show { opacity: 1; transition: none; }

/* detail sheet */
.sheet-bg { position: fixed; inset: 0; background: #000a; display: none; z-index: 80; }
.sheet-bg.open { display: block; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 80vh; overflow: auto; z-index: 90; background: var(--surface); border-top: 3px solid var(--pc); border-radius: 18px 18px 0 0;
  padding: 18px max(20px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); transform: translateY(105%); transition: transform .25s ease; }
.sheet.open { transform: none; }
.sh-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.sh-head .art { width: 120px; color: var(--pc); }
.sh-head h3 { margin: 0; font-size: 22px; }
.sh-head .x { margin-left: auto; background: var(--surface-3); border: 0; border-radius: 50%; width: 36px; height: 36px; cursor: pointer; font-size: 18px; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 8px 14px; cursor: pointer; font: 700 12px var(--mono); color: var(--muted); }
.seg button.sel { background: var(--surface-3); color: var(--ink); }
.seg button.sel[data-s="on"] { color: var(--on); }
.sh-sec { margin-top: 18px; } .sh-sec h4 { margin: 0 0 8px; font-size: 11px; letter-spacing: .12em; color: var(--muted); text-transform: uppercase; }
.styles { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.styles button { background: var(--surface-2); border: 1px solid var(--rule); border-radius: 8px; padding: 8px 6px 6px; cursor: pointer; display: grid; gap: 4px; color: var(--muted); font: 600 10px var(--mono); text-align: center; }
.styles button .art { color: #cfd6dd; width: 72px; justify-self: center; }
.styles button.sel { border-color: var(--pc); color: var(--ink); background: color-mix(in srgb, var(--pc) 18%, var(--surface-2)); }
.styles button.sel .art { color: var(--pc); }
.bigknobs { display: flex; gap: 22px; flex-wrap: wrap; }
