/* ACORN Utilities (GitHub Pages). Tokens and components follow web/css/app.css; keep them in step. */

:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 14px;
  --radius-sm: 9px;
  --topbar-h: 56px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

[data-theme="light"] {
  --bg: #f3f1ea;
  --surface: #ffffff;
  --surface-2: #f8f7f2;
  --sunken: #ebe8df;
  --ink: #121211;
  --ink-2: #3b3a36;
  --muted: #6e6c64;
  --line: #e2dfd5;
  --line-strong: #cbc7ba;
  --on-ink: #ffffff;
  --ok: #1c7a4b;       --ok-bg: #e1f1e7;
  --warn: #975f00;     --warn-bg: #fbeed2;
  --fault: #b5311b;    --fault-bg: #fbe4de;
  --focus: #2f6fdd;
  --shadow: 0 1px 2px rgba(20, 18, 10, .05), 0 2px 8px rgba(20, 18, 10, .04);
}

[data-theme="dark"] {
  --bg: #0e0e0d;
  --surface: #181816;
  --surface-2: #1e1e1b;
  --sunken: #0a0a09;
  --ink: #f2f0ea;
  --ink-2: #d4d1c8;
  --muted: #9a978d;
  --line: #2b2a26;
  --line-strong: #3d3c37;
  --on-ink: #0e0e0d;
  --ok: #43b97d;       --ok-bg: #12291c;
  --warn: #e3a73e;     --warn-bg: #2d2210;
  --fault: #ff6f56;    --fault-bg: #33150f;
  --focus: #7aa7ff;
  --shadow: 0 1px 0 rgba(255, 255, 255, .02);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---- Icons ---------------------------------------------------------------------------- */
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon.sm { width: 16px; height: 16px; }
.icon.lg { width: 24px; height: 24px; }

/* ---- Shell ---------------------------------------------------------------------------- */
.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar-h);
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); }
.brand-icon { width: 24px; height: 30px; }
.brand-word { width: 78px; height: 12px; }
.site-chip { min-width: 0; display: flex; flex-direction: column; line-height: 1.15; padding-left: 12px; border-left: 1px solid var(--line); text-decoration: none; }
.site-chip b { font-size: 13px; font-weight: 650; white-space: nowrap; }
.site-chip span { font: 11px var(--mono); color: var(--muted); white-space: nowrap; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px;
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none;
}
.icon-btn:hover { border-color: var(--line-strong); }

.view {
  flex: 1;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  outline: none;
}
@media (min-width: 900px) {
  .topbar { padding: 0 24px; }
  .view { padding: 36px 32px 64px; }
}

.footer {
  border-top: 1px solid var(--line);
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  font-size: 13px; color: var(--muted); text-align: center;
}
.footer a { color: var(--ink-2); }

/* ---- Page headers --------------------------------------------------------------------- */
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 13px; font-weight: 750; letter-spacing: .18em; text-transform: uppercase; }
.page-head .sub { flex-basis: 100%; color: var(--muted); font-size: 14px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: 13px; margin-bottom: 10px; }
.back:hover { color: var(--ink); }

.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---- Cards ---------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card + .card { margin-top: 12px; }
.grid > .card, .stack > .card { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h3 { font-size: 15px; font-weight: 650; }
.card-head .step { font: 700 12px var(--mono); color: var(--muted); }
.card-head .actions { margin-left: auto; display: flex; gap: 6px; }
.card.disabled { opacity: .5; pointer-events: none; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }

.meter { height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--ink); border-radius: 3px; }

/* ---- Hub tools ------------------------------------------------------------------------ */
.hero {
  position: relative;
  border-radius: var(--radius);
  padding: 22px 20px;
  overflow: hidden;
  background: var(--ink); color: var(--on-ink);
  margin-bottom: 20px;
}
.hero .eyebrow { color: inherit; opacity: .7; }
.hero h1 { font-size: 26px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; margin: 4px 0 8px; }
.hero p { max-width: 560px; opacity: .88; }
.hero .mark { position: absolute; right: -18px; bottom: -26px; width: 140px; height: 172px; opacity: .14; }

.tool-card { display: grid; gap: 10px; text-decoration: none; transition: border-color .15s; }
.tool-card:hover { border-color: var(--ink); }
.tool-card .tool-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--sunken); }
.tool-card h3 { font-size: 17px; font-weight: 650; }
.tool-card p { color: var(--ink-2); font-size: 14px; }
.tool-card .open { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }

