/* Audio Detector. Night-city sci-fi in pixel type: deep navy, steel, amber.
   Chunky panels with hard shadows, HUD corner marks, a little bounce.
   Mobile first; desktop (>= 900px) widens the Data tab to three columns.

   One color, one meaning. Blue and red mean only human and AI, everywhere:
   blue = human · red = AI · amber = selected or action · all else neutral

   Text rule: all text is easy to read on a phone. Nothing under 15px (captions, labels);
   body 17px; controls 16px. Canvas text follows the same floor. */
:root {
  color-scheme: dark;
  --bg: #0a0f1c;
  --panel: #121a2c;
  --panel-2: #0c1322;
  --edge: #26334f;
  --shadow: #03060c;
  --ink: #f1ece4;
  --ink-2: #8d9bb5;
  --human: #4f8bff;
  --ai: #ff3b30;
  --gold: #ffb000;
  --hud: rgba(141, 155, 181, 0.5);
  --bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --mono: "Share Tech Mono", ui-monospace, monospace; /* body text, controls, data */
  --pixel: "Pixelify Sans", ui-monospace, monospace; /* headings only */
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  font: 400 17px/1.35 var(--mono);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
/* Night sky: a red glow up high, cyan haze below, a faint grid. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -2;
  background:
    radial-gradient(55% 40% at 88% 4%, rgba(124, 92, 255, 0.16), transparent 70%),
    radial-gradient(70% 45% at 8% 100%, rgba(110, 130, 170, 0.12), transparent 70%),
    linear-gradient(180deg, #0a0f1c, #0b1527);
}
body::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(rgba(141, 155, 181, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(141, 155, 181, 0.05) 1px, transparent 1px);
  background-size: 24px 24px;
  -webkit-mask-image: radial-gradient(ellipse at 50% 40%, #000 30%, transparent 80%);
  mask-image: radial-gradient(ellipse at 50% 40%, #000 30%, transparent 80%);
}
.vignette {
  position: fixed; inset: 0; z-index: 50; pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.07) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 62%, rgba(0, 0, 0, 0.4));
}
a { color: var(--ink); }
.screen { display: none; }
body[data-screen="model"] #model, body[data-screen="try"] #try { display: block; }
body[data-screen="home"] #home { display: flex; flex-direction: column; min-height: 100dvh; }
body[data-screen="data"] { height: 100dvh; overflow: hidden; }
body[data-screen="data"] #data { display: flex; }
.col { width: 100%; max-width: 480px; margin: 0 auto; padding: 0 16px; }

/* ---------- parts ---------- */
.panel {
  position: relative; background: var(--panel);
  border: 2px solid var(--edge); border-radius: 8px; box-shadow: 0 4px 0 var(--shadow);
}
/* HUD corner marks */
.panel::after {
  content: ""; position: absolute; inset: -2px; pointer-events: none; border-radius: inherit;
  --l: 12px;
  background:
    linear-gradient(var(--hud), var(--hud)) top left / var(--l) 2px no-repeat,
    linear-gradient(var(--hud), var(--hud)) top left / 2px var(--l) no-repeat,
    linear-gradient(var(--hud), var(--hud)) top right / var(--l) 2px no-repeat,
    linear-gradient(var(--hud), var(--hud)) top right / 2px var(--l) no-repeat,
    linear-gradient(var(--hud), var(--hud)) bottom left / var(--l) 2px no-repeat,
    linear-gradient(var(--hud), var(--hud)) bottom left / 2px var(--l) no-repeat,
    linear-gradient(var(--hud), var(--hud)) bottom right / var(--l) 2px no-repeat,
    linear-gradient(var(--hud), var(--hud)) bottom right / 2px var(--l) no-repeat;
}
.btn {
  font: inherit; font-size: 16px; color: var(--ink); text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--edge);
  box-shadow: 0 3px 0 var(--shadow), inset 0 -2px 0 rgba(0, 0, 0, 0.25);
  transition: translate 60ms, box-shadow 60ms, filter 120ms;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { translate: 0 2px; box-shadow: 0 1px 0 var(--shadow), inset 0 -1px 0 rgba(0, 0, 0, 0.25); }
.btn-gold { background: var(--gold); color: #1b1300; }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: 16px; }
.btn svg { width: 16px; height: 16px; display: block; }
select, input[type="search"] {
  font: inherit; font-size: 16px; /* 16px stops iOS from zooming on focus */
  color: var(--ink); background: var(--panel-2);
  border: 2px solid var(--edge); border-radius: 8px; min-height: 40px; padding: 0 10px; min-width: 0;
}
select:focus, input:focus { outline: 2px solid var(--gold); outline-offset: 0; }
.tog { position: relative; display: inline-flex; cursor: pointer; }
.tog input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tog span {
  display: inline-flex; align-items: center; min-height: 38px; padding: 0 12px;
  border: 2px solid var(--edge); border-radius: 999px; color: var(--ink-2); font-size: 16px;
}
.tog input:checked + span { background: var(--gold); border-color: var(--gold); color: #1b1300; }
.tog input:focus-visible + span { outline: 2px solid var(--gold); }

/* ---------- home button (each tab) ---------- */
.home-btn { flex: 0 0 auto; width: 40px; padding: 0; }
.home-btn svg { width: 18px; height: 18px; }

/* ---------- home ---------- */
#home .col { flex: 1; display: flex; flex-direction: column; justify-content: center; padding-top: max(36px, env(safe-area-inset-top)); text-align: center; }
.title {
  margin: 0; font-family: var(--pixel); font-size: clamp(40px, 12vw, 60px); font-weight: 700; line-height: 1; letter-spacing: 0.01em;
  text-shadow: 0 4px 0 var(--shadow);
}
#hero { display: block; width: 100%; aspect-ratio: 96 / 30; margin: 22px 0 6px; image-rendering: pixelated; }
.menu { display: flex; flex-direction: column; gap: 10px; margin: 20px 0 8px; text-align: left; }
.item {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px; color: var(--ink); text-decoration: none;
  background: var(--panel); border: 2px solid var(--edge); border-radius: 8px; box-shadow: 0 3px 0 var(--shadow);
  transition: border-color 150ms ease-out, translate 80ms;
}
.item:hover { border-color: var(--ink-2); }
.item:active { translate: 0 2px; box-shadow: 0 1px 0 var(--shadow); }
.item-art { flex: 0 0 44px; height: 44px; display: grid; place-items: center; color: var(--ink); background: var(--panel-2); border: 2px solid var(--edge); border-radius: 6px; }
.item-art svg { display: block; width: 24px; height: auto; }
.item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item-text b { font-family: var(--pixel); font-size: 22px; font-weight: 600; }
.item-go { font-size: 26px; line-height: 1; color: var(--ink-2); }
.credit { padding: 28px 16px max(16px, env(safe-area-inset-bottom)); text-align: right; font-size: 15px; color: var(--ink-2); }
.credit p { margin: 0 0 8px; }
.credit .links { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Data and Stats tabs (one explorer; data-tab picks the view) ---------- */
#data { flex: 1; min-height: 0; flex-direction: column; }
.ex-head { padding: 10px 10px 0; padding-top: max(10px, env(safe-area-inset-top)); }
.ex-bar { display: flex; align-items: center; gap: 8px; }
.btn svg[viewBox="0 0 7 7"] { width: 14px; height: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 10px; }
.chip {
  display: inline-flex; align-items: center; height: 32px; padding: 0 10px; font-size: 16px; font-weight: 600;
  background: var(--panel-2); border: 2px solid var(--edge); border-radius: 6px; box-shadow: 0 2px 0 var(--shadow);
  font-variant-numeric: tabular-nums;
}
.chip.h { background: var(--human); border-color: var(--human); color: #fff; }
.chip.a { background: var(--ai); border-color: var(--ai); color: #fff; }
/* If the phone is short, the area under the header scrolls; the list keeps 3 rows. */
.ex-main { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 10px; }
#right { order: 1; }
#right { flex: none; }
#mid { order: 2; flex: 1 1 0; min-height: 152px; }
#left { order: 3; flex: 1; min-height: 0; overflow-y: auto; }
#data[data-tab="clips"] #left { display: none; }
#data[data-tab="stats"] #mid, #data[data-tab="stats"] #right { display: none; }

/* clip list */
#mid { display: flex; flex-direction: column; overflow: hidden; }
#thead { display: flex; justify-content: space-between; overflow: hidden; flex-shrink: 0; background: var(--panel-2); border-bottom: 2px solid var(--edge); border-radius: 6px 6px 0 0; font-size: 15px; user-select: none; }
#thead span { padding: 6px 12px; color: var(--ink-2); }
#tbody { flex: 1; min-height: 0; overflow: auto; position: relative; -webkit-overflow-scrolling: touch; }
#rows { position: absolute; top: 0; left: 0; right: 0; }
.r { position: absolute; left: 0; right: 0; display: flex; align-items: center; border-bottom: 1px solid rgba(38, 51, 79, 0.6); cursor: pointer; font-size: 17px; font-variant-numeric: tabular-nums; }
.r:hover { background: rgba(255, 255, 255, 0.03); }
.r.sel { background: rgba(255, 176, 0, 0.14); box-shadow: inset 3px 0 0 var(--gold); }
.r { justify-content: space-between; padding: 0 10px 0 12px; }
.lab, .badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 68px; height: 28px; padding: 0 8px;
  border-radius: 4px; font-size: 16px; font-weight: 700; color: #fff; background: var(--edge); box-shadow: 0 2px 0 var(--shadow);
}
.lab.human, .badge.human { background: var(--human); }
.lab.ai, .badge.ai { background: var(--ai); }
.r.err { text-decoration: line-through; }

/* player */
#right { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.clip-top { display: flex; align-items: center; gap: 10px; }
#clip-head { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; font-size: 20px; }
.info-btn {
  flex: none; width: 36px; height: 36px; padding: 0; cursor: pointer;
  font: 700 19px/1 var(--mono); color: var(--ink); background: transparent;
  border: 2px solid var(--ink-2); border-radius: 50%;
}
.info-btn[aria-expanded="true"] { background: var(--gold); border-color: var(--gold); color: #1b1300; }
#clip-info { padding: 10px 12px; font-size: 15px; background: var(--panel-2); border: 2px solid var(--edge); border-radius: 6px; }
#clip-info .method { display: flex; flex-direction: column; gap: 2px; padding-bottom: 8px; border-bottom: 2px solid var(--edge); }
#clip-info .method b { font-size: 17px; }
#clip-info .grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; padding-top: 8px; font-variant-numeric: tabular-nums; }
#clip-info .k { color: var(--ink-2); }
#clip-info .g { grid-column: 1 / -1; margin-top: 8px; font-family: var(--pixel); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }
#text { margin: 0; font-size: 17px; line-height: 1.4; }
#text .dim { font-size: inherit; }
.dim { color: var(--ink-2); font-size: 15px; }
/* Phone: the spectrogram is full width and about a third of the screen height. */
#viz { position: relative; cursor: pointer; overflow: hidden; border: 2px solid var(--edge); border-radius: 6px; background: #000; }
#wave { display: block; width: 100%; height: 40px; background: var(--panel-2); }
#spec { display: block; width: 100%; height: 33dvh; background: #000; }
#head { position: absolute; top: 0; bottom: 0; left: 0; width: 2px; display: none; pointer-events: none; background: var(--gold); box-shadow: 0 0 6px var(--gold); }
#ctrl { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#ctrl .btn { min-width: 44px; padding: 0 10px; }
#ctrl .tog span { padding: 0 9px; }
#b-rand svg { width: 18px; height: 18px; }
#time { position: absolute; right: 4px; bottom: 4px; padding: 1px 5px; border-radius: 3px; background: rgba(3, 6, 12, 0.7); color: var(--ink); font-size: 15px; pointer-events: none; }
#time:empty { display: none; }

/* stats: histograms */
#left { padding: 0 2px 8px; }
.grp { display: flex; align-items: center; gap: 8px; margin: 14px 2px 8px; font-family: var(--pixel); font-size: 15px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-2); }
.grp::after { content: ""; flex: 1; height: 2px; background: var(--edge); }
.grp:first-child { margin-top: 2px; }
.hist { margin-bottom: 10px; padding: 8px; background: var(--panel); border: 2px solid var(--edge); border-radius: 8px; box-shadow: 0 3px 0 var(--shadow); }
.hist canvas { display: block; width: 100%; height: 64px; background: var(--panel-2); border-radius: 4px; cursor: crosshair; touch-action: pan-y; }
.hist .cap { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; margin-bottom: 6px; font-size: 15px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.hist .cap b { color: var(--ink); font-size: 17px; font-weight: 600; }
.hist .nm { cursor: help; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist .cap .rng, .hist .cap .auc { white-space: nowrap; }
.hist .cap .auc { cursor: help; }
.hist .tip .dim { font-size: inherit; }
.hist .cap .rng { margin-left: auto; }
.hist .cap .auc.hi { color: var(--gold); font-weight: 700; }
.hist .cap .clr { min-height: 0; padding: 0 6px; font: inherit; font-size: 15px; line-height: 22px; color: var(--ink); background: var(--edge); border: 0; border-radius: 4px; cursor: pointer; }
.hist .tip { display: none; padding: 0 0 6px; font-size: 15px; color: var(--ink-2); }
.hist.info .tip { display: block; }
#note { margin: 12px 2px 0; font-size: 15px; color: var(--ink-2); }
#note a { color: var(--ink); }

/* ---------- Model and Try it tabs ---------- */
.pg-head { display: flex; align-items: center; gap: 12px; padding: max(12px, env(safe-area-inset-top)) 0 4px; }
.pg-head h2 { margin: 0; font-family: var(--pixel); font-size: 26px; text-shadow: 0 3px 0 var(--shadow); }
.pg-head select { margin-left: auto; max-width: 52%; }
.seg { display: flex; gap: 6px; margin-top: 10px; }
.seg[hidden] { display: none; }
.seg button {
  flex: 1; font: inherit; font-weight: 600; min-height: 40px; color: var(--ink-2); cursor: pointer;
  background: var(--panel); border: 2px solid var(--edge); border-radius: 8px; box-shadow: 0 3px 0 var(--shadow);
}
.seg button.on { background: var(--gold); border-color: var(--gold); color: #1b1300; }
#m-body { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.m-card { margin-top: 14px; padding: 14px; }
.m-card h3 { margin: 0 0 8px; font-family: var(--pixel); font-size: 22px; font-weight: 600; }
.m-card p { margin: 8px 0 0; }
.m-meta { color: var(--gold); }
.m-dim { color: var(--ink-2); font-size: 16px; }
.legend { display: flex; gap: 16px; font-size: 16px; }
.legend i, .tip-box i { display: inline-block; width: 12px; height: 12px; margin-right: 6px; border-radius: 3px; vertical-align: -1px; }
.chart { position: relative; margin-top: 6px; }
.chart svg { display: block; touch-action: pan-y; }
.chart text { fill: var(--ink-2); font: 15px var(--mono); }
.chart .grid { stroke: var(--edge); stroke-width: 1; }
.chart .kept { stroke: var(--ink-2); stroke-width: 1; }
.chart .kept-t { fill: var(--ink); }
.chart .xh { stroke: var(--ink); stroke-width: 1; }
.tip-box {
  position: absolute; top: 4px; padding: 6px 8px; font-size: 15px; line-height: 1.4; pointer-events: none; white-space: nowrap;
  background: var(--panel-2); border: 2px solid var(--edge); border-radius: 6px; box-shadow: 0 3px 0 var(--shadow);
}
.m-res { width: 100%; margin-top: 4px; border-collapse: collapse; font-size: 16px; font-variant-numeric: tabular-nums; }
.m-res th, .m-res td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--edge); }
.m-res th { color: var(--ink-2); font-weight: 400; font-size: 15px; }
.m-res th:first-child, .m-res td:first-child { text-align: left; }
.m-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.m-h h3 { margin: 0; }
.sys-info { margin-bottom: 12px; padding: 10px; background: var(--panel-2); border: 2px solid var(--edge); border-radius: 6px; }
.sys-info p:first-child { margin-top: 0; }
.sys-info dl { display: grid; grid-template-columns: 44px 1fr; gap: 4px 8px; margin: 0; font-size: 16px; }
.sys-info dt { color: var(--gold); }
.sys-info dd { margin: 0; }
.bars { display: grid; gap: 6px; margin-top: 4px; }
.bar-row { display: grid; grid-template-columns: 44px 1fr 64px; align-items: center; gap: 8px; font-size: 16px; font-variant-numeric: tabular-nums; }
.bt { height: 12px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.bt span { display: block; height: 100%; background: var(--ink-2); border-radius: 0 4px 4px 0; }
.bv { text-align: right; }

#try .col { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
#t-slot { margin-top: 10px; min-height: 176px; padding: 14px; transition: border-color 120ms; }
#t-slot.over { border-color: var(--gold); border-style: dashed; }
.t-empty { margin: 0; min-height: 144px; display: grid; place-items: center; text-align: center; color: var(--ink-2); }
.t-head { display: flex; align-items: center; gap: 10px; }
.t-head b { font-size: 18px; }
.t-play { margin-left: auto; width: 44px; padding: 0; }
.t-clear { width: 44px; padding: 0; font-size: 24px; line-height: 1; }
.t-rec-note + .t-clear { margin-left: auto; }
.t-sub, .t-wait { margin: 6px 0 0; color: var(--ink-2); font-size: 16px; }
.t-score { margin-top: 10px; font-size: 20px; }
.t-score b { font-family: var(--pixel); font-size: 44px; line-height: 1; }
#try .h { color: var(--human); }
#try .a { color: var(--ai); }
.meter { position: relative; height: 12px; margin-top: 8px; background: var(--panel-2); border-radius: 4px; }
.meter span { display: block; height: 100%; border-radius: 4px; }
.meter span.h { background: var(--human); }
.meter span.a { background: var(--ai); }
.meter i { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; background: var(--ink); }
.t-verdict { margin: 10px 0 0; }
.t-verdict .ok { color: #3ecf8e; }
.t-verdict .no { color: var(--gold); }
.btn-rec { width: 100%; margin-top: 12px; min-height: 48px; font-weight: 600; }
.t-rec-note { margin: 0; flex: 1; color: var(--ink-2); font-size: 16px; }
#t-live { display: block; width: 100%; height: 132px; margin-top: 10px; background: var(--panel-2); border-radius: 6px; }
.btn-rec .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--ai); }
.btn-rec.on { background: var(--ai); }
.btn-rec.on .dot { background: #fff; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.t-grp { margin: 16px 0 8px; font-size: 16px; color: var(--ink-2); }
.t-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.t-tile {
  display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 6px 8px; font: inherit; color: var(--ink); cursor: grab;
  background: var(--panel); border: 2px solid var(--edge); border-radius: 8px; box-shadow: 0 3px 0 var(--shadow);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.t-tile .lab { min-width: 64px; height: 26px; font-size: 15px; }
.t-tile.on { border-color: var(--gold); }
.t-tile.ghost { position: fixed; z-index: 60; pointer-events: none; translate: -50% -50%; opacity: 0.9; cursor: grabbing; }
.t-note { margin: 16px 0 0; font-size: 15px; color: var(--ink-2); }
@media (prefers-reduced-motion: reduce) { .btn-rec.on .dot { animation: none; } }

/* ---------- desktop ---------- */
@media (min-width: 900px) {
  .only-m { display: none !important; }
  .col { max-width: 560px; }
  .ex-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 14px 0; }
  .ex-bar { display: contents; }
  .home-btn { order: -2; }
  #stats { order: 2; flex: 0 0 auto; margin-left: auto; padding: 0; }
  select, input[type="search"] { font-size: 16px; min-height: 38px; }
  .ex-main { padding: 12px 14px 14px; }
  #data[data-tab="clips"] .ex-main { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 12px; }
  #data[data-tab="clips"] #right { order: 2; overflow-y: auto; }
  #data[data-tab="clips"] #mid { order: 1; }
  #data[data-tab="stats"] #left { width: 100%; max-width: 1100px; margin: 0 auto; }
  #hists { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 0 12px; }
  #hists .grp { grid-column: 1 / -1; }
  #wave { height: 70px; }
  #spec { height: 260px; }
}

@media (prefers-reduced-motion: reduce) {
  .item, .btn { transition: none; }
}
