:root {
  --bg: #06080c;
  --glass: rgba(13, 17, 25, 0.74);
  --glass-strong: rgba(13, 17, 25, 0.9);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e9eef6;
  --muted: #8d99ab;
  --accent: #4fd1ff;
  --accent-ink: #00202c;
  --warm: #ffd166;
  --radius: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }
.mono { font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace; font-variant-numeric: tabular-nums; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#app, #app canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* ---------------------------------------------------------------- loading */
#loading { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; z-index: 50; background: radial-gradient(ellipse at 50% 40%, #0f1724, #05070b 70%); transition: opacity .5s; }
#loading.done { opacity: 0; pointer-events: none; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 3px solid rgba(79, 209, 255, .18); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--muted); font-size: 14px; letter-spacing: .02em; }
#progress { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 40; pointer-events: none; opacity: 0; transition: opacity .3s; }
#progress.on { opacity: 1; }
#progress i { display: block; height: 100%; width: 40%; background: linear-gradient(90deg, transparent, var(--accent), transparent); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

/* ---------------------------------------------------------------- top bar */
#topbar { position: fixed; z-index: 20; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; border-radius: 14px; max-width: calc(100vw - 90px); }
.logo-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); flex: none; }
.titles { display: flex; flex-direction: column; min-width: 0; }
.titles b { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titles small { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, .06); }

/* ---------------------------------------------------------------- toolbar */
#toolbar { position: fixed; z-index: 20; right: calc(10px + var(--safe-r)); top: calc(10px + var(--safe-t)); display: flex; flex-direction: column; padding: 5px; border-radius: 16px; gap: 2px; }
#toolbar button { width: 52px; height: 50px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: #c7d1de; }
#toolbar button span { font-size: 9.5px; letter-spacing: .02em; color: var(--muted); }
#toolbar button:hover { background: rgba(255, 255, 255, .06); color: #fff; }
#toolbar button.active { background: var(--accent); color: var(--accent-ink); }
#toolbar button.active span { color: var(--accent-ink); }

