:root {
  color-scheme: light;
  --app-bg: #eef1f5;
  --panel-bg: #ffffff;
  --panel-muted: #f6f7f9;
  --chrome-ink: #17202c;
  --chrome-muted: #667085;
  --chrome-border: #d6dbe3;
  --focus: #1478f2;
  --canvas-bg: #f8fafc;
  --ink: #17202c;
  --muted: #6d7788;
  --line: #303948;
  --border: #cfd8e6;
  --fallback: #fff8ef;
  --platform: #ebfaf4;
  --hub: #edf6ff;
  --tracking: #f7faff;
  --events: #f8f0ff;
  --external: #f7f9fc;
  --component-fill: #ffffff;
  --fallback-accent: #f0b66f;
  --platform-accent: #54b58f;
  --hub-accent: #5d9bd6;
  --tracking-accent: #7b8fb4;
  --events-accent: #9a78d0;
  --external-accent: #9aa8bb;
  --shadow-color: rgb(23 32 44 / 12%);
  --diagram-gap-sm: clamp(5px, 0.45vw, 8px);
  --diagram-gap-md: clamp(8px, 0.75vw, 13px);
  --diagram-gap-lg: clamp(12px, 1vw, 18px);
}

body[data-style="blueprint"] {
  --canvas-bg: #f7fbff;
  --ink: #102033;
  --muted: #52708b;
  --line: #1f4d75;
  --border: #b8d4eb;
  --fallback: #eff7ff;
  --platform: #eaf6ff;
  --hub: #e8f3ff;
  --tracking: #f5fbff;
  --events: #eef4ff;
  --external: #f3f8fd;
  --component-fill: #ffffff;
  --fallback-accent: #3c7db8;
  --platform-accent: #2f89c5;
  --hub-accent: #4d9ed8;
  --tracking-accent: #7aa9ca;
  --events-accent: #5b7fb5;
  --external-accent: #8da9bd;
}

body[data-style="boardroom"] {
  --canvas-bg: #fbfaf7;
  --ink: #1f2933;
  --muted: #68717f;
  --line: #374151;
  --border: #d9d2c4;
  --fallback: #fff7e8;
  --platform: #f1f7ee;
  --hub: #eef4f7;
  --tracking: #f8f8f4;
  --events: #f5eef7;
  --external: #f7f6f2;
  --component-fill: #fffefb;
  --fallback-accent: #d8a452;
  --platform-accent: #6ca47f;
  --hub-accent: #6b93af;
  --tracking-accent: #8794a6;
  --events-accent: #a579b3;
  --external-accent: #9c968c;
}

body[data-style="mono"] {
  --canvas-bg: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #1f2937;
  --border: #d1d5db;
  --fallback: #fafafa;
  --platform: #f7f7f7;
  --hub: #f4f4f5;
  --tracking: #f9fafb;
  --events: #f5f5f5;
  --external: #f8fafc;
  --component-fill: #ffffff;
  --fallback-accent: #6b7280;
  --platform-accent: #4b5563;
  --hub-accent: #64748b;
  --tracking-accent: #94a3b8;
  --events-accent: #52525b;
  --external-accent: #9ca3af;
}

body[data-theme="dark"] {
  color-scheme: dark;
  --app-bg: #0c1119;
  --panel-bg: #111827;
  --panel-muted: #182130;
  --chrome-ink: #f4f7fb;
  --chrome-muted: #9ba8ba;
  --chrome-border: #2d394a;
  --focus: #70aefb;
  --canvas-bg: #10141b;
  --ink: #f5f7fb;
  --muted: #a8b3c3;
  --line: #c9d2df;
  --border: #334155;
  --fallback: #2b231a;
  --platform: #172a25;
  --hub: #162536;
  --tracking: #171d28;
  --events: #251d31;
  --external: #1a202b;
  --component-fill: #111827;
  --shadow-color: rgb(0 0 0 / 28%);
}

body[data-theme="dark"][data-style="blueprint"] {
  --canvas-bg: #071421;
  --line: #badcf7;
  --border: #244967;
  --fallback: #10283f;
  --platform: #0d2d42;
  --hub: #0d2944;
  --tracking: #0a2034;
  --events: #10243e;
  --external: #0e1d2c;
  --component-fill: #071421;
}

