:root {
    /* ---- surface tiers (pure monochrome, OKLCH, never #000) ---- */
    --bg:       oklch(0.155 0 0);   /* page */
    --panel:    oklch(0.185 0 0);   /* control panel */
    --surface:  oklch(0.205 0 0);   /* inputs, seg, meters */
    --elev:     oklch(0.255 0 0);   /* active / hover fill */
    --line:     oklch(0.285 0 0);   /* border */
    --line2:    oklch(0.225 0 0);   /* subtle divider */
    /* ---- ink (off-white, never #fff) ---- */
    --ink:      oklch(0.945 0 0);
    --muted:    oklch(0.640 0 0);
    --subtle:   oklch(0.480 0 0);
    /* ---- the one high-contrast moment: light fill (mono primary) ---- */
    --accent:      oklch(0.945 0 0);
    --accent-hi:   oklch(0.985 0 0);   /* hover */
    --accent-ink:  oklch(0.185 0 0);   /* text on accent */
    --accent-soft: oklch(0.945 0 0 / 0.20);   /* focus ring */
    --accent-dim:  oklch(0.945 0 0 / 0.14);

    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    /* radii (concentric scale) */
    --r-sm: 5px; --r-md: 7px; --r-lg: 10px; --r-xl: 13px;

    --label-col: 90px;   /* Figma-style property label column */

    --ease: cubic-bezier(.2,0,0,1);
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; margin: 0; }
  body { background: var(--bg); color: var(--ink); font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
    display: grid; grid-template-columns: 1fr 340px; height: 100vh; }
  @media (max-width: 720px) { body { grid-template-columns: 1fr; grid-template-rows: 55vh auto; } }

  /* ---------- stage ---------- */
  .stage { position: relative; overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
  .stagebar { display: flex; align-items: center; justify-content: flex-start; gap: 20px;
    padding: 11px 16px; border-bottom: 1px solid var(--line2); flex: none; }
  .canvas-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
    overflow: hidden; padding: 24px; }
  canvas { max-width: 100%; max-height: 100%; display: block; border-radius: var(--r-sm);
    box-shadow: 0 0 0 1px var(--line), 0 18px 50px -20px rgba(0,0,0,.7); }
  .tag { font-size: 11px; letter-spacing: .16em; color: var(--ink); text-transform: uppercase; font-weight: 500; }
  .bar-left { display: flex; align-items: center; gap: 10px; }
  .ver { font-size: 10px; color: var(--subtle); letter-spacing: .05em; }
  .about { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 50%;
    width: 20px; height: 20px; font-size: 11px; line-height: 1; cursor: pointer; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    transition: color .15s var(--ease), border-color .15s var(--ease), background-color .15s var(--ease); }
  .about:hover { color: var(--ink); border-color: var(--muted); background: var(--surface); }
  .about:active { transform: scale(.94); }
  .about:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); border-color: var(--accent); }

  /* ---------- resolution control ---------- */
  .resctl { display: flex; align-items: center; gap: 9px; font-size: 11px; color: var(--muted); }
  .resctl label { text-transform: uppercase; letter-spacing: .10em; font-size: 10px; }
  .resctl select, .rescustom input { background: var(--surface); color: var(--ink);
    border: 1px solid var(--line); border-radius: var(--r-sm); padding: 5px 7px; font: inherit; font-size: 11px;
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease); }
  .resctl select:hover, .rescustom input:hover { border-color: var(--muted); }
  .resctl select:focus-visible, .rescustom input:focus-visible { outline: none;
    border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  .resctl { flex-wrap: nowrap; }
  .resctl select { flex: none; width: auto; max-width: 220px; }   /* not 100% — leave room for custom inputs */
  .rescustom { display: inline-flex; align-items: center; gap: 6px; flex: none; }   /* never shrink — keeps w × h on screen */
  .rescustom[hidden] { display: none; }   /* show only when Custom… is selected */
  .rescustom input { flex: none; width: 76px; text-align: center; padding: 5px 8px;
    -webkit-appearance: none; -moz-appearance: textfield; appearance: none; }
  .rescustom input::-webkit-outer-spin-button,
  .rescustom input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

  /* ---------- welcome modal ---------- */
  .welcome { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
    background: color-mix(in oklab, var(--bg) 70%, transparent); backdrop-filter: blur(6px); padding: 20px; }
  .welcome[hidden] { display: none; }
  .welcome-card { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--r-xl); padding: 24px 24px 22px;
    box-shadow: 0 1px 0 0 rgba(255,255,255,.03) inset, 0 30px 70px -20px rgba(0,0,0,.75); }
  .welcome-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
  .welcome-head h2 { margin: 0; font-size: 18px; letter-spacing: .01em; text-wrap: balance; }
  .welcome-ver { font-size: 11px; color: var(--subtle); font-weight: 400; margin-left: 5px; }
  .welcome-x { background: none; border: 0; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer;
    padding: 0 4px; transition: color .15s var(--ease); }
  .welcome-x:hover { color: var(--ink); }
  .welcome-x:focus-visible { outline: none; color: var(--ink); box-shadow: 0 0 0 3px var(--accent-soft); border-radius: var(--r-sm); }
  .welcome-lede { margin: 0 0 16px; color: var(--ink); font-size: 12.5px; line-height: 1.6; text-wrap: pretty; }
  .welcome-feats { margin: 0 0 16px; padding: 0; list-style: none; display: grid; gap: 9px; }
  .welcome-feats li { font-size: 12px; line-height: 1.5; color: var(--muted); padding-left: 16px; position: relative; }
  .welcome-feats li::before { content: ''; position: absolute; left: 0; top: 6px; width: 5px; height: 5px;
    background: var(--accent); border-radius: 50%; }
  .welcome-feats b { color: var(--ink); font-weight: 600; }
  .welcome-tip { margin: 0 0 20px; font-size: 12px; color: var(--muted); line-height: 1.5; text-wrap: pretty; }
  .welcome-go { width: 100%; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: var(--r-md);
    padding: 11px; font: inherit; font-weight: 600; font-size: 13px; cursor: pointer;
    transition: background-color .15s var(--ease), transform .08s var(--ease); }
  .welcome-go:hover { background: var(--accent-hi); }
  .welcome-go:active { transform: scale(.98); }
  .welcome-go:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

  /* ---------- panel ---------- */
  .panel { background: var(--panel); border-left: 1px solid var(--line2); overflow-y: auto; font-size: 12px; }
  .panel::-webkit-scrollbar { width: 11px; }
  .panel::-webkit-scrollbar-thumb { background: var(--line); border: 3px solid var(--panel); border-radius: 999px; }
  .panel::-webkit-scrollbar-thumb:hover { background: var(--subtle); }
  .panel { scrollbar-width: thin; scrollbar-color: var(--line) var(--panel); }

  .head { padding: 20px 18px 16px; border-bottom: 1px solid var(--line2); position: sticky; top: 0;
    background: var(--panel); z-index: 2; }
  .head h1 { font-size: 12px; letter-spacing: .18em; text-transform: uppercase; margin: 0 0 3px; font-weight: 600; }
  .head .sub { color: var(--muted); margin: 0; font-size: 11px; letter-spacing: .02em; }

  details { border-bottom: 1px solid var(--line2); }
  summary { list-style: none; cursor: pointer; padding: 15px 18px; font-size: 10px;
    letter-spacing: .16em; text-transform: uppercase; color: var(--ink);
    display: flex; align-items: center; justify-content: space-between; user-select: none; font-weight: 500;
    transition: color .15s var(--ease); }
  summary::-webkit-details-marker { display: none; }
  summary::after { content: '+'; color: var(--subtle); font-size: 14px; line-height: 1;
    transition: color .15s var(--ease); }
  details[open] > summary::after { content: '\2013'; }
  summary:hover { color: var(--accent); }
  summary:hover::after { color: var(--accent); }
  summary:focus-visible { outline: none; color: var(--accent); }
  .group { padding: 4px 18px 20px; }

  /* ---------- fields ---------- */
  .field { margin-bottom: 11px; }
  .field:last-child { margin-bottom: 2px; }
  .field > label { display: flex; justify-content: space-between; align-items: baseline; color: var(--muted);
    letter-spacing: .07em; text-transform: uppercase; font-size: 10px; margin-bottom: 7px; }
  .field .val { color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: 0; }
  .row { display: flex; gap: 8px; } .row > * { flex: 1; min-width: 0; }

  /* ===== Figma-style property rows: label-left, control-right, aligned column ===== */
  /* slider rows: NAME | slider | value */
  .field:has(> input[type=range]) {
    display: grid; grid-template-columns: var(--label-col, 78px) 1fr auto;
    align-items: center; column-gap: 11px; margin-bottom: 9px; }
  .field:has(> input[type=range]) > label {
    display: contents; }
  .field:has(> input[type=range]) > label .val {
    order: 3; min-width: 30px; text-align: right; font-size: 11px; }
  .field:has(> input[type=range]) > input[type=range] { order: 2; }
  /* select / segmented rows WITH a label: NAME | control */
  .field:has(> select):has(> label),
  .field:has(> .seg):has(> label) {
    display: grid; grid-template-columns: var(--label-col, 78px) 1fr;
    align-items: center; column-gap: 11px; }
  .field:has(> select) > label,
  .field:has(> .seg) > label { margin-bottom: 0; }
  /* control-only seg (no label, e.g. Source toggle) stays full width — default block */
  /* paired sub-controls inside a .row keep their stacked mini-label (W/H, FG/BG, FPS…) */
  .row > div > label { display: flex; justify-content: space-between; align-items: baseline;
    color: var(--muted); font-size: 10px; letter-spacing: .07em; text-transform: uppercase;
    margin-bottom: 7px; }
  .row > div > label .val { color: var(--ink); }

  /* ---------- inputs ---------- */
  select, textarea, input[type=color], input[type=file], input[type=number] {
    width: 100%; background: var(--surface); color: var(--ink);
    border: 1px solid var(--line); border-radius: var(--r-md); padding: 8px 9px;
    font-family: var(--mono); font-size: 12px;
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease), background-color .15s var(--ease); }
  select:hover, textarea:hover, input[type=number]:hover, input[type=file]:hover { border-color: var(--muted); }
  select:focus-visible, textarea:focus-visible, input[type=number]:focus-visible,
  input[type=color]:focus-visible, input[type=file]:focus-visible {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  input[type=file] { color: var(--muted); font-size: 11px; padding: 7px 9px; cursor: pointer; }
  input[type=color] { padding: 4px; height: 34px; cursor: pointer; }
  textarea { resize: vertical; min-height: 56px; line-height: 1.45; }

  /* ---------- range slider (custom, cross-browser) ---------- */
  input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px;
    background: transparent; cursor: pointer; }
  input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 999px;
    background: var(--elev); }
  input[type=range]::-moz-range-track { height: 4px; border-radius: 999px; background: var(--elev); }
  input[type=range]::-moz-range-progress { height: 4px; border-radius: 999px; background: var(--accent-dim); }
  input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none;
    width: 14px; height: 14px; margin-top: -5px; border-radius: 50%;
    background: var(--ink); border: 1px solid var(--line);
    box-shadow: 0 1px 3px rgba(0,0,0,.5);
    transition: background-color .12s var(--ease), transform .12s var(--ease), box-shadow .12s var(--ease); }
  input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%;
    background: var(--ink); border: 1px solid var(--line); box-shadow: 0 1px 3px rgba(0,0,0,.5);
    transition: background-color .12s var(--ease), transform .12s var(--ease); }
  input[type=range]:hover::-webkit-slider-thumb { background: var(--accent); border-color: var(--accent); }
  input[type=range]:hover::-moz-range-thumb { background: var(--accent); border-color: var(--accent); }
  input[type=range]:active::-webkit-slider-thumb { transform: scale(1.12); }
  input[type=range]:focus-visible { outline: none; }
  input[type=range]:focus-visible::-webkit-slider-thumb {
    background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
  input[type=range]:focus-visible::-moz-range-thumb {
    background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

  /* ---------- segmented control (active = light fill, accent reserved) ---------- */
  .seg { display: flex; background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-md); overflow: hidden; padding: 2px; gap: 2px; }
  .seg button { flex: 1; background: transparent; color: var(--muted); border: 0; padding: 6px 0;
    font-family: var(--mono); font-size: 11px; cursor: pointer; border-radius: var(--r-sm);
    transition: color .15s var(--ease), background-color .15s var(--ease); }
  .seg button:hover { color: var(--ink); }
  .seg button[aria-pressed=true] { background: var(--elev); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.35); }
  .seg button:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--accent-soft); position: relative; z-index: 1; }
  .seg button:active { transform: scale(.97); }

  /* ---------- buttons ---------- */
  .playbtn { width: 100%; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: var(--r-md);
    padding: 10px 0; font-family: var(--mono); font-size: 12px; font-weight: 600; cursor: pointer; letter-spacing: .04em;
    transition: background-color .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease),
      transform .08s var(--ease), box-shadow .15s var(--ease); }
  .playbtn:hover { background: var(--accent-hi); }
  .playbtn:active { transform: scale(.97); }
  .playbtn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
  .playbtn.playing { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
  .playbtn:disabled { opacity: .4; cursor: default; transform: none; }
  .playbtn.alt { background: var(--surface); color: var(--ink); border: 1px solid var(--line); font-weight: 500; }
  .playbtn.alt:hover { background: var(--elev); border-color: var(--muted); }
  .playbtn.alt.playing { background: var(--accent); color: var(--accent-ink); border: 0; }

  /* ---------- spectrum meters ---------- */
  .meters { display: flex; gap: 6px; height: 44px; align-items: flex-end; }
  .meter { flex: 1; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
    height: 100%; display: flex; align-items: flex-end; overflow: hidden; }
  .meter i { display: block; width: 100%; height: 0%; background: var(--accent);
    transition: height .06s linear; }
  .meterlabels { display: flex; gap: 6px; margin-top: 6px; }
  .meterlabels span { flex: 1; text-align: center; color: var(--subtle); font-size: 9px;
    text-transform: uppercase; letter-spacing: .10em; }

  /* ---------- export sub-sections ---------- */
  .subhead { display: flex; align-items: center; gap: 6px;
    color: var(--muted); font-size: 9px; letter-spacing: .16em; text-transform: uppercase;
    margin: 6px 0 12px; padding-top: 16px; border-top: 1px solid var(--line2); }
  .subhead:first-child { padding-top: 0; border-top: 0; }

  /* info ⓘ trigger + hover/focus tooltip (replaces inline .note blocks) */
  .info { position: relative; flex: none; margin-left: auto; width: 15px; height: 15px;
    border: 1px solid var(--line); border-radius: 50%; background: none; color: var(--subtle);
    font: 600 9px/1 var(--mono); cursor: help; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    transition: color .15s var(--ease), border-color .15s var(--ease); }
  .info::before { content: 'i'; transform: translateY(.5px); }
  .info:hover, .info:focus-visible { outline: none; color: var(--ink); border-color: var(--muted); }
  .info:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); }
  .tip { position: absolute; bottom: calc(100% + 9px); right: -2px; width: 250px; max-width: 80vw;
    background: var(--elev); color: var(--muted); border: 1px solid var(--line); border-radius: var(--r-md);
    padding: 10px 12px; font: 400 10.5px/1.55 var(--mono); letter-spacing: 0; text-transform: none;
    text-align: left; text-wrap: pretty; box-shadow: 0 14px 34px -12px rgba(0,0,0,.8);
    opacity: 0; visibility: hidden; transform: translateY(4px); pointer-events: none; z-index: 6;
    transition: opacity .15s var(--ease), transform .15s var(--ease), visibility .15s var(--ease); }
  .info:hover .tip, .info:focus-visible .tip { opacity: 1; visibility: visible; transform: translateY(0); }

  /* ---------- time / progress ---------- */
  .timerow { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; margin-bottom: 7px;
    font-variant-numeric: tabular-nums; }
  .track { height: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
  .track i { display: block; height: 100%; width: 0%; background: var(--accent); transition: width .1s linear; }
  #beatdot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
    opacity: .18; vertical-align: middle; margin-left: 3px; transition: opacity .08s var(--ease); }
