:root {
  --bg: #0c0e12;
  --panel: #151922;
  --border: #2a3140;
  --text: #e8ecf4;
  --dim: #8b93a5;
  --accent: #00d280;
  --amber: #f5b919;
  --danger: #f04646;
  --track: #464e5e;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 13px/1.4 "Segoe UI", system-ui, sans-serif; }

#app {
  display: grid;
  grid-template-columns: 220px 1fr 280px;
  grid-template-rows: 52px 1fr;
  height: 100vh;
  min-height: 0;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  min-height: 52px;
}

.mode-tabs {
  display: flex;
  gap: 4px;
  background: #0c0e12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}

.mode-tab {
  padding: 5px 12px;
  border-radius: 6px;
  border: none;
  background: transparent;
}

.mode-tab.active {
  background: var(--accent);
  color: #06140e;
  font-weight: 700;
}

.mode-label {
  color: var(--accent);
  font-weight: 600;
  font-size: 12px;
}

.zoom-label {
  color: var(--dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.zoom-controls button {
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  background: #1c2230;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
}

.zoom-controls button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.zoom-controls select {
  background: #0c0e12;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 4px 6px;
  font: inherit;
  font-size: 12px;
}

body.gauge-mode .layout-only {
  display: none !important;
}

.speed-extras {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.speed-extras.hidden {
  display: none;
}

.speed-extras h2 {
  margin: 0 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dim);
}

.speed-extras label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--dim);
  font-size: 11px;
  margin-bottom: 8px;
}

.speed-extras label.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}

.speed-extras input[type="text"],
.speed-extras input[type="number"] {
  background: #0c0e12;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 8px;
  font: inherit;
}

.layout-anim-note {
  margin: 0;
  font-size: 11px;
  line-height: 1.4;
}

.btn-edit-inline {
  width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  background: #1c2230;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}

.btn-edit-inline:hover {
  background: #13261c;
}

.brand { font-weight: 700; letter-spacing: 0.04em; white-space: nowrap; }
.brand span { color: var(--accent); font-weight: 600; }

.toolbar { display: flex; flex-wrap: wrap; gap: 6px; }
.hint { margin-left: auto; color: var(--dim); font-size: 11px; white-space: nowrap; }

button, .file-btn {
  background: #1c2230;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font: inherit;
}
button:hover, .file-btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #06140e; border-color: var(--accent); font-weight: 700; }
button.danger { border-color: var(--danger); color: #ffb4b4; }
.file-btn { display: inline-block; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: auto;
  padding: 10px;
}
.sidebar.right { border-right: none; border-left: 1px solid var(--border); }
.sidebar h2 {
  margin: 8px 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dim);
}

.layer-list { display: flex; flex-direction: column; gap: 2px; }
.layer-item {
  text-align: left;
  padding: 7px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
}
.layer-item:hover { background: #1c2230; }
.layer-item.active { border-color: var(--accent); background: #13261c; }
.layer-item .sub { color: var(--dim); font-size: 11px; }
.layer-item.indent { padding-left: 18px; font-size: 12px; }

.side-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }

.stage-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #080a0e;
  overflow: hidden;
}
.stage-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.stage-meta label { display: flex; align-items: center; gap: 6px; color: var(--dim); }
.stage-meta input[type="number"] { width: 72px; }
.sel-info { color: var(--amber); margin-left: auto; font-variant-numeric: tabular-nums; }

.stage {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0;
}

.canvas-shell {
  flex-shrink: 0;
  display: block;
  box-sizing: content-box;
  min-width: min-content;
  min-height: min-content;
}

#canvas {
  background: #10131a;
  box-shadow: 0 12px 40px rgba(0,0,0,0.55);
  cursor: default;
  display: block;
  flex-shrink: 0;
}

body.gauge-mode #canvas {
  border: 2px dashed var(--border);
  border-radius: 12px;
}

.center-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 8px;
}

.center-btns button {
  flex: 1;
  min-width: 72px;
  font-size: 11px;
  padding: 5px 6px;
}

.inspector { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.inspector label, .preset-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--dim);
  font-size: 11px;
}
.inspector label.check, .preset-fields label.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}
.inspector input[type="text"],
.inspector input[type="number"],
.inspector select,
.preset-fields input[type="text"],
.preset-fields select {
  background: #0c0e12;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 8px;
  font: inherit;
}
.inspector input[type="color"], .preset-fields input[type="color"] {
  width: 100%;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0c0e12;
  padding: 2px;
}
.inspector .row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.inspector .row3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.zone-row {
  padding: 8px;
  margin-bottom: 8px;
  background: #12161f;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.zone-row-top {
  align-items: end;
}

.btn-zone-remove {
  padding: 6px 8px;
  font-size: 11px;
  border-color: var(--danger);
  color: #ffb4b4;
}

.btn-zone-remove:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-secondary {
  width: 100%;
  margin: 4px 0 8px;
  padding: 7px 10px;
  background: #1c2230;
  color: var(--amber);
  border: 1px solid #4a4030;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}

.btn-secondary:hover {
  border-color: var(--amber);
}

.color-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 2px 0 8px;
}

.color-swatch {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  border: 2px solid #2a3140;
  cursor: pointer;
}

