/* EL PIERO MUSIC STUDIO PRO — dark studio theme (dark only by design). */
:root {
  --bg: #070807; --panel: #111413; --panel2: #171b19; --line: #262c29; --line2: #343c38;
  --text: #e9eeeb; --muted: #8f9a95; --neon: #39ff88; --neon-dim: #1f9e57; --neon-glow: rgba(57, 255, 136, .35);
  --silver1: #dfe5e2; --silver2: #8a9590; --danger: #ff4d5e; --warn: #ffb547;
  --radius: 12px; --tap: 44px; --gutter: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; }
body { min-height: 100dvh; overflow-x: hidden; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
h2 { font-size: 1.05rem; margin: 0; letter-spacing: .02em; }
h3 { font-size: .95rem; margin: 18px 0 6px; color: var(--silver1); }
[hidden] { display: none !important; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px var(--gutter); background: linear-gradient(180deg, #151917, #0c0e0d); border-bottom: 1px solid var(--line); }
.chrome { position: sticky; top: 0; z-index: 30; }
.brand { display: flex; align-items: center; gap: 8px; white-space: nowrap; font-size: .9rem; letter-spacing: .08em; }
.brand b { background: linear-gradient(180deg, var(--silver1), var(--silver2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand i { color: var(--neon); font-style: normal; font-weight: 700; text-shadow: 0 0 10px var(--neon-glow); }
.project-name { background: none; border: 1px solid var(--line2); border-radius: 999px; padding: 4px 12px; color: var(--silver1); max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.save-status { margin-left: auto; color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Tabs: top on desktop, bottom on phones */
.tabs { display: flex; gap: 4px; padding: 6px var(--gutter); background: #0c0e0d; border-bottom: 1px solid var(--line); }
.tabs button { display: flex; align-items: center; gap: 8px; background: none; border: 1px solid transparent; border-radius: 10px; padding: 8px 14px; color: var(--muted); cursor: pointer; min-height: var(--tap); }
.tabs svg { width: 20px; height: 20px; }
.tabs button[aria-current="page"] { color: var(--neon); border-color: var(--line2); background: var(--panel2); box-shadow: inset 0 -2px 0 var(--neon); }

/* Transport */
.transport { display: flex; align-items: center; gap: 8px; padding: 8px var(--gutter); background: var(--panel); border-bottom: 1px solid var(--line); }
.tp { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line2); background: radial-gradient(circle at 30% 25%, #2a312d, #121614); color: var(--silver1); display: grid; place-items: center; cursor: pointer; }
.tp svg { width: 22px; height: 22px; }
.tp.play { width: 58px; height: 58px; color: var(--neon); border-color: var(--neon-dim); box-shadow: 0 0 14px var(--neon-glow); }
.tp.on { color: var(--neon); border-color: var(--neon); }
.clock { display: flex; gap: 14px; align-items: baseline; margin-left: 8px; font-variant-numeric: tabular-nums; flex-wrap: wrap; min-width: 0; }
#tp-time { font-size: 1.35rem; font-weight: 600; color: var(--neon); text-shadow: 0 0 8px var(--neon-glow); }
#tp-bar { color: var(--silver1); }
#tp-bpm { color: var(--muted); font-size: .85rem; }

main { padding: 12px var(--gutter) 24px; max-width: 1600px; margin: 0 auto; }
.view { display: block; }

/* Cards & controls */
.card { background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 12px; align-items: start; }
.btn { min-height: var(--tap); padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line2); background: linear-gradient(180deg, #252b28, #191d1b); color: var(--text); cursor: pointer; touch-action: manipulation; }
.btn:hover:not(:disabled) { border-color: var(--silver2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { border-color: var(--neon-dim); color: #04140a; background: linear-gradient(180deg, #5dffa0, #22d06c); font-weight: 600; }
.btn.danger { border-color: #7a2630; color: #ffd6da; background: linear-gradient(180deg, #4a1a20, #2a0f13); }
.btn.ghost { background: transparent; }
.btn.on { border-color: var(--neon); color: var(--neon); box-shadow: 0 0 8px var(--neon-glow) inset; }
.btn.primary.on { color: #04140a; }
.btn.big { font-size: 1.05rem; padding: 10px 18px; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.btn-row.tight { gap: 6px; margin: 4px 0; align-items: center; }
.row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.row.wrap { flex-wrap: wrap; }
.inline { display: inline-flex; align-items: center; gap: 6px; }
.grow { flex: 1; min-width: 0; }
.lbl { color: var(--muted); white-space: nowrap; }
.inp { background: #0b0d0c; border: 1px solid var(--line2); border-radius: 8px; padding: 8px 10px; min-height: 40px; min-width: 0; }
.inp.num { width: 96px; }
.inp:focus, .btn:focus-visible, input[type=range]:focus-visible { outline: 2px solid var(--neon); outline-offset: 1px; }
.muted { color: var(--muted); } .small { font-size: .82rem; }
.empty { color: var(--muted); padding: 16px; border: 1px dashed var(--line2); border-radius: 10px; text-align: center; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line2); font-size: .78rem; margin-right: 4px; color: var(--silver1); }
.tag.neon { border-color: var(--neon-dim); color: var(--neon); }
.tag.warn { border-color: var(--warn); color: var(--warn); }
.tag.pulse { animation: pulse 1s infinite alternate; border-color: var(--neon-dim); color: var(--neon); }
@keyframes pulse { from { opacity: .5; } to { opacity: 1; } }
.neon { color: var(--neon); }
.seg { display: inline-flex; gap: 4px; }
.warnbox { border: 1px solid var(--warn); color: var(--warn); border-radius: 10px; padding: 10px; background: rgba(255, 181, 71, .07); }

/* Sliders */
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 32px; background: transparent; touch-action: pan-y; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: linear-gradient(90deg, #2b332f, #3a433f); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: #333b37; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -9px; border-radius: 50%; border: 2px solid var(--neon); background: radial-gradient(circle at 35% 30%, #f3f6f4, #9aa5a0); box-shadow: 0 0 8px var(--neon-glow); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--neon); background: #cfd6d2; }
.params { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: 4px 16px; }
.param { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.param > span:first-child { display: flex; justify-content: space-between; gap: 6px; color: var(--muted); font-size: .85rem; }
.param b { color: var(--silver1); font-weight: 600; font-variant-numeric: tabular-nums; }
.param.wide { grid-column: 1 / -1; }

/* Switch */
.sw { position: relative; display: inline-block; width: 38px; height: 22px; vertical-align: middle; }
.sw input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.sw span { position: absolute; inset: 0; border-radius: 999px; background: #2a312e; border: 1px solid var(--line2); transition: .15s; }
.sw span::after { content: ''; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--silver2); transition: .15s; }
.sw input:checked + span { background: var(--neon-dim); border-color: var(--neon); }
.sw input:checked + span::after { left: 18px; background: #eafff2; }

/* Library */
#view-library.drag .card:first-child { outline: 2px dashed var(--neon); }
.src-list, .proj-list, .phrases { list-style: none; margin: 0; padding: 0; }
.src { border-top: 1px solid var(--line); padding: 10px 0; }
.src-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.src-name { overflow-wrap: anywhere; }
.proj-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-top: 1px solid var(--line); padding: 8px 0; flex-wrap: wrap; }

/* Editor */
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tool { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 58px; min-height: 52px; padding: 4px 6px; border-radius: 10px; border: 1px solid var(--line2); background: linear-gradient(180deg, #222826, #171b19); cursor: pointer; touch-action: manipulation; }
.tool .ic { font-size: 1.15rem; line-height: 1; }
.tool .tl { font-size: .68rem; color: var(--muted); margin-top: 3px; white-space: nowrap; }
.tool.on { border-color: var(--neon); color: var(--neon); }
.tool.on .tl { color: var(--neon); }
.tool:disabled { opacity: .4; }
.timeline { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #0b0d0c; margin-bottom: 12px; }
.tl-body { display: flex; max-height: 62vh; overflow-y: auto; overscroll-behavior: contain; }
.tl-headers { flex: 0 0 116px; width: 116px; min-width: 0; overflow: hidden; background: #0e1110; border-right: 1px solid var(--line); }
.tl-head { display: flex; flex-direction: column; justify-content: center; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--line); border-left: 4px solid; }
.tl-name { max-width: 100%; background: none; border: none; color: var(--silver1); text-align: left; padding: 0; font-weight: 600; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.tl-ms { display: flex; gap: 6px; }
.ms { width: 36px; height: 30px; border-radius: 7px; border: 1px solid var(--line2); background: #1a1f1d; font-weight: 700; font-size: .8rem; cursor: pointer; }
.ms.on.mute { background: #5a2a14; border-color: var(--warn); color: var(--warn); }
.ms.on.solo { background: #13402a; border-color: var(--neon); color: var(--neon); }
.tl-canvas-wrap { flex: 1; min-width: 0; }
.tl-canvas { display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
.tl-scroll { display: block; border-top: 1px solid var(--line); height: 26px; padding: 0 8px; }
#clip-panel h2 { overflow-wrap: anywhere; }
details.fx { border: 1px solid var(--line); border-radius: 10px; margin: 8px 0; background: #0f1211; }
details.fx > summary { padding: 10px 12px; cursor: pointer; display: flex; align-items: center; gap: 10px; color: var(--silver1); min-height: var(--tap); list-style: none; }
details.fx > summary::-webkit-details-marker { display: none; }
details.fx.active > summary { color: var(--neon); }
details.fx > .params, details.fx > p, details.fx > .btn-row { padding: 0 12px 10px; }
.band { border-top: 1px solid var(--line); padding-top: 4px; }

/* Mixer */
.strips { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; align-items: start; }
.strip { border-top: 3px solid var(--tc, var(--silver2)); }
.strip.master { border-top-color: var(--neon); }
.strip-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.meter { width: 100%; height: 14px; border-radius: 4px; display: block; margin-bottom: 4px; }
.clip-ind { padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line2); color: var(--muted); font-weight: 700; font-size: .75rem; }
.clip-ind.on { background: var(--danger); color: #fff; border-color: var(--danger); }

/* DJ */
.phrases li { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--line); padding: 6px 0; flex-wrap: wrap; }
.btn.tap { min-width: 90px; }
.decks { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.deck { border: 1px solid var(--line2); border-radius: 12px; padding: 10px; background: #0d100f; min-width: 0; }
.deck-head { display: flex; gap: 8px; align-items: center; }
.deck-id { font-size: 1.4rem; color: var(--neon); width: 28px; text-align: center; }
.deck-info { display: flex; gap: 8px; align-items: baseline; margin: 8px 0; font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.big-num { font-size: 1.5rem; font-weight: 700; }
.deck-wave { width: 100%; height: 70px; border-radius: 8px; display: block; background: #0a0c0b; }
.btn.hc { min-width: 44px; }
.btn.hc.on { color: var(--warn); border-color: var(--warn); }
.xf input { height: 40px; }

/* Export */
.filename { font-family: ui-monospace, Menlo, Consolas, monospace; background: #0b0d0c; border: 1px solid var(--line2); padding: 10px; border-radius: 8px; overflow-wrap: anywhere; color: var(--silver1); }
.progress { height: 8px; background: #1b201e; border-radius: 4px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--neon-dim), var(--neon)); transition: width .2s; }
.result { margin-top: 14px; border: 1px solid var(--neon-dim); border-radius: 10px; padding: 12px; }
.result.bad { border-color: var(--danger); }
.kv { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 4px; }
.kv li { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); padding: 4px 0; }

/* Overlays */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 100; width: min(92vw, 520px); pointer-events: none; }
.toast { background: #1b201e; border: 1px solid var(--line2); border-left: 4px solid var(--silver2); border-radius: 10px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .5); transition: opacity .3s; }
.toast.ok { border-left-color: var(--neon); } .toast.error { border-left-color: var(--danger); } .toast.warn { border-left-color: var(--warn); }
.toast.out { opacity: 0; }
.busy { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 90; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid #26302b; border-top-color: var(--neon); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.busy-text { color: var(--silver1); max-width: 80vw; text-align: center; overflow-wrap: anywhere; }
.update-bar { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 110; background: var(--panel2); border: 1px solid var(--neon-dim); border-radius: 12px; padding: 8px 12px; display: flex; gap: 12px; align-items: center; }
dialog.dlg { background: var(--panel2); color: var(--text); border: 1px solid var(--line2); border-radius: 14px; padding: 18px; width: min(92vw, 460px); }
dialog.dlg::backdrop { background: rgba(0, 0, 0, .6); }
dialog.dlg h3 { margin-top: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

/* Phones (portrait): bottom navigation, compact header, transport above the nav */
@media (max-width: 760px) {
  :root { --tap: 46px; }
  .brand span { display: none; }
  .project-name { max-width: 46vw; }
  .tabs { position: fixed; top: auto; bottom: 0; left: 0; right: 0; justify-content: space-around; padding: 4px 4px calc(4px + var(--safe-b)); border-top: 1px solid var(--line); border-bottom: none; z-index: 40; }
  .tabs button { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: .72rem; flex: 1; min-width: 0; }
  .tabs button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .tabs svg { width: 22px; height: 22px; }
  .transport { position: fixed; top: auto; bottom: calc(62px + var(--safe-b)); left: 0; right: 0; border-top: 1px solid var(--line); border-bottom: none; z-index: 39; padding: 6px 12px; }
  .tp { width: 46px; height: 46px; } .tp.play { width: 56px; height: 56px; }
  .clock { gap: 8px; flex-direction: column; align-items: flex-start; } #tp-time { font-size: 1.1rem; } #tp-bpm { display: none; }
  main { padding-bottom: calc(150px + var(--safe-b)); }
  .tl-headers { flex-basis: 84px; width: 84px; }
  .tl-head { padding: 6px 4px 6px 6px; }
  .tl-name { font-size: .78rem; }
  .ms { width: 32px; }
  .tl-body { max-height: 55vh; }
  .decks { grid-template-columns: 1fr; }
  .toasts { bottom: calc(150px + var(--safe-b)); }
  .tool { min-width: 52px; }
  .tool .tl { font-size: .62rem; }
}
/* Phones in landscape: maximise the timeline, side-by-side decks */
@media (max-height: 520px) and (orientation: landscape) {
  .topbar { padding: 4px var(--gutter); }
  .brand span, .save-status { display: none; }
  .tabs { position: fixed; top: auto; bottom: 0; left: 0; right: 0; padding: 2px var(--gutter) calc(2px + var(--safe-b)); justify-content: space-around; z-index: 40; border-top: 1px solid var(--line); }
  .tabs button { padding: 4px 10px; min-height: 40px; }
  .transport { position: fixed; top: auto; bottom: 46px; left: 0; right: 0; padding: 4px var(--gutter); z-index: 39; }
  .tp { width: 40px; height: 40px; } .tp.play { width: 46px; height: 46px; }
  .clock { flex-direction: row; }
  main { padding-bottom: 110px; }
  .tl-body { max-height: calc(100dvh - 210px); }
  .decks { grid-template-columns: 1fr 1fr; }
}
/* Fine pointers (mouse, S Pen hover-capable): slightly denser controls */
@media (pointer: fine) { .tool { min-height: 46px; } }
