:root {
  color-scheme: dark;
  --bg: #1e1e24;
  --panel: #26262e;
  --border: #3a3a44;
  --text: #e8e8ec;
  --muted: #9a9aa5;
  --accent: #6c8cff;
  --accent-text: #0d0d10;
}
body.light {
  color-scheme: light;
  --bg: #f5f5f7;
  --panel: #ffffff;
  --border: #dcdce2;
  --text: #1c1c22;
  --muted: #6a6a74;
  --accent: #3d5fd6;
  --accent-text: #ffffff;
}
* {
  box-sizing: border-box;
  font-family:
    Arimo,
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  letter-spacing: 0.25px;
}
html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}
body {
  background: var(--bg);
  color: var(--text);
  transition:
    background 0.2s ease,
    color 0.2s ease;
}
button {
  font: inherit;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
button:hover {
  border-color: var(--accent);
}
button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 600;
}

/* Hamburger trigger — always reachable, fades back when idle so it
         doesn't intrude on a stakeholder view of the diagram */
#hamburger {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 30;
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--panel);
  opacity: 0.55;
  transition:
    opacity 0.15s ease,
    border-color 0.15s ease;
}
#hamburger:hover,
#hamburger:focus-visible,
body.drawer-open #hamburger {
  opacity: 1;
}
#hamburger svg {
  width: 18px;
  height: 18px;
}
#hamburger .icon-close {
  display: none;
}
body.drawer-open #hamburger .icon-open {
  display: none;
}
body.drawer-open #hamburger .icon-close {
  display: block;
}

/* Slide-out drawer holding the editor + theme controls */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 20;
}
body.drawer-open #overlay {
  opacity: 1;
  pointer-events: auto;
}
#drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 380px;
  max-width: 88vw;
  background: var(--panel);
  border-right: 1px solid var(--border);
  z-index: 25;
  display: flex;
  flex-direction: column;
  padding: 16px;
  padding-top: 64px;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  box-shadow: 2px 0 24px rgba(0, 0, 0, 0.25);
}
body.drawer-open #drawer {
  transform: translateX(0);
}

#drawer h1 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 14px;
}
#drawer label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: block;
}
.theme-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 16px;
  width: fit-content;
}
.theme-toggle button {
  border: none;
  border-radius: 0;
  margin: 0;
}
.theme-toggle button.active {
  background: var(--accent);
  color: var(--accent-text);
}
textarea {
  flex: 1;
  min-height: 240px;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: Cousine, "SF Mono", "Cascadia Code", Consolas, monospace;
  font-size: 14px;
  line-height: 1.5;
}
textarea:focus {
  outline: none;
  border-color: var(--accent);
}
#render-btn {
  margin-top: 10px;
  width: 100%;
}
#live-toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}
#live-toggle-row input {
  accent-color: var(--accent);
}
#status {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  min-height: 14px;
}
#error-box {
  display: none;
  background: #3a1f1f;
  border: 1px solid #7a3a3a;
  color: #ffb4b4;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  font-family: monospace;
  white-space: pre-wrap;
  margin-top: 10px;
  overflow: auto;
  max-height: 160px;
}
body.light #error-box {
  background: #fdecec;
  border-color: #f2b8b8;
  color: #a02020;
}

/* Full-page pan/zoom stage behind the drawer */
#stage {
  height: 100%;
  width: 100%;
  overflow: hidden;
  position: relative;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#stage.grabbing {
  cursor: grabbing;
}
#canvas {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  display: inline-flex;
  /* No permanent will-change here: promoting this to a GPU layer at all
           times causes Chromium to rasterize it once and scale the bitmap on
           zoom, which is what makes the SVG go blurry/pixelated. We toggle
           will-change on only while actively panning/zooming (see JS) and
           remove it right after, so the resting frame is native vector SVG. */
}
#canvas.interacting {
  will-change: transform;
}
#diagram-card {
  padding: 8px;
}
.mermaid {
  text-align: center;
}
#placeholder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 40px;
  white-space: nowrap;
}

/* Zoom control cluster, bottom-right, same fade behavior as hamburger */
#zoom-controls {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  opacity: 0.55;
  transition: opacity 0.15s ease;
}
#zoom-controls:hover {
  opacity: 1;
}
#zoom-controls button {
  border: none;
  background: transparent;
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  border-radius: 5px;
}
#zoom-controls button:hover {
  background: var(--bg);
  border-color: transparent;
}
#zoom-pct {
  font-size: 12px;
  color: var(--muted);
  width: 46px;
  text-align: center;
  user-select: none;
}
#zoom-fit {
  font-size: 11px !important;
  width: auto !important;
  padding: 0 8px !important;
}

.hint {
  position: fixed;
  bottom: 16px;
  left: 16px;
  font-size: 11px;
  color: var(--muted);
  opacity: 0.5;
  z-index: 5;
  pointer-events: none;
}
