:root {
  --bg: #121110; --panel: #1d1c1a; --edge: #3a3733; --text: #f1ece2; --sub: #a59e90; --accent: #e9a23b; --on-accent: #1a1206; --knob: #0c0c0c; --trim: #7a4a24;
  --safe-l: env(safe-area-inset-left); --safe-r: env(safe-area-inset-right); --safe-t: env(safe-area-inset-top); --safe-b: env(safe-area-inset-bottom);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overscroll-behavior: none; }
body { -webkit-tap-highlight-color: transparent; }
#app { height: 100%; display: flex; padding: var(--safe-t) var(--safe-r) 0 var(--safe-l); }
body.wood #app { border-left: 10px solid var(--trim); border-right: 10px solid var(--trim); }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
h1, h2, h3, h4 { margin: 0; }
small { color: var(--sub); }
a { color: var(--accent); }

/* ---------- common controls ---------- */
.icon { background: none; border: 0; min-width: 40px; height: 40px; font-size: 20px; border-radius: 20px; position: relative; color: var(--text); display: inline-flex; align-items: center; justify-content: center; }
.icon:active { background: color-mix(in srgb, var(--text) 12%, transparent); }
.icon.small { min-width: 28px; height: 28px; font-size: 18px; color: var(--sub); }
.icon.star { font-size: 24px; color: var(--sub); } .icon.star.on { color: var(--accent); }
.ico { width: 24px; height: 24px; display: inline-block; line-height: 0; } .ico.mini { width: 14px; height: 14px; vertical-align: -2px; } .ico.mini svg { width: 14px; height: 14px; }
.badge { position: absolute; top: 2px; right: 0; background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 700; border-radius: 9px; min-width: 18px; height: 18px; line-height: 18px; padding: 0 4px; }
.chip { background: transparent; border: 1px solid color-mix(in srgb, var(--accent) 70%, var(--edge)); border-radius: 8px; height: 34px; padding: 0 12px; white-space: nowrap; color: var(--accent); font-size: 14px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.chip.acc { height: 36px; border-radius: 6px; font-weight: 600; }
button.text { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 8px 10px; border-radius: 8px; white-space: nowrap; }
button.text.small { padding: 4px 8px; font-size: 13px; }
button.text:active { background: color-mix(in srgb, var(--accent) 15%, transparent); }
button.filled { background: var(--accent); color: var(--on-accent); border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); text-align: left; text-decoration: underline; text-underline-offset: 3px; }
.danger { color: #E5484D !important; }
button.filled.danger { background: #D93A3F; color: #fff !important; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); background: color-mix(in srgb, var(--panel) 70%, var(--bg)); border: 1px solid var(--edge); border-radius: 10px; padding: 10px 12px; width: 100%; }
textarea { resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
input[type=range] { padding: 0; accent-color: var(--accent); background: none; border: 0; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
.spacer { flex: 1; }
.hint { color: var(--sub); font-size: 13px; line-height: 1.45; margin: 4px 0; }
.hint.pad { padding: 16px; }
.center { text-align: center; }
.error { color: #E5484D; font-size: 14px; min-height: 1em; margin: 4px 0 0; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--edge); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 8px 12px; min-width: 40px; color: var(--text); }
.seg button.on { background: var(--accent); color: var(--on-accent); font-weight: 700; }

/* ---------- screens ---------- */
.screen { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100%; }
.topbar { display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 10px; min-height: 54px; flex: none; }
.app-logo { line-height: 0; padding-left: 4px; flex: none; }
.app-logo svg { display: block; }
.r-title { font-size: 18px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; padding-left: 4px; color: var(--accent); }
.sync-dot { width: 9px; height: 9px; border-radius: 5px; margin: 0 8px; flex: none; }
.sync-dot.offline { border: 2px solid var(--sub); } .sync-dot.error, .sync-dot.signedout { background: #E5484D; }

/* auth */
.auth { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-box { width: 100%; max-width: 360px; }
.auth-box .logo { margin-bottom: 18px; line-height: 0; font-size: 28px; font-weight: 800; }
.auth-box .logo svg { display: block; max-width: 100%; }
.auth-box h1 { font-size: 20px; margin-bottom: 14px; }
.auth-box form { display: flex; flex-direction: column; gap: 10px; }
.auth-box button.filled { margin-top: 6px; padding: 12px; }
.auth-tabs { display: flex; width: 100%; margin-bottom: 14px; } .auth-tabs button { flex: 1; }
.auth-install { margin-top: 18px; text-align: center; }

/* library */
.lib-head { padding: 0 12px; flex: none; display: flex; flex-direction: column; gap: 8px; }
label.search { display: flex; align-items: center; gap: 10px; border: 1px solid var(--edge); border-radius: 10px; padding: 0 12px; height: 50px; }
label.search .search-ico { color: var(--sub); flex: none; }
label.search input { border: 0; background: transparent; padding: 0; height: 100%; flex: 1; min-width: 0; outline: none; }
label.search:focus-within { border-color: var(--accent); }
.seg.scopes { align-self: flex-start; } .seg.scopes button { padding: 6px 12px; font-size: 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips .chip { flex: 1 1 auto; padding: 0 8px; }
.count { font-size: 12px; color: var(--sub); padding: 0 4px 4px; }
.lib-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 2px 0 calc(80px + var(--safe-b)); }
.lib-list.inline { overflow: visible; padding: 4px 0 0; }
.lib-row { display: flex; align-items: center; gap: 10px; margin: 0 10px 8px; padding: 10px 4px 10px 12px; background: var(--panel); border: 1px solid var(--edge); border-radius: 10px; cursor: pointer; }
.lib-list.inline .lib-row { margin: 0 0 8px; }
.lib-row:active { background: color-mix(in srgb, var(--text) 6%, var(--panel)); }
.lib-row.current { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--panel)); }
.lib-main { flex: 1; min-width: 0; }
.lib-title { font-weight: 700; font-size: 16px; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-sub { font-size: 13px; color: var(--text); opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.lib-meta { font-size: 12px; color: var(--sub); margin-top: 2px; }
.lib-row .star { background: none; border: 0; font-size: 22px; width: 44px; height: 44px; color: var(--sub); flex: none; }
.lib-row .star.on { color: var(--accent); }
.install-banner { display: flex; align-items: center; gap: 8px; margin: 0 12px 10px; padding: 8px 4px 8px 14px; border-radius: 12px; background: color-mix(in srgb, var(--accent) 14%, var(--panel)); border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--edge)); font-size: 14px; line-height: 1.35; flex: none; }
.install-banner span { flex: 1; } .install-banner button.filled { padding: 8px 14px; }

/* two panes on tablets and desktops */
.two-pane { flex: 1; display: flex; min-width: 0; height: 100%; }
.two-pane .left { width: 380px; flex: none; display: flex; border-right: 1px solid var(--edge); }
.two-pane .right { flex: 1; display: flex; min-width: 0; }
.empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--sub); }

/* recipe */
.r-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 14px calc(40px + var(--safe-b)); }
.r-body > section { padding: 14px 0; border-bottom: 1px solid color-mix(in srgb, var(--edge) 60%, transparent); max-width: 900px; margin: 0 auto; }
.r-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--sub); }
.r-sec-head { display: flex; align-items: center; justify-content: space-between; min-height: 30px; margin-bottom: 6px; }
.r-cat { font-weight: 700; color: var(--accent); font-size: 14px; } .r-cat span { color: var(--sub); font-weight: 400; }
.r-summary { font-size: 16px; line-height: 1.5; margin: 8px 0 12px; }
.needs-head { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--sub); margin: 10px 0 6px; }
.needs { display: flex; flex-wrap: wrap; gap: 6px; }
.need { border: 1px solid color-mix(in srgb, var(--accent) 60%, var(--edge)); color: var(--text); border-radius: 999px; padding: 4px 10px; font-size: 13px; background: color-mix(in srgb, var(--accent) 10%, transparent); }
.clip { display: flex; flex-direction: column; gap: 4px; margin: 6px 0 8px; } .clip audio { width: 100%; }
ol.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.step-group { margin-bottom: 12px; }
.step-group h4 { font-size: 14px; color: var(--accent); margin-bottom: 4px; }
.step-group ul { margin: 0; padding-left: 0; list-style: none; }
.step-group ul li { counter-increment: step; position: relative; padding: 4px 0 4px 32px; line-height: 1.5; }
.step-group ul li::before { content: counter(step); position: absolute; left: 0; top: 5px; width: 22px; height: 22px; border-radius: 11px; background: var(--panel); border: 1px solid var(--edge); color: var(--sub); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.songs ul { margin: 6px 0; padding-left: 20px; line-height: 1.7; }
ul.sources { margin: 0; padding-left: 20px; line-height: 1.6; font-size: 14px; }
.edit-note { margin: 10px auto 0; max-width: 900px; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--accent) 14%, var(--panel)); border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--edge)); font-size: 14px; }
.screen.recipe.editing .topbar { background: color-mix(in srgb, var(--accent) 10%, var(--bg)); }
button.filled.save { padding: 8px 16px; margin-right: 4px; }
.song-head { text-align: center; padding: 20px 0 !important; }
.song-title { font-size: 22px; font-weight: 800; } .song-artist { color: var(--sub); font-size: 16px; margin-top: 4px; }
.song .r-body h3 { margin-bottom: 8px; }