/* ---------------------------------------------------------------- dock */
#dock { position: fixed; z-index: 25; left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r)); bottom: calc(8px + var(--safe-b)); border-radius: 20px; padding: 4px 12px 12px; max-height: 58vh; display: flex; flex-direction: column; }
#grabber { align-self: center; width: 100%; height: 22px; display: grid; place-items: center; }
#grabber span { width: 40px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .25); }
.dock-body { overflow-y: auto; overscroll-behavior: contain; padding: 2px 2px 4px; margin-top: 8px; -webkit-user-select: none; }
#dock.collapsed .dock-body { display: none; }
#dock h4 { margin: 16px 0 8px; font-size: 11px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px; scroll-snap-type: x proximity; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; scroll-snap-align: start; height: 38px; padding: 0 14px; border-radius: 12px; display: flex; align-items: center; gap: 8px; background: rgba(255, 255, 255, .05); border: 1px solid transparent; font-size: 13.5px; font-weight: 500; color: #cdd6e2; white-space: nowrap; }
.chip i { width: 14px; height: 14px; border-radius: 4px; display: block; flex: none; }
.chip.active { background: rgba(79, 209, 255, .14); border-color: rgba(79, 209, 255, .55); color: #fff; }

.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { height: 34px; padding: 0 12px; border-radius: 999px; display: flex; align-items: center; gap: 7px; font-size: 13px; background: rgba(255, 255, 255, .05); border: 1px solid var(--line); color: #cdd6e2; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, .22); }
.pill.on { border-color: rgba(79, 209, 255, .6); color: #fff; background: rgba(79, 209, 255, .12); }
.pill.on::before { background: var(--accent); box-shadow: 0 0 8px var(--accent); }

#modePanel, #togglePanel { display: grid; gap: 10px; }
#modePanel { margin-top: 12px; }
#togglePanel:not(:empty) { margin-top: 12px; }
.note { font-size: 12.5px; color: var(--muted); line-height: 1.45; margin: 0; }
.legend { height: 10px; border-radius: 6px; }
.legend-labels { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.swatches { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: #cdd6e2; }
.swatches span { display: flex; align-items: center; gap: 6px; }
.swatches i { width: 12px; height: 12px; border-radius: 4px; display: block; }

.field { display: grid; gap: 6px; margin-bottom: 8px; }
.field label { display: flex; justify-content: space-between; font-size: 12.5px; color: #c4cedb; }
.field output { color: var(--muted); font-variant-numeric: tabular-nums; }
.field select { height: 34px; border-radius: 10px; background: rgba(255, 255, 255, .06); color: var(--text); border: 1px solid var(--line); padding: 0 10px; font: inherit; font-size: 13px; }
.dual { position: relative; height: 26px; }
.dual input { position: absolute; inset: 0; width: 100%; pointer-events: none; background: none; }
.dual input::-webkit-slider-thumb { pointer-events: auto; }
.dual input::-moz-range-thumb { pointer-events: auto; }
.dual .track { position: absolute; left: 0; right: 0; top: 11px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .12); }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 26px; background: transparent; margin: 0; touch-action: pan-y; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .14); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .14); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -8px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); box-shadow: 0 2px 8px rgba(0, 0, 0, .4); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
.dual input[type=range]::-webkit-slider-runnable-track { background: transparent; }
.dual input[type=range]::-moz-range-track { background: transparent; }

#stats { margin-top: 6px; font-size: 11px; color: #6f7b8c; }

/* ---------------------------------------------------------------- bars */
.pill-bar { position: fixed; z-index: 22; left: 50%; transform: translateX(-50%); top: calc(70px + var(--safe-t)); display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; border-radius: 999px; font-size: 13px; max-width: calc(100vw - 20px); white-space: nowrap; }
.txt-btn { height: 32px; padding: 0 10px; border-radius: 999px; font-size: 13px; color: #cdd6e2; background: rgba(255, 255, 255, .06); }
.txt-btn.accent, .txt-btn.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.round-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.round-btn svg { fill: currentColor; stroke: none; }
.round-btn .i-pause, .round-btn.playing .i-play { display: none; }
.round-btn.playing .i-pause { display: block; }
#replaySeek { width: min(40vw, 320px); }
#replayTime { color: var(--muted); font-size: 12px; min-width: 70px; text-align: center; }

/* ---------------------------------------------------------------- compare split */
#split { position: fixed; z-index: 15; top: 0; bottom: 0; left: 50%; width: 0; }
#split .line { position: absolute; top: 0; bottom: 0; left: -1px; width: 2px; background: rgba(255, 255, 255, .85); box-shadow: 0 0 12px rgba(79, 209, 255, .8); pointer-events: none; }
#split .handle { position: absolute; top: 50%; left: -22px; width: 44px; height: 44px; margin-top: -22px; border-radius: 50%; background: #fff; color: #0b1220; display: grid; place-items: center; box-shadow: 0 4px 16px rgba(0, 0, 0, .5); touch-action: none; cursor: ew-resize; }
#split .lab { position: absolute; top: calc(120px + var(--safe-t)); font-size: 12px; padding: 4px 9px; border-radius: 999px; background: var(--glass-strong); border: 1px solid var(--line); white-space: nowrap; pointer-events: none; }
#split .lab.left { right: 12px; }
#split .lab.right { left: 12px; }

/* ---------------------------------------------------------------- labels / toasts */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 12; }
.mlabel { position: absolute; transform: translate(-50%, -130%); background: rgba(10, 14, 20, .9); border: 1px solid rgba(255, 209, 102, .6); color: #fff; font-size: 12.5px; padding: 4px 9px; border-radius: 8px; white-space: nowrap; }
.mlabel small { color: var(--warm); margin-left: 6px; }
.toast { position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); top: calc(70px + var(--safe-t)); background: var(--glass-strong); border: 1px solid var(--line); padding: 9px 14px; border-radius: 12px; font-size: 13px; max-width: calc(100vw - 24px); text-align: center; pointer-events: none; }
.toast.hint { top: auto; bottom: calc(110px + var(--safe-b)); color: #cfd8e4; line-height: 1.5; }

/* ---------------------------------------------------------------- info sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .45); display: grid; align-items: end; justify-items: center; }
.sheet { position: relative; width: min(560px, 100vw); max-height: 82vh; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 22px 20px calc(22px + var(--safe-b)); background: var(--glass-strong); }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.sheet h3 { margin: 18px 0 8px; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.sheet p, .sheet li { font-size: 13.5px; line-height: 1.55; color: #cdd6e2; }
.sheet ul { padding-left: 18px; margin: 6px 0; }
.sheet .kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 13px; }
.sheet .kv span:nth-child(odd) { color: var(--muted); }
.sheet-close { position: absolute; top: 12px; right: 12px; }
kbd { font-family: inherit; font-size: 11.5px; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line); background: rgba(255, 255, 255, .06); }

#fatal { position: fixed; inset: 0; z-index: 70; display: grid; place-content: center; padding: 24px; text-align: center; background: var(--bg); color: #ffb4a8; font-size: 14px; }

/* ---------------------------------------------------------------- desktop */
@media (min-width: 900px) {
  #dock { left: auto; right: calc(12px + var(--safe-r)); top: 12px; bottom: 12px; width: 330px; max-height: none; padding: 12px 14px 14px; }
  #dock.collapsed .dock-body { display: block; }
  #grabber { display: none; }
  .chips { flex-wrap: wrap; overflow: visible; }
  #toolbar { right: 356px; top: 12px; }
  .pill-bar { top: auto; bottom: 22px; left: calc(50% - 170px); }
  .toast { top: auto; bottom: 90px; left: calc(50% - 170px); }
  .toast.hint { bottom: 30px; }
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; }
  #split .lab { top: 80px; }
}
@media (max-width: 899px) {
  #toolbar button { width: 46px; height: 46px; }
  #toolbar button span { display: none; }
  #toolbar { top: calc(64px + var(--safe-t)); }
  .pill-bar { left: calc(10px + var(--safe-l)); right: calc(72px + var(--safe-r)); transform: none; max-width: none; border-radius: 16px; flex-wrap: wrap; white-space: normal; justify-content: space-between; row-gap: 4px; padding: 8px 10px; }
  #replaySeek { order: 9; width: 100%; flex-basis: 100%; }
  #replayTime { min-width: 0; }
  .toast { top: calc(150px + var(--safe-t)); }
}
@media (max-width: 899px) and (max-height: 520px) {
  #dock { max-height: 70vh; }
  #toolbar { top: calc(10px + var(--safe-t)); right: auto; left: calc(10px + var(--safe-l)); top: calc(64px + var(--safe-t)); flex-direction: column; }
}
