:root {
  --bg: #f4f3ef;
  --panel: #ffffff;
  --ink: #16161a;
  --ink-2: #5b5b66;
  --ink-3: #9a9aa5;
  --line: #e4e2dc;
  --soft: #efede7;
  --accent: #ff5a1f;
  --accent-ink: #ffffff;
  --accent-soft: #ffe7dc;
  --code-bg: #16161a;
  --code-ink: #e9e7e1;
  --radius: 14px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter Tight", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f12;
    --panel: #17171c;
    --ink: #f1f0ec;
    --ink-2: #a9a9b3;
    --ink-3: #6c6c78;
    --line: #2a2a32;
    --soft: #212128;
    --accent: #ff6a33;
    --accent-ink: #120a06;
    --accent-soft: #3a1e12;
    --code-bg: #0b0b0e;
    --code-ink: #e9e7e1;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 20px 24px 8px;
  max-width: 1400px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 34px; height: 34px; color: var(--ink); flex: none; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: -0.01em; }
.brand p { margin: 0; color: var(--ink-2); font-size: 13px; }

/* Layout */
.layout {
  max-width: 1400px; margin: 0 auto; padding: 16px 24px 24px;
  display: grid; gap: 16px;
  grid-template-columns: 250px minmax(0, 1fr) 320px;
  grid-template-areas:
    "presets stage controls"
    "presets export export";
  align-items: start;
}
.presets { grid-area: presets; }
.stage-panel { grid-area: stage; }
.controls { grid-area: controls; }
.export { grid-area: export; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.panel-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-2); margin: 0 0 12px; font-weight: 600;
}

/* Buttons */
.btn {
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 10px; padding: 8px 14px; font-weight: 600; font-size: 14px;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; white-space: nowrap; }

.seg {
  display: inline-flex; background: var(--soft); border-radius: 10px; padding: 3px; gap: 2px;
  flex-wrap: wrap;
}
.seg button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 500; color: var(--ink-2);
}
.seg button[aria-selected="true"], .seg button.on {
  background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12);
}
.seg.full { display: flex; }
.seg.full button { flex: 1; }

/* Presets */
.preset-list { display: flex; flex-direction: column; gap: 6px; }
.preset {
  display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: center;
  text-align: left; border: 1px solid transparent; background: transparent;
  border-radius: 10px; padding: 8px;
}
.preset:hover { background: var(--soft); }
.preset.on { border-color: var(--accent); background: var(--accent-soft); }
.preset svg { width: 44px; height: 32px; }
.preset svg path { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.preset b { display: block; font-size: 14px; font-weight: 600; }
.preset small { display: block; color: var(--ink-2); font-size: 12px; line-height: 1.3; }
.preset .tag {
  display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); margin-left: 4px; font-weight: 600;
}

/* Stage */
.stage-head { display: flex; justify-content: space-between; margin-bottom: 12px; }
.stage {
  position: relative; height: 260px; border-radius: 12px; overflow: hidden;
  background:
    radial-gradient(circle at 1px 1px, var(--line) 1px, transparent 0) 0 0 / 16px 16px,
    var(--soft);
}
.scene { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; }
.scene.on { display: flex; }

/* Move */
.track { position: relative; width: 78%; height: 64px; border-radius: 32px; background: var(--panel); border: 1px dashed var(--line); }
.puck { position: absolute; left: 6px; top: 6px; width: 52px; height: 52px; border-radius: 50%; background: var(--accent); will-change: transform; }

/* Phone-ish screen */
.screen {
  position: relative; width: 200px; height: 232px; border-radius: 18px; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line);
}
.fake-ui { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.fake-ui i { display: block; height: 34px; border-radius: 8px; background: var(--soft); }
.scrim { position: absolute; inset: 0; background: rgba(10,10,14,.45); opacity: 0; }
.modal {
  position: absolute; left: 16px; right: 16px; top: 50px; padding: 14px;
  border-radius: 14px; background: var(--panel); box-shadow: 0 12px 30px rgba(0,0,0,.25);
  display: flex; flex-direction: column; gap: 8px; opacity: 0; will-change: transform, opacity;
}
.line { height: 8px; border-radius: 4px; background: var(--soft); }
.line.strong { height: 10px; background: var(--ink-3); }
.w50 { width: 50%; } .w70 { width: 70%; } .w90 { width: 90%; }
.btn-row { display: flex; justify-content: flex-end; gap: 6px; margin-top: 4px; }
.btn-row span { width: 44px; height: 20px; border-radius: 6px; background: var(--soft); }
.btn-row span.primary { background: var(--accent); }

/* Dropdown */
.dd { position: relative; width: 210px; align-self: flex-start; margin-top: 36px; }
.dd-trigger {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; display: flex; justify-content: space-between; font-weight: 500; font-size: 14px;
}
.dd-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px;
  box-shadow: 0 12px 30px rgba(0,0,0,.14); transform-origin: top center; opacity: 0;
  font-size: 14px; will-change: transform, opacity;
}
.dd-menu div { padding: 8px 10px; border-radius: 8px; }
.dd-menu .active { background: var(--soft); }