body[data-theme="dark"][data-style="boardroom"] {
  --canvas-bg: #16130f;
  --line: #d6cabc;
  --border: #4a4136;
  --fallback: #302515;
  --platform: #1d2a1e;
  --hub: #1a2630;
  --tracking: #20211e;
  --events: #2b2130;
  --external: #24231f;
  --component-fill: #17130f;
}

body[data-theme="dark"][data-style="mono"] {
  --canvas-bg: #0f1115;
  --line: #d1d5db;
  --border: #374151;
  --fallback: #1a1c21;
  --platform: #181b20;
  --hub: #171a20;
  --tracking: #161a20;
  --events: #1d1c22;
  --external: #181c22;
  --component-fill: #101318;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background: var(--app-bg);
  color: var(--chrome-ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  transition:
    background-color 160ms ease,
    color 160ms ease;
}

body.help-open {
  overflow: hidden;
}

body[data-mode="basic"] [data-layercake-only] {
  display: none;
}

button,
select,
textarea {
  font: inherit;
}

button,
summary,
select {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
summary:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 35%, transparent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(170px, 0.6fr) minmax(320px, 1fr) minmax(390px, 1.2fr);
  align-items: center;
  gap: 18px;
  height: 76px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--chrome-border);
  background: color-mix(in srgb, var(--panel-bg) 92%, transparent);
  box-shadow: 0 4px 18px rgb(15 23 42 / 4%);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  width: max-content;
}

.brand img {
  display: block;
  width: 166px;
  height: 48px;
  object-fit: cover;
  object-position: center 43%;
  filter: saturate(1.2) contrast(1.35) brightness(0.76);
}

body[data-theme="dark"] .brand img {
  filter: saturate(1.06) contrast(1.06) drop-shadow(0 8px 18px rgb(20 120 242 / 18%));
}

.project-tools,
.file-tools,
.style-controls {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.file-tools {
  justify-content: flex-end;
}

.project-select,
.quiet-button,
.theme-button,
.action-menu summary {
  min-height: 36px;
  border: 1px solid var(--chrome-border);
  border-radius: 9px;
  color: var(--chrome-ink);
  background: var(--panel-bg);
  font-size: 13px;
  font-weight: 720;
  line-height: 1;
}

.project-select {
  min-width: 180px;
  max-width: 270px;
  padding: 0 32px 0 11px;
  text-overflow: ellipsis;
}

.quiet-button,
.theme-button,
.action-menu summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 11px;
  cursor: pointer;
  user-select: none;
}

.quiet-button:hover,
.theme-button:hover,
.action-menu summary:hover {
  border-color: color-mix(in srgb, var(--chrome-muted) 55%, var(--chrome-border));
  background: var(--panel-muted);
}

.primary-button {
  border-color: var(--chrome-ink);
  color: var(--panel-bg);
  background: var(--chrome-ink);
}

.action-menu summary.primary-button {
  border-color: var(--chrome-ink);
  color: var(--panel-bg);
  background: var(--chrome-ink);
}

.primary-button:hover,
.action-menu summary.primary-button:hover {
  border-color: var(--chrome-ink);
  color: var(--panel-bg);
  background: color-mix(in srgb, var(--chrome-ink) 86%, var(--panel-bg));
}

.danger-button {
  color: #b42318;
}

body[data-theme="dark"] .danger-button {
  color: #ff9b91;
}

.theme-button {
  width: 36px;
  padding: 0;
  border-radius: 999px;
  font-size: 17px;
}

.action-menu {
  position: relative;
}

.action-menu summary {
  list-style: none;
}

.action-menu summary::-webkit-details-marker {
  display: none;
}

.action-menu summary::after {
  content: "";
  width: 6px;
  height: 6px;
  margin: -3px 0 0 8px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  opacity: 0.7;
}

.action-menu[open] summary::after {
  margin-top: 3px;
  transform: rotate(225deg);
}

.action-menu-options {
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  z-index: 20;
  width: 190px;
  padding: 6px;
  border: 1px solid var(--chrome-border);
  border-radius: 12px;
  background: var(--panel-bg);
  box-shadow: 0 16px 38px rgb(15 23 42 / 16%);
}

.action-menu-options button {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 7px;
  color: var(--chrome-ink);
  background: transparent;
  font-size: 13px;
  font-weight: 680;
  text-align: left;
  cursor: pointer;
}

.action-menu-options button:hover,
.action-menu-options button:focus-visible {
  background: var(--panel-muted);
}

.action-menu-options button[hidden] {
  display: none;
}

