/* Copyright (c) 2026 Daan Suijkerbuijk / Audiopeek
   SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Peek-MBG-Commercial
   Dual-licensed, with additional GPL terms (attribution, names). See LICENSING.md. */
/* Styled with the Audiopeek Apps design system: the interface as a mixing desk.
   Keys that press down, LEDs that are on or off, numbered panels, tape labels.
   No gradients, glow or soft shadows. Tokens live in tokens.css. */

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-sans); font-size: 15px; line-height: 1.5;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
button, select, input { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------------------------------------------------------- system parts */
.apa-grid { background-color: var(--bg); background-image: radial-gradient(var(--line) 1px, rgba(0,0,0,0) 1.2px); background-size: 16px 16px; background-position: 8px 8px; }
:where(.apa-key, .apa-keyrow__key, .chips button, .select, .fader, .swatches input, .pal, .card):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.apa-led { width: 8px; height: 8px; border-radius: var(--radius-round); flex: none; background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--line); }

/* AppBar: always Deep Signal */
.apa-appbar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); height: 52px; padding: 0 var(--space-4); background: var(--deep-signal); color: var(--studio-white); border-bottom: 1px solid #04161B; }
.apa-appbar__lead, .apa-appbar__trail { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.apa-appbar__title { font-size: 17px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.apa-appbar__sub { font-family: var(--font-mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: #9FB3B6; padding-left: var(--space-3); border-left: 1px solid #2C5159; white-space: nowrap; }
.appbar-peak { flex: none; }
.apa-appbar .apa-key { --line-strong: #04161B; background: #10343E; color: var(--studio-white); box-shadow: 0 2px 0 #04161B; }
.apa-appbar .apa-key:hover { background: #163E49; }

/* Keys */
.apa-key { font-family: var(--font-mono); font-weight: 700; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface-1); color: var(--text); box-shadow: var(--key); display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); cursor: pointer; position: relative; top: 0; transition: top var(--duration-key) linear, box-shadow var(--duration-key) linear, background-color var(--duration-key) linear; white-space: nowrap; }
.apa-key:hover { background: var(--surface-2); }
.apa-key:active { top: 2px; box-shadow: none; }
.apa-key--sm { height: 30px; padding: 0 var(--space-3); font-size: 11px; }
.apa-key--md { height: 38px; padding: 0 var(--space-4); }
.apa-key--block { width: 100%; }
.apa-key--icon-only { padding: 0; aspect-ratio: 1; }
.apa-key--primary { background: var(--accent); color: var(--on-accent); }
.apa-key--primary:hover { background: var(--accent); filter: brightness(1.06); }
.apa-key--tape { background: var(--tape); color: var(--on-accent); }
.apa-key--tape:hover { background: var(--tape); filter: brightness(1.04); }
.apa-key--danger { color: var(--danger); }
.apa-key:disabled { opacity: .4; cursor: not-allowed; top: 2px; box-shadow: none; }

/* Key row (segmented) */
.apa-keyrow { display: inline-flex; border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm); box-shadow: var(--key); overflow: hidden; background: var(--surface-1); flex: none; }
.apa-keyrow__key { display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 var(--space-3); border: 0; border-left: 1px solid var(--line); background: transparent; color: var(--text-muted); font-family: var(--font-mono); font-weight: 700; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; cursor: pointer; white-space: nowrap; }
.apa-keyrow__key:first-child { border-left: 0; }
.apa-keyrow__key:hover { color: var(--text); }
.apa-keyrow__key.is-on { background: var(--surface-3); color: var(--text); }
.apa-keyrow__key.is-on .apa-led { background: var(--accent); box-shadow: none; }

/* Status LED + label */
.apa-status { display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--text-muted); white-space: nowrap; }
.apa-status--accent { color: var(--accent-text); }
.apa-status--accent .apa-led { background: var(--accent); box-shadow: none; }

/* Panels */
.apa-panel { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--panel); display: flex; flex-direction: column; min-width: 0; }
.apa-panel__bar { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-4) 0; min-height: 28px; }
.apa-panel__index { font-family: var(--font-mono); font-size: 11px; font-weight: 700; color: var(--bg); background: var(--text); padding: 3px 5px; border-radius: var(--radius-xs); letter-spacing: .04em; line-height: 1.2; }
.apa-panel__label { font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--text-muted); white-space: nowrap; }
.apa-panel__rule { flex: 1; height: 1px; background: var(--line); min-width: 12px; }
.apa-panel__inner { padding: var(--space-3) var(--space-4) var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); }

