/* Analog FPV — mobile-first UI.
   Portrait: video feed on top, a radio-transmitter style control deck below.
   Landscape: full-screen video with the sticks floating in the bottom corners. */

:root {
  --bg: #090b0e;
  --surface: #12161b;
  --surface-2: #1a1f26;
  --surface-3: #232a33;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #eef1f4;
  --muted: #8d97a3;
  --accent: #d4ff3a;
  --accent-ink: #11140a;
  --danger: #ff6b6b;
  --rec: #ff3b3b;
  --scrim: rgba(7, 9, 12, 0.72);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --osd-fs: 13px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body { position: fixed; inset: 0; }
html { touch-action: manipulation; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-user-select: none; user-select: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* ---------- Video stage ---------- */

.stage {
  position: absolute;
  inset: 0;
  background: #000;
  overflow: hidden;
  touch-action: none;
}

.view { display: block; width: 100%; height: 100%; }

.app[data-mode="editor"] .stage { visibility: hidden; }

/* Darken the attract-mode video behind menus. */
.app[data-mode="menu"] .stage::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(9, 11, 14, 0.35) 0%, rgba(9, 11, 14, 0.15) 40%, rgba(9, 11, 14, 0.85) 100%);
  pointer-events: none;
}

/* ---------- OSD ---------- */

.osd {
  position: absolute;
  inset: 7% 9%;
  display: none;
  font: 700 var(--osd-fs)/1.2 var(--mono);
  letter-spacing: 0.04em;
  color: #f3f5f7;
  text-transform: uppercase;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 0 0 3px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  white-space: pre;
}
.app[data-mode="play"] .osd { display: block; }

.osd-row { position: absolute; left: 0; right: 0; display: grid; grid-template-columns: 1fr auto 1fr; gap: 1em; }
.osd-top { top: 0; }
.osd-bottom { bottom: 0; align-items: end; }
.osd-cell { display: flex; flex-direction: column; gap: 0.15em; }
.osd-c { align-items: center; text-align: center; }
.osd-r { align-items: flex-end; text-align: right; }
.osd-big { font-size: 1.35em; }
#osdWarn { color: #ffd23a; }
#osdBest { color: var(--accent); }

