/* Sinebloom workspace. Root rules are scoped to .uwapp-root.uwapp-sinebloom (the body carries the class too).
   Colours: system tokens (light) and the --d-* constants (dark), DESIGN_SYSTEM.md §9. The scope is a dark "screen" in
   both themes. No animations except hover colour changes, and none under prefers-reduced-motion. */
.uwapp-root.uwapp-sinebloom {
  --sb-bg: var(--canvas); --sb-surface: var(--surface); --sb-surface-2: var(--surface-2); --sb-ink: var(--ink); --sb-muted: var(--muted);
  --sb-line: var(--line); --sb-control: var(--control); --sb-accent: var(--primary); --sb-accent-ink: var(--primary-text); --sb-on-accent: var(--on-accent);
  --sb-focus: var(--focus-color); --sb-danger: var(--danger, #b42318); --sb-info-bg: var(--info-bg); --sb-info-line: var(--info-line);
  --sb-knob-track: #c9d2d6; --sb-knob-fill: var(--primary); --sb-knob-face: var(--surface);
  --sb-white-key: #fbfbf8; --sb-black-key: #1d2428; --sb-key-on: #8fd3c4; --sb-key-on-black: #2f8f7f; --sb-key-line: #6b7a80;
  --sb-scope-bg: #0f1a1f; --sb-scope-grid: #2a3b42; --sb-scope-line: #7ee0c3;
  --sb-pop-shadow: var(--shadow-2); --sb-dlg-shadow: var(--shadow-3);
  background: var(--sb-bg); color: var(--sb-ink); color-scheme: light; font-family: var(--font-sans);
}
:root[data-theme="dark"] .uwapp-root.uwapp-sinebloom {
  --sb-bg: var(--d-canvas); --sb-surface: var(--d-surface); --sb-surface-2: var(--d-surface-2); --sb-ink: var(--d-ink); --sb-muted: var(--d-muted);
  --sb-line: var(--d-line); --sb-control: var(--d-control); --sb-accent: var(--d-primary); --sb-accent-ink: var(--d-focus); --sb-on-accent: var(--d-on-accent);
  --sb-focus: var(--d-focus); --sb-danger: var(--d-danger, #fca5a5); --sb-info-bg: var(--d-info-bg); --sb-info-line: var(--d-info-line);
  --sb-knob-track: #3b4a51; --sb-knob-fill: var(--d-primary); --sb-knob-face: var(--d-surface);
  --sb-white-key: #d9dedf; --sb-key-on: #5fc4b0; --sb-pop-shadow: var(--d-shadow-2); --sb-dlg-shadow: 0 16px 48px rgb(0 0 0 / .55);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .uwapp-root.uwapp-sinebloom {
    --sb-bg: var(--d-canvas); --sb-surface: var(--d-surface); --sb-surface-2: var(--d-surface-2); --sb-ink: var(--d-ink); --sb-muted: var(--d-muted);
    --sb-line: var(--d-line); --sb-control: var(--d-control); --sb-accent: var(--d-primary); --sb-accent-ink: var(--d-focus); --sb-on-accent: var(--d-on-accent);
    --sb-focus: var(--d-focus); --sb-danger: var(--d-danger, #fca5a5); --sb-info-bg: var(--d-info-bg); --sb-info-line: var(--d-info-line);
    --sb-knob-track: #3b4a51; --sb-knob-fill: var(--d-primary); --sb-knob-face: var(--d-surface);
    --sb-white-key: #d9dedf; --sb-key-on: #5fc4b0; --sb-pop-shadow: var(--d-shadow-2); --sb-dlg-shadow: 0 16px 48px rgb(0 0 0 / .55);
    color-scheme: dark;
  }
}

/* platform element defaults leak into workspaces: reset at zero specificity */
:where(.sb-app) button { font: inherit; font-size: .9rem; font-weight: 600; padding: 0; border: 0; border-radius: 8px; background: none; color: inherit; cursor: pointer; width: auto; min-height: 0; }
:where(.sb-app) button:hover { background: none; }
:where(.sb-app, .sb-dialog) :is(input, select, textarea) { font: inherit; font-size: .9rem; color: var(--sb-ink); background: var(--sb-surface); border: 1px solid var(--sb-control); border-radius: 8px; padding: .3rem .45rem; min-height: 32px; box-sizing: border-box; max-width: 100%; }
:where(.sb-app, .sb-dialog) table { border-collapse: collapse; width: 100%; margin: 0; font-size: .9rem; }
:where(.sb-app, .sb-dialog) :is(th, td) { text-align: start; padding: 4px 6px; border-bottom: 1px solid var(--sb-line); vertical-align: middle; }
:where(.sb-app, .sb-dialog) thead th { background: var(--sb-surface-2); color: var(--sb-ink); }
:where(.sb-app, .sb-dialog) kbd { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; padding: 1px 6px; border: 1px solid var(--sb-control); border-bottom-width: 2px; border-radius: 5px; background: var(--sb-surface-2); color: var(--sb-ink); }
:where(.sb-app, .sb-dialog) a { color: var(--sb-accent-ink); }

.sb-app { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; background: var(--sb-bg); color: var(--sb-ink); }
.sb-app :focus-visible, .sb-dialog :focus-visible { outline: 3px solid var(--sb-focus); outline-offset: 2px; }
.sb-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
.sb-hint { color: var(--sb-muted); font-size: .85rem; margin: .2rem 0; }
.sb-error { color: var(--sb-danger); font-weight: 600; font-size: .88rem; margin: .2rem 0; }
.sb-error:empty { display: none; }
.sb-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.sb-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; margin: .4rem 0; }
.sb-badge { margin-inline-start: .4rem; font-size: .75rem; padding: 0 .4rem; border: 1px solid var(--sb-control); border-radius: 999px; color: var(--sb-muted); }

/* buttons */
.sb-btn { display: inline-flex; align-items: center; gap: .35rem; min-height: 34px; padding: .3rem .7rem; border: 1px solid var(--sb-control); border-radius: 8px; background: var(--sb-surface); color: var(--sb-ink); font-size: .88rem; }
.sb-btn:hover:not([disabled]) { background: var(--sb-surface-2); }
.sb-btn[disabled], .sb-icon-btn[disabled] { opacity: .5; cursor: not-allowed; }
.sb-btn-primary { background: var(--sb-accent); border-color: var(--sb-accent); color: var(--sb-on-accent); }
.sb-btn-primary:hover:not([disabled]) { background: var(--sb-accent-ink); border-color: var(--sb-accent-ink); color: var(--sb-on-accent); }
.sb-icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 1px solid transparent; border-radius: 8px; color: var(--sb-ink); }
.sb-icon-btn:hover:not([disabled]) { background: var(--sb-surface-2); border-color: var(--sb-line); }
.sb-audio-btn { display: inline-flex; align-items: center; gap: .4rem; min-height: 36px; padding: .3rem .85rem; border: 2px solid var(--sb-control); border-radius: 999px; background: var(--sb-surface); color: var(--sb-ink); }
.sb-audio-btn.is-on { border-color: var(--sb-accent); background: var(--sb-info-bg); color: var(--sb-accent-ink); }
.sb-rec-btn.is-rec { border-color: var(--sb-danger); color: var(--sb-danger); background: var(--sb-surface-2); }
.sb-sketch-btn.is-playing { background: var(--sb-ink); border-color: var(--sb-ink); color: var(--sb-surface); }
.sb-sound-name { min-height: 34px; padding: .2rem .6rem; border-radius: 8px; font-family: var(--font-display); font-size: 1.05rem; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-sound-name:hover { background: var(--sb-surface-2); }

/* toolbar + menus */
.sb-toolbar { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: .45rem .9rem; padding: .45rem .8rem; background: var(--sb-surface); border-bottom: 1px solid var(--sb-line); }
.sb-tb-group { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; min-width: 0; }
.sb-menu-wrap { position: relative; }
.sb-menu-btn { display: inline-flex; align-items: center; gap: .2rem; min-height: 34px; padding: .3rem .6rem; border-radius: 8px; color: var(--sb-ink); }
.sb-menu-btn:hover, .sb-menu-btn[aria-expanded="true"] { background: var(--sb-surface-2); }
.sb-menu { position: absolute; z-index: 30; inset-inline-start: 0; top: calc(100% + 4px); min-width: 15rem; max-width: min(22rem, 92vw); max-height: 70vh; overflow: auto; padding: .3rem; background: var(--sb-surface); border: 1px solid var(--sb-control); border-radius: var(--r-md); box-shadow: var(--sb-pop-shadow); }
.sb-menu[hidden] { display: none; }
.sb-menu-item { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 1rem; min-height: 32px; padding: .35rem .6rem; border-radius: 6px; text-align: start; font-weight: 500; color: var(--sb-ink); }
.sb-menu-item:hover, .sb-menu-item:focus { background: var(--sb-surface-2); }
.sb-menu-item[aria-disabled="true"] { color: var(--sb-muted); cursor: not-allowed; }
.sb-menu-key { color: var(--sb-muted); font-size: .78rem; font-weight: 600; }
.sb-menu-sep { height: 1px; margin: .3rem .2rem; background: var(--sb-line); }
.sb-audio-note { margin: 0; padding: .35rem .9rem; font-size: .88rem; color: var(--sb-ink); background: var(--sb-surface-2); border-bottom: 1px solid var(--sb-line); }
.sb-audio-note:empty { display: none; }

/* panels */
.sb-main { flex: 1; min-height: 0; overflow: auto; padding: .75rem; }
.sb-panels { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: .75rem; align-items: start; }
.sb-panel { min-width: 0; background: var(--sb-surface); border: 1px solid var(--sb-line); border-radius: var(--r-lg, 12px); padding: .6rem .75rem .75rem; }
.sb-panel-osc, .sb-panel-fx { grid-column: 1 / -1; }
@media (min-width: 760px) { .sb-panel-matrix { grid-column: span 2; } }
.sb-panel-h { margin: 0 0 .4rem; font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; letter-spacing: -.01em; }
.sb-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); gap: .6rem; }
.sb-card { min-width: 0; border: 1px solid var(--sb-line); border-radius: var(--r-md, 10px); padding: .5rem .6rem; }
.sb-card.is-off { background: var(--sb-surface-2); border-style: dashed; }
.sb-card-title { margin: 0 0 .3rem; font-size: .95rem; font-weight: 600; }
.sb-card-head { margin-bottom: .2rem; font-weight: 600; }
.sb-fields { display: flex; flex-wrap: wrap; gap: .4rem .7rem; align-items: end; margin-bottom: .35rem; }
.sb-field { display: flex; flex-direction: column; gap: .15rem; min-width: 0; font-size: .85rem; }
.sb-field label { color: var(--sb-ink); font-weight: 600; }
.sb-field-wide { width: 100%; }
.sb-field-wide textarea { width: 100%; resize: vertical; }
.sb-field-inline { flex-direction: row; align-items: center; gap: .4rem; }
.sb-field-inline input { width: 5.5rem; }
.sb-check { display: inline-flex; align-items: center; gap: .4rem; min-height: 32px; font-size: .9rem; }
.sb-check input { width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--sb-accent); }
.sb-check label { font-weight: 600; }