.color-swatch:hover {
  border-color: var(--accent);
  transform: scale(1.08);
}
.muted { color: var(--dim); }
.section-title {
  margin-top: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.brand {
  text-decoration: none;
  color: inherit;
}

.site-link {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

body.screenshot-mode #sidebar-left,
body.screenshot-mode #sidebar-right,
body.screenshot-mode .stage-meta,
body.screenshot-mode .toolbar,
body.screenshot-mode .hint {
  display: none !important;
}

body.screenshot-mode #app {
  grid-template-columns: 1fr;
  grid-template-rows: 52px 1fr;
}

body.screenshot-mode .stage {
  padding: 32px;
}

.exit-screenshot {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 100;
  background: var(--accent);
  color: #06140e;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.cookie-banner {
  position: fixed;
  inset: auto 16px 16px 16px;
  z-index: 10000;
  max-width: 520px;
  margin: 0 auto;
  left: 0;
  right: 0;
}

.cookie-banner.hidden {
  display: none;
}

.cookie-banner-inner {
  background: #1a1f2a;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
}

.cookie-banner-inner p {
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
}

.cookie-banner-text {
  color: var(--dim) !important;
  font-size: 12px !important;
}

.cookie-banner-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

.cookie-banner-actions button {
  min-width: 88px;
}

.save-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  background: #13261c;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  transition: opacity 0.25s ease;
}

.save-toast.hidden {
  opacity: 0;
  pointer-events: none;
}

#gauge-style-panel.hidden {
  display: none;
}

#gauge-style-panel h2 {
  margin: 1.25rem 0 0.35rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--dim);
}

#gauge-style-panel h2:first-child {
  margin-top: 0.5rem;
}

.style-scale-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.style-scale-row input[type="range"] {
  flex: 1;
}

.style-scale-val {
  min-width: 3rem;
  font-size: 12px;
  color: var(--dim);
  text-align: right;
}

/* ── Mobile layout: canvas-first, sidebars as drawers ─────────────────── */

.mobile-dock,
.mobile-backdrop {
  display: none;
}

@media (max-width: 900px) {
  html, body {
    height: 100%;
    overflow: hidden;
  }

  #app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    height: 100vh;
    min-height: 0;
    grid-template-columns: unset;
    grid-template-rows: unset;
  }

  .topbar {
    flex-shrink: 0;
    padding: 8px 10px;
    gap: 8px;
    align-items: flex-start;
  }

  .brand {
    font-size: 12px;
    flex: 1 1 100%;
  }

  .mode-tabs {
    order: 2;
    flex-shrink: 0;
  }

  .toolbar {
    order: 3;
    flex: 1 1 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
    max-width: 100%;
  }

  .toolbar::-webkit-scrollbar {
    display: none;
  }

  .toolbar button,
  .toolbar .file-btn {
    flex-shrink: 0;
    font-size: 12px;
    padding: 6px 8px;
  }

  .hint {
    display: none;
  }

  .stage-wrap {
    flex: 1;
    min-height: 0;
    min-width: 0;
    width: 100%;
  }

  .stage-meta {
    padding: 6px 8px;
    gap: 6px;
    font-size: 11px;
  }

  .stage-meta label.layout-only {
    display: none;
  }

  .stage-meta .mode-label {
    flex: 1 1 100%;
    font-size: 11px;
  }

  .sel-info {
    margin-left: 0;
    flex: 1 1 100%;
    font-size: 10px;
  }

  .sidebar.left,
  .sidebar.right {
    position: fixed;
    left: 0;
    right: auto;
    top: 0;
    bottom: 0;
    width: min(300px, 88vw);
    max-width: 88vw;
    z-index: 400;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(60px, calc(52px + env(safe-area-inset-bottom)));
  }

  .sidebar.right {
    left: auto;
    right: 0;
    transform: translateX(105%);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.45);
  }

  body.mobile-show-layers .sidebar.left {
    transform: translateX(0);
  }

  body.mobile-show-inspector .sidebar.right {
    transform: translateX(0);
  }

  .mobile-dock {
    display: flex;
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    background: var(--panel);
    padding: 6px 8px max(6px, env(safe-area-inset-bottom));
    gap: 6px;
    z-index: 350;
  }

  .mobile-dock-btn {
    flex: 1;
    padding: 10px 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #1c2230;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
  }

  .mobile-dock-btn.active {
    background: var(--accent);
    color: #06140e;
    border-color: var(--accent);
  }

  .mobile-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 350;
    background: rgba(0, 0, 0, 0.55);
  }

  body.mobile-show-layers .mobile-backdrop,
  body.mobile-show-inspector .mobile-backdrop {
    display: block;
  }

  body.screenshot-mode .mobile-dock {
    display: none;
  }

  body.screenshot-mode #app {
    display: flex;
    flex-direction: column;
  }

  body.screenshot-mode .exit-screenshot {
    bottom: max(16px, env(safe-area-inset-bottom));
    right: max(16px, env(safe-area-inset-right));
  }

  .cookie-banner {
    inset: auto 8px max(60px, calc(52px + env(safe-area-inset-bottom))) 8px;
  }

  .save-toast {
    bottom: max(64px, calc(56px + env(safe-area-inset-bottom)));
    right: 8px;
    left: 8px;
    text-align: center;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  .topbar {
    flex-wrap: nowrap;
    align-items: center;
  }

  .brand {
    flex: 0 1 auto;
  }

  .toolbar {
    flex: 1 1 auto;
  }
}