/* ---- Badges --------------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 11px;
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap;
  background: var(--sunken); color: var(--ink-2);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.fault { background: var(--fault-bg); color: var(--fault); }
.badge .icon { width: 12px; height: 12px; stroke-width: 2.4; }

/* ---- Buttons -------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 40px; padding: 0 15px;
  border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font-size: 14px; font-weight: 600; text-decoration: none; white-space: nowrap;
  cursor: pointer; user-select: none;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; border-color: var(--line-strong); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.btn.primary:hover:not(:disabled) { background: var(--ink-2); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--sunken); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.lg { min-height: 54px; padding: 0 24px; font-size: 16px; border-radius: 12px; }
.btn.busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.busy::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--muted) transparent var(--muted) transparent;
  animation: spin .8s linear infinite;
}
.btn.primary.busy::after { border-color: var(--on-ink) transparent var(--on-ink) transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Forms ---------------------------------------------------------------------------- */
.form { display: grid; gap: 16px; }
.form-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field > label, .field > .label { font-size: 12px; font-weight: 650; letter-spacing: .04em; color: var(--ink-2); }
.field .hint { font-size: 12.5px; color: var(--muted); }
.input, .select {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 15px;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 12%, transparent); }
.input.mono { font-family: var(--mono); font-size: 14px; }
.input[readonly] { background: var(--sunken); color: var(--ink-2); }
.select { appearance: none; padding-right: 34px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 17px) 18px, calc(100% - 12px) 18px; background-size: 5px 5px; background-repeat: no-repeat; }
.input.invalid { border-color: var(--fault); box-shadow: 0 0 0 3px var(--fault-bg); }

.seg { display: inline-flex; padding: 3px; gap: 3px; border-radius: 10px; background: var(--sunken); flex-wrap: wrap; justify-self: start; }
.seg button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 7px;
  font-size: 12.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); cursor: pointer;
}
.seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow), 0 0 0 1px var(--line); }
.seg button:disabled { cursor: not-allowed; opacity: .5; }

.range-wrap { display: flex; align-items: center; gap: 12px; }
.range-wrap output { min-width: 42px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
input[type="range"] { flex: 1; accent-color: var(--ink); height: 28px; min-width: 0; }

/* ---- Audio ---------------------------------------------------------------------------- */
.dropzone {
  display: grid; place-items: center; gap: 6px; text-align: center;
  padding: 34px 16px; border: 1.5px dashed var(--line-strong); border-radius: var(--radius);
  color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--ink); background: var(--surface-2); color: var(--ink); }
.dropzone b { color: var(--ink); }

.source { display: grid; gap: 14px; }
.source-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 650; overflow-wrap: anywhere; }

.wave {
  position: relative; height: 150px;
  border-radius: var(--radius-sm); background: var(--sunken);
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: crosshair;
}
.wave canvas { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: inherit; }
.wave-shade { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--bg) 72%, transparent); pointer-events: none; }
.wave-shade.left { left: 0; border-top-left-radius: inherit; border-bottom-left-radius: inherit; }
.wave-shade.right { right: 0; border-top-right-radius: inherit; border-bottom-right-radius: inherit; }
.wave-handle {
  position: absolute; top: 0; bottom: 0; width: 22px; margin-left: -11px;
  cursor: ew-resize; touch-action: none;
}
.wave-handle::before { content: ""; position: absolute; top: 0; bottom: 0; left: 10px; width: 2px; background: var(--ink); }
.wave-handle::after {
  content: ""; position: absolute; top: 50%; left: 5px; width: 12px; height: 30px; margin-top: -15px;
  border-radius: 4px; background: var(--ink); box-shadow: 0 0 0 2px var(--sunken);
}
.wave-handle:focus-visible { outline: none; }
.wave-handle:focus-visible::after { box-shadow: 0 0 0 2px var(--sunken), 0 0 0 4px var(--focus); }
.wave-playhead { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--ok); pointer-events: none; }
.wave-ticks { position: relative; height: 16px; margin-top: 4px; }
.wave-ticks span { position: absolute; transform: translateX(-50%); font: 10.5px var(--mono); color: var(--muted); white-space: nowrap; }
.wave-ticks span:first-child { transform: none; }
.wave-ticks span:last-child { transform: translateX(-100%); }

.transport { display: flex; gap: 10px; flex-wrap: wrap; }
.transport .btn { flex: 1; min-width: 130px; }
.progress-line { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 6px; }

.export-bar { display: flex; justify-content: flex-end; padding-top: 16px; border-top: 1px solid var(--line); }
@media (max-width: 520px) { .export-bar .btn { flex: 1; } }

/* ---- Feedback ------------------------------------------------------------------------- */
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius-sm); font-size: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.notice.ok { background: var(--ok-bg); border-color: transparent; }
.notice.ok > .icon { color: var(--ok); }
.notice.warn { background: var(--warn-bg); border-color: transparent; }
.notice.warn > .icon { color: var(--warn); }
.notice.fault { background: var(--fault-bg); border-color: transparent; }
.notice.fault > .icon { color: var(--fault); }
.notice > div { display: grid; gap: 4px; }
.notices { display: grid; gap: 8px; }
.notices:empty { display: none; }

.toasts { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; width: min(440px, calc(100% - 24px)); pointer-events: none; }
@media (min-width: 900px) { .toasts { bottom: 24px; left: auto; right: 24px; transform: none; } }
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: 12px;
  background: var(--ink); color: var(--on-ink);
  font-size: 14px; box-shadow: 0 8px 28px rgba(0, 0, 0, .25);
  pointer-events: auto; animation: toast-in .25s var(--ease);
}
.toast.ok .icon { color: var(--ok); }
.toast.fault { background: var(--fault); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.divider { height: 1px; background: var(--line); margin: 16px 0; border: 0; }