.new-diagram-menu .action-menu-options {
  right: auto;
  left: 0;
  width: 270px;
  max-height: min(620px, calc(100vh - 96px));
  overflow-y: auto;
}

.action-menu-options .diagram-type-option {
  padding-block: 10px;
}

.diagram-type-option strong,
.diagram-type-option span {
  display: block;
}

.diagram-type-option.compact {
  padding-block: 8px;
}

.diagram-type-group {
  margin: 8px 10px 4px;
  color: var(--chrome-muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.diagram-type-option span {
  margin-top: 4px;
  color: var(--chrome-muted);
  font-size: 11px;
  font-weight: 560;
  line-height: 1.35;
}

.more-menu .action-menu-options {
  width: 220px;
}

.menu-separator {
  height: 1px;
  margin: 5px 6px;
  background: var(--chrome-border);
}

.action-menu-options .danger-button {
  color: #b42318;
}

body[data-theme="dark"] .action-menu-options .danger-button {
  color: #ff9b91;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.78fr) minmax(0, 1.55fr);
  gap: 12px;
  height: calc(100vh - 76px);
  padding: 12px;
}

.editor-panel,
.preview-panel {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--chrome-border);
  border-radius: 15px;
  background: var(--panel-bg);
  box-shadow: 0 8px 28px rgb(15 23 42 / 5%);
}

.editor-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.preview-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.panel-header {
  min-height: 68px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--chrome-border);
}

.editor-header,
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-kicker {
  margin: 0 0 4px;
  color: var(--chrome-muted);
  font-size: 10px;
  font-weight: 820;
  letter-spacing: 0.095em;
  line-height: 1;
  text-transform: uppercase;
}

.panel-header h1,
.panel-header h2 {
  max-width: min(52vw, 680px);
  margin: 0;
  overflow: hidden;
  color: var(--chrome-ink);
  font-size: 18px;
  font-weight: 790;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-state {
  color: #087853;
  font-size: 11px;
  font-weight: 720;
  white-space: nowrap;
}

.save-state[data-state="saving"] {
  color: var(--chrome-muted);
}

.save-state[data-state="error"] {
  color: #b42318;
}

body[data-theme="dark"] .save-state {
  color: #70d8ae;
}

.source-editor {
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  padding: 18px 20px 28px;
  border: 0;
  border-radius: 0;
  outline: 0;
  color: #dce7f6;
  background: #111722;
  caret-color: #77b3ff;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  font-variant-ligatures: none;
  line-height: 1.58;
  tab-size: 2;
}

.source-editor::selection {
  color: #ffffff;
  background: rgb(20 120 242 / 44%);
}

.basic-tools {
  min-height: 0;
  overflow-y: auto;
  background: var(--panel-bg);
}

.basic-tools[hidden] {
  display: none;
}

.basic-tool-section {
  padding: 18px;
  border-bottom: 1px solid var(--chrome-border);
}

.basic-tool-heading {
  margin: 0 0 11px;
  color: var(--chrome-ink);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.basic-field {
  display: grid;
  gap: 7px;
  color: var(--chrome-muted);
  font-size: 11px;
  font-weight: 740;
}

.basic-field input {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--chrome-border);
  border-radius: 8px;
  color: var(--chrome-ink);
  background: var(--panel-bg);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
}

.basic-field input:disabled {
  color: var(--chrome-muted);
  background: var(--panel-muted);
  cursor: not-allowed;
}

.basic-field input:focus-visible,
.tool-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 35%, transparent);
  outline-offset: 2px;
}

.basic-tool-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.tool-button {
  display: flex;
  min-height: 70px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--chrome-border);
  border-radius: 10px;
  color: var(--chrome-ink);
  background: var(--panel-bg);
  font-size: 12px;
  font-weight: 760;
  cursor: pointer;
}

.tool-button:hover,
.tool-button[aria-pressed="true"] {
  border-color: var(--chrome-ink);
  background: var(--panel-muted);
}

.tool-button-icon {
  font-family: ui-monospace, monospace;
  font-size: 25px;
  font-weight: 400;
  line-height: 1;
}

.tool-button-text-icon {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 22px;
  font-weight: 750;
}

.basic-tool-note,
.basic-selection-hint,
.basic-instructions p {
  margin: 10px 0 0;
  color: var(--chrome-muted);
  font-size: 11px;
  line-height: 1.5;
}

.basic-selection-hint {
  min-height: 17px;
  margin: -3px 0 12px;
}