/* knobs */
.sb-knobs { display: flex; flex-wrap: wrap; gap: .35rem .5rem; }
.sb-knob { display: flex; flex-direction: column; align-items: center; width: 4.6rem; min-width: 0; text-align: center; }
.sb-knob-dial { width: 48px; height: 48px; border-radius: 50%; touch-action: none; cursor: ns-resize; }
.sb-knob-dial[hidden] { display: none; }
.sb-knob-svg { display: block; width: 48px; height: 48px; }
.sb-knob-track, .sb-knob-fill { fill: none; stroke-width: 5; stroke-linecap: round; }
.sb-knob-track { stroke: var(--sb-knob-track); }
.sb-knob-fill { stroke: var(--sb-knob-fill); }
.sb-knob-tick { stroke: var(--sb-ink); stroke-width: 3; stroke-linecap: round; }
.sb-knob-value { font-size: .78rem; font-variant-numeric: tabular-nums; color: var(--sb-ink); white-space: nowrap; }
.sb-knob-label { font-size: .78rem; color: var(--sb-muted); line-height: 1.15; overflow-wrap: anywhere; }
.sb-knob-entry { width: 4.4rem; text-align: center; margin: 7px 0; }

/* matrix */
.sb-table-wrap { position: relative; overflow-x: auto; max-width: 100%; }
.sb-matrix select { max-width: 9.5rem; }
.sb-matrix .sb-knob { width: 4rem; }