/* ---------- synth panel ---------- */
.synth-panel { display: flex; flex-direction: column; gap: 10px; background: var(--panel); border: 1px solid var(--edge); border-radius: 14px; padding: 10px; box-shadow: inset 0 1px 0 color-mix(in srgb, var(--text) 8%, transparent); }
body.wood .synth-panel { border-left: 8px solid var(--trim); border-right: 8px solid var(--trim); }
.p-sec { border-top: 1px solid var(--edge); padding-top: 6px; }
.p-sec:first-child { border-top: 0; padding-top: 0; }
.p-sec-head { display: flex; align-items: center; justify-content: space-between; min-height: 26px; }
.p-sec h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--accent); }
.p-empty { color: var(--sub); font-size: 13px; padding: 4px 0 6px; }
.p-row { display: flex; align-items: flex-start; gap: 6px; padding: 4px 0; }
.p-row + .p-row { border-top: 1px dashed color-mix(in srgb, var(--edge) 70%, transparent); }
.p-row-head { width: 52px; flex: none; display: flex; flex-direction: column; align-items: flex-start; font-size: 11px; font-weight: 700; color: var(--sub); text-transform: uppercase; letter-spacing: .06em; padding-top: 14px; }
.p-ctls { display: flex; flex-wrap: wrap; gap: 4px 6px; flex: 1; min-width: 0; }
.ctl { display: flex; flex-direction: column; align-items: center; min-width: 54px; padding: 2px 0; border-radius: 8px; }
.ctl svg { display: block; }
.ctl-val { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: -2px; white-space: nowrap; }
.ctl-lab { font-size: 10px; color: var(--sub); text-transform: uppercase; letter-spacing: .05em; margin-top: 1px; white-space: nowrap; }
.ctl.off .ctl-val { color: var(--sub); font-weight: 600; }
.ctl.pill { justify-content: flex-start; padding-top: 10px; }
.pill-face { display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 6px; background: color-mix(in srgb, var(--bg) 55%, var(--knob)); border: 1px solid var(--edge); font-size: 13px; font-weight: 700; white-space: nowrap; color: var(--text); }
.ctl.pill.off .pill-face { color: var(--sub); font-weight: 500; }
.pill-face .wave { color: var(--accent); line-height: 0; }
.ctl.pill .ctl-lab { margin-top: 5px; }
.env-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; padding: 4px 0; }
.env-card { border: 1px solid var(--edge); border-radius: 10px; padding: 8px; background: color-mix(in srgb, var(--bg) 35%, transparent); }
.env-head { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 4px; } .env-head b { color: var(--text); }
.env-target { display: flex; gap: 8px; font-size: 12px; flex: 1; justify-content: flex-end; }
.env-graph { line-height: 0; }
.env-vals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; margin-top: 4px; }
.env-val { background: none; border: 0; padding: 2px 0; display: flex; flex-direction: column; align-items: center; color: var(--text); }
.env-val span { font-size: 10px; color: var(--sub); } .env-val b { font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.synth-panel:not(.editing) [data-path], .synth-panel:not(.editing) .env-val, .synth-panel:not(.editing) button.link { cursor: default; pointer-events: none; text-decoration: none; }
.synth-panel:not(.editing) .env-target button.link { color: var(--accent); }
.synth-panel.editing .ctl { cursor: pointer; }
.synth-panel.editing .ctl:hover, .synth-panel.editing .env-val:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.synth-panel.editing .ctl:active { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* settings / admin */
.screen.simple { overflow: hidden; }
.settings { flex: 1; overflow-y: auto; padding: 4px 16px calc(40px + var(--safe-b)); max-width: 760px; width: 100%; margin: 0 auto; }
.settings section { padding: 14px 0; border-bottom: 1px solid color-mix(in srgb, var(--edge) 60%, transparent); display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.settings h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--sub); }
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; width: 100%; }
.theme { border: 2px solid; border-radius: 10px; padding: 10px 10px 10px 16px; text-align: left; font-weight: 600; display: flex; flex-direction: column; gap: 6px; }
.theme.on { outline: 2px solid var(--accent); outline-offset: 1px; }
.sw { display: flex; gap: 3px; } .sw i { width: 18px; height: 10px; border-radius: 2px; display: block; border: 1px solid rgba(127,127,127,.35); }
.kv-row { display: flex; align-items: center; gap: 6px; width: 100%; flex-wrap: wrap; min-height: 44px; }
.kv-row > span { flex: 1; min-width: 160px; }
pre.format { white-space: pre-wrap; font-size: 13px; line-height: 1.45; background: color-mix(in srgb, var(--panel) 70%, var(--bg)); padding: 14px; border-radius: 10px; border: 1px solid var(--edge); user-select: text; }
.actions.left { justify-content: flex-start; margin-top: 0; }
b.code { font-family: ui-monospace, Menlo, monospace; letter-spacing: .03em; user-select: text; }
input.link { font-size: 13px; }

