/* Architecture diagram editor — /diagram/
 * Self-contained: no font CDN, no external stylesheet, no icon font.
 */

:root {
  color-scheme: light dark;
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --surface-3: #eef2f6;
  --ink: #0f172a;
  --ink-2: #475569;
  --muted: #94a3b8;
  --line: #dde3ea;
  --line-strong: #c3ccd6;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --danger: #dc2626;
  --canvas: #ffffff;
  --grid: #e6ebf1;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 6px 20px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 18px 44px rgba(15, 23, 42, 0.18);
  --radius: 9px;
  --topbar-h: 52px;
  --font: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #131c2b;
  --surface-2: #182234;
  --surface-3: #1f2b3f;
  --ink: #e8edf5;
  --ink-2: #a8b6cb;
  --muted: #6b7c93;
  --line: #263349;
  --line-strong: #35455f;
  --accent: #5b91ff;
  --accent-soft: rgba(91, 145, 255, 0.16);
  --canvas: #0f1726;
  --grid: #1c2739;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ------------------------------------------------------------------ topbar */

.dg-topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 30;
}

.dg-brand {
  display: flex;
  align-items: baseline;
  gap: 9px;
  text-decoration: none;
  color: inherit;
  padding-right: 4px;
  white-space: nowrap;
}

.dg-brand b { font-size: 15px; letter-spacing: -0.01em; }
.dg-brand span { font-size: 11.5px; color: var(--muted); }

.dg-title-input {
  min-width: 120px;
  max-width: 260px;
  flex: 0 1 auto;
  padding: 6px 9px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  font-weight: 600;
  font-size: 13.5px;
  text-overflow: ellipsis;
}
.dg-title-input:hover { background: var(--surface-2); }
.dg-title-input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
}

.dg-toolbar {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  flex-wrap: nowrap;
}

.dg-sep {
  width: 1px;
  height: 22px;
  background: var(--line);
  margin: 0 3px;
  flex: none;
}

.dg-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 550;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.dg-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.dg-btn:active:not(:disabled) { transform: translateY(0.5px); }
.dg-btn:disabled { opacity: 0.38; cursor: not-allowed; }
.dg-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.dg-btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.dg-btn--primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); color: #fff; }
.dg-btn--icon { width: 32px; padding: 0; justify-content: center; }
.dg-btn svg { width: 15px; height: 15px; flex: none; }

/* ------------------------------------------------------------------ shell */

.dg-shell {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr) 252px;
  height: calc(100% - var(--topbar-h));
  min-height: 0;
  /* Below 900px the side panels become off-canvas drawers parked at
     `translateX(100%)`. A transform moves an element visually but leaves its
     layout box where it was, so the document ends up 246px wider than the
     viewport. `overflow: hidden` on the root only hides the scrollbar — the
     root stays a scroll container, and anything that scrolls it
     programmatically (focus moving into a closed drawer is enough) slides the
     whole app sideways and exposes a blank strip.
     `position` makes this the drawers' containing block so `clip` actually
     reaches them; `clip` rather than `hidden` so this does not itself become a
     scroll container. */
  position: relative;
  overflow: clip;
}

