/* Visual Harmonics: design tokens + shared components (see PLAN.md §3). */
:root {
  --bg: #0b0d12; --surface: #141824; --surface-2: #1a1f2e; --line: #262b3a;
  --text: #d8dce6; --muted: #7a8194; --accent: #6fa3ff; --glow: #9ff;
  --h-navy: #080a28; --h-violet: #611a8c; --h-cyan: #00bfdc; --h-white: #fff;
  --radius: 10px; --top: 52px; --ease: 200ms ease; --panel-w: 340px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font);
  display: grid; grid-template-rows: var(--top) 1fr; height: 100dvh; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }

/* ---------- top bar ---------- */
.vh-top {
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  border-bottom: 1px solid var(--line); background: rgba(11, 13, 18, 0.92); position: relative; z-index: 20;
}
.vh-brand { display: flex; align-items: center; gap: 9px; color: var(--text); text-decoration: none; font-weight: 600; letter-spacing: 0.04em; flex: 1 1 0; min-width: 0; white-space: nowrap; }
.vh-brand svg { flex: none; }
.vh-brand span { overflow: hidden; text-overflow: ellipsis; }
.vh-tabs { display: flex; gap: 4px; padding: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; flex: none; }
.vh-tab {
  border: 0; background: transparent; color: var(--muted); padding: 5px 14px; border-radius: 999px; cursor: pointer;
  text-decoration: none; font-size: 13px; transition: background var(--ease), color var(--ease);
}
.vh-tab:hover { color: var(--text); }
.vh-tab[aria-current="page"] { background: var(--accent); color: #07101f; font-weight: 600; }
.vh-top-right { flex: 1 1 0; display: flex; justify-content: flex-end; }
.vh-icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: transparent;
  color: var(--muted); cursor: pointer; font-size: 17px; line-height: 1; transition: color var(--ease), border-color var(--ease);
}
.vh-icon-btn:hover { color: var(--text); border-color: var(--muted); }
.vh-text-btn {
  height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent;
  color: var(--muted); cursor: pointer; font-size: 13px; letter-spacing: 0.02em; transition: color var(--ease), border-color var(--ease);
}
.vh-text-btn:hover { color: var(--text); border-color: var(--muted); }
@media (max-width: 620px) {
  .vh-brand span { display: none; }
  .vh-top { padding: 0 10px; gap: 8px; }
  .vh-tab { padding: 5px 10px; }
}

