/* Tonic — application layout: top bar, side panels, stage, keyboard dock. */

.app {
  --lw: 296px; --rw: 332px; --dock: 112px;
  position: fixed; inset: 0; display: grid; grid-template-columns: var(--lw) minmax(0, 1fr) var(--rw); grid-template-rows: auto minmax(0, 1fr) var(--dock);
  grid-template-areas: "top top top" "left stage right" "dock dock dock"; background: var(--bg);
  transition: grid-template-columns .38s var(--ease-out), grid-template-rows .38s var(--ease-out);
}
.app.no-left { --lw: 0px; } .app.no-right { --rw: 0px; } .app.no-dock { --dock: 0px; }
.app.booting { opacity: 0; } .app { opacity: 1; transition: opacity .5s, grid-template-columns .38s var(--ease-out), grid-template-rows .38s var(--ease-out); }

/* ─────────── top bar ─────────── */
.topbar {
  grid-area: top; display: flex; flex-wrap: wrap; align-items: center; gap: 0 6px; padding: 0 12px 0 10px; min-height: var(--topbar); background: var(--panel); border-bottom: 1px solid var(--line); position: relative; z-index: 30; min-width: 0;
}
.tb-group { display: flex; align-items: center; gap: 4px; flex: none; }
.tb-sep { width: 1px; height: 24px; background: var(--line); margin: 0 6px; flex: none; }
.tb-spacer { flex: 1 1 0; min-width: 8px; }
.brand { display: flex; align-items: center; gap: 9px; padding: 4px 8px 4px 4px; border-radius: 10px; transition: background .16s; flex: none; }
.brand:hover { background: var(--panel-3); }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: #fff; background: linear-gradient(145deg, var(--accent-hi), var(--accent-lo)); box-shadow: 0 6px 14px -5px var(--accent), inset 0 1px 0 rgba(255, 255, 255, .3); }
.brand-name { font: italic 400 24px/1 var(--serif); letter-spacing: -.02em; }
.brand-back { color: var(--muted); display: grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; margin-right: -3px; transition: color .16s, transform .2s var(--ease-out); }
.brand:hover .brand-back { color: var(--accent); transform: translateX(-2px); }

.proj { display: flex; flex-direction: column; justify-content: center; min-width: 0; max-width: 220px; padding: 3px 10px; border-radius: 9px; text-align: left; transition: background .16s; flex: 0 1 auto; }
.proj:hover { background: var(--panel-3); }
.proj-name { font-weight: 800; font-size: 13px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.25; }
.proj-sub { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); font-weight: 600; line-height: 1.25; white-space: nowrap; }
.save-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); transition: background .3s, transform .3s; flex: none; }
.save-dot.saving { background: var(--warn); transform: scale(.8); } .save-dot.error { background: var(--bad); }
.proj-input { font: 800 13px/1.25 var(--sans); letter-spacing: -.01em; background: var(--panel-3); border: 1px solid var(--accent); box-shadow: var(--ring); border-radius: 7px; padding: 2px 8px; width: 190px; }

.pill-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 11px 0 12px; border-radius: 10px; background: var(--panel-3); font-weight: 800; font-size: 13px; letter-spacing: -.01em;
  transition: background .16s, box-shadow .16s; white-space: nowrap; flex: none;
}
.pill-btn:hover { background: var(--accent-ghost); } .pill-btn[aria-expanded="true"] { background: var(--accent-ghost); box-shadow: inset 0 0 0 1px var(--accent-soft); }
.pill-btn .sub { font-weight: 600; color: var(--muted); font-size: 11.5px; }
.pill-btn .ico { color: var(--muted); }
.pill-btn .pill-ico { color: var(--accent); }

