/* Light, airy editorial theme: cool grey paper, column rules, oversized light type, frosted pills */
:root {
  --bg: #e4e6e7;
  --ink: #0c0d0d;
  --slate: #73848c;
  --slate-2: #61686b;
  --mist: rgba(199, 206, 209, .5);
  --glass: rgba(255, 255, 255, .5);
  --glass-2: rgba(255, 255, 255, .72);
  --hair: rgba(12, 13, 13, .08);
  --hair-2: rgba(12, 13, 13, .14);
  --shadow: 0 1px 2px rgba(12, 13, 13, .04), 0 8px 24px rgba(12, 13, 13, .06);
  --font: "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 22px;
  --surface: #fff;
  --on-ink: #fff;
  --field: rgba(255, 255, 255, .7);
  --glass-border: rgba(255, 255, 255, .75);
  --panel-soft: rgba(255, 255, 255, .55);
  --thead: rgba(244, 245, 246, .95);
  --row-sel: rgba(255, 255, 255, .9);
  --blob-opacity: .6;
  color-scheme: light;
}
/* dark theme: same structure, inverted tokens */
:root[data-theme="dark"] {
  --bg: #0e1011;
  --ink: #eef1f2;
  --slate: #8d9ba2;
  --slate-2: #a9b3b8;
  --mist: rgba(255, 255, 255, .06);
  --glass: rgba(22, 25, 27, .58);
  --glass-2: rgba(30, 34, 37, .82);
  --hair: rgba(255, 255, 255, .08);
  --hair-2: rgba(255, 255, 255, .16);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 10px 30px rgba(0, 0, 0, .35);
  --surface: #2a2f32;
  --on-ink: #0c0d0d;
  --field: rgba(255, 255, 255, .06);
  --glass-border: rgba(255, 255, 255, .08);
  --panel-soft: rgba(0, 0, 0, .25);
  --thead: rgba(26, 29, 31, .97);
  --row-sel: rgba(255, 255, 255, .07);
  --blob-opacity: .42;
  color-scheme: dark;
}
html { background: var(--bg); }
body, .card, .modes, .panel-toggle, select, input, button, pre#output, .table-wrap, thead th, fieldset, .graph-wrap {
  transition-property: background-color, border-color, color, box-shadow, opacity, transform, padding;
  transition-duration: .35s; }