.dg-panel {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.dg-panel--left { border-right: 1px solid var(--line); }
.dg-panel--right { border-left: 1px solid var(--line); }

.dg-panel-head {
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.dg-panel-title {
  margin: 0 0 8px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Only reachable on mobile, where the panels slide over the canvas and cover
   the toggle that opened them. */
.dg-panel-close {
  display: none;
  width: 26px;
  height: 26px;
  margin: -4px -4px -4px 0;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--ink-2);
  font-size: 20px;
  line-height: 1;
}
.dg-panel-close:hover { background: var(--surface-2); color: var(--ink); }

/* ------------------------------------------------------------------ palette */

.dg-search {
  width: 100%;
  height: 31px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  font-size: 13px;
}
.dg-search:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.dg-search::placeholder { color: var(--muted); }

.dg-tabs {
  display: flex;
  gap: 3px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.dg-tab {
  flex: 1 1 auto;
  height: 26px;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 600;
}
.dg-tab:hover { background: var(--surface-3); }
.dg-tab[aria-selected="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.dg-palette {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 8px 20px;
  flex: 1 1 auto;
  min-height: 0;
}

.dg-cat {
  margin: 10px 4px 5px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.dg-cat:first-child { margin-top: 4px; }

.dg-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.dg-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 3px 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  cursor: grab;
  text-align: center;
  transition: background 0.1s, border-color 0.1s;
}
.dg-item:hover { background: var(--surface-2); border-color: var(--line); }
.dg-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.dg-item:active { cursor: grabbing; }
.dg-item svg { width: 26px; height: 26px; pointer-events: none; }
.dg-item--mono svg { color: var(--ink-2); }

/* Imported icons only: a remove control laid over the tile's corner. */
.dg-item-wrap { position: relative; display: flex; }
.dg-item-wrap .dg-item { flex: 1 1 auto; min-width: 0; }
.dg-item-remove {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 17px;
  height: 17px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.1s, background 0.1s, color 0.1s;
}
/* Revealed by keyboard focus as well as hover — hiding the ports behind hover
   alone is what produced the "there are no arrows" feedback. */
.dg-item-wrap:hover .dg-item-remove,
.dg-item-wrap:focus-within .dg-item-remove { opacity: 1; }
.dg-item-remove:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.dg-item-remove:focus-visible {
  opacity: 1;
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
/* Tile drawn before its group's path data has arrived. The empty <svg> keeps
   the grid from reflowing when the real icon replaces it. */
.dg-item.is-loading svg {
  border-radius: 5px;
  background: var(--surface-3);
  animation: dg-pulse 1.1s ease-in-out infinite;
}
.dg-item.is-loading { cursor: progress; }
@keyframes dg-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.85; }
}
.dg-item span {
  font-size: 9.5px;
  line-height: 1.2;
  color: var(--ink-2);
  overflow-wrap: anywhere;
  pointer-events: none;
}

.dg-empty {
  padding: 26px 12px;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
}

.dg-credit {
  padding: 9px 12px 12px;
  border-top: 1px solid var(--line);
  font-size: 10px;
  line-height: 1.5;
  color: var(--muted);
  flex: none;
}
.dg-credit a { color: var(--ink-2); }

/* ------------------------------------------------------------------ canvas */

.dg-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  overflow: hidden;
}

.dg-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: default;
}
.dg-stage[data-mode="pan"] .dg-canvas { cursor: grab; }
.dg-stage[data-mode="panning"] .dg-canvas { cursor: grabbing; }
.dg-stage[data-mode="connect"] .dg-canvas { cursor: crosshair; }

.dg-hint {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  color: var(--muted);
  max-width: 340px;
}
.dg-hint h2 { margin: 0 0 8px; font-size: 15px; font-weight: 650; color: var(--ink-2); }

/* Templates live in the empty-canvas hint: it is the one moment the offer is
   useful, and it costs no toolbar space. */
.dg-templates {
  margin-top: 18px;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  text-align: left;
}
.dg-templates-head {
  margin: 0 0 2px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
}
.dg-template {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: left;
  transition: background 0.12s, border-color 0.12s;
}
.dg-template:hover { background: var(--surface-2); border-color: var(--accent); }
.dg-template:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.dg-template b { font-size: 12.5px; font-weight: 600; color: var(--ink); }
.dg-template span { font-size: 11px; line-height: 1.45; color: var(--muted); }
.dg-hint p { margin: 0; font-size: 12.5px; line-height: 1.65; }
.dg-hint kbd {
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink-2);
}

/* Bottom-right, where Figma, draw.io and Excalidraw all put it — two rounds of
   feedback went "where is zoom out?" while it sat bottom-left, tucked against
   the palette edge. The status pill, which is passive, takes the left corner
   instead: the interactive control gets the conventional spot. */