.tempo { display: inline-flex; align-items: center; height: 36px; border-radius: 10px; background: var(--panel-3); padding: 0 3px; flex: none; }
.tempo .icon-btn { width: 26px; height: 28px; }
.tempo-val { min-width: 60px; text-align: center; cursor: ns-resize; user-select: none; touch-action: none; padding: 0 2px; line-height: 1; }
.tempo-val b { display: block; font: 500 15px/1 var(--mono); letter-spacing: -.02em; }
.tempo-val small { display: block; margin-top: 2px; font: 700 8.5px/1 var(--sans); letter-spacing: .12em; color: var(--muted); }
.tempo-input { width: 54px; font: 500 15px/1 var(--mono); text-align: center; background: var(--panel); border: 1px solid var(--accent); border-radius: 6px; padding: 3px 0; box-shadow: var(--ring); }
.tap { height: 28px; padding: 0 9px; border-radius: 7px; font: 800 10.5px/1 var(--sans); letter-spacing: .08em; color: var(--muted); transition: background .1s, color .1s, transform .1s; }
.tap:hover { background: var(--accent-ghost); color: var(--accent); } .tap.hit { background: var(--accent); color: var(--accent-ink); transform: scale(.94); }

/* transport */
.transport { display: flex; align-items: center; gap: 4px; padding: 4px; border-radius: 14px; background: var(--panel-3); flex: none; }
.t-btn { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: var(--ink-2); transition: background .16s, color .16s, transform .16s var(--ease-out); }
.t-btn:hover { background: var(--panel); color: var(--ink); box-shadow: var(--shadow-xs); } .t-btn:active { transform: scale(.9); }
.t-btn.on { color: var(--accent); background: var(--panel); box-shadow: var(--shadow-xs), inset 0 0 0 1px var(--accent-soft); }
.t-btn.rec.on { color: #fff; background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 25%, transparent); animation: rec-pulse 1.4s infinite; }
@keyframes rec-pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--bad) 8%, transparent); } }
.t-play { width: 44px; height: 38px; border-radius: 11px; background: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 0 rgba(255, 255, 255, .3) inset, 0 8px 18px -6px var(--accent); }
.t-play:hover { background: var(--accent-hi); color: var(--accent-ink); box-shadow: 0 1px 0 rgba(255, 255, 255, .3) inset, 0 10px 22px -6px var(--accent); }
.t-play .ico { transition: transform .3s var(--ease-spring); } .t-play:active .ico { transform: scale(.8); }
.readout { min-width: 98px; padding: 0 10px; text-align: center; line-height: 1; cursor: pointer; border-radius: 9px; align-self: stretch; display: grid; align-content: center; gap: 3px; }
.readout:hover { background: var(--panel); }
.readout b { font: 500 16px/1 var(--mono); letter-spacing: -.02em; }
.readout small { font: 500 10px/1 var(--mono); color: var(--muted); letter-spacing: .02em; }
.cnt { position: absolute; }

/* ─────────── side panels ─────────── */
.side { position: relative; background: var(--panel); min-width: 0; overflow: hidden; display: flex; flex-direction: column; border-color: var(--line); }
.side.left { grid-area: left; border-right: 1px solid var(--line); }
.side.right { grid-area: right; border-left: 1px solid var(--line); }
.side > .inner { display: flex; flex-direction: column; width: var(--lw); height: 100%; min-height: 0; }
.side.right > .inner { width: var(--rw); }
.tabs { display: flex; gap: 2px; padding: 8px 10px 0; border-bottom: 1px solid var(--line); flex: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: 1; height: 36px; padding: 0 8px; font-weight: 700; font-size: 12px; color: var(--muted);
  border-radius: 8px 8px 0 0; transition: color .16s, background .16s; white-space: nowrap;
}
.tab:hover { color: var(--ink); background: var(--panel-3); }
.tab[aria-selected="true"] { color: var(--accent); }
.tab::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent); transform: scaleX(0); transition: transform .3s var(--ease-out); }
.tab[aria-selected="true"]::after { transform: scaleX(1); }
.tab .count { font: 700 10px/1 var(--mono); background: var(--accent); color: var(--accent-ink); padding: 2px 5px; border-radius: 99px; }
.pane { flex: 1; min-height: 0; overflow: auto; padding: 14px 14px 22px; display: none; }
.pane.on { display: block; animation: pane-in .34s var(--ease-out); }
@keyframes pane-in { from { opacity: 0; transform: translateY(6px); } }
.sec { margin-bottom: 20px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 9px; min-height: 22px; }
.sec-head .label { display: flex; align-items: center; gap: 6px; }
.sec-head .note { font-size: 11px; color: var(--muted); font-weight: 600; }