* { box-sizing: border-box; }
html, body { margin: 0; color: var(--ink); font: 300 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
body {
  min-height: 100vh;
  background-color: var(--bg);
  /* soft vertical column rules */
}
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- animated background: flat grey with soft blurred lights drifting behind ---------- */
.bg-fx { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
/* saturated warm lights glowing along the bottom edge, as on the reference site */
.blob { position: absolute; display: block; width: max(35vw, 260px); height: max(35vh, 240px); border-radius: 50%;
  filter: blur(100px); opacity: var(--blob-opacity); will-change: transform;
  animation: drift var(--dur, 30s) ease-in-out var(--delay, 0s) infinite alternate; }
.b1 { --dur: 26s; --delay: -3s;  background: #fca162; left: -15vw; top: 80vh; }
.b2 { --dur: 31s; --delay: -12s; background: #ff7d9b; left: 10vw;  top: 84vh; }
.b3 { --dur: 23s; --delay: -7s;  background: #c8edff; left: 50vw;  top: 76vh; }
.b4 { --dur: 35s; --delay: -18s; background: #fa9c52; left: 70vw;  top: 82vh; }
.b5 { --dur: 28s; --delay: -9s;  background: #ed836a; left: 97vw;  top: 80vh; margin-left: -20vw; }
@keyframes drift {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  25%  { transform: translate3d(14vw, -10vh, 0) scale(1.15); }
  50%  { transform: translate3d(-8vw, -22vh, 0) scale(.95); }
  75%  { transform: translate3d(10vw, -6vh, 0) scale(1.2); }
  100% { transform: translate3d(-12vw, -14vh, 0) scale(1.05); }
}
@media (prefers-reduced-motion: reduce) { .blob { animation: none; } }

/* oversized background lettering */
.backdrop { position: fixed; inset: 0; z-index: 0; pointer-events: none; display: flex; flex-direction: column;
  justify-content: space-between; padding: 12vh 1vw 10vh; overflow: hidden; }
.backdrop span { font-weight: 200; font-size: clamp(64px, 13.5vw, 240px); line-height: .85; letter-spacing: -.03em;
  color: rgba(255, 255, 255, .78); white-space: nowrap; text-shadow: 0 0 40px rgba(255, 255, 255, .4); }
.backdrop span:nth-child(2) { align-self: flex-end; }

/* header */
.top { position: relative; z-index: 2; display: flex; align-items: center; gap: 24px; padding: 22px 28px 10px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 400; font-size: 12.5px; line-height: 1.15; }
.logo { font-size: 34px; font-weight: 200; line-height: 1; color: var(--ink); width: auto; height: auto; background: none; }
.top-right { margin-left: auto; display: flex; gap: 18px; color: var(--slate-2); font-size: 13px; }
.top-right label { display: flex; align-items: center; gap: 8px; }

/* mode switch: floating pill bar, bottom centre */
.modes { position: fixed; z-index: 20; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; gap: 4px;
  padding: 5px; border-radius: 999px; background: var(--glass); backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2); box-shadow: var(--shadow); border: 1px solid var(--glass-border); }
.modes button { border: 0; background: transparent; padding: 9px 20px; border-radius: 999px; cursor: pointer; color: var(--slate-2); font-weight: 400; }
.modes button { white-space: nowrap; }
@media (max-width: 600px) { .modes button { padding: 8px 13px; font-size: 13px; } }
.modes button:hover { color: var(--ink); }
.modes button.active { background: var(--surface); color: var(--ink); box-shadow: 0 2px 8px rgba(12, 13, 13, .08); }

/* form controls */
select, input[type=number] { background-color: var(--field); border: 1px solid var(--hair); border-radius: 999px; padding: 5px 10px; outline: none; }
select { -webkit-appearance: none; -moz-appearance: none; appearance: none; padding: 5px 30px 5px 12px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2373848c' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 10px 6px; }
select:focus, input[type=number]:focus { border-color: var(--slate); background-color: var(--surface); }
input[type=number] { width: 100%; font-family: var(--mono); font-size: 12px; border-radius: 10px; padding: 4px 7px; }
input[type=checkbox] { accent-color: var(--ink); }
input[type=range] { accent-color: var(--ink); }

button.primary, .btn.primary { background: var(--ink); color: var(--on-ink); border: 0; border-radius: 999px; padding: 9px 20px;
  font-weight: 400; cursor: pointer; box-shadow: 0 2px 10px rgba(12, 13, 13, .15); transition: transform .15s, opacity .15s; }
button.primary:hover, .btn.primary:hover { transform: translateY(-1px); }
button.primary:disabled { opacity: .25; cursor: default; transform: none; }
button.ghost, .btn.ghost { background: var(--surface); border: 0; border-radius: 999px; padding: 8px 18px; cursor: pointer; color: var(--ink);
  font-weight: 400; box-shadow: 0 1px 2px rgba(12, 13, 13, .05), 0 4px 14px rgba(12, 13, 13, .06); transition: box-shadow .15s; }
button.ghost:hover, .btn.ghost:hover { box-shadow: 0 1px 2px rgba(12, 13, 13, .08), 0 8px 22px rgba(12, 13, 13, .1); }
button.ghost.on { background: var(--ink); color: var(--on-ink); }

/* layout */
.layout { position: relative; z-index: 1; display: grid; grid-template-columns: minmax(0, 1fr) 590px; gap: 20px; padding: 12px 28px 110px; }
@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }
@media (max-width: 600px) { .layout { padding: 10px 16px 110px; } .top { padding: 18px 16px 8px; } }
.left, .right { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.card { background: var(--glass); backdrop-filter: blur(18px) saturate(1.15); -webkit-backdrop-filter: blur(18px) saturate(1.15);
  border: 1px solid var(--glass-border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
h2 { margin: 0; font-size: 26px; font-weight: 300; letter-spacing: -.01em; display: flex; align-items: baseline; gap: 10px; }
.pill { font-size: 13px; font-weight: 400; color: var(--slate); background: none; border: 0; padding: 0; }
.muted { color: var(--slate); }
.small { font-size: 12px; margin: 8px 0 0; }

/* graph */
.graph-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.hint { color: var(--slate-2); font-size: 13px; max-width: 560px; }
.stats { font-size: 12px; color: var(--slate); display: flex; gap: 18px; flex-wrap: wrap; }
.stats b { color: var(--ink); font-weight: 400; font-family: var(--mono); font-size: 12px; margin-left: 4px; }
.graph-wrap { position: relative; height: 460px; border-radius: 16px; overflow: hidden; background: var(--panel-soft);
  border: 1px solid var(--glass-border); }
@media (max-width: 700px) { .graph-wrap { height: 320px; } }
#graph { width: 100%; height: 100%; display: block; touch-action: none; }
.toolbar { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; align-items: center; }
.tb-group { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tb-group.right { margin-left: auto; gap: 16px; }
.check { display: inline-flex; gap: 7px; align-items: center; color: var(--slate-2); cursor: pointer; user-select: none; }

/* image */
.img-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.btn.file { position: relative; overflow: hidden; display: inline-block; }
.btn.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.img-stage { position: relative; min-height: 240px; border-radius: 16px; overflow: hidden; background: var(--panel-soft);
  border: 1px dashed var(--hair-2); display: grid; place-items: center; }
.img-stage.drag { border-color: var(--ink); background: var(--field); }
#imgCanvas { display: block; max-width: 100%; touch-action: none; }
.drop-msg { position: absolute; color: var(--slate); pointer-events: none; font-size: 22px; font-weight: 200; }
.img-controls { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 14px; margin-top: 14px; }
@media (max-width: 900px) { .img-controls { grid-template-columns: 1fr; } }
fieldset { border: 0; border-radius: 16px; padding: 14px 16px 16px; margin: 0; min-width: 0; background: var(--panel-soft); }
legend { float: left; width: 100%; padding: 0; margin-bottom: 4px; font-weight: 400; font-size: 15px; }
legend b { font-weight: 200; font-size: 28px; margin-right: 8px; color: var(--slate); vertical-align: -3px; }
fieldset > *:not(legend) { clear: both; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.grid4 label { font-size: 12px; color: var(--slate); display: flex; flex-direction: column; gap: 4px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 2px 8px rgba(12, 13, 13, .12); background: #ff3b3b; }
.slider { display: flex; align-items: center; gap: 10px; color: var(--slate-2); }
.slider input { flex: 1; }
.slider span { font-family: var(--mono); font-size: 12px; min-width: 24px; text-align: right; color: var(--ink); }

/* filters */
.fit-row { display: flex; gap: 16px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.fit-row .slider { flex: 1; min-width: 200px; }
.fit-row label { color: var(--slate-2); display: flex; gap: 8px; align-items: center; }
.table-wrap { max-height: 430px; overflow: auto; border-radius: 14px; background: var(--panel-soft); }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
thead th { position: sticky; top: 0; background: var(--thead); color: var(--slate); font-weight: 400; text-align: left; padding: 9px 6px; z-index: 1; font-size: 11.5px; }
tbody td { padding: 4px 4px; border-top: 1px solid var(--hair); }
tbody tr { transition: background .15s; }
tbody tr.sel { background: var(--row-sel); }
tbody tr.off { opacity: .4; }
td select { width: 100%; padding: 3px 22px 3px 8px; font-size: 12px; border-radius: 10px; background-position: right 8px center; }
td .resolved { font-size: 10.5px; color: var(--slate); padding-left: 6px; }
td.num { width: 80px; }
td.dot { width: 26px; text-align: center; }
.dotc { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; color: #fff; font-weight: 500; font-size: 10px; }
td .del { background: none; border: 0; color: var(--slate); cursor: pointer; font-size: 18px; font-weight: 200; padding: 0 4px; }
td .del:hover { color: var(--ink); }
input:disabled { opacity: .3; }

/* output */
.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--mist); }
.tabs button { border: 0; background: transparent; padding: 7px 16px; border-radius: 999px; color: var(--slate-2); cursor: pointer; font-weight: 400; }
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: 0 2px 8px rgba(12, 13, 13, .08); }
.out-opts { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; color: var(--slate-2); }
.out-opts label { display: flex; gap: 8px; align-items: center; }
.out-opts select { max-width: 290px; }
pre#output { margin: 0; background: var(--panel-soft); border-radius: 14px; padding: 14px 16px; font-family: var(--mono);
  font-size: 11.5px; line-height: 1.65; max-height: 340px; overflow: auto; white-space: pre; color: var(--ink); }
.out-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.out-actions .muted { margin: 0 auto 0 0; }

.toast { position: fixed; z-index: 30; bottom: 84px; left: 50%; transform: translateX(-50%) translateY(10px); background: var(--ink); color: var(--on-ink);
  padding: 9px 18px; border-radius: 999px; opacity: 0; transition: .25s; pointer-events: none; font-weight: 400; }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- collapsible side panels ---------- */
.layout { transition: grid-template-columns .5s cubic-bezier(.4, 0, .2, 1), column-gap .5s cubic-bezier(.4, 0, .2, 1); }
.layout > .right { transition: opacity .35s ease, transform .5s cubic-bezier(.4, 0, .2, 1); }
.layout.collapsed { grid-template-columns: minmax(0, 1fr) 0px; column-gap: 0; }
.layout.collapsed > .right { opacity: 0; transform: translateX(60px); pointer-events: none; overflow: hidden; visibility: hidden;
  max-height: 0; align-self: start; /* hidden column must not keep its height, or the page scrolls into empty space */
  transition: opacity .3s ease, transform .5s cubic-bezier(.4, 0, .2, 1), visibility 0s linear .5s, max-height 0s linear .5s; }
.graph-wrap { transition: height .5s cubic-bezier(.4, 0, .2, 1); }
.layout.collapsed .graph-wrap { height: max(300px, calc(100vh - 350px)); } /* 350 = header + card chrome + fixed mode bar + 28px gap */
@media (max-width: 1100px) { .layout.collapsed { grid-template-columns: 1fr; } .layout.collapsed > .right { display: none; } }

.panel-toggle { position: fixed; z-index: 25; right: 0; top: 50%; transform: translateY(-50%); display: flex; align-items: center; gap: 8px;
  padding: 14px 10px 14px 12px; border: 1px solid var(--glass-border); border-right: 0; border-radius: 999px 0 0 999px;
  background: var(--glass-2); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow);
  color: var(--ink); cursor: pointer; font-weight: 400; font-size: 13px; transition: padding .25s ease, background .2s; }
.panel-toggle svg { transition: transform .4s cubic-bezier(.4, 0, .2, 1); flex: none; }
.panel-toggle .pt-label { max-width: 0; overflow: hidden; white-space: nowrap; transition: max-width .3s ease; }
.panel-toggle:hover { background: var(--surface); padding-right: 16px; }
.panel-toggle:hover .pt-label, .panel-toggle:focus-visible .pt-label { max-width: 120px; }
.panel-toggle[aria-expanded="false"] svg { transform: rotate(180deg); }
@media (min-width: 1101px) { .layout { padding-right: 52px; } }
.tb-group.right { flex-wrap: nowrap; }

/* mode description: always a single line */
.graph-head { flex-wrap: nowrap; align-items: center; }
.hint { flex: 1 1 0; max-width: none; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats { margin-left: auto; flex: none; flex-wrap: nowrap; white-space: nowrap; }
.layout.collapsed { padding-bottom: 98px; }

/* ---------- light / dark toggle (top right) ---------- */
.top-right { align-items: center; }
.theme-toggle { border: 0; background: none; padding: 0; cursor: pointer; color: var(--slate-2); }
.tt-track { position: relative; display: flex; align-items: center; justify-content: space-between; width: 62px; height: 32px; padding: 0 9px;
  border-radius: 999px; background: var(--field); border: 1px solid var(--hair); box-shadow: inset 0 1px 2px rgba(0, 0, 0, .06); }
.tt-track svg { position: relative; z-index: 1; transition: color .3s; }
.tt-knob { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18), 0 2px 8px rgba(0, 0, 0, .08); transition: transform .35s cubic-bezier(.4, 0, .2, 1), background-color .35s; }
.theme-toggle[aria-checked="false"] .tt-sun { color: var(--ink); }
.theme-toggle[aria-checked="true"] .tt-moon { color: var(--ink); }
.theme-toggle[aria-checked="true"] .tt-knob { transform: translateX(30px); }
.theme-toggle:focus-visible .tt-track { outline: 2px solid var(--slate); outline-offset: 2px; }
:root[data-theme="dark"] .modes button.active,
:root[data-theme="dark"] .tabs button.active { background: #3b4246; box-shadow: 0 2px 10px rgba(0, 0, 0, .35); }

/* Target / Bands toggles sit inline after the toolbar buttons */
.tb-group.right { margin-left: 6px; flex-direction: row; flex-wrap: nowrap; gap: 16px; }
.toolbar .check { white-space: nowrap; }
.brand { font-size: 14px; white-space: nowrap; }
.brand .logo { font-size: 26px; }

/* ---------- audio mode ---------- */
.audio-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.audio-head .tabs { flex: none; }
#audioSubHint { font-size: 13px; }
.audio-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 700px) { .audio-slots { grid-template-columns: 1fr; } }
.slot { position: relative; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 12px; align-items: center;
  padding: 16px 18px; border-radius: 16px; border: 1px dashed var(--hair-2); background: var(--panel-soft); cursor: pointer; min-width: 0;
  transition: border-color .2s, background-color .2s; }
.slot:hover, .slot.drag { border-color: var(--slate); }
.slot.loaded { border-style: solid; border-color: var(--hair-2); }
.slot input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.slot-step { grid-row: 1 / 3; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; font-weight: 500; font-size: 13px;
  background: var(--slot-color, var(--slate)); color: #0c0d0d; }
#slotA { --slot-color: #c8edff; } #slotB { --slot-color: #fca162; }
.slot-title { font-size: 15px; font-weight: 400; }
.slot-file { font-size: 12px; color: var(--slate); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.audio-controls { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 14px; margin-top: 14px; }
@media (max-width: 900px) { .audio-controls { grid-template-columns: 1fr; } }
.audio-controls .slider { margin: 10px 0; }
.audio-controls .inline { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--slate-2); }
.brand .logo { font-weight: 600; font-size: 26px; line-height: 1; transform: translateY(-1px); }

/* output actions: status text on its own line, the three buttons always on one line */
.out-actions { flex-wrap: wrap; row-gap: 10px; }
.out-actions #outInfo { flex: 1 1 100%; margin: 0; min-height: 0; }
.out-actions #outInfo:empty { display: none; }
.out-actions .btn, .out-actions button { flex: none; white-space: nowrap; }
.out-actions .btn.file { margin-left: auto; }

/* ---------- audio player ---------- */
.player { display: grid; grid-template-columns: auto auto 1fr auto; grid-template-areas: "play src seek time" "opts opts opts opts";
  align-items: center; gap: 12px 14px; margin-top: 14px; padding: 14px 16px; border-radius: 16px; background: var(--panel-soft); }
.pl-play { grid-area: play; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--ink); color: var(--on-ink); box-shadow: 0 2px 10px rgba(0, 0, 0, .2); transition: transform .15s, opacity .2s; }
.pl-play:hover:not(:disabled) { transform: scale(1.05); }
.pl-play:disabled { opacity: .3; cursor: default; }
.pl-play .pl-i-pause, .pl-play.playing .pl-i-play { display: none; }
.pl-play.playing .pl-i-pause { display: block; }
.pl-play .pl-i-play { margin-left: 2px; }
.pl-src { grid-area: src; }
.pl-src button:disabled { opacity: .35; cursor: default; }
.pl-seek { grid-area: seek; width: 100%; min-width: 80px; }
.pl-time { grid-area: time; font-family: var(--mono); font-size: 12px; color: var(--slate-2); white-space: nowrap; }
.pl-opts { grid-area: opts; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.pl-opts #plRender { margin-left: auto; }
@media (max-width: 760px) {
  .player { grid-template-columns: auto 1fr; grid-template-areas: "play src" "seek seek" "time time" "opts opts"; }
}

/* slope + channel columns */
td.num { width: 62px; }
td.slope { width: 58px; }
td.ch { width: 82px; }
td.slope select, td.ch select { width: 100%; font-size: 12px; }
td.slope .na { display: block; text-align: center; color: var(--slate, #8693a3); opacity: .6; }
@media (max-width: 1240px) and (min-width: 1101px) { .layout { grid-template-columns: minmax(0, 1fr) 540px; } }
/* table number fields: no spin buttons, so values are never clipped (arrow keys still step) */
#ftable input[type=number] { -moz-appearance: textfield; appearance: textfield; padding-left: 6px; padding-right: 4px; }
#ftable input[type=number]::-webkit-inner-spin-button, #ftable input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* match basis */
.basis-group { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.basis-group .muted { font-size: 13px; }
.audio-controls .inline + .inline { margin-top: 10px; }
#monoRow { margin-top: 8px; }

.pl-mon { display: flex; align-items: center; gap: 8px; }
.pl-mon .muted { font-size: 13px; }
.pl-mon .tabs button { padding: 5px 12px; }
/* audio controls: three equal boxes that wrap when narrow; sliders may shrink */
.audio-controls { grid-template-columns: repeat(auto-fit, minmax(205px, 1fr)); }
.audio-controls .slider input { min-width: 0; }
.audio-controls .slider span { min-width: 38px; }

.mono-row { display: flex; align-items: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.mono-row input[type=number] { width: 62px; }
.mono-row .muted { font-size: 12px; }
/* limits: 2 × 2 so values like 16000 are never clipped */
.audio-controls .grid4 { grid-template-columns: repeat(2, 1fr); }

/* ================= narrow screens (phones, small tablets) ================= */
@media (max-width: 1100px) {
  /* two views side by side; the panel toggle slides between them */
  .layout { grid-template-columns: 100% 100%; column-gap: 32px; overflow-x: hidden; align-items: start; }
  .layout > .left, .layout > .right { transition: transform .45s cubic-bezier(.4, 0, .2, 1), opacity .3s ease; }
  .layout > .right { opacity: 0; visibility: hidden; max-height: 0; overflow: hidden;
    transition: transform .45s cubic-bezier(.4, 0, .2, 1), opacity .3s ease, visibility 0s linear .45s, max-height 0s linear .45s; }
  .layout.m-panels > .left, .layout.m-panels > .right { transform: translateX(calc(-100% - 32px)); }
  .layout.m-panels > .right { opacity: 1; visibility: visible; max-height: none; overflow: visible;
    transition: transform .45s cubic-bezier(.4, 0, .2, 1), opacity .3s ease; }
  .layout.m-panels > .left { opacity: 0; visibility: hidden; max-height: 0; overflow: hidden;
    transition: transform .45s cubic-bezier(.4, 0, .2, 1), opacity .3s ease, visibility 0s linear .45s, max-height 0s linear .45s; }
  /* toggle: a labelled tab on the right edge */
  .panel-toggle.narrow .pt-label { max-width: 140px; }
  .panel-toggle.narrow { top: auto; bottom: calc(86px + env(safe-area-inset-bottom)); transform: none; padding: 10px 14px 10px 12px; }
}
@media (max-width: 700px) {
  .top { gap: 12px; }
  .top-right { gap: 10px; font-size: 12px; flex-wrap: wrap; }
  .card { padding: 14px; border-radius: 18px; }
  h2 { font-size: 22px; }
  /* iOS Safari zooms into fields with text under 16 px */
  input[type=number], select { font-size: 16px; }
  #ftable input[type=number], td select { font-size: 16px; }
  .graph-head { flex-wrap: wrap; }
  .hint { flex: 1 1 100%; white-space: normal; }
  .stats { margin-left: 0; flex-wrap: wrap; gap: 10px; }
  .toolbar { gap: 8px; }
  .tb-group.right { margin-left: 0; }
  .img-controls, .audio-controls { grid-template-columns: 1fr; }
  .audio-head { gap: 10px; }
  .basis-group { margin-left: 0; flex-wrap: wrap; }
  .player { padding: 12px; }
  .pl-src button, .pl-mon .tabs button { padding: 6px 10px; }
  .out-actions { justify-content: stretch; }
  .out-actions .btn, .out-actions button { flex: 1 1 auto; }
  .out-actions .btn.file { margin-left: 0; }
  .fit-row .slider { min-width: 0; flex: 1 1 100%; }
}
/* the floating mode bar stays clear of the iPhone home indicator */
.modes { bottom: calc(20px + env(safe-area-inset-bottom)); }
.layout { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }

/* ---------- phones: filter rows become two-line cards ---------- */
@media (max-width: 700px) {
  .table-wrap { max-height: none; background: transparent; overflow: visible; }
  #ftable thead { display: none; }
  #ftable, #ftable tbody { display: block; }
  #ftable tbody tr { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 8px 6px; align-items: center;
    padding: 10px 10px 12px; margin-bottom: 8px; border-radius: 14px; background: var(--panel-soft); }
  #ftable tbody tr.sel { background: var(--row-sel); box-shadow: inset 0 0 0 1px var(--hair-2); }
  #ftable tbody td { border: 0; padding: 0; width: auto; min-width: 0; }
  #ftable td:nth-child(1) { grid-column: span 1; }               /* number */
  #ftable td:nth-child(2) { grid-column: span 1; text-align: center; } /* on */
  #ftable td:nth-child(3) { grid-column: span 6; }               /* type */
  #ftable td:nth-child(8) { grid-column: span 3; }               /* channel */
  #ftable td:nth-child(9) { grid-column: span 1; text-align: right; } /* delete */
  #ftable td:nth-child(4), #ftable td:nth-child(5), #ftable td:nth-child(6), #ftable td:nth-child(7) { grid-column: span 3; grid-row: 2; }
  #ftable td:nth-child(4) { grid-column: 1 / span 3; } #ftable td:nth-child(5) { grid-column: 4 / span 3; }
  #ftable td:nth-child(6) { grid-column: 7 / span 3; } #ftable td:nth-child(7) { grid-column: 10 / span 3; }
  #ftable td:nth-child(4)::before { content: 'Freq (Hz)'; } #ftable td:nth-child(5)::before { content: 'Gain (dB)'; }
  #ftable td:nth-child(6)::before { content: 'Q'; } #ftable td:nth-child(7)::before { content: 'dB/oct'; }
  #ftable td:nth-child(n+4):nth-child(-n+7)::before { display: block; font-size: 11px; color: var(--slate); margin: 0 0 3px 2px; }
  #ftable td select, #ftable input[type=number] { width: 100%; }
  #ftable td .resolved { padding: 2px 0 0 4px; }
  td.slope .na { line-height: 34px; }
  /* theme switch sits in the header corner instead of taking a row */
  .top { position: relative; }
  .brand { padding-right: 84px; }
  .top-right { width: 100%; flex-wrap: nowrap; gap: 8px; }
  .top-right label { gap: 6px; }
  .top-right select { padding: 4px 26px 4px 10px; background-position: right 9px center; }
  #ftable td:nth-child(n+4):nth-child(-n+7) { align-self: end; }
  .theme-toggle { position: absolute; top: 16px; right: 16px; }
}
@media (max-width: 700px) {
  /* player: labels never wrap */
  .pl-src button { white-space: nowrap; padding: 6px 9px; font-size: 13px; }
  /* slim edge tab instead of a labelled one, so it doesn't cover the content */
  .panel-toggle.narrow .pt-label { display: none; }
  .panel-toggle.narrow { padding: 16px 8px 16px 10px; bottom: calc(96px + env(safe-area-inset-bottom)); }
}

/* ---------- panels button: in the header, next to the theme switch (all screen sizes) ---------- */
.top-actions { display: flex; align-items: center; gap: 10px; }
.panel-toggle, .panel-toggle.narrow {
  position: static; transform: none; top: auto; right: auto; bottom: auto; z-index: auto;
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 14px 0 12px;
  border: 1px solid var(--hair); border-radius: 999px; background: var(--field); box-shadow: none;
  color: var(--slate-2); font-size: 13px; font-weight: 400; cursor: pointer; white-space: nowrap;
  backdrop-filter: none; -webkit-backdrop-filter: none; transition: background-color .2s, color .2s, border-color .2s; }
.panel-toggle:hover { background: var(--surface); color: var(--ink); padding: 0 14px 0 12px; }
.panel-toggle svg, .panel-toggle[aria-expanded="false"] svg { transform: none; transition: none; }
.panel-toggle .pt-label, .panel-toggle:hover .pt-label { max-width: none; overflow: visible; }
.panel-toggle .pt-pane { opacity: 0; transition: opacity .25s; }
.panel-toggle[aria-expanded="true"] { color: var(--ink); }
.panel-toggle[aria-expanded="true"] .pt-pane { opacity: .9; }
.panel-toggle:focus-visible { outline: 2px solid var(--slate); outline-offset: 2px; }
@media (min-width: 1101px) { .layout { padding-right: 28px; } }
@media (max-width: 700px) {
  .theme-toggle { position: static; }
  .top-actions { position: absolute; top: 14px; right: 16px; gap: 8px; }
  .brand { padding-right: 120px; }
  .panel-toggle, .panel-toggle.narrow { width: 40px; padding: 0; justify-content: center; }
  .panel-toggle .pt-label, .panel-toggle.narrow .pt-label { display: none; }
}
@media (max-width: 700px) {
  .out-opts label { flex: 1 1 100%; min-width: 0; }
  .out-opts select { flex: 1; min-width: 0; max-width: none; width: 100%; }
  .out-actions { flex-wrap: wrap; justify-content: flex-end; }
  .out-actions #outInfo { flex: 1 1 100%; }
  .out-actions .btn, .out-actions button { flex: 0 1 auto; padding: 8px 12px; font-size: 14px; }
  .out-actions .btn.file { margin-left: auto; }
}