/* Collapsible panels: the bar is the summary */
details.apa-panel > summary { list-style: none; cursor: pointer; padding-bottom: var(--space-3); }
details.apa-panel[open] > summary { padding-bottom: 0; }
details.apa-panel > summary::-webkit-details-marker { display: none; }
details.apa-panel > summary::after { content: '+'; font-family: var(--font-mono); font-weight: 700; font-size: 13px; color: var(--text-soft); width: 12px; text-align: center; }
details.apa-panel[open] > summary::after { content: '−'; }

/* Tape tag */
.apa-tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--on-accent); border-radius: var(--radius-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: calc(100% - 16px); }
.apa-tag--tape { background: var(--tape); }
.apa-tag--ch { background: #F4F1E8; border-top: 3px solid var(--ch); box-shadow: inset 0 0 0 1px rgba(11,42,51,.12); }

/* Toast */
.apa-toast { display: flex; align-items: stretch; width: 380px; max-width: calc(100vw - 32px); background: var(--surface-1); border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm); box-shadow: var(--float); overflow: hidden; }
.apa-toast__code { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; padding: 0 8px; font: 700 11px var(--font-mono); letter-spacing: .08em; color: var(--deep-signal); flex: none; background: var(--accent); }
.apa-toast--danger .apa-toast__code { background: var(--led-red); }
.apa-toast__text { flex: 1; padding: var(--space-3) var(--space-4); }
.apa-toast__title { font-size: 15px; font-weight: 600; }

/* ----------------------------------------------------------------- layout */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; height: calc(100% - 52px); }
.stage { padding: var(--space-6); overflow: auto; min-width: 0; display: flex; flex-direction: column; gap: var(--space-6); }
.panel { border-left: 1px solid var(--line); background: var(--bg); overflow-y: auto; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }

/* Preview */
.preview-panel { max-width: 100%; }
.preview-screen { margin: var(--space-3) auto 0; max-width: calc(100% - 32px); background: #000; border: 1px solid var(--line); border-radius: var(--radius-xs); overflow: hidden; }
#preview { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; }
.preview-bar { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4) var(--space-4); }
.preview-bar .fader { flex: 1; }
.history { display: flex; gap: var(--space-2); }
.readout-sm { font-family: var(--font-mono); font-size: 12px; font-variant-numeric: tabular-nums; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-xs); padding: 2px 6px; white-space: nowrap; }

/* Library */
.gallery-panel .apa-panel__bar { flex-wrap: wrap; row-gap: var(--space-2); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: var(--space-3); }
.card { position: relative; display: block; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-xs); overflow: hidden; background: #000; cursor: pointer; text-align: left; }
.card:hover { border-color: var(--line-strong); }
.card img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.card .apa-tag { position: absolute; left: 8px; bottom: 8px; }
.card .del { position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; font-size: 11px; }
.empty { color: var(--text-muted); font-size: 13px; padding: var(--space-2) 0; }

/* Look / finish selectors: latching keys with an LED */
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--space-2); }
.chips button { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 var(--space-2); font-family: var(--font-mono); font-weight: 700; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); background: var(--surface-1); border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm); box-shadow: var(--key); cursor: pointer; position: relative; top: 0; transition: top var(--duration-key) linear, box-shadow var(--duration-key) linear; white-space: nowrap; overflow: hidden; }
.chips button:hover { color: var(--text); background: var(--surface-2); }
.chips button.on { top: 2px; box-shadow: none; background: var(--surface-2); color: var(--text); }
.chips button.on .apa-led { background: var(--accent); box-shadow: none; }

/* Palettes: hard colour blocks, never a gradient */
.palettes { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--space-2); }
.pal { display: flex; height: 22px; padding: 0; border: 1.5px solid var(--line-strong); border-radius: var(--radius-xs); overflow: hidden; cursor: pointer; background: none; }
.pal i { flex: 1; }
.swatches { display: flex; gap: var(--space-2); align-items: center; margin-top: var(--space-1); }
.swatches input[type=color] { width: 34px; height: 30px; padding: 2px; border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface-2); cursor: pointer; }
.swatches .lbl { font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--text-soft); margin-left: var(--space-2); }

