:root {
  --bg: #0b0e12;
  --surface: #14181e;
  --surface-2: #1b2029;
  --surface-3: #232935;
  --line: #ffffff14;
  --line-strong: #ffffff24;
  --text: #e9edf2;
  --muted: #8d97a5;
  --accent: #5ac8fa;
  --accent-deep: #2aa9e0;
  --accent-soft: #5ac8fa1f;
  --stage: #0d1117;
  --ok: #30d158;
  --bad: #ff453a;
  --warn: #ffd60a;
  --rec: #ff453a;
  --radius: 10px;
  --shadow: 0 1px 2px #00000040, 0 10px 30px #00000038;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13.5px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.005em;
  display: grid;
  grid-template-rows: 48px 1fr;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #ffffff1f; border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #ffffff33; background-clip: content-box; }

header {
  display: flex; align-items: center; gap: 14px;
  padding: 0 16px;
  background: #14181ecc;
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
header .brand { font-weight: 600; letter-spacing: -0.01em; }
header .build { color: var(--muted); font-size: 11px; font-family: var(--mono); opacity: .7; }
header .id { color: var(--muted); }
header .id b { color: var(--text); font-weight: 600; }
header .spacer { flex: 1; }
header #language { width: auto; padding: 4px 6px; }
header .status { color: var(--muted); font-size: 12.5px; }
header .status.bad { color: var(--bad); }

.btn {
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 500;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: transparent; color: #04202c; font-weight: 600; }
.btn.primary:hover { background: #7ad4fb; }
.btn.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn.danger:hover { color: var(--bad); border-color: #ff453a66; }
.btn.small { padding: 2px 9px; font-size: 12px; }
.btn.icon { padding: 5px 9px; min-width: 32px; font-size: 12px; line-height: 1.4; }
.btn:disabled { opacity: .35; cursor: default; }
.btn:disabled:hover { background: var(--surface-2); }

main {
  display: grid;
  grid-template-columns: 46px 1fr 330px;
  grid-template-rows: 1fr auto;
  min-height: 0;
}

/* tool rail */
.rail {
  grid-row: 1 / 3; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 0; background: var(--surface); border-right: 1px solid var(--line);
}
.rail .tool {
  width: 32px; height: 32px; display: grid; place-items: center;
  background: none; border: 0; border-radius: 8px; cursor: pointer; color: var(--muted);
  transition: background .15s, color .15s;
}
.rail .tool svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 1.4; fill: currentColor; }
.rail .tool svg [fill="none"] { fill: none; }
.rail .tool:hover { background: var(--surface-2); color: var(--text); }
.rail .tool.on { background: var(--accent-soft); color: var(--accent); }
.rail #record.on { background: #ff453a24; color: var(--rec); }
.rail #record.armed { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.rail .sep { width: 18px; height: 1px; background: var(--line-strong); margin: 6px 0; }

/* sidebar */
aside {
  grid-row: 1 / 3; grid-column: 3;
  background: var(--surface); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.outliner { border-bottom: 1px solid var(--line); padding: 10px 12px 6px; max-height: 34%; display: flex; flex-direction: column; min-height: 0; }
.outliner h2 { display: flex; align-items: center; gap: 4px; margin: 0 0 8px; }
.outliner h2 .grow { flex: 1; }
.outliner .list { overflow-y: auto; margin: 0 -2px; padding: 0 2px; }
.props { padding: 10px 12px 0; border-bottom: 1px solid var(--line); }
.props .card { margin-bottom: 10px; }
.props .card h3 .kind { color: var(--muted); font-size: 11px; font-weight: 500; text-transform: none; }
.props .card.rec h3 .kind { color: var(--rec); }
.props > .hint { margin: 0 0 10px; }

.tabs {
  display: flex; gap: 2px; margin: 10px 12px 4px; padding: 2px;
  background: var(--surface-2); border-radius: 9px;
}
.tabs button {
  flex: 1; background: none; border: 0; border-radius: 7px; padding: 5px 0; cursor: pointer;
  color: var(--muted); font-size: 12.5px; font-weight: 500;
}
.tabs button.on { background: var(--surface-3); color: var(--text); }
.panel { overflow-y: auto; padding: 12px 14px 24px; flex: 1; }

.list { display: flex; flex-direction: column; gap: 3px; margin-bottom: 14px; }
.item {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid transparent; cursor: pointer;
}
.item:hover { border-color: var(--line-strong); }
.item.on { background: var(--accent-soft); color: var(--accent); }
.item .kind { color: var(--muted); font-size: 12px; margin-left: auto; font-weight: 400; }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }

.card {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 12px 4px; margin-bottom: 10px;
}
.card.rec { border-color: #ff453a55; }
.card h3 { margin: 0 0 10px; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px 8px; flex-wrap: wrap; }
.card h3 .grow { flex: 1; }
.card h3 .kind { color: var(--rec); font-size: 11.5px; font-weight: 500; }

h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin: 6px 0 8px; }

.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line-strong); border-radius: 8px; padding: 5px 9px;
  transition: border-color .15s, box-shadow .15s;
}
select {
  appearance: none; padding-right: 26px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6' fill='none' stroke='%238d97a5' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5 5 5 9 1.5'/%3E%3C/svg%3E");
  background-position: right 9px center; background-size: 10px 6px; background-repeat: no-repeat;
}
select:hover { background-color: var(--surface-2); }
select:hover, select:focus { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6' fill='none' stroke='%235ac8fa' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5 5 5 9 1.5'/%3E%3C/svg%3E"); }
option { background: var(--surface-2); color: var(--text); }

/* number inputs: the native arrows are hidden, ours sit inside the field */
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num { position: relative; display: block; }
.num input { width: 100%; padding-right: 22px; }
.num .spin {
  position: absolute; right: 3px; top: 2px; bottom: 2px; width: 16px;
  display: flex; flex-direction: column; gap: 1px; opacity: .7; transition: opacity .12s;
}
.num:hover .spin, .num:focus-within .spin { opacity: 1; }
.num .spin button {
  flex: 1; display: grid; place-items: center; padding: 0; font-size: 10px; line-height: 1;
  background: #ffffff0f; color: var(--text); border: 0; border-radius: 3px; cursor: pointer;
}
.num .spin button:hover { background: var(--accent); color: #04202c; }
.num .spin button:active { transform: translateY(0.5px); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 64px; font-family: var(--mono); font-size: 12.5px; }
input.bad, textarea.bad { border-color: var(--bad); }
.triple { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.triple input { font-family: var(--mono); font-size: 12.5px; text-align: right; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; cursor: pointer; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }
.hint { color: var(--muted); font-size: 12px; margin: -4px 0 10px; }
.error { color: var(--bad); font-size: 12px; margin: -4px 0 10px; }

/* viewport */
.viewport {
  position: relative; min-height: 0; min-width: 0;
  margin: 10px; border-radius: 14px; overflow: hidden;
  background: var(--stage); box-shadow: var(--shadow);
}
.viewport canvas { display: block; width: 100%; height: 100%; }
.toolbar {
  position: absolute; left: 10px; right: 10px; top: 10px;
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  pointer-events: none;
}
.toolbar .group {
  display: flex; gap: 4px; align-items: center; pointer-events: auto;
  background: #161c25cc; backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--line); border-radius: 12px; padding: 4px;
  box-shadow: 0 2px 14px #00000047;
}
.toolbar .group:last-child { margin-left: auto; }
.toolbar select, .toolbar .btn { width: auto; background-color: transparent; border-color: transparent; box-shadow: none; }
.toolbar .btn { background-image: none; }
.toolbar select { max-width: 170px; text-overflow: ellipsis; }
.toolbar select:hover, .toolbar .btn:hover:not(:disabled) { background-color: #ffffff12; }
.toolbar select:focus { box-shadow: none; border-color: transparent; }
.toolbar .tick { font-family: var(--mono); font-size: 11.5px; color: var(--muted); padding: 0 8px; white-space: nowrap; }

/* timeline */
.timeline { background: var(--surface); border-top: 1px solid var(--line); padding: 10px 14px 14px; max-height: 45vh; overflow-y: auto; }
.timeline[hidden] { display: none; }
.timeline .head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.timeline .head b { color: var(--accent); }
.timeline .head .gap { flex: 1; }
.timeline .head label { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.timeline .head select { width: auto; min-width: 140px; }
.timeline .head .num { width: 74px; }
.timeline .head .tick { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.tracks { display: grid; grid-template-columns: 258px 1fr; gap: 4px 12px; align-items: center; }
.tracklabel { display: flex; gap: 4px; align-items: center; }
.tracklabel select:nth-of-type(1) { width: 82px; flex: none; }
.tracklabel select:nth-of-type(2) { flex: 1; min-width: 0; }
.tracklabel.muted { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.tracklabel select { padding: 2px 18px 2px 6px; font-size: 12px; background-position: right 5px center; background-size: 8px 5px; }

.scrub {
  position: relative; height: 22px; cursor: ew-resize; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  touch-action: none; user-select: none;
}
.scrub i {
  position: absolute; top: 3px; font-style: normal; font-size: 10px; font-family: var(--mono);
  color: var(--muted); transform: translateX(-50%); pointer-events: none;
}
.lane {
  position: relative; height: 24px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; cursor: copy;
}
.lane .key {
  position: absolute; top: 50%; width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px; transform: rotate(45deg);
  background: var(--accent); border: 2px solid var(--bg); border-radius: 2px; cursor: ew-resize;
}
.lane .key.on { background: var(--warn); }
.lane .ghost {
  position: absolute; top: 50%; width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px; transform: rotate(45deg);
  border: 1.5px solid var(--accent); border-radius: 2px; opacity: 0; pointer-events: none; transition: opacity .1s;
}
.lane:hover .ghost { opacity: .55; }
.tracklabel .btn.key { padding: 2px 6px; color: var(--accent); }
.lane .ruler { position: absolute; inset: 0; pointer-events: none; }
.lane .ruler i { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line); }
.playhead {
  position: absolute; top: -1px; bottom: -1px; width: 2px; margin-left: -1px; border-radius: 2px;
  background: var(--ok); pointer-events: none; box-shadow: 0 0 8px #30d15880;
}
.inspector { display: grid; grid-template-columns: 90px 110px 1fr 160px auto; gap: 8px; align-items: end; margin-top: 12px; }
.inspector canvas { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }

/* right-click menu */
.menu {
  position: fixed; z-index: 20; min-width: 190px; padding: 5px;
  background: #1b2029f2; backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: 0 12px 34px #00000073;
}
.menu button {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: none; border: 0; border-radius: 6px; padding: 5px 9px; cursor: pointer; font-size: 13px;
}
.menu button:hover:not(:disabled) { background: var(--accent); color: #04202c; }
.menu button:hover:not(:disabled) kbd { color: #04202cb3; }
.menu button.danger:hover:not(:disabled) { background: var(--bad); color: #fff; }
.menu button:disabled { opacity: .45; cursor: default; }
.menu kbd { margin-left: auto; font: 11px var(--mono); color: var(--muted); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }

/* landing & dialogs */
.landing { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 5; }
.landing[hidden] { display: none; }
.landing .box {
  width: min(440px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px; box-shadow: var(--shadow);
}
.landing h1 { margin: 0 0 6px; font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.landing p { color: var(--muted); margin: 0 0 18px; }
.landing code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.modal { position: fixed; inset: 0; background: #000000a6; backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 6; }
.modal[hidden] { display: none; }
.modal .box {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 22px;
  width: min(520px, calc(100vw - 32px)); box-shadow: 0 20px 60px #00000080;
}
.modal h2 { color: var(--text); font-size: 15px; text-transform: none; letter-spacing: -0.01em; }
.command { font-family: var(--mono); background: var(--bg); border-radius: 10px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.command code { flex: 1; overflow-x: auto; }
.problems { color: var(--bad); padding-left: 18px; }

.tools { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.tools input[type=color] { width: 28px; height: 24px; padding: 0 2px; border-radius: 6px; cursor: pointer; }
.picker { display: flex; gap: 6px; margin: 4px 0 6px; }
.picker select { flex: 1; min-width: 0; }
.swap { border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin-bottom: 8px; }
.swap .grow { flex: 1; }
.axis { position: relative; }
.axis::before { content: attr(data-axis-label); position: absolute; left: 7px; top: 50%; transform: translateY(-50%); font-size: 10px; color: var(--muted); pointer-events: none; z-index: 1; }
.axis input { padding-left: 18px; }
.steps { padding-left: 18px; margin: 6px 0 0; }
.steps li { margin-bottom: 4px; }
.modal .steps { color: var(--muted); }
table.keys { width: 100%; border-collapse: collapse; margin-bottom: 14px; font-size: 12.5px; }
table.keys td { padding: 3px 6px; color: var(--muted); }
table.keys kbd { font-family: var(--mono); color: var(--text); white-space: nowrap; }
header .status { cursor: default; }
.landing h2 { margin: 18px 0 6px; font-size: 12px; }
.landing label.btn { display: inline-flex; align-items: center; cursor: pointer; }
.landing .card { margin-bottom: 12px; }

@media (max-width: 980px) {
  main { grid-template-columns: 46px 1fr; grid-template-rows: 44vh auto auto; }
  aside { grid-row: auto; grid-column: 2; order: 3; border-left: 0; border-top: 1px solid var(--line); max-height: none; }
  .rail { grid-row: 1 / 4; }
  .viewport { order: 1; }
  .timeline { order: 2; }
  .tracks { grid-template-columns: 1fr; }
  .inspector { grid-template-columns: 1fr 1fr; }
  .toolbar .group:last-child { margin-left: 0; }
}

.recipes summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.recipes select, .recipes input[type=text], .recipes input[type=number] { width: 100%; margin-top: 8px; }
.recipes > .btn.primary { margin-top: 4px; }