/* menus and dialogs */
.scrim { position: fixed; inset: 0; z-index: 50; }
.popover { position: fixed; z-index: 51; background: var(--panel); color: var(--text); border: 1px solid var(--edge); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.35); min-width: 200px; max-width: calc(100vw - 12px); max-height: 70vh; overflow-y: auto; padding: 6px 0; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 11px 16px; font-size: 15px; color: var(--text); }
.menu-item:active, .menu-item:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.menu-item.bold { font-weight: 800; color: var(--accent); }
.menu-item.on { color: var(--accent); font-weight: 700; }
.popover hr { border: 0; border-top: 1px solid var(--edge); margin: 4px 0; }
.choice-list, .send-list { display: flex; flex-direction: column; max-height: 60vh; overflow-y: auto; margin: 0 -18px; }
.dialog-wrap { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog { background: var(--panel); color: var(--text); border-radius: 16px; padding: 18px; width: 100%; max-width: 440px; max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 16px 40px rgba(0,0,0,.4); }
.dialog.wide { max-width: 620px; }
.dialog h2 { font-size: 18px; margin-bottom: 12px; }
.dialog p { line-height: 1.45; }
.form { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--sub); }
.actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 14px; flex-wrap: wrap; }
.send-list .kv-row { padding: 0 18px; }
#toast { position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translate(-50%, 160%); transition: transform .2s; z-index: 70; background: #222; color: #fff; padding: 10px 14px; border-radius: 10px; display: flex; gap: 10px; align-items: center; max-width: calc(100vw - 24px); box-shadow: 0 6px 20px rgba(0,0,0,.35); font-size: 14px; }
#toast.show { transform: translate(-50%, 0); }
#toast button.text { color: #FFB27A; }
.install-steps ol { padding-left: 22px; line-height: 1.55; margin: 0 0 10px; }
.install-steps li { margin-bottom: 6px; }
.share-icon { width: 20px; height: 20px; vertical-align: -4px; color: #3B82F6; }

@media (max-width: 420px) {
  .p-row { flex-direction: column; gap: 0; }
  .p-row-head { flex-direction: row; width: 100%; padding-top: 2px; justify-content: space-between; }
  .ctl { min-width: 50px; }
}
@media (max-width: 520px) {
  body.wood .synth-panel { border-left-width: 1px; border-right-width: 1px; }
  .r-body { padding-left: 10px; padding-right: 10px; }
  .synth-panel { padding: 8px; }
}