/* Sliders = faders */
.ctl { display: grid; grid-template-columns: 112px 1fr 48px; align-items: center; gap: var(--space-2); min-height: 28px; }
.ctl label { font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctl output { font-family: var(--font-mono); font-size: 11px; font-variant-numeric: tabular-nums; text-align: center; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-xs); padding: 1px 2px; }
#ctl-finish { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-2); }

.fader { -webkit-appearance: none; appearance: none; width: 100%; height: 20px; background: transparent; cursor: pointer; margin: 0; }
.fader::-webkit-slider-runnable-track { height: 6px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-xs); }
.fader::-moz-range-track { height: 6px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-xs); }
.fader::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 18px; margin-top: -7px; background: var(--surface-1); border: 1.5px solid var(--line-strong); border-radius: 2px; box-shadow: inset 0 0 0 4px var(--surface-1), inset 0 0 0 6px var(--text); }
.fader::-moz-range-thumb { width: 9px; height: 15px; background: var(--surface-1); border: 1.5px solid var(--line-strong); border-radius: 2px; box-shadow: inset 0 0 0 3px var(--surface-1), inset 0 0 0 5px var(--text); }

/* Export */
.row { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: var(--space-2); }
.row__label { font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.select { width: 100%; min-width: 0; height: 32px; padding: 0 var(--space-2); background: var(--surface-2); border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm); color: var(--text); font-size: 13px; }
.buttons { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); margin-top: var(--space-2); }
.progress { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-2); }
.progress__row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
/* Segmented progress, like a level meter: it fills per segment */
.seg-track { height: 12px; padding: 3px; background: #082028; border-radius: var(--radius-xs); }
.seg-track span { display: block; height: 100%; width: 0; background: repeating-linear-gradient(90deg, var(--bright-cyan) 0 6px, transparent 6px 8px); }
.hint { margin: var(--space-1) 0 0; font-size: 13px; color: var(--text-soft); line-height: 1.45; }

/* Toast position */
.toast { position: fixed; left: 50%; bottom: var(--space-6); transform: translate(-50%, 8px); opacity: 0; pointer-events: none; transition: opacity var(--duration-base) linear, transform var(--duration-base) linear; z-index: 10; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .stage { padding: var(--space-4); }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .apa-appbar__sub { display: none; }
}
@media (max-width: 600px) {
  .preview-bar { flex-wrap: wrap; }
  .preview-bar .fader { flex: 1 1 140px; }
  .history { width: 100%; }
  .history .apa-key { flex: 1; }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card .apa-tag { font-size: 10px; height: 20px; padding: 0 6px; left: 6px; bottom: 6px; }
}
@media (max-width: 480px) {
  .apa-appbar { padding: 0 var(--space-3); gap: var(--space-2); }
  .apa-appbar__title { display: none; }
  .ctl { grid-template-columns: 96px 1fr 44px; }
}

/* ?live: only the background, edge to edge */
body.live { overflow: hidden; background: #000; }
body.live .apa-appbar, body.live .panel, body.live .gallery-panel, body.live .preview-panel > .apa-panel__bar,
body.live .preview-bar, body.live .toast { display: none !important; }
body.live .layout { display: block; height: 100vh; }
body.live .stage { padding: 0; overflow: hidden; background: #000; }
body.live .preview-panel { position: fixed; inset: 0; width: 100vw !important; border: 0; border-radius: 0; background: #000; }
body.live .preview-screen { margin: 0; width: 100vw !important; max-width: none; border: 0; border-radius: 0; }
body.live #preview { width: 100vw; height: 100vh; aspect-ratio: auto !important; }

/* Licence notice at the foot of the controls (GPL "Appropriate Legal Notices") */
.legal { margin: var(--space-2) 0 0; font-size: 11px; line-height: 1.45; color: var(--text-soft); }

/* Shown when the GPU or WebGL2 is not available */
.fatal { margin: 0; padding: var(--space-6); font: 400 15px var(--font-sans); color: var(--studio-white); background: var(--deep-signal); min-height: 100vh; }