.osd-cross {
  position: absolute;
  left: 50%;
  top: 50%;
  display: flex;
  gap: 0.35em;
  align-items: center;
  transform: translate(-50%, -50%);
  opacity: 0.85;
}
.osd-cross i { width: 0.9em; height: 2px; background: #fff; box-shadow: 0 0 0 1px #000; }
.osd-cross b { width: 4px; height: 4px; background: #fff; box-shadow: 0 0 0 1px #000; }
.osd-cross.is-off { display: none; }

.osd-msg {
  position: absolute;
  left: 0;
  right: 0;
  top: 30%;
  text-align: center;
}
#osdMsg { font-size: 2.2em; letter-spacing: 0.08em; }
#osdSub { font-size: 1.05em; margin-top: 0.3em; }
#osdMsg.is-go { color: var(--accent); }
#osdMsg.is-bad { color: #ff6464; }

.osd-arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2.2em;
  height: 2.2em;
  margin: -1.1em 0 0 -1.1em;
  display: none;
  will-change: transform;
}
.osd-arrow svg { width: 100%; height: 100%; fill: #fff; stroke: #000; stroke-width: 1.5; }
.osd-arrow.is-on { display: block; }

/* ---------- HUD buttons ---------- */

.hud {
  position: absolute;
  top: calc(var(--st) + 10px);
  right: calc(var(--sr) + 10px);
  display: none;
  gap: 8px;
  z-index: 6;
}
.app[data-mode="play"] .hud { display: flex; }
.hud-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: rgba(10, 12, 15, 0.45);
  color: #fff;
}
.hud-btn:active { background: rgba(10, 12, 15, 0.75); }

/* ---------- Touch transmitter ---------- */

.controls { display: none; }
.app[data-mode="play"] .controls { display: grid; }

.zone { position: relative; display: grid; place-items: center; touch-action: none; }

.gimbal {
  position: relative;
  width: var(--gimbal, 150px);
  height: var(--gimbal, 150px);
  border-radius: 28%;
  background:
    linear-gradient(var(--line-strong), var(--line-strong)) center / 1px 72% no-repeat,
    linear-gradient(var(--line-strong), var(--line-strong)) center / 72% 1px no-repeat,
    radial-gradient(circle at 50% 40%, #1c2229, #0f1216 75%);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.7), inset 0 0 0 1px rgba(255, 255, 255, 0.05), 0 1px 0 rgba(255, 255, 255, 0.06);
  display: grid;
  place-items: center;
  pointer-events: none;
  transition: opacity 0.2s;
}
.gimbal-label {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  text-align: center;
  font: 600 10px/1 var(--mono);
  letter-spacing: 0.14em;
  color: var(--muted);
  white-space: nowrap;
}
.knob {
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f6f8fa, #9aa3ad 55%, #5b636c);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6), 0 0 0 4px rgba(255, 255, 255, 0.05);
  will-change: transform;
}
.gimbal.is-active .knob { box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6), 0 0 0 4px rgba(212, 255, 58, 0.35); }

.tx-mid { display: flex; flex-direction: column; justify-content: center; gap: 10px; padding: 0 4px; }
.tx-lcd { display: none; }
.tx-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 76px;
  height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: linear-gradient(#1d232a, #151a20);
  font: 700 11px/1 var(--mono);
  letter-spacing: 0.1em;
  color: #c9d0d8;
}
.tx-btn:active { background: #0f1317; }
.tx-led { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.tx-btn.is-acro .tx-led { background: #ff9d2e; box-shadow: 0 0 6px #ff9d2e; }

/* Portrait: video on top, control deck below. */
@media (orientation: portrait) {
  .app { --stage-h: min(112vw, calc(100vh - 300px)); }
  @supports (height: 100dvh) {
    .app { --stage-h: min(112vw, calc(100dvh - 300px)); }
  }
  .app[data-mode="play"] .stage { inset: 0 0 auto 0; height: var(--stage-h); }
  .app[data-mode="play"] .controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: var(--stage-h);
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas: "mid mid" "l r";
    padding: 0 calc(var(--sr) + 6px) calc(var(--sb) + 12px) calc(var(--sl) + 6px);
    background:
      radial-gradient(120% 70% at 50% 0%, rgba(255, 255, 255, 0.05), transparent 60%),
      linear-gradient(#15191e, #0c0e11);
    border-top: 1px solid var(--line-strong);
    --gimbal: min(42vw, 190px);
  }
  .zone-l { grid-area: l; }
  .zone-r { grid-area: r; }
  .app[data-mode="play"] .controls .zone { align-items: end; padding-bottom: 6px; }
  .tx-lcd {
    display: block;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 58px;
    bottom: calc(var(--gimbal) + 58px + var(--sb));
    width: min(64vw, 320px);
    border-radius: 12px;
    background: #0a0d0b;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.07), inset 0 2px 10px rgba(0, 0, 0, 0.8), 0 1px 0 rgba(255, 255, 255, 0.05);
    overflow: hidden;
    pointer-events: none;
    z-index: 1;
  }
  .tx-lcd canvas { display: block; width: 100%; height: 100%; opacity: 0.92; }
  .tx-lcd::after {
    content: "";
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 3px);
  }
  .tx-lcd-text {
    position: absolute;
    left: 8px;
    bottom: 6px;
    font: 700 11px/1 var(--mono);
    letter-spacing: 0.08em;
    color: var(--accent);
    text-shadow: 0 1px 2px #000;
    z-index: 1;
  }
  .tx-mid { grid-area: mid; flex-direction: row; justify-content: center; gap: 8px; padding: 10px 0 2px; }
  .tx-btn { min-width: 0; flex: 0 1 96px; height: 36px; }
  .app[data-mode="play"] .hud { display: none; }
  .gimbal { margin-bottom: 18px; }
}

/* Landscape: full-screen video, sticks overlaid. */
@media (orientation: landscape) {
  .app[data-mode="play"] .controls {
    position: absolute;
    inset: 0;
    grid-template-columns: 1fr 1fr;
    z-index: 4;
    --gimbal: min(36vh, 170px);
  }
  .controls .zone { align-items: end; padding-bottom: calc(var(--sb) + 7vh); }
  .zone-l { justify-items: start; padding-left: calc(var(--sl) + 5vw); }
  .zone-r { justify-items: end; padding-right: calc(var(--sr) + 5vw); }
  .tx-mid { display: none; }
  .gimbal { opacity: 0.5; background: rgba(10, 12, 15, 0.35); box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.28); }
  .gimbal.is-active { opacity: 0.85; }
  .gimbal-label { display: none; }
  .app.hide-sticks .gimbal { opacity: 0; }
  .app.sticks-visible .osd-bottom { padding: 0 24%; }
  .osd-top { padding-right: max(0px, calc(118px - 9vw)); }
}

.app.no-touch .controls .gimbal { display: none; }
@media (orientation: landscape) {
  .app.no-touch[data-mode="play"] .controls { display: none; }
}

/* ---------- Panels ---------- */

.panel { display: none; position: absolute; inset: 0; z-index: 20; }
.app[data-panel="home"] #panel-home,
.app[data-panel="tracks"] #panel-tracks,
.app[data-panel="settings"] #panel-settings,
.app[data-panel="help"] #panel-help,
.app[data-panel="pause"] #panel-pause,
.app[data-panel="results"] #panel-results,
.app[data-panel="coach"] #panel-coach,
.app[data-panel="import"] #panel-import,
.app[data-panel="share"] #panel-share,
.app[data-panel="confirm"] #panel-confirm,
.app[data-under="home"] #panel-home,
.app[data-under="tracks"] #panel-tracks,
.app[data-under="settings"] #panel-settings { display: flex; }

.panel-home {
  flex-direction: column;
  justify-content: flex-end;
  padding: calc(var(--st) + 24px) calc(var(--sr) + 24px) calc(var(--sb) + 28px) calc(var(--sl) + 24px);
}
.home { width: 100%; max-width: 420px; margin: 0 auto; display: flex; flex-direction: column; gap: 28px; }
.brand h1 {
  margin: 10px 0 6px;
  font-size: clamp(44px, 13vw, 64px);
  line-height: 0.95;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.brand h1 span {
  display: inline-block;
  margin-left: 0.18em;
  font-family: var(--mono);
  font-weight: 800;
  letter-spacing: 0;
  color: var(--accent);
}
.brand p { margin: 0; color: #c3cad2; font-size: 16px; }
.rec {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 700 12px/1 var(--mono);
  letter-spacing: 0.16em;
  color: #fff;
  text-shadow: 0 1px 2px #000;
}
.rec i { width: 9px; height: 9px; border-radius: 50%; background: var(--rec); animation: blink 1.2s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
.home-actions { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.fs-btn { position: absolute; top: calc(var(--st) + 12px); right: calc(var(--sr) + 12px); background: rgba(10, 12, 15, 0.5); }

@media (orientation: landscape) and (max-height: 520px) {
  .panel-home { justify-content: center; }
  .home { max-width: 760px; flex-direction: row; align-items: flex-end; gap: 40px; }
  .brand { flex: 1; }
  .home-actions { flex: 0 0 300px; }
}

.panel-sheet {
  flex-direction: column;
  background: rgba(9, 11, 14, 0.94);
  padding: var(--st) var(--sr) 0 var(--sl);
}
@media (min-width: 700px) and (orientation: landscape) {
  .panel-sheet { padding-left: calc(50% - 320px); padding-right: calc(50% - 320px); }
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { flex: 1; margin: 0; font-size: 18px; font-weight: 700; }
.head-spacer { width: 44px; }
.panel-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 14px 16px calc(var(--sb) + 24px);
  -webkit-user-select: none;
  user-select: none;
}

.panel-dialog { align-items: center; justify-content: center; background: var(--scrim); padding: 16px; z-index: 22; }
.dialog {
  width: 100%;
  max-width: 380px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px 20px 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.dialog h2 { margin: 4px 0 12px; font-size: 22px; }
.dialog-kicker { margin: 0; font: 700 11px/1 var(--mono); letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }
.dialog-text { margin: 0 0 12px; color: var(--muted); }
.dialog-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* Results */
.res-time { font: 800 44px/1 var(--mono); letter-spacing: -0.02em; margin: 8px 0 6px !important; }
.res-best { margin: 0; color: var(--muted); font-weight: 600; }
.res-best.is-new { color: var(--accent); }
.res-laps { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 4px; }
.res-laps li { display: flex; justify-content: space-between; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); font: 600 14px/1.2 var(--mono); }
.res-laps li span:first-child { color: var(--muted); font-family: var(--font); }
.res-laps li.is-best span:last-child { color: var(--accent); }
.res-meta { margin: 10px 0 0; color: var(--muted); font-size: 13px; }

/* Coach marks */
.panel-coach { background: rgba(7, 9, 12, 0.55); align-items: flex-end; justify-content: center; padding-bottom: calc(var(--sb) + 24px); }
.coach { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 12px; max-width: 760px; }
.coach-card { background: var(--surface); border: 1px solid var(--line-strong); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.coach-card b { color: var(--text); font-size: 15px; }
.coach .btn { grid-column: 1 / -1; }
@media (orientation: portrait) {
  .panel-coach { align-items: flex-start; padding-top: var(--stage-h); }
  .coach { margin-top: 12px; }
}

/* ---------- Buttons & form controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-weight: 650;
  font-size: 15px;
  white-space: nowrap;
  transition: background 0.15s, transform 0.08s;
}
.btn:active { transform: scale(0.98); background: var(--surface-3); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:active { background: #c1ec2a; }
.btn-primary svg { fill: currentColor; stroke: none; width: 18px; height: 18px; }
.btn-ghost { background: transparent; }
.btn-lg { min-height: 56px; font-size: 17px; border-radius: 14px; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-danger { color: var(--danger); }
.btn-danger-solid { background: var(--danger); color: #1a0606; border-color: transparent; }
.panel-home .btn:not(.btn-primary) { background: rgba(22, 26, 32, 0.82); }
.panel-home .btn-ghost { background: transparent !important; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  flex: none;
}
.icon-btn:active { background: var(--surface-3); }
.icon-btn:disabled { opacity: 0.3; }
.icon-btn-sm { width: 34px; height: 34px; border-radius: 9px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button {
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
  font-size: 14px;
}
.seg button.is-on { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4); }
.seg-sm button { min-height: 34px; padding: 0 11px; font-size: 13px; }
.seg-wrap { display: grid; grid-template-columns: repeat(2, 1fr); }
@media (orientation: portrait) {
  .seg-wrap { grid-template-columns: repeat(4, 1fr); }
}
.seg-row { display: flex; gap: 10px; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
#runSeg button.is-on { background: var(--accent); color: var(--accent-ink); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 32px;
  background: transparent;
  touch-action: pan-x;
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--surface-3); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--surface-3); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--accent); border: 3px solid var(--bg); }

input[type="checkbox"][role="switch"] {
  -webkit-appearance: none;
  appearance: none;
  width: 48px;
  height: 28px;
  border-radius: 14px;
  background: var(--surface-3);
  position: relative;
  flex: none;
  margin: 0;
  transition: background 0.15s;
}
input[type="checkbox"][role="switch"]::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #c8cfd6;
  transition: transform 0.15s;
}
input[type="checkbox"][role="switch"]:checked { background: var(--accent); }
input[type="checkbox"][role="switch"]:checked::after { transform: translateX(20px); background: var(--accent-ink); }

.text-input, .code-box {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--bg);
  padding: 10px 12px;
  font-size: 16px;
  -webkit-user-select: text;
  user-select: text;
}
.code-box { font: 13px/1.4 var(--mono); resize: none; word-break: break-all; }
.import-preview { display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 14px; background: var(--surface-2); }
.import-preview canvas { width: 88px; height: 88px; border-radius: 10px; flex: none; }
.import-preview .card-name { white-space: normal; }
input[type="checkbox"]:not([role="switch"]) { accent-color: var(--accent); width: 18px; height: 18px; }
.form-error { min-height: 1.2em; margin: 8px 0 0; color: var(--danger); font-size: 13px; }
.mono { font-family: var(--mono); }

/* ---------- Track list ---------- */

.track-list { display: grid; gap: 10px; }
@media (min-width: 640px) { .track-list { grid-template-columns: 1fr 1fr; } }
.card {
  display: grid;
  grid-template-columns: 88px 1fr;
  grid-template-areas: "thumb body" "actions actions";
  gap: 10px 12px;
  padding: 10px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  cursor: pointer;
  text-align: left;
}
.card:active { background: var(--surface-2); }
.card-thumb { grid-area: thumb; width: 88px; height: 88px; border-radius: 10px; display: block; background: var(--surface-2); }
.card-body { grid-area: body; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.card-name { margin: 0; font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { margin: 0; color: var(--muted); font-size: 13px; }
.card-best { margin: 0; font: 600 13px/1.3 var(--mono); color: var(--accent); }
.card-best.is-none { color: var(--muted); font-family: var(--font); font-weight: 500; }
.card-actions { grid-area: actions; display: flex; gap: 6px; }
.card-actions .btn { min-height: 36px; padding: 0 12px; font-size: 13px; }
.card-actions .btn-primary { flex: 1; max-width: 140px; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 6px; background: var(--surface-3); color: #c3cad2; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; margin-right: 6px; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px 12px; }
.empty-title { color: var(--text); font-weight: 700; font-size: 17px; margin: 0 0 6px; }
#newTrackBtn { margin-top: 14px; }

/* ---------- Settings & help ---------- */

.settings h3, .help h3 {
  margin: 22px 0 6px;
  font: 700 11px/1 var(--mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}
.settings h3:first-child { margin-top: 6px; }
.set {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.set-label { display: flex; flex-direction: column; gap: 2px; font-weight: 600; }
.set-label small { font-weight: 400; color: var(--muted); font-size: 13px; }
.set-range { flex-direction: column; align-items: stretch; gap: 4px; }
.set-range .set-label { flex-direction: row; justify-content: space-between; }
.set-range output { font: 600 14px var(--mono); color: var(--muted); }
.set-note { color: var(--muted); font-size: 13px; margin: 6px 0; }
.pad-map { display: grid; gap: 8px; margin: 6px 0; }
.pad-row { display: grid; grid-template-columns: 64px 1fr 74px 60px; gap: 8px; align-items: center; font-size: 13px; }
.pad-row select {
  min-height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
  padding: 0 6px;
}
.pad-row label { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.pad-bar { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; position: relative; }
.pad-bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 50%; background: var(--accent); }
.settings > .btn { margin-top: 22px; }

.help-sticks { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.help-sticks figure { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.stick-fig { width: 100%; height: auto; display: block; margin-bottom: 8px; }
.stick-fig rect { fill: #0f1216; stroke: var(--line-strong); stroke-width: 1.5; }
.stick-fig .axis { stroke: rgba(255, 255, 255, 0.15); stroke-width: 1.5; }
.stick-fig .knob-fig { fill: #c6ccd3; stroke: none; }
.stick-fig .arrow { fill: var(--accent); stroke: none; }
.help figcaption { font-size: 13px; color: var(--muted); }
.help figcaption b { display: block; color: var(--text); font-size: 15px; margin-bottom: 2px; }
.tips { margin: 12px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.tips li { background: var(--surface); border-radius: 12px; padding: 12px 14px; color: #c3cad2; }
.tips b { color: var(--text); }

/* ---------- Toast & loading ---------- */

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--sb) + 96px);
  transform: translate(-50%, 20px);
  max-width: min(92vw, 420px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #f1f4f6;
  color: #0d1013;
  font-weight: 600;
  font-size: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }
.app[data-mode="editor"] .toast { bottom: auto; top: calc(var(--st) + 120px); }

.loading {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(9, 11, 14, 0.8);
  font: 600 12px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.loading.is-on { display: flex; }
.loading-bar { width: 140px; height: 3px; border-radius: 2px; background: var(--surface-3); overflow: hidden; position: relative; }
.loading-bar::after { content: ""; position: absolute; inset: 0; width: 40%; background: var(--accent); animation: load 0.9s ease-in-out infinite; }
@keyframes load { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

.fatal {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: var(--bg);
}
.fatal p { color: var(--muted); max-width: 360px; }

/* ---------- Editor ---------- */

.editor { display: none; position: absolute; inset: 0; z-index: 10; background: #0b0d10; }
.app[data-mode="editor"] .editor { display: block; }
.ed-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.ed-top, .ed-tools, .ed-inspector, .ed-sheet, .ed-zoom {
  position: absolute;
  background: rgba(16, 19, 24, 0.92);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.ed-top {
  top: calc(var(--st) + 8px);
  left: calc(var(--sl) + 8px);
  right: calc(var(--sr) + 8px);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  z-index: 3;
}
.ed-title { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0 4px; }
.ed-name {
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  font-size: 16px;
  font-weight: 700;
  padding: 2px 0;
  -webkit-user-select: text;
  user-select: text;
  text-overflow: ellipsis;
}
.ed-name:focus { outline: none; box-shadow: 0 1px 0 var(--accent); }
.ed-saved { font-size: 11px; color: var(--muted); }
.ed-actions { display: flex; align-items: center; gap: 0; }
.ed-fly { margin-left: 4px; }
@media (max-width: 400px) {
  .ed-actions .icon-btn { width: 38px; }
}

.ed-hint {
  position: absolute;
  top: calc(var(--st) + 72px);
  left: 50%;
  transform: translate(-50%, -6px);
  max-width: calc(100% - 120px);
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(16, 19, 24, 0.92);
  font-size: 13px;
  color: #c3cad2;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 2;
}
.ed-hint.is-show { opacity: 1; transform: translate(-50%, 0); }

.ed-zoom {
  right: calc(var(--sr) + 8px);
  top: calc(var(--st) + 72px);
  display: flex;
  flex-direction: column;
  padding: 3px;
  z-index: 2;
}

.ed-tools {
  display: flex;
  gap: 2px;
  padding: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  touch-action: pan-x;
  z-index: 3;
  left: calc(var(--sl) + 8px);
  right: calc(var(--sr) + 8px);
  bottom: calc(var(--sb) + 8px);
}
.ed-tools::-webkit-scrollbar { display: none; }
.ed-tools button {
  flex: none;
  width: 60px;
  height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}
.ed-tools button.is-on { background: var(--accent); color: var(--accent-ink); }
.ed-tools button[data-tool="erase"].is-on { background: var(--danger); color: #1a0606; }

.ed-inspector, .ed-sheet {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px 12px;
  z-index: 4;
  left: calc(var(--sl) + 8px);
  right: calc(var(--sr) + 8px);
  bottom: calc(var(--sb) + 82px);
  max-height: 46%;
  overflow-y: auto;
  touch-action: pan-y;
}
.editor.has-sel .ed-inspector { display: flex; }
.editor.sheet-open .ed-sheet { display: flex; z-index: 5; }
.editor.sheet-open .ed-inspector { display: none; }
.ins-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ins-title { font-weight: 700; font-size: 15px; }
.ins-order { display: flex; gap: 6px; }
.ins-order[hidden] { display: none; }
.ins-fields { display: grid; gap: 0 16px; }
@media (orientation: portrait) {
  .ins-fields.is-multi { grid-template-columns: 1fr 1fr; }
}
.ins-actions { display: flex; gap: 8px; margin-top: 6px; }
.ins-actions .btn { flex: 1; }

.field { display: flex; flex-direction: column; gap: 0; padding: 2px 0; }
.field-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-weight: 600; }
.field-top output { font-family: var(--mono); color: var(--text); }
.field-inline { flex-direction: row; justify-content: space-between; align-items: center; font-size: 14px; font-weight: 600; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 6px; background: var(--surface-2); border-radius: 10px; padding: 2px; }
.stepper output { min-width: 20px; text-align: center; font-family: var(--mono); color: var(--text); }

@media (orientation: landscape) {
  .ed-tools {
    flex-direction: column;
    right: auto;
    top: calc(var(--st) + 68px);
    bottom: calc(var(--sb) + 8px);
    width: 70px;
    overflow-x: hidden;
    overflow-y: auto;
    touch-action: pan-y;
  }
  .ed-tools button { width: 60px; height: 52px; }
  .ed-inspector, .ed-sheet {
    left: auto;
    right: calc(var(--sr) + 8px);
    top: calc(var(--st) + 68px);
    bottom: auto;
    width: 270px;
    max-height: calc(100% - var(--st) - var(--sb) - 76px);
  }
  .ed-zoom { top: auto; bottom: calc(var(--sb) + 8px); flex-direction: row; }
  .ed-hint { left: calc(var(--sl) + 88px); transform: translate(0, -6px); max-width: calc(100% - var(--sl) - var(--sr) - 410px); text-align: left; }
  .ed-hint.is-show { transform: translate(0, 0); }
  .editor.has-sel .ed-zoom, .editor.sheet-open .ed-zoom { right: calc(var(--sr) + 286px); }
}

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