:root {
  --desk: #22262b;
  --panel: #2b3037;
  --panel-2: #343a42;
  --ink: #e8eaed;
  --ink-dim: #9aa2ac;
  --accent: #f4b23e;
  --accent-ink: #241a05;
  --sel: #37a4e8;
  --danger: #e46a5a;
  --radius: 10px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--desk); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; display: flex; flex-direction: column; }
button, select, input { font: inherit; color: inherit; }

#topbar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; background: var(--panel);
  border-bottom: 1px solid rgba(0,0,0,0.35);
  flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: 0.4px; margin-right: 4px; white-space: nowrap; }
.brand .dot { color: var(--accent); }

.tbtn {
  min-width: 44px; min-height: 44px; padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--panel-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  cursor: pointer; user-select: none; -webkit-user-select: none;
}
.tbtn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tbtn:disabled { opacity: 0.35; cursor: default; }
.tbtn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tbtn.danger.active { background: var(--danger); border-color: var(--danger); color: #2a0c07; }
.sep { width: 1px; align-self: stretch; margin: 4px 2px; background: rgba(255,255,255,0.1); }
.spacer { flex: 1; }
.sel {
  min-height: 44px; padding: 0 10px;
  background: var(--panel-2); border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  -webkit-appearance: none; appearance: none;
}

#main { flex: 1; display: flex; min-height: 0; }
#stageCol { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
#stage { flex: 1; min-height: 0; touch-action: none; display: block; width: 100%; height: 100%; }
#stageWrap { flex: 1; min-height: 0; position: relative; }
#hint {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  background: rgba(20,22,25,0.85); border: 1px solid rgba(255,255,255,0.12);
  color: var(--ink-dim); padding: 7px 14px; border-radius: 999px;
  pointer-events: none; max-width: 92%; text-align: center; font-size: 14px;
  transition: opacity 0.3s; z-index: 5;
}

#transport {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: var(--panel);
  border-top: 1px solid rgba(0,0,0,0.35); flex-wrap: wrap;
}
#timeInfo { font-variant-numeric: tabular-nums; color: var(--ink-dim); white-space: nowrap; }
#timeInfo b { color: var(--ink); font-weight: 600; }
#gChip { color: var(--ink-dim); white-space: nowrap; }

#panel {
  width: 330px; max-width: 44vw;
  background: var(--panel);
  border-left: 1px solid rgba(0,0,0,0.35);
  display: none; flex-direction: column; min-height: 0;
}
#panel.open { display: flex; }
#panelTabs { display: flex; gap: 6px; padding: 8px; }
.ptab { flex: 1; }
#panelBody { flex: 1; overflow: auto; padding: 0 12px 12px; -webkit-overflow-scrolling: touch; }

.prow { display: flex; align-items: center; gap: 8px; min-height: 44px; flex-wrap: wrap; }
.prow label { color: var(--ink-dim); min-width: 86px; font-size: 14px; }
.prow output { min-width: 58px; text-align: right; font-variant-numeric: tabular-nums; }
.prow input[type=range] { flex: 1; min-width: 90px; height: 40px; -webkit-appearance: none; background: transparent; }
.prow input[type=range]::-webkit-slider-runnable-track { height: 5px; border-radius: 3px; background: var(--panel-2); }
.prow input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); margin-top: -10px; border: 2px solid #1c1608;
}
.num { width: 84px; min-height: 42px; padding: 0 8px; border-radius: var(--radius); border: 1px solid rgba(255,255,255,0.1); background: var(--panel-2); }
label.chk { display: flex; align-items: center; gap: 10px; min-height: 44px; }
label.chk input { width: 22px; height: 22px; }
.swRow { display: flex; gap: 8px; flex-wrap: wrap; padding: 4px 0; }
.sw { width: 34px; height: 34px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.25); cursor: pointer; padding: 0; }
.sw.active { border-color: #fff; box-shadow: 0 0 0 3px rgba(244,178,62,0.4); }
.pbtnRow { display: flex; gap: 8px; padding: 8px 0; }
.pbtnRow .tbtn { flex: 1; }
.phint { color: var(--ink-dim); padding: 10px 2px; font-size: 14px; line-height: 1.5; }
h4.psec { margin: 12px 2px 2px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-dim); font-weight: 600; }

#chartBox { background: var(--panel-2); border-radius: var(--radius); padding: 6px; margin-top: 8px; }
#chartBox svg { display: block; width: 100%; height: auto; }
.axisLine { stroke: rgba(255,255,255,0.55); stroke-width: 1; }
.gridLine { stroke: rgba(255,255,255,0.10); stroke-width: 1; }
.tickText { fill: var(--ink-dim); font-size: 11px; }
.axLabel { fill: var(--ink); font-size: 12px; }

#menuOverlay, #confirmOverlay {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(10,12,14,0.6);
  display: none; align-items: center; justify-content: center; padding: 16px;
}
#menuOverlay.open, #confirmOverlay.open { display: flex; }
.sheet {
  background: var(--panel); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px; padding: 14px;
  width: min(440px, 94vw); max-height: 86vh; overflow: auto;
  display: flex; flex-direction: column; gap: 8px;
}
.sheet h3 { margin: 6px 2px 0; font-size: 15px; color: var(--ink-dim); font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row .grow { flex: 1; }
.menuBtn {
  min-height: 48px; padding: 0 12px;
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2); border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius); cursor: pointer; text-align: left; width: 100%;
}
.menuBtn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#toast {
  position: fixed; left: 50%; bottom: 86px; transform: translateX(-50%);
  background: rgba(20,22,25,0.95); color: var(--ink);
  border: 1px solid rgba(255,255,255,0.15);
  padding: 10px 16px; border-radius: 999px;
  z-index: 50; display: none; max-width: 90vw; text-align: center;
}
#restoreBanner {
  position: fixed; left: 50%; top: 66px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px; padding: 10px 12px; z-index: 40;
  display: none; gap: 8px; align-items: center; flex-wrap: wrap; max-width: 94vw;
}
#restoreBanner.open { display: flex; }

@media (max-width: 900px) {
  #main { flex-direction: column; }
  #panel { width: 100%; max-width: none; border-left: none; border-top: 1px solid rgba(0,0,0,0.35); height: 46%; }
}
[hidden] { display: none !important; }