.dg-zoombar {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.dg-zoombar button {
  width: 27px;
  height: 27px;
  border: none;
  border-radius: 5px;
  background: none;
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1;
}
.dg-zoombar button:hover { background: var(--surface-2); color: var(--ink); }
.dg-zoom-level {
  min-width: 46px;
  text-align: center;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.dg-status {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  max-width: 46%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* selection chrome drawn inside the SVG overlay layer */
.dg-sel-outline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.dg-handle {
  fill: var(--surface);
  stroke: var(--accent);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
  cursor: nwse-resize;
}
.dg-handle[data-dir="ne"], .dg-handle[data-dir="sw"] { cursor: nesw-resize; }
.dg-port {
  fill: var(--surface);
  stroke: var(--accent);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
  cursor: crosshair;
  opacity: 0;
  transition: opacity 0.1s;
}
.dg-port-hit { fill: transparent; cursor: crosshair; }
.dg-ports:hover .dg-port,
.dg-ports.is-visible .dg-port,
.dg-port.is-active { opacity: 1; }
.dg-marquee {
  fill: var(--accent-soft);
  stroke: var(--accent);
  stroke-width: 1;
  stroke-dasharray: 4 3;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.dg-linking {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 5 4;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.dg-drop-target {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 5 4;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.dg-edge-hit { stroke: transparent; stroke-width: 14; fill: none; cursor: pointer; }
.dg-edge-selected { stroke: var(--accent); stroke-width: 1.5; fill: none;
  stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; pointer-events: none; }

/* ------------------------------------------------------------------ inspector */

.dg-inspector {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px;
  flex: 1 1 auto;
  min-height: 0;
}

.dg-field { margin-bottom: 11px; }
.dg-field:last-child { margin-bottom: 0; }

.dg-label {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-2);
}

.dg-input, .dg-select, .dg-textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 12.5px;
}
.dg-input:focus, .dg-select:focus, .dg-textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.dg-textarea { resize: vertical; min-height: 54px; font-family: inherit; }

.dg-row { display: flex; gap: 6px; }
.dg-row > * { flex: 1 1 0; min-width: 0; }

.dg-swatches { display: flex; flex-wrap: wrap; gap: 4px; }
.dg-swatch {
  width: 21px;
  height: 21px;
  border: 2px solid transparent;
  border-radius: 50%;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.14);
}
.dg-swatch[aria-pressed="true"] { border-color: var(--ink); }

.dg-seg { display: flex; gap: 0; }
.dg-seg button {
  flex: 1 1 0;
  height: 28px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 600;
  margin-left: -1px;
}
.dg-seg button:first-child { margin-left: 0; border-radius: 6px 0 0 6px; }
.dg-seg button:last-child { border-radius: 0 6px 6px 0; }
.dg-seg button[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  position: relative;
  z-index: 1;
}

.dg-inspector-empty {
  padding: 30px 8px;
  text-align: center;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted);
}

.dg-actions { display: flex; flex-direction: column; gap: 5px; margin-top: 14px; }
.dg-actions .dg-btn { width: 100%; justify-content: center; }
.dg-btn--danger { color: var(--danger); border-color: var(--line); }
.dg-btn--danger:hover:not(:disabled) { background: rgba(220, 38, 38, 0.09); color: var(--danger); }

.dg-shortcuts {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.9;
}
.dg-shortcuts div { display: flex; justify-content: space-between; gap: 10px; }
.dg-shortcuts kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface-2);
  color: var(--ink-2);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ toast */

.dg-toasts {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: center;
  z-index: 60;
  pointer-events: none;
}

.dg-toast {
  padding: 8px 15px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--surface);
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: dg-toast-in 0.16s ease-out;
  max-width: 82vw;
}
.dg-toast--error { background: var(--danger); color: #fff; }

@keyframes dg-toast-in {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: none; }
}

/* Inline label editor laid over the canvas. Sized and coloured from the label
   it replaces so the text does not jump when editing starts. */
.dg-inline-edit {
  position: absolute;
  z-index: 14;
  margin: 0;
  padding: 2px 4px;
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-family: inherit;
  line-height: 1.25;
  resize: none;
  overflow: hidden;
  white-space: pre-wrap;
}
.dg-inline-edit:focus { outline: none; }

/* Dropping a diagram or an SVG onto the canvas. */
.dg-stage.is-file-over::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  background: var(--accent-soft);
  pointer-events: none;
  z-index: 12;
}

/* ---------------------------------------------------------- custom icons */

.dg-custom-actions {
  padding: 2px 0 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}