.basic-delete {
  width: 100%;
  margin-top: 11px;
}

.basic-instructions p + p {
  margin-top: 5px;
}

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 8px 12px 8px 15px;
  border-top: 1px solid var(--chrome-border);
  background: var(--panel-muted);
}

.editor-status {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--chrome-muted);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-status[data-valid="true"]::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 999px;
  background: #18a46f;
}

.editor-status[data-valid="false"] {
  color: #b42318;
}

body[data-theme="dark"] .editor-status[data-valid="false"] {
  color: #ff9b91;
}

.syntax-help-trigger {
  flex: 0 0 auto;
  padding: 3px 1px;
  border: 0;
  color: var(--chrome-ink);
  background: transparent;
  font-size: 11px;
  font-weight: 760;
  cursor: pointer;
}

.syntax-help-trigger:hover {
  color: var(--focus);
}

.cloud-dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--chrome-border);
  border-radius: 14px;
  color: var(--chrome-ink);
  background: var(--panel-bg);
  box-shadow: 0 24px 70px rgb(15 23 42 / 28%);
}

.cloud-dialog::backdrop {
  background: rgb(15 23 42 / 36%);
  backdrop-filter: blur(2px);
}

.cloud-dialog-card {
  display: grid;
  gap: 16px;
  padding: 24px;
}

.cloud-dialog-card h2,
.cloud-dialog-card p {
  margin: 0;
}

.cloud-dialog-copy {
  color: var(--chrome-muted);
  font-size: 14px;
  line-height: 1.5;
}

.cloud-auth-form {
  display: grid;
  gap: 12px;
}

.cloud-auth-form[hidden],
.cloud-auth-form [hidden] {
  display: none;
}

.cloud-auth-form label {
  display: grid;
  gap: 6px;
  color: var(--chrome-ink);
  font-size: 12px;
  font-weight: 760;
}

.cloud-auth-form input {
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--chrome-border);
  border-radius: 9px;
  color: var(--chrome-ink);
  background: var(--panel-bg);
  font: inherit;
  font-size: 14px;
}

.cloud-auth-form input:focus {
  border-color: var(--focus);
  outline: 2px solid color-mix(in srgb, var(--focus) 24%, transparent);
  outline-offset: 1px;
}

.cloud-change-email {
  justify-self: start;
  padding: 0;
}

.cloud-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.cloud-dialog-actions [hidden] {
  display: none;
}

.account-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--chrome-border);
  border-radius: 10px;
  background: var(--panel-muted);
}

.account-profile[hidden] {
  display: none;
}

.account-profile img {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  object-fit: cover;
  background: var(--panel-bg);
}

.account-profile strong,
.account-profile span {
  display: block;
}

.account-profile span {
  margin-top: 3px;
  color: var(--chrome-muted);
  font-size: 12px;
}

.help-sidebar {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(470px, calc(100vw - 24px));
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--chrome-border);
  border-width: 0 0 0 1px;
  color: var(--chrome-ink);
  background: var(--panel-bg);
  box-shadow: -20px 0 55px rgb(15 23 42 / 22%);
  overscroll-behavior: contain;
}

.help-sidebar::backdrop {
  background: rgb(15 23 42 / 34%);
  backdrop-filter: blur(2px);
}

.help-sidebar[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.help-sidebar-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 15px 18px 14px 22px;
  border-bottom: 1px solid var(--chrome-border);
  background: color-mix(in srgb, var(--panel-bg) 94%, transparent);
  backdrop-filter: blur(14px);
}

.help-sidebar-header h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.15;
}

.help-close {
  display: grid;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--chrome-border);
  border-radius: 999px;
  place-items: center;
  color: var(--chrome-ink);
  background: var(--panel-bg);
  font-size: 25px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
}

.help-close:hover {
  border-color: color-mix(in srgb, var(--chrome-muted) 55%, var(--chrome-border));
  background: var(--panel-muted);
}

.help-sidebar-content {
  overflow-y: auto;
  padding: 22px 24px 40px;
  font-size: 13px;
  line-height: 1.58;
}

.help-sidebar-content section {
  padding-top: 20px;
  margin-top: 20px;
  border-top: 1px solid var(--chrome-border);
}

.help-sidebar-content h3 {
  margin: 0 0 9px;
  font-size: 14px;
  line-height: 1.25;
}