/* ─────────── stage (timeline + roll) ─────────── */
.stage { grid-area: stage; position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); overflow: hidden; }
.splitter { height: 9px; margin: -4px 0; position: relative; z-index: 6; cursor: row-resize; flex: none; }
.splitter::after { content: ""; position: absolute; left: 0; right: 0; top: 4px; height: 1px; background: var(--line-2); transition: background .16s, height .16s, top .16s; }
.splitter:hover::after, .splitter.drag::after { background: var(--accent); height: 3px; top: 3px; }

/* ─────────── dock ─────────── */
.dock { grid-area: dock; position: relative; background: var(--panel); border-top: 1px solid var(--line); overflow: hidden; z-index: 20; }
.dock-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 38px; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0; border-right: 1px solid var(--line); background: var(--panel-2); z-index: 2; }
.dock canvas { position: absolute; left: 38px; top: 0; right: 0; bottom: 0; width: calc(100% - 38px); height: 100%; cursor: pointer; touch-action: none; }
.dock-bar .dk-oct { font: 500 12px/1 var(--mono); color: var(--muted); }
.dock-hint { position: absolute; right: 14px; top: 8px; display: flex; gap: 6px; align-items: center; pointer-events: none; font-size: 11px; color: var(--muted); font-weight: 600; opacity: .9; z-index: 2; }
.dock-hint .kpill { background: color-mix(in srgb, var(--panel) 82%, transparent); backdrop-filter: blur(4px); padding: 4px 9px; border-radius: 99px; box-shadow: 0 0 0 1px var(--line); }

/* ─────────── responsive ─────────── */
@media (max-width: 1560px) { .tb-wide { display: none !important; } }                 /* import · share · theme live in the ⋯ menu */
@media (max-width: 1400px) { .tb-w2 { display: none !important; } }                   /* projects too (⋯ menu, ⌘O) */
@media (max-width: 1360px) { .app { --rw: 312px; --lw: 276px; } }
@media (max-width: 1320px) { .brand-name, .tempo .tap { display: none !important; } }
@media (max-width: 1180px) {
  .app { --lw: 0px; }
  .side.left { position: fixed; left: 0; top: var(--tbh, var(--topbar)); bottom: var(--dock); width: 296px; z-index: 40; box-shadow: var(--shadow-lg); transform: translateX(-102%); transition: transform .4s var(--ease-out); }
  .side.left > .inner { width: 296px; }
  .app.open-left .side.left { transform: none; }
}
@media (max-width: 1260px) {
  /* key / tempo / metre drop to their own centred row instead of vanishing */
  .tb-group.tb-mid { order: 10; flex: 1 1 100%; justify-content: center; padding: 2px 0 9px; }
  .tb-sep.tb-mid { display: none; }
}
@media (max-width: 920px) {
  .app { --rw: 0px; --dock: 0px; }
  .side.right { position: fixed; right: 0; top: var(--tbh, var(--topbar)); bottom: 0; width: min(92vw, 352px); z-index: 40; box-shadow: var(--shadow-lg); transform: translateX(102%); transition: transform .4s var(--ease-out); }
  .side.right > .inner { width: min(92vw, 352px); }
  .app.open-right .side.right { transform: none; }
  .dock { display: none; }
  .brand-name, .proj-sub, .tb-narrow-hide { display: none !important; }
  .readout { min-width: 76px; }
}
@media (max-width: 640px) {
  .topbar { padding: 0 6px; }
  .topbar .tb-spacer { display: none; }
  .topbar .proj { flex: 1 1 0; max-width: none; }
  .transport { order: 9; flex: 1 1 100%; justify-content: center; margin: 2px 0 4px; }
  .tempo .tap, .tb-phone-hide { display: none !important; }
  .tb-group.tb-mid { justify-content: space-between; }
  .tb-group.tb-mid .pill-btn { padding: 0 9px; }
}
.scrim { position: fixed; inset: var(--tbh, var(--topbar)) 0 0; z-index: 35; background: rgba(14, 16, 40, .35); backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity .3s; }
.app.open-left .scrim, .app.open-right .scrim { opacity: 1; pointer-events: auto; }