.dg-custom-actions p {
  margin: 0 0 9px;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--muted);
}
.dg-custom-actions .dg-btn { justify-content: center; }

/* ------------------------------------------------------------------- help */

/* Above the toasts (60) — the dialog is modal, so nothing may overlap it. */
.dg-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.45);
  animation: dg-fade-in 0.14s ease-out;
}
.dg-modal-backdrop[hidden] { display: none; }

.dg-modal {
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  max-height: min(700px, 86vh);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.dg-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.dg-modal-head h2 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 650;
  letter-spacing: 0.2px;
  color: var(--ink);
}
.dg-modal-close {
  width: 26px;
  height: 26px;
  margin: -4px -4px -4px 0;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--ink-2);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.dg-modal-close:hover { background: var(--surface-2); color: var(--ink); }

.dg-modal-body { padding: 2px 16px 14px; overflow-y: auto; }

.dg-steps { margin: 0; padding: 0; list-style: none; counter-reset: dg-step; }
.dg-steps li {
  position: relative;
  padding: 12px 0 12px 32px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  line-height: 1.68;
  color: var(--ink-2);
}
.dg-steps li:last-child { border-bottom: none; }
.dg-steps li::before {
  counter-increment: dg-step;
  content: counter(dg-step);
  position: absolute;
  left: 0;
  top: 13px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 700;
}
.dg-steps b { color: var(--ink); font-weight: 600; }

.dg-modal kbd {
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 1px 4px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface-2);
  color: var(--ink-2);
  white-space: nowrap;
}

.dg-modal-foot {
  padding: 11px 16px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--muted);
}

@keyframes dg-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ------------------------------------------------------------------ mobile */

.dg-mobile-tabs { display: none; }

@media (max-width: 900px) {
  .dg-shell { grid-template-columns: 208px minmax(0, 1fr); }

  /* Ten buttons plus a title no longer fit; drop to icons and let the strip
     scroll rather than pushing Export off the edge. */
  .dg-btn span.dg-btn-text { display: none; }
  .dg-btn { padding: 0 8px; flex: none; }
  .dg-sep { flex: none; }
  .dg-title-input { max-width: 150px; }
  .dg-toolbar {
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-end;
    padding-left: 4px;
  }
  .dg-toolbar::-webkit-scrollbar { display: none; }
  .dg-panel--right {
    position: absolute;
    right: 0;
    /* Offsets are against `.dg-shell`, which already starts below the topbar. */
    top: 0;
    bottom: 0;
    width: 246px;
    z-index: 20;
    box-shadow: var(--shadow-lg);
    transform: translateX(100%);
    transition: transform 0.18s ease;
  }
  .dg-panel--right.is-open { transform: none; }
  .dg-panel--right .dg-panel-close { display: block; }

  /* The inspector goes off-canvas here, so its toggle has to appear here too —
     not at the 720px breakpoint, or this band has no way to open it. */
  .dg-mobile-tabs { display: flex; }
  .dg-mobile-tabs #dg-toggle-palette { display: none; }
}

@media (max-width: 720px) {
  :root { --topbar-h: 48px; }

  .dg-brand span { display: none; }
  .dg-title-input { max-width: 116px; }

  /* The palette undocks here, so bring its toggle back — the 900px band hid it
     because the palette was still docked there. */
  .dg-mobile-tabs #dg-toggle-palette { display: inline-flex; }

  .dg-shell { grid-template-columns: minmax(0, 1fr); }

  .dg-panel--left {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 232px;
    z-index: 20;
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform 0.18s ease;
  }
  .dg-panel--left.is-open { transform: none; }
  .dg-panel--left .dg-panel-close { display: block; }

  .dg-mobile-tabs {
    display: flex;
    position: absolute;
    left: 12px;
    top: 12px;
    gap: 5px;
    z-index: 15;
  }
  .dg-mobile-tabs .dg-btn { background: var(--surface); box-shadow: var(--shadow-sm); }

  .dg-hint { top: 52%; max-width: 74%; }
  .dg-hint .dg-hint-desktop { display: none; }
}

@media (max-width: 520px) {
  /* Reclaim the last of the topbar: the title stays editable in Properties. */
  .dg-title-input { display: none; }
}

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