/* scope + meters */
.sb-scope { display: block; width: 100%; height: 140px; border-radius: 8px; background: var(--sb-scope-bg); }
.sb-segment { display: inline-flex; border: 1px solid var(--sb-control); border-radius: 999px; padding: 2px; }
.sb-seg { min-height: 30px; padding: .15rem .7rem; border-radius: 999px; color: var(--sb-ink); font-size: .85rem; }
.sb-seg[aria-pressed="true"] { background: var(--sb-info-bg); color: var(--sb-accent-ink); }
.sb-meters { display: flex; flex-wrap: wrap; gap: .3rem 1rem; margin-top: .45rem; font-size: .85rem; font-variant-numeric: tabular-nums; }
.sb-meter { display: inline-flex; align-items: center; gap: .35rem; }
.sb-meter-l { color: var(--sb-muted); }
.sb-meter meter { width: 5rem; }

/* keyboard */
.sb-keysbar { flex: none; display: flex; flex-wrap: wrap; align-items: stretch; gap: .4rem .8rem; padding: .45rem .8rem .6rem; background: var(--sb-surface); border-top: 1px solid var(--sb-line); }
.sb-keys-controls { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.sb-oct-ctl { display: inline-flex; align-items: center; gap: .2rem; }
.sb-oct { font-size: .85rem; min-width: 6.5rem; text-align: center; }
.sb-piano { position: relative; display: flex; flex: 1 1 420px; min-width: 0; height: 120px; user-select: none; touch-action: none; }
.sb-key { position: relative; border: 1px solid var(--sb-key-line); padding: 0; min-height: 0; }
.sb-key-white { flex: 1 1 0; min-width: 0; height: 100%; background: var(--sb-white-key); border-radius: 0 0 6px 6px; color: #1d2428; display: flex; align-items: flex-end; justify-content: center; }
.sb-key-black { position: absolute; top: 0; z-index: 2; width: 1.7rem; max-width: 4.6vw; min-width: 24px; height: 62%; transform: translateX(-50%); background: var(--sb-black-key); border: 1px solid #000; border-radius: 0 0 5px 5px; }
.sb-key-white[aria-pressed="true"] { background: var(--sb-key-on); }
.sb-key-black[aria-pressed="true"] { background: var(--sb-key-on-black); }
.sb-key-name { font-size: .7rem; font-weight: 600; margin-bottom: 4px; pointer-events: none; }
.sb-statusbar { flex: none; min-height: 28px; padding: .25rem .8rem; font-size: .85rem; color: var(--sb-muted); background: var(--sb-surface-2); border-top: 1px solid var(--sb-line); }

/* dialogs */
.sb-dialog { max-width: min(34rem, 94vw); width: 100%; padding: 0; color: var(--sb-ink); background: var(--sb-surface); border: 1px solid var(--sb-line); border-radius: var(--r-lg, 12px); box-shadow: var(--sb-dlg-shadow); }
.sb-dialog-wide { max-width: min(52rem, 96vw); }
.sb-dialog::backdrop { background: var(--overlay, rgb(0 0 0 / .45)); }
.sb-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem .9rem .3rem; }
.sb-dialog-head h2 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 1.2rem; }
.sb-dialog-lede { margin: 0 .9rem .4rem; color: var(--sb-muted); font-size: .9rem; }
.sb-dialog-body { padding: .3rem .9rem .9rem; max-height: 75vh; overflow: auto; }
.sb-dialog-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }
.sb-preset-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr)); gap: .6rem; }
.sb-preset-group h3 { margin: .2rem 0 .3rem; font-size: .95rem; }
.sb-preset-group ul, .sb-recent, .sb-templates { list-style: none; margin: 0; padding: 0; display: grid; gap: .25rem; }
.sb-preset { display: flex; align-items: center; gap: .2rem; }
.sb-preset-load { flex: 1; min-height: 34px; padding: .3rem .55rem; text-align: start; border: 1px solid var(--sb-line); border-radius: 8px; font-weight: 500; }
.sb-preset-load:hover { background: var(--sb-surface-2); }
.sb-preset-load.is-current { background: var(--sb-info-bg); border-color: var(--sb-info-line); color: var(--sb-accent-ink); }
.sb-recent li { display: flex; align-items: center; gap: .3rem; }
.sb-template { display: flex; flex-direction: column; align-items: flex-start; gap: .15rem; width: 100%; padding: .5rem .7rem; text-align: start; border: 1px solid var(--sb-line); border-radius: 8px; }
.sb-template:hover { background: var(--sb-surface-2); }
.sb-template span { font-weight: 400; color: var(--sb-muted); font-size: .88rem; }
.sb-take p { margin: .3rem 0; }

@media (max-width: 640px) {
  .sb-toolbar { padding: .4rem .5rem; gap: .35rem .5rem; }
  .sb-btn, .sb-icon-btn, .sb-menu-btn, .sb-audio-btn { min-height: 44px; }
  .sb-icon-btn { width: 44px; height: 44px; }
  .sb-main { padding: .5rem; }
  .sb-sound-name { max-width: 11rem; }
  .sb-piano { flex-basis: 100%; height: 104px; }
  .sb-keysbar { padding: .4rem .5rem; }
  .sb-knob { width: 4.2rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .sb-btn, .sb-icon-btn, .sb-menu-item, .sb-preset-load { transition: background-color .15s cubic-bezier(.2, .8, .2, 1); }
}