.help-sidebar-content p {
  margin: 0 0 12px;
  color: var(--chrome-muted);
}

.help-sidebar-content .help-intro {
  margin: 0;
  color: var(--chrome-ink);
  font-size: 14px;
}

.help-warning {
  padding: 13px 14px;
  margin-top: 18px;
  border: 1px solid color-mix(in srgb, #d97706 45%, var(--chrome-border));
  border-radius: 10px;
  background: color-mix(in srgb, #f59e0b 10%, var(--panel-bg));
}

.help-warning strong {
  display: block;
  margin-bottom: 4px;
  color: var(--chrome-ink);
  font-size: 13px;
}

.help-warning p {
  margin: 0;
}

.help-sidebar-content code {
  padding: 0.1em 0.3em;
  border-radius: 4px;
  color: var(--chrome-ink);
  background: var(--panel-muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.92em;
}

.help-sidebar-content pre {
  margin: 12px 0;
  overflow-x: auto;
  padding: 14px 15px;
  border: 1px solid var(--chrome-border);
  border-radius: 10px;
  color: #dce7f6;
  background: #111722;
  line-height: 1.55;
}

.help-sidebar-content pre code {
  padding: 0;
  color: inherit;
  background: transparent;
}

.help-table-wrap {
  overflow-x: auto;
  margin: 12px 0;
  border: 1px solid var(--chrome-border);
  border-radius: 10px;
}

.help-sidebar-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.help-sidebar-content th,
.help-sidebar-content td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--chrome-border);
  text-align: left;
  vertical-align: top;
}

.help-sidebar-content th {
  background: var(--panel-muted);
  font-weight: 760;
}

.help-sidebar-content tr:last-child td {
  border-bottom: 0;
}

.preview-title-block {
  min-width: 0;
}

.style-label {
  margin-right: 2px;
  color: var(--chrome-muted);
  font-size: 11px;
  font-weight: 720;
}

.style-swatch {
  width: 23px;
  height: 23px;
  padding: 0;
  border: 2px solid var(--panel-bg);
  border-radius: 999px;
  box-shadow: 0 0 0 1px var(--chrome-border);
  cursor: pointer;
}

.style-swatch[data-style-option="diagrammar"] {
  background: conic-gradient(#f0b66f, #54b58f, #5d9bd6, #9a78d0, #f0b66f);
}

.style-swatch[data-style-option="blueprint"] {
  background: conic-gradient(#3c7db8, #4d9ed8, #5b7fb5, #3c7db8);
}

.style-swatch[data-style-option="boardroom"] {
  background: conic-gradient(#d8a452, #6ca47f, #a579b3, #d8a452);
}

.style-swatch[data-style-option="mono"] {
  background: conic-gradient(#111827, #6b7280, #d1d5db, #111827);
}

.style-swatch:hover,
.style-swatch:focus-visible {
  transform: translateY(-1px);
}

.style-swatch[aria-pressed="true"] {
  box-shadow:
    0 0 0 2px var(--chrome-ink),
    0 0 0 5px var(--panel-bg);
}

.preview-stage {
  display: grid;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  place-items: center;
  padding: clamp(12px, 2vw, 28px);
  background:
    radial-gradient(
      circle at 50% 45%,
      color-mix(in srgb, var(--focus) 4%, transparent),
      transparent 60%
    ),
    var(--panel-muted);
}

.preview-canvas {
  --diagram-gap-sm: clamp(5px, 0.45cqw, 8px);
  --diagram-gap-md: clamp(8px, 0.75cqw, 13px);
  --diagram-gap-lg: clamp(12px, 1cqw, 18px);
  position: relative;
  container-type: inline-size;
  width: 100%;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--border) 88%, transparent);
  border-radius: 12px;
  color: var(--ink);
  background: var(--canvas-bg);
  box-shadow: 0 22px 56px var(--shadow-color);
  isolation: isolate;
}

body[data-mode="basic"] .preview-stage {
  place-items: stretch;
}

body[data-mode="basic"] .preview-canvas {
  min-width: 720px;
  min-height: 460px;
}

body[data-mode="mermaid"] .preview-stage {
  place-items: stretch;
}

body[data-mode="mermaid"] .preview-canvas {
  display: grid;
  min-width: 620px;
  min-height: 460px;
  place-items: center;
  padding: clamp(22px, 4vw, 56px);
}

.mermaid-diagram {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
}

.mermaid-diagram > svg {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  color: var(--ink);
}

.basic-diagram-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  touch-action: none;
  user-select: none;
}

.basic-diagram-title {
  fill: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 28px;
  font-weight: 700;
}

.basic-box {
  --box-fill: var(--tracking);
  color: var(--ink);
  cursor: grab;
}

.basic-box:active {
  cursor: grabbing;
}

.basic-box-shape {
  fill: var(--box-fill);
  stroke: var(--border);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.basic-box text {
  fill: currentColor;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 17px;
  font-weight: 720;
  pointer-events: none;
}

.basic-box.is-selected .basic-box-shape,
.basic-box.is-connecting .basic-box-shape {
  stroke-width: 4;
}

.basic-box.is-connecting .basic-box-shape {
  stroke-dasharray: 8 5;
}

.basic-arrow {
  cursor: pointer;
}

.basic-arrow-line {
  fill: none;
  stroke: var(--line);
  stroke-width: 2.25;
  vector-effect: non-scaling-stroke;
}

.basic-arrow-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 18;
  vector-effect: non-scaling-stroke;
}

.basic-arrow.is-selected .basic-arrow-line {
  stroke: var(--focus);
}

.basic-arrowhead {
  fill: var(--line);
}

.basic-arrowhead.is-selected {
  fill: var(--focus);
}

.basic-arrow-label rect {
  fill: var(--canvas-bg);
  stroke: var(--border);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.basic-arrow-label text {
  fill: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  font-weight: 680;
}

.basic-free-text {
  color: var(--ink);
  cursor: grab;
}

.basic-free-text:active {
  cursor: grabbing;
}

.basic-free-text-hit {
  fill: transparent;
  stroke: transparent;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.basic-free-text.is-selected .basic-free-text-hit {
  fill: color-mix(in srgb, var(--focus) 7%, transparent);
  stroke: var(--focus);
  stroke-dasharray: 4 3;
}

.basic-free-text text {
  fill: currentColor;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 18px;
  font-weight: 500;
  pointer-events: none;
}

.basic-empty-message {
  fill: var(--muted);
  font-size: 18px;
  font-weight: 650;
}

.diagram-content {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: clamp(13px, 1.55cqw, 25px);
}

.diagram-heading {
  flex: 0 0 auto;
  margin: 0 0 clamp(7px, 0.75cqw, 12px);
  overflow: hidden;
  color: var(--ink);
  font-size: clamp(14px, 1.4cqw, 24px);
  font-weight: 820;
  letter-spacing: -0.02em;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diagram-root,
.layout,
.box-children {
  display: flex;
  min-width: 0;
  min-height: 0;
}

.diagram-root {
  flex: 1 1 auto;
  flex-direction: column;
  gap: var(--diagram-gap-md);
}

.layout {
  position: relative;
  gap: var(--diagram-gap-md);
}

.layout-row {
  flex-direction: row;
}

.layout-column {
  flex-direction: column;
}

.layout.has-title {
  padding-top: clamp(18px, 2cqw, 28px);
}

.layout-title {
  position: absolute;
  top: 1px;
  left: 2px;
  max-width: calc(100% - 4px);
  overflow: hidden;
  color: var(--muted);
  font-size: clamp(7px, 0.7cqw, 11px);
  font-weight: 850;
  letter-spacing: 0.1em;
  line-height: 1.1;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.diagram-box {
  --box-fill: var(--tracking);
  --box-accent: var(--tracking-accent);
  position: relative;
  z-index: 1;
  display: flex;
  flex-basis: 0;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: clamp(8px, 0.9cqw, 15px);
  border: 1px solid var(--border);
  border-radius: clamp(7px, 0.8cqw, 13px);
  background: var(--box-fill);
  box-shadow: 0 5px 13px color-mix(in srgb, var(--shadow-color) 65%, transparent);
}

.diagram-box::before {
  content: "";
  position: absolute;
  top: clamp(8px, 0.9cqw, 15px);
  bottom: clamp(8px, 0.9cqw, 15px);
  left: clamp(6px, 0.7cqw, 11px);
  width: clamp(3px, 0.34cqw, 6px);
  border-radius: 999px;
  background: var(--box-accent);
}

.role-application,
.tone-0 {
  --box-fill: var(--fallback);
  --box-accent: var(--fallback-accent);
}

.role-platform,
.tone-1 {
  --box-fill: var(--platform);
  --box-accent: var(--platform-accent);
}

.role-hub,
.tone-2 {
  --box-fill: var(--hub);
  --box-accent: var(--hub-accent);
}

.role-input,
.tone-3 {
  --box-fill: var(--tracking);
  --box-accent: var(--tracking-accent);
}

.role-events,
.tone-4 {
  --box-fill: var(--events);
  --box-accent: var(--events-accent);
}

.role-external,
.tone-5 {
  --box-fill: var(--external);
  --box-accent: var(--external-accent);
}

.box-title {
  flex: 0 0 auto;
  margin: 0 0 clamp(6px, 0.65cqw, 11px);
  padding-left: clamp(8px, 0.9cqw, 15px);
  overflow: hidden;
  color: var(--ink);
  font-size: clamp(7px, 0.72cqw, 12px);
  font-weight: 850;
  letter-spacing: 0.025em;
  line-height: 1.12;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.box-children {
  flex: 1 1 auto;
  gap: var(--diagram-gap-md);
  padding: 0 clamp(1px, 0.3cqw, 5px) clamp(1px, 0.2cqw, 4px) clamp(7px, 0.8cqw, 13px);
}

.flow-row {
  flex-direction: row;
}

.flow-column {
  flex-direction: column;
}

.diagram-node {
  position: relative;
  z-index: 3;
  display: grid;
  flex: 1 1 0;
  min-width: 0;
  min-height: clamp(30px, 3.7cqw, 62px);
  max-width: clamp(112px, 21cqw, 250px);
  max-height: clamp(42px, 5.6cqw, 82px);
  place-items: center;
  padding: clamp(5px, 0.7cqw, 11px);
  border: 1.5px solid var(--line);
  border-radius: clamp(6px, 0.7cqw, 11px);
  color: var(--ink);
  background: var(--component-fill);
  box-shadow: 0 4px 10px color-mix(in srgb, var(--shadow-color) 70%, transparent);
}

.flow-column > .diagram-node {
  width: min(82%, 280px);
  flex: 1 1 0;
}

.node-label {
  overflow: hidden;
  font-size: clamp(8px, 0.88cqw, 14px);
  font-weight: 800;
  line-height: 1.12;
  text-align: center;
  text-overflow: ellipsis;
  white-space: pre-line;
}

.connection-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.connection-path {
  fill: none;
  stroke: var(--line);
  stroke-width: clamp(1.2px, 0.16cqw, 2.1px);
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.7;
}

.connection-label-bg {
  fill: var(--canvas-bg);
  stroke: var(--border);
  stroke-width: 1px;
  opacity: 0.96;
}

.connection-label {
  fill: var(--muted);
  font-family: Inter, ui-sans-serif, sans-serif;
  font-size: clamp(7px, 0.62cqw, 10px);
  font-weight: 720;
  text-anchor: middle;
}

.diagram-empty {
  display: grid;
  height: 100%;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 40px));
  padding: 11px 14px;
  border: 1px solid var(--chrome-border);
  border-radius: 10px;
  color: var(--chrome-ink);
  background: var(--panel-bg);
  box-shadow: 0 18px 42px rgb(15 23 42 / 20%);
  font-size: 13px;
  font-weight: 680;
  visibility: hidden;
  opacity: 0;
  transform: translateY(6px);
  transition: 150ms ease;
}

.toast[data-visible="true"] {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1100px) {
  .app-header {
    grid-template-columns: 150px minmax(260px, 1fr) auto;
    gap: 10px;
    padding-inline: 14px;
  }

  .brand img {
    width: 145px;
  }

  .project-tools .quiet-button,
  .project-tools .action-menu summary {
    padding-inline: 8px;
    font-size: 12px;
  }

  .project-select {
    min-width: 145px;
    max-width: 210px;
  }

  .file-tools > .quiet-button {
    padding-inline: 9px;
  }
}

@media (max-width: 840px) {
  body {
    overflow: auto;
  }

  .app-header {
    position: sticky;
    top: 0;
    grid-template-columns: 1fr auto;
    height: auto;
    min-height: 72px;
  }

  .brand {
    display: none;
  }

  .project-tools {
    overflow-x: auto;
  }

  .file-tools {
    flex-wrap: wrap;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(460px, 62vh) minmax(480px, 74vh);
    height: auto;
  }

  .preview-canvas {
    width: 100%;
  }

  .help-sidebar {
    width: min(100%, 470px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto;
    transition-duration: 0.01ms;
  }
}