/* Toast */
.toast {
  position: absolute; left: 12px; right: 12px; bottom: 14px;
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 12px;
  font-size: 13px; font-weight: 500; display: flex; gap: 8px; align-items: center;
  will-change: transform;
}
.toast .tick { color: var(--accent); font-weight: 700; }

/* Toggle */
.toggle-wrap {
  display: flex; align-items: center; gap: 18px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 16px 20px; font-weight: 500;
}
.switch {
  --p: 0;
  position: relative; width: 56px; height: 32px; border-radius: 16px;
  background: color-mix(in oklab, var(--accent) calc(var(--p) * 100%), var(--line));
}
.knob {
  position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); will-change: transform;
}

/* Tabs */
.tabbar {
  position: relative; display: flex; gap: 4px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; padding: 6px 6px 10px;
}
.tabbar span { padding: 8px 14px; font-size: 14px; font-weight: 500; }
.ink { position: absolute; bottom: 5px; height: 3px; border-radius: 2px; background: var(--accent); }

/* Playbar */
.playbar { display: flex; align-items: center; gap: 16px; margin: 12px 0; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.check input { accent-color: var(--accent); }
.meta { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--ink-2); }

/* Graph */
.graph-wrap { border-top: 1px solid var(--line); padding-top: 12px; }
#graph { width: 100%; max-width: 480px; margin: 0 auto; height: auto; display: block; touch-action: none; user-select: none; }
#graph .axis { stroke: var(--line); stroke-width: 1; }
#graph .guide { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 4; }
#graph .axis-label { fill: var(--ink-3); font: 10px var(--mono); }
#graph .curve { fill: none; stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
#graph .arm { stroke: var(--accent); stroke-width: 1.5; }
#graph .handle { fill: var(--panel); stroke: var(--accent); stroke-width: 2.5; cursor: grab; }
#graph .handle:hover { fill: var(--accent-soft); }
#graph .handle-hit { fill: transparent; cursor: grab; }
#playhead { fill: var(--accent); }
.hint { margin: 6px 0 0; font-size: 12px; color: var(--ink-3); }

/* Controls */
.field { display: block; margin-bottom: 16px; }
.label {
  display: flex; justify-content: space-between; font-size: 12px; font-weight: 600;
  color: var(--ink-2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .06em;
}
.label output { font-family: var(--mono); color: var(--ink); text-transform: none; letter-spacing: 0; font-weight: 500; }
input[type="text"], input[type="number"] {
  width: 100%; background: var(--soft); border: 1px solid transparent; border-radius: 8px;
  padding: 8px 10px; font-family: var(--mono); font-size: 13px;
}
input[type="text"]:focus, input[type="number"]:focus { border-color: var(--accent); outline: none; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.quad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.quad label small { display: block; font-family: var(--mono); font-size: 11px; color: var(--ink-3); margin-bottom: 2px; }
.quad input { padding: 6px; }

.feel { background: var(--soft); border-radius: 10px; padding: 12px; }
.feel p { margin: 0 0 8px; font-weight: 500; }
.feel dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.feel dt { color: var(--ink-2); }
.feel dd { margin: 0; font-family: var(--mono); text-align: right; }

/* Export */
.export-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.export-head .panel-title { margin: 0; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button {
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 5px 12px; font-size: 13px; font-weight: 500; color: var(--ink-2);
}
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.export-desc { color: var(--ink-2); font-size: 14px; margin: 12px 0; }
.code-wrap { position: relative; }
.code-wrap pre {
  margin: 0; background: var(--code-bg); color: var(--code-ink); border-radius: 12px;
  padding: 18px; overflow: auto; font: 13px/1.6 var(--mono); max-height: 360px;
}
.btn.copy {
  position: absolute; top: 10px; right: 10px; background: var(--accent); color: var(--accent-ink);
  border: 0; padding: 6px 12px; font-size: 13px;
}

.foot {
  max-width: 1400px; margin: 0 auto; padding: 8px 24px 32px;
  display: flex; justify-content: space-between; color: var(--ink-3); font-size: 13px;
}

.toast-note {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s cubic-bezier(0.2, 0, 0, 1);
}
.toast-note.show { opacity: 1; transform: translate(-50%, 0); }

/* Responsive */
@media (max-width: 1100px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-areas: "stage controls" "export export" "presets presets";
  }
  .preset-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}
@media (max-width: 760px) {
  .top { padding: 16px 16px 4px; }
  .brand p { display: none; }
  .layout {
    padding: 12px 16px 16px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "stage" "controls" "export" "presets";
  }
  .stage { height: 240px; }
  .foot { padding: 8px 16px 24px; flex-direction: column; gap: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  .toast-note { transition: none; }
}
