:root {
  --bg: #0f0f13;
  --panel: #15151b;
  --card: #1d1d25;
  --card2: #24242e;
  --line: #2a2a34;
  --text: #ececf1;
  --muted: #8e8ea3;
  --a1: #ffb547;
  --a2: #ff5d8f;
  --grad: linear-gradient(90deg, var(--a1), var(--a2));
  --r: 10px;
  --lib-w: 232px;
  --insp-w: 340px;
  --tl-h: clamp(220px, 38vh, 320px);
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, Segoe UI, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: var(--lib-w) minmax(0, 1fr) var(--insp-w);
  grid-template-rows: 56px minmax(0, 1fr) var(--tl-h);
  grid-template-areas: "top top top" "lib stage insp" "tl tl insp";
}
.app.lib-hidden { --lib-w: 0px; }
.app.lib-hidden .library { display: none; }

/* top bar */
.topbar { grid-area: top; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 14px; border-bottom: 1px solid var(--line); background: #121217; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: .2px; }
.proj-btn { display: flex; align-items: center; gap: 6px; background: none; border: 0; font-size: 15px; padding: 6px 10px; border-radius: 8px; max-width: 40vw; }
.proj-btn:hover { background: var(--card); }
.proj-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.btn-grad { background: var(--grad); color: #1d0c12; border: 0; border-radius: 9px; padding: 9px 22px; font-weight: 700; }
.btn-grad:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 0; background: none; color: var(--text); }
.icon-btn:hover { background: var(--card); }
.icon-btn:disabled { opacity: .35; cursor: default; background: none; }
.icon-btn.small { width: 28px; height: 28px; }
.icon-btn.small svg { width: 15px; height: 15px; }

/* library */
.library { grid-area: lib; overflow-x: hidden; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; overflow: auto; }
.lib-head { display: flex; align-items: center; gap: 6px; padding: 12px 10px 10px 14px; font-weight: 600; }
.lib-head > span { flex: 1; }
.chip-btn { display: inline-flex; align-items: center; gap: 5px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.chip-btn svg { width: 14px; height: 14px; }
.chip-btn:hover { border-color: #3a3a46; }
.chip-btn.small { padding: 3px 8px; font-size: 12px; }
.lib-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 14px; }
.lib-item { position: relative; cursor: grab; }
.lib-item .th { aspect-ratio: 16/10; border-radius: 8px; overflow: hidden; background: var(--card); border: 2px solid transparent; position: relative; }
.lib-item .th img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lib-item:hover .th { border-color: var(--line); }
.lib-item .name { font-size: 12px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #cfcfdb; }
.lib-item .play { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.lib-item .play svg { width: 22px; height: 22px; fill: #fff; stroke: none; filter: drop-shadow(0 1px 3px #000); }
.lib-item .del { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.7); color: #fff; display: none; place-items: center; }
.lib-item .del svg { width: 12px; height: 12px; }
.lib-item:hover .del { display: grid; }
.lib-hint { color: var(--muted); font-size: 12px; padding: 4px 14px; margin: 8px 0; line-height: 1.4; }
.lib-audio { margin-top: auto; padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.audio-card { display: block; min-width: 0; overflow: hidden; border-radius: 12px; padding: 10px 12px; background: linear-gradient(135deg, rgba(255,181,71,.12), rgba(255,93,143,.10)); border: 1.5px solid rgba(255,140,90,.55); cursor: pointer; }
.audio-card.vocals { background: var(--card); border: 1px dashed #3a3a46; }
.audio-card.vocals.has { border-style: solid; border-color: rgba(255,140,90,.4); }
.ac-top { display: flex; gap: 10px; align-items: center; }
.ac-icon { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; background: rgba(255,255,255,.07); flex: none; }
.ac-text { flex: 1; min-width: 0; }
.ac-text b { display: block; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-text small { color: var(--muted); font-size: 12px; }
#audioMini { width: 100%; max-width: 100%; height: 34px; display: block; margin-top: 6px; }
.lib-open[hidden] { display: none; }
.lib-open { position: fixed; left: 0; top: 50%; z-index: 5; width: 22px; height: 54px; border: 1px solid var(--line); border-left: 0; border-radius: 0 8px 8px 0; background: var(--panel); display: grid; place-items: center; color: var(--muted); }

/* stage */
.stage { grid-area: stage; display: flex; flex-direction: column; min-height: 0; min-width: 0; position: relative; padding: 8px 16px 6px; }
.stage-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.fmt-toggles { display: flex; gap: 6px; }
.fmt-toggles button { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--muted); }
.fmt-toggles button.on { color: var(--text); border-color: #4a4a56; background: var(--card); }
.switch-label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; }
.switch-label.small { font-size: 12px; }
.switch { appearance: none; width: 34px; height: 20px; border-radius: 999px; background: #3a3a46; position: relative; cursor: pointer; transition: .15s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: .15s; }
.switch:checked { background: var(--a1); }
.switch:checked::after { left: 17px; }
.previews { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; gap: 22px; }
.pv { display: flex; flex-direction: column; gap: 6px; }
.pv-label { font-size: 13px; color: #cfcfdb; }
.pv canvas { display: block; border-radius: 10px; background: #000; box-shadow: 0 8px 30px rgba(0,0,0,.45); cursor: pointer; }
.transport { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding-top: 6px; }
.tp-mid { display: flex; align-items: center; gap: 6px; }
.tp-right { text-align: right; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
.time b { color: var(--text); font-weight: 600; }
.bpm { font-size: 12px; color: var(--muted); }
.play-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: #fff; color: #111; display: grid; place-items: center; margin: 0 6px; }
.play-btn svg { fill: #111; stroke: none; width: 18px; height: 18px; }

/* tap panel */
.tap-panel { position: absolute; left: 16px; right: 16px; bottom: 60px; z-index: 10; background: rgba(20,20,27,.97); border: 1px solid #3a3a46; border-radius: 14px; padding: 14px 16px; display: grid; grid-template-columns: 1fr 200px; grid-template-rows: auto auto; gap: 8px 16px; box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.tap-panel[hidden] { display: none; }
.tap-info small { color: var(--muted); }
.tap-line { font-size: 22px; font-weight: 800; margin: 4px 0; }
.tap-next { color: var(--muted); font-size: 14px; min-height: 1.2em; }
.tap-btn { grid-row: span 2; border: 0; border-radius: 14px; background: var(--grad); color: #1d0c12; font-weight: 900; font-size: 22px; letter-spacing: 3px; user-select: none; touch-action: none; }
.tap-btn.down { filter: brightness(1.25); transform: scale(.98); }
.tap-tools { display: flex; gap: 8px; }
.tap-help { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 12px; }
kbd { background: var(--card2); border: 1px solid #3a3a46; border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 11px; font-family: inherit; }

/* inspector */
.inspector { grid-area: insp; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; gap: 22px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; padding: 14px 0 12px; color: var(--muted); font-size: 15px; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--a1); border-bottom-color: var(--a1); }
.pane { display: none; overflow: auto; flex: 1; min-height: 0; }
.pane.on { display: block; }
.sec { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.sec h4 { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: #cfcfdb; }
.acc { border-bottom: 1px solid var(--line); }
.acc summary { list-style: none; cursor: pointer; padding: 14px 18px; font-size: 15px; display: flex; align-items: center; gap: 10px; }
.acc summary::-webkit-details-marker { display: none; }
.acc summary::before { content: ""; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: .15s; margin: 0 2px; }
.acc[open] summary::before { transform: rotate(45deg); }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0 18px 16px; }
.tiles.small { padding: 0 0 10px; }
.tile { background: var(--card); border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 4px 8px; display: grid; justify-items: center; gap: 6px; font-size: 13px; }
.tile .ico { font-size: 20px; line-height: 24px; height: 24px; font-weight: 900; font-style: italic; color: #d9d9e4; }
.tile:hover { border-color: #3a3a46; }
.tile.on { border-color: var(--a1); box-shadow: 0 0 0 1px var(--a1) inset; background: rgba(255,181,71,.06); }
.tile.on .ico { color: var(--a1); }
.field { display: grid; gap: 6px; margin: 10px 0; }
.field > span { font-size: 12px; color: var(--muted); }
.input, textarea { width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; outline: none; }
.input:focus, textarea:focus { border-color: var(--a1); }
textarea { min-height: 150px; resize: vertical; line-height: 1.45; font-size: 13px; }
.btn { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: 13px; font-weight: 500; }
.btn:hover { border-color: #3a3a46; background: var(--card2); }
.btn.primary { background: var(--grad); color: #1d0c12; border: 0; font-weight: 700; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.wide { width: 100%; }
.btn.danger { color: #ff8a8a; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; line-height: 1.45; }
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { flex: 1; background: none; border: 0; border-radius: 6px; padding: 6px 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.seg button.on { background: #34343f; color: var(--text); }
.seg button:disabled { opacity: .35; cursor: not-allowed; }
.nudge { display: flex; }
.nudge button { width: 30px; background: var(--card2); border: 1px solid var(--line); }
.nudge button:first-child { border-radius: 8px 0 0 8px; }
.nudge button:last-child { border-radius: 0 8px 8px 0; }
.nudge input { width: 100%; min-width: 0; text-align: center; background: var(--card); border: 1px solid var(--line); border-left: 0; border-right: 0; padding: 7px 2px; font-variant-numeric: tabular-nums; outline: none; }
.slider { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; margin: 12px 0; font-size: 14px; }
.slider output { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.slider input { grid-column: 1 / -1; width: 100%; accent-color: var(--a1); }
input[type=range] { accent-color: var(--a1); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--a1); width: 16px; height: 16px; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sw { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; padding: 0; box-shadow: 0 0 0 1px rgba(255,255,255,.12) inset; }
.sw.on { border-color: #fff; }
.sw-custom { position: relative; overflow: hidden; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); }
.sw-custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.clip-name { font-weight: 600; margin-bottom: 10px; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* timeline */
.timeline { grid-area: tl; border-top: 1px solid var(--line); background: #121217; display: grid; grid-template-rows: 34px minmax(0, 1fr) 14px; position: relative; min-width: 0; }
.tl-resize { position: absolute; top: -4px; left: 0; right: 0; height: 8px; cursor: ns-resize; z-index: 3; }
.tl-head { display: grid; grid-template-columns: 150px minmax(0, 1fr); align-items: end; }
.tl-corner { display: flex; align-items: center; gap: 4px; padding: 0 8px 2px 10px; height: 100%; }
.tl-corner .switch-label { margin-left: auto; }
.tl-ruler { height: 30px; min-width: 0; }
.tl-ruler canvas { display: block; height: 30px; cursor: pointer; }
.tl-body { display: grid; grid-template-columns: 150px minmax(0, 1fr); overflow-y: auto; overflow-x: hidden; min-height: 0; }
.tl-labels { padding: 0 8px 0 10px; }
.tl-label { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; background: #18181f; border-radius: 8px; padding: 0 12px; font-size: 14px; color: #d9d9e4; }
.tl-label svg { color: var(--muted); }
.tl-tracks { min-width: 0; padding-right: 10px; }
.tl-tracks canvas { display: block; touch-action: none; }
.tl-foot { display: grid; grid-template-columns: 150px minmax(0, 1fr); align-items: center; padding-right: 10px; }
.tl-hbar { height: 8px; background: #1b1b22; border-radius: 99px; position: relative; cursor: pointer; }
.tl-hbar > div { position: absolute; top: 0; bottom: 0; background: #3c3c48; border-radius: 99px; min-width: 20px; }
.tl-hbar:hover > div { background: #50505e; }

/* dialogs */
.dlg { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(520px, 92vw); }
.dlg::backdrop { background: rgba(0,0,0,.6); }
.dlg h2 { margin: 0 0 12px; font-size: 18px; }
.progress { height: 8px; background: var(--card); border-radius: 99px; overflow: hidden; margin: 14px 0 8px; }
.progress > div { height: 100%; width: 0; background: var(--grad); transition: width .2s; }
.ex-results { display: grid; gap: 6px; margin-top: 10px; }
.ex-results .res { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--card); border-radius: 8px; padding: 8px 12px; font-size: 13px; }
.ex-results a { color: var(--a1); font-weight: 600; text-decoration: none; }
.proj-list { display: grid; gap: 6px; max-height: 50vh; overflow: auto; margin-top: 10px; }
.proj-item { display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 8px; padding: 8px 10px; }
.proj-item.on { outline: 1px solid var(--a1); }
.proj-item .nm { flex: 1; min-width: 0; }
.proj-item .nm b { display: block; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-item .nm small { color: var(--muted); font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px); background: #2b2b38; border: 1px solid #3a3a46; padding: 9px 16px; border-radius: 999px; font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* drop overlay */
body.dragging-file::after { content: "Drop your song, vocals, photos or clips"; position: fixed; inset: 12px; border: 2px dashed var(--a1); border-radius: 16px; display: grid; place-items: center; font-size: 20px; background: rgba(15,15,19,.8); z-index: 60; pointer-events: none; }

@media (max-width: 1180px) { :root { --lib-w: 200px; --insp-w: 310px; } }
@media (max-width: 900px) {
  body::before { content: "SoManyWords is built for a laptop or desktop screen."; position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 100; padding: 30px; text-align: center; font-size: 18px; }
}