/* ---------- stage + experiment layout ---------- */
.vh-stage { position: relative; overflow: hidden; min-height: 0; }
.vh-exp { position: absolute; inset: 0; }
.vh-canvas-box {
  position: absolute; inset: 0; padding: 14px 16px 118px; display: flex; align-items: center; justify-content: center;
}
.vh-canvas-box canvas { display: block; touch-action: none; border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45); }
.vh-caption {
  position: absolute; left: 16px; right: 16px; bottom: 84px; text-align: center; color: var(--muted);
  font: 12px/1.4 var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
.vh-caption b { color: var(--text); font-weight: 600; }
.vh-sw { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin: 0 4px 0 10px; vertical-align: 0; }

/* ---------- dock ---------- */
.vh-dock {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 5;
  display: flex; gap: 4px; padding: 5px; max-width: calc(100% - 16px); overflow-x: auto; scrollbar-width: none;
  background: rgba(20, 24, 36, 0.88); border: 1px solid var(--line); border-radius: 14px;
  backdrop-filter: blur(8px); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.vh-dock::-webkit-scrollbar { display: none; }
.vh-dock-btn {
  flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 58px; height: 54px; padding: 4px 8px; border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; color: var(--text); cursor: pointer; transition: background var(--ease), border-color var(--ease), color var(--ease);
  position: relative; user-select: none;
}
.vh-dock-btn:hover { background: var(--surface-2); }
.vh-dock-btn .ic { font-size: 18px; line-height: 20px; height: 20px; display: flex; align-items: center; gap: 4px; }
.vh-dock-btn .lb { font-size: 11px; color: var(--muted); white-space: nowrap; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
.vh-dock-btn[aria-pressed="true"] { background: rgba(111, 163, 255, 0.16); border-color: rgba(111, 163, 255, 0.5); }
.vh-dock-btn[aria-pressed="true"] .lb { color: var(--accent); }
.vh-dock-sep { width: 1px; margin: 8px 2px; background: var(--line); flex: none; }
.vh-dock-select select {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.vh-dock-select:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.vh-dock-select .lb { color: var(--text); }
.vh-dock-select .lb::after { content: ' ▾'; color: var(--muted); }
.vh-swatches { display: flex; gap: 5px; }
.vh-swatches i { width: 12px; height: 12px; border-radius: 50%; opacity: 0.35; transition: opacity var(--ease), transform var(--ease); }
.vh-swatches i.on { opacity: 1; transform: scale(1.25); }
@media (max-width: 460px) {
  .vh-dock-btn { min-width: 50px; padding: 4px 5px; }
  .vh-dock-btn .lb { max-width: 76px; }
}

/* ---------- Settings panel: pushes the stage on desktop, bottom sheet on phones ---------- */
.vh-drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: var(--panel-w); z-index: 10;
  background: var(--surface); border-left: 1px solid var(--line);
  transform: translateX(105%); transition: transform 220ms ease, visibility 0s 220ms; visibility: hidden;
  display: flex; flex-direction: column;
}
.vh-drawer.open { transform: none; visibility: visible; transition: transform 220ms ease; }
.vh-drawer-grab { display: none; }
.vh-drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 8px; border-bottom: 1px solid var(--line); }
.vh-drawer-head h2 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: 0.03em; }
.vh-drawer-body { overflow-y: auto; padding: 6px 14px 24px; flex: 1; }
@media (min-width: 900px) {
  .vh-exp.vh-pushed > .vh-canvas-box { right: var(--panel-w); }
  .vh-exp.vh-pushed > .vh-caption { right: calc(var(--panel-w) + 16px); }
  .vh-exp.vh-pushed > .vh-dock { left: calc((100% - var(--panel-w)) / 2); max-width: calc(100% - var(--panel-w) - 16px); }
}
@media (max-width: 899px) {
  .vh-drawer {
    top: auto; left: 0; width: auto; max-height: min(64%, 520px); border-left: 0; border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0; box-shadow: 0 -16px 50px rgba(0, 0, 0, 0.55); transform: translateY(105%);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .vh-drawer-grab { display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 0; flex: none; }
  .vh-drawer-head { padding-top: 6px; }
}
/* panel navigation: category tabs + filter (shown once two or more groups have sections) */
.vh-drawer.vh-tabbed .vh-drawer-head { border-bottom: 0; padding-bottom: 2px; }
.vh-drawer-nav { flex: none; display: flex; flex-direction: column; gap: 8px; padding: 0 14px 10px; border-bottom: 1px solid var(--line); }
.vh-ptabs { display: flex; gap: 2px; margin: 0 -14px; padding: 0 10px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.vh-ptabs::-webkit-scrollbar { display: none; }
.vh-ptab {
  flex: none; position: relative; border: 0; background: transparent; color: var(--muted); padding: 9px 10px 10px; font-size: 13px;
  cursor: pointer; border-radius: 8px 8px 0 0; transition: color var(--ease), background var(--ease);
}
.vh-ptab:hover { color: var(--text); background: rgba(255, 255, 255, 0.03); }
.vh-ptab:focus-visible { outline-offset: -2px; }
.vh-ptab[aria-selected="true"] { color: var(--text); font-weight: 600; }
.vh-ptab[aria-selected="true"]::after {
  content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent);
}
.vh-drawer.vh-filtering .vh-ptab[aria-selected="true"]::after { opacity: 0.25; }
.vh-ptab.vh-has-hit::before { content: ''; position: absolute; top: 7px; right: 3px; width: 5px; height: 5px; border-radius: 50%; background: var(--glow); }
.vh-filter {
  display: flex; align-items: center; gap: 7px; height: 30px; padding: 0 10px; color: var(--muted); cursor: text;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; transition: border-color var(--ease);
}
.vh-filter:focus-within { border-color: var(--accent); }
.vh-filter input { flex: 1; min-width: 0; height: 100%; border: 0; padding: 0; background: transparent; color: var(--text); font-size: 13px; outline: none; }
.vh-filter input::placeholder { color: var(--muted); }
.vh-drawer.vh-tabbed .vh-drawer-body { padding-top: 0; }
/* accordion sections */
.vh-acc { border-bottom: 1px solid var(--line); }
.vh-pane > .vh-acc:last-child { border-bottom: 0; }
.vh-acc-h { margin: 0; }
.vh-acc-btn {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 13px 2px 11px 0; border: 0; background: transparent; cursor: pointer;
  color: #aab3c8; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; text-align: left; transition: color var(--ease);
}
.vh-acc-btn:hover { color: var(--text); }
.vh-acc-btn:focus-visible { outline-offset: -2px; border-radius: 6px; }
.vh-acc-btn .t { flex: 1; min-width: 0; }
.vh-acc-btn .chev {
  flex: none; width: 7px; height: 7px; margin: 0 5px 3px 0; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg); transition: transform var(--ease);
}
.vh-acc.closed .vh-acc-btn .chev { transform: rotate(-45deg); margin-bottom: 0; }
.vh-acc-tag { flex: none; font-size: 10px; font-weight: 500; letter-spacing: 0.03em; text-transform: none; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; }
.vh-acc-body { padding-bottom: 12px; }
.vh-acc-body > :first-child { margin-top: 0; }
.vh-acc-plain > .vh-acc-body { padding-top: 10px; }
.vh-acc.closed > .vh-acc-body { display: none; }
.vh-drawer.vh-filtering .vh-acc.vh-hit > .vh-acc-body { display: block; }
.vh-drawer.vh-filtering .vh-pane::before {
  content: attr(data-label) " tab"; display: block; margin: 14px 0 0; font-size: 10.5px; font-weight: 600; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.1em;
}
.vh-miss { display: none !important; }
.vh-filter-empty { color: var(--muted); font-size: 13px; padding: 22px 0; text-align: center; }
/* the Settings toggle stays in reach when the dock scrolls (narrow screens) */
.vh-dock > .vh-settings-btn { position: sticky; right: 0; z-index: 1; background: #161a26; box-shadow: -10px 0 12px -8px rgba(0, 0, 0, 0.7); }
.vh-dock > .vh-settings-btn:hover { background: var(--surface-2); }
.vh-dock > .vh-settings-btn[aria-pressed="true"] { background: #1c2740; }

.vh-select {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; color: var(--text);
  cursor: pointer; max-width: 100%;
}
.vh-section h3 { margin: 16px 0 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.vh-ctl { margin: 10px 0; }
.vh-ctl label { display: flex; justify-content: space-between; font-size: 12px; color: #aab3c8; }
.vh-ctl label span { color: #fff; font-family: var(--mono); }
.vh-ctl input[type="range"] { width: 100%; margin: 6px 0 0; accent-color: var(--accent); }
.vh-desc { font-size: 12px; color: var(--muted); margin: 4px 0; }
.vh-note { font-size: 12px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); padding: 6px 9px; margin: 10px 0; }
.vh-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.vh-btn {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 11px; cursor: pointer;
  color: #c8cde0; transition: background var(--ease), border-color var(--ease);
}
.vh-btn:hover { border-color: var(--muted); }
.vh-btn[aria-pressed="true"] { background: rgba(111, 163, 255, 0.18); border-color: var(--accent); color: #fff; }
.vh-mono { font: 12px/1.6 var(--mono); white-space: pre-wrap; color: #cfd5e6; }
.vh-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.vh-table td { padding: 2px 0; color: #aab3c8; }
.vh-table td + td { text-align: right; color: #fff; font-family: var(--mono); }

/* ---------- local-only banner (file://) ---------- */
body.vh-has-banner { grid-template-rows: var(--top) auto 1fr; }
.vh-banner {
  display: flex; align-items: center; justify-content: center; gap: 10px; padding: 5px 44px 5px 16px; position: relative; z-index: 19;
  background: #1a2133; border-bottom: 1px solid #33405e; color: #cfd8ee; font-size: 12.5px; line-height: 1.35; text-align: center;
}
.vh-banner span { min-width: 0; }
.vh-banner-x {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; line-height: 1;
}
.vh-banner-x:hover { color: var(--text); border-color: var(--line); }

/* ---------- shortcut sheet ("?") ---------- */
.vh-sheet {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(5, 6, 10, 0.66); animation: vh-fade 160ms ease;
}
@keyframes vh-fade { from { opacity: 0; } }
.vh-sheet-card {
  width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px 20px 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.vh-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.vh-sheet-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.vh-sheet-head .vh-icon-btn { width: 30px; height: 30px; font-size: 13px; }
.vh-sheet h3 { margin: 14px 0 6px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.vh-sheet dl { margin: 0; }
.vh-sc-row { display: grid; grid-template-columns: minmax(120px, 46%) 1fr; gap: 12px; align-items: baseline; padding: 5px 0; border-top: 1px solid rgba(255, 255, 255, 0.05); }
.vh-sc-row dt { margin: 0; line-height: 1.9; }
.vh-sc-alt { white-space: nowrap; }
.vh-sc-row dd { margin: 0; color: #c3c9d8; font-size: 13px; }
.vh-sheet kbd {
  display: inline-block; min-width: 22px; padding: 1px 6px; border: 1px solid #3a4157; border-bottom-width: 2px; border-radius: 6px;
  background: var(--surface-2); color: var(--text); font: 11.5px/1.5 var(--mono); text-align: center;
}
.vh-sheet dt i { font-style: normal; color: var(--muted); margin: 0 3px; font-size: 11px; }
.vh-sheet dt i.or { margin: 0 6px; }
.vh-sheet-foot { margin: 14px 0 0; color: var(--muted); font-size: 12px; }
@media (max-width: 460px) {
  .vh-sheet-card { padding: 14px 14px 12px; }
  .vh-sc-row { grid-template-columns: 1fr; gap: 2px; }
}

/* ---------- hint ---------- */
.vh-hint {
  position: absolute; left: 50%; bottom: 100px; transform: translateX(-50%); z-index: 4; pointer-events: none;
  max-width: calc(100% - 32px); text-align: center; color: var(--text); font-size: 13px;
  background: rgba(11, 13, 18, 0.72); border: 1px solid var(--line); border-radius: 16px; padding: 6px 14px;
  transition: opacity 600ms ease;
}
.vh-hint.gone { opacity: 0; }

/* ---------- about dialog ---------- */
.vh-about {
  max-width: min(520px, calc(100% - 32px)); background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.vh-about::backdrop { background: rgba(5, 6, 10, 0.7); }
.vh-about h2 { margin: 0 0 10px; font-size: 18px; }
.vh-about p { color: #b9bfcd; margin: 0 0 10px; }
.vh-about .vh-credits { font-size: 12px; color: var(--muted); }
.vh-about form { text-align: right; margin: 0; }

/* ---------- lab ---------- */
.vh-lab { position: absolute; inset: 0; overflow-y: auto; padding: 28px 16px 40px; }
.vh-lab h1 { font-size: 20px; font-weight: 600; margin: 0 auto 4px; max-width: 900px; }
.vh-lab > p { color: var(--muted); margin: 0 auto 20px; max-width: 900px; }
.vh-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; max-width: 900px; margin: 0 auto; }
.vh-card {
  text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 0; cursor: pointer;
  overflow: hidden; transition: border-color var(--ease), transform var(--ease); color: var(--text);
}
.vh-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.vh-card .art { height: 110px; display: block; width: 100%; }
.vh-card .txt { padding: 12px 14px 14px; }
.vh-card b { display: block; font-size: 15px; margin-bottom: 3px; }
.vh-card span { color: var(--muted); font-size: 13px; }
.vh-frame { position: absolute; inset: 0; display: flex; flex-direction: column; }
.vh-frame-bar { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--surface); }
.vh-frame-bar span { color: var(--muted); font-size: 13px; }
.vh-frame iframe { flex: 1; width: 100%; border: 0; background: #0b0d12; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
