@font-face {
  font-family: Montserrat;
  src: url("/fonts/montserrat-latin-500.woff2") format("woff2");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}

:root {
  color-scheme: light;
  --paper: #f5f0e5;
  --panel: #fbf8f0;
  --canvas: #f9f6ed;
  --ink: #222b26;
  --muted: #585b51;
  --edge: #dcd6c8;
  --accent: #294f82;
  --accent-hover: #1f406c;
  --selection: #e8edf4;
  --danger: #8b382e;
  --radius: 8px;
  font-family: system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

[hidden], .mobile-only { display: none !important; }
.symbols { position: absolute; width: 0; height: 0; overflow: hidden; }

h1, h2, p, ul { margin: 0; }
button, input { font: inherit; }
button { color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.library-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding-inline: 4px;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 23px;
  white-space: nowrap;
}

.brand, #map-title {
  font-family: Montserrat, system-ui, sans-serif;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  border: 1px solid #d1d9e2;
  background: #eaf0f5;
  color: var(--accent);
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-mark .icon { width: 20px; height: 20px; }

.workspace {
  position: relative;
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}

.library {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding: calc(8px + env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  background: var(--paper);
  border-right: 1px solid var(--edge);
}

.library-heading {
  display: grid;
  gap: 8px;
  padding: 0 4px 12px;
}

.library-heading h2 { font-size: 15px; font-weight: 650; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: #294f8224;
  transition: background-color 130ms ease, border-color 130ms ease;
}

.primary { color: #fff; background: var(--accent); }
.primary:hover:not(:disabled) { background: var(--accent-hover); }
.subtle:hover:not(:disabled) { background: #ece8de; }
.icon-button { width: 36px; padding: 0; }
.button:disabled { opacity: .36; cursor: default; }
.destructive:hover:not(:disabled) { color: var(--danger); background: #f3e7df; }

.map-list {
  min-height: 0;
  overflow: auto;
  list-style: none;
  padding: 4px;
  display: grid;
  gap: 4px;
}

.map-list-button {
  width: 100%;
  min-height: 36px;
  padding: 7px 8px;
  text-align: start;
  overflow-wrap: anywhere;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
}

.map-list-button:hover { background: #ede8dd; }
.map-list-button[aria-current="true"] {
  background: var(--selection);
  border-color: #d1dbe7;
  color: var(--accent);
  box-shadow: inset 2px 0 var(--accent);
  font-weight: 600;
}

.library-tools {
  display: grid;
  margin-top: auto;
  padding: 12px 4px 0;
  border-top: 1px solid var(--edge);
}

.library-tools .button { justify-content: flex-start; padding-inline: 8px; }
.library-tools p { color: var(--muted); font-size: 12px; padding: 12px 8px 4px; }
.library-tools a, .privacy-page a { color: var(--accent); }

.privacy-page { height: auto; min-height: 100dvh; overflow: auto; }
.privacy-page main {
  display: grid;
  gap: 16px;
  width: min(100%, 680px);
  margin-inline: auto;
  padding: 24px 20px 40px;
  line-height: 1.65;
}
.privacy-page h1 { font: 500 clamp(1.8rem, 5vw, 2.4rem)/1.25 Montserrat, system-ui, sans-serif; }
.privacy-page h2 { margin-top: 12px; font-size: 1.125rem; }

.account-tools {
  display: grid;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--edge);
}
.account-tools:not(:has(> :not([hidden]))) { display: none; }
.account-tools p { padding: 4px 8px; overflow-wrap: anywhere; }
.account-tools .account-summary { font-size: 13px; color: var(--ink); }
.account-tools .sync-status { min-height: 24px; }

.main {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}

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

.editor-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas: "title actions tools";
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--edge);
}

h1 {
  font-family: Georgia, serif;
  font-size: clamp(28px, 4vw, 43px);
  line-height: 1.12;
  letter-spacing: -.04em;
  font-weight: 400;
  overflow-wrap: anywhere;
}

.editor-heading {
  grid-area: title;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(19px, 2.2vw, 28px);
}

.map-actions, .map-utilities, .editor-tools, .branch-tools, .dialog-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.map-actions { grid-area: actions; position: relative; }
.editor-tools { grid-area: tools; border-left: 1px solid var(--edge); padding-left: 8px; }
.toolbar-group-label {
  margin-inline-end: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

#layout-toggle { border-color: var(--edge); }
.delete-map-label { display: none; }

.editor-tools .primary {
  background: var(--selection);
  border-color: #d0dae7;
  color: var(--accent-hover);
}
.editor-tools .primary:hover:not(:disabled) { background: #dce6f2; }
.branch-tools { border-left: 1px solid var(--edge); padding-left: 4px; }

.viewport, .empty {
  background-color: var(--canvas);
}

.surface, .empty {
  background-image: radial-gradient(circle, #e7e1d5 .75px, transparent 1px);
  background-size: 24px 24px;
}

.viewport {
  isolation: isolate;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #cfc9bc transparent;
  touch-action: pinch-zoom;
  cursor: grab;
}

.viewport:focus-visible { outline-offset: -3px; }
.viewport.is-panning, .viewport.is-panning * { cursor: grabbing; }

.surface {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}

.map {
  position: absolute;
  zoom: var(--zoom, 1);
}

.connections {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
  stroke-width: 1.6;
  opacity: .74;
  pointer-events: none;
}

.wing, .children, .branch {
  display: contents;
  list-style: none;
  padding: 0;
}

.node-card {
  position: absolute;
  display: grid;
  grid-auto-flow: column;
  align-items: center;
  width: max-content;
  user-select: none;
  -webkit-touch-callout: none;
}

.node-card[data-side="left"] > .node-action { grid-column: 1; grid-row: 1; }
.node-card[data-side="left"] > .node { grid-column: 2; grid-row: 1; }
.node-card:focus-within { z-index: 2; }
.node-card.is-dragging { z-index: 3; }

.node {
  width: 124px;
  z-index: 1;
  min-height: 38px;
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid #cfc9bc;
  border-radius: var(--radius);
  text-align: start;
  font-size: 13px;
  line-height: 1.35;
  font-weight: 570;
  overflow-wrap: anywhere;
  cursor: grab;
}

.node-card[data-side="left"] .node { border-right: 3px solid var(--branch-color); }
.node-card[data-side="right"] .node { border-left: 3px solid var(--branch-color); }
.node:hover { background: #fffdf8; }
.node[aria-pressed="true"] {
  background: var(--selection);
  box-shadow: inset 0 0 0 1px #b9cadf;
}

.node.root {
  width: 152px;
  padding: 8px 12px;
  min-height: 44px;
  border: 1px solid var(--ink);
  background: var(--ink);
  border-radius: 10px;
  text-align: center;
  font-size: 15px;
  color: #fffaf0;
  cursor: pointer;
}
.node.root:hover { background: #35433a; }
.node.root[aria-pressed="true"] {
  background: #304458;
  box-shadow: inset 0 0 0 1px #88a4c3;
}

.node-card.is-dragging .node {
  cursor: grabbing;
  box-shadow: 0 3px 8px #222b2633;
}

.node-action {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  width: 28px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.node-action::before {
  position: absolute;
  z-index: -1;
  width: 17px;
  height: 17px;
  border: 1px solid #ccd6e1;
  border-radius: 50%;
  background: var(--panel);
  content: "";
}

.node-action:hover::before, .node-action:focus-visible::before { background: var(--selection); }
.node-action .icon { width: 12px; height: 12px; }

.empty {
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 24px 20px;
}

.empty-content {
  display: grid;
  justify-items: center;
  gap: 12px;
  text-align: center;
}

.empty-content p {
  max-width: 32ch;
  line-height: 1.55;
  color: var(--muted);
  font-size: 15px;
}

.empty-content .button { margin-top: 8px; padding-inline: 16px; }
.empty-map { width: min(66vw, 288px); height: auto; margin-bottom: 8px; }
.empty-map path { fill: none; stroke-width: 1.5; stroke-linecap: round; }
.empty-left, .empty-leaf.left { stroke: #a05436; }
.empty-right, .empty-leaf.right { stroke: #3d69a1; }
.empty-leaf.left { fill: #f6e9df; }
.empty-leaf.right { fill: #eaf0f5; }
.empty-root { fill: var(--ink); }
.empty-map .empty-ink { stroke: #fffcf3; stroke-width: 1.8; }

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px env(safe-area-inset-bottom);
  border-top: 1px solid var(--edge);
}

.footer:not(:has(#zoom-controls:not([hidden]), .status:not(:empty))) { display: none; }

.status {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.status.error, .dialog-error { color: var(--danger); }
.zoom-controls { display: flex; align-items: center; gap: 4px; margin-left: auto; }
#zoom-level {
  min-width: 40px;
  text-align: center;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

#zoom-fit { border-left: 1px solid var(--edge); border-radius: 0 var(--radius) var(--radius) 0; }

dialog {
  width: min(100% - 32px, 420px);
  max-height: calc(100% - 32px);
  padding: 24px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--edge);
  border-radius: 16px;
  box-shadow: 0 16px 64px #25232226;
}

dialog::backdrop { background: #1e231e52; }
dialog form { display: grid; gap: 12px; }

dialog h2 {
  font-family: Georgia, serif;
  font-size: 26px;
  font-weight: 400;
  letter-spacing: -.025em;
}

dialog label, dialog p { font-size: 14px; line-height: 1.5; }

dialog input {
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  border: 1px solid #b8b1a3;
  border-radius: var(--radius);
  color: var(--ink);
  background: #fffdf7;
  font-size: 16px;
}

.dialog-actions { justify-content: flex-end; gap: 8px; margin-top: 4px; }
#account-dialog > :not(:first-child):not([hidden]) { margin-top: 12px; }
.account-google { width: 100%; text-decoration: none; border-color: var(--edge); }
.account-google:hover { background: var(--paper); }
.copy-maps-options { display: grid; gap: 4px; max-height: 40vh; overflow: auto; }
.copy-maps-options label { display: flex; align-items: center; gap: 8px; }
.copy-maps-options input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.no-script { padding: 16px; }

#layout-dialog {
  inset: 60px 12px auto auto;
  width: min(100% - 24px, 430px);
  max-height: calc(100% - 72px);
  margin: 0;
  padding: 16px;
}

#layout-dialog::backdrop { background: #1e231e24; }

.layout-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.layout-dialog-header h2 { font-size: 23px; }

.layout-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.layout-option {
  position: relative;
  display: grid;
  grid-template-rows: 44px 1fr;
  justify-items: center;
  align-items: center;
  gap: 4px;
  min-height: 88px;
  padding: 8px;
  border: 1px solid var(--edge);
  border-radius: 10px;
  background: #fffdf7;
  font-size: 13px;
  font-weight: 550;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
}

.layout-option:hover:not(:disabled):not([aria-pressed="true"]) { background: var(--paper); }
.layout-option[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--selection);
  color: var(--accent);
}

.layout-option[aria-pressed="true"]::after {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 5px;
  height: 9px;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  content: "";
}

.layout-option:disabled { opacity: .6; cursor: default; }
.layout-option:focus-visible { outline-offset: 2px; }

.layout-preview {
  width: min(100%, 88px);
  height: 44px;
  fill: none;
  stroke: #5f6b76;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.layout-preview :is(rect, circle) { fill: var(--panel); }
.layout-preview .preview-root { fill: #5f6b76; }
.layout-option[aria-pressed="true"] .layout-preview { stroke: var(--accent); }
.layout-option[aria-pressed="true"] .preview-root { fill: var(--accent); }
#layout-error { margin-top: 8px; }

@media (max-width: 720px), (pointer: coarse) and (max-width: 1024px) {
  .mobile-only:not([hidden]) { display: inline-flex !important; }
  .brand { font-size: 22px; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  #sidebar-toggle {
    position: absolute;
    z-index: 1;
    top: calc(2px + env(safe-area-inset-top));
    left: max(4px, env(safe-area-inset-left));
  }
  .workspace:has(.library.open) #sidebar-toggle { visibility: hidden; }
  .library {
    display: none;
    position: absolute;
    z-index: 3;
    inset: 0 auto 0 0;
    width: min(320px, 85%);
    padding-left: max(12px, env(safe-area-inset-left));
  }
  .library.open { display: flex; }
  #sidebar-dismiss {
    position: absolute;
    z-index: 2;
    inset: 0;
    border: 0;
    background: #1e231e52;
  }
  .button { min-height: 44px; }
  .icon-button, #edit-node { width: 44px; padding: 0; }
  .editor-toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "title actions" "tools tools";
    gap: 0 4px;
    padding: calc(2px + env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 2px max(8px, env(safe-area-inset-left));
  }
  .editor-heading { padding-inline-start: 44px; }
  .editor-tools .edit-label { display: none; }
  .editor-tools { border-left: 0; padding-left: 0; }
  .editor-tools, .branch-tools, .map-actions { gap: 0; }
  .map-utilities {
    position: absolute;
    z-index: 2;
    inset: calc(100% + 4px) 0 auto auto;
    display: grid;
    gap: 0;
    padding: 4px;
    border: 1px solid var(--edge);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: 0 4px 16px #222b2626;
  }
  #map-actions-toggle[aria-expanded="true"] { background: var(--selection); color: var(--accent); }
  #map-actions-toggle[aria-expanded="false"] + .map-utilities { display: none; }
  .map-utilities .button { justify-content: flex-start; width: 100%; padding-inline: 12px; }
  .map-utilities .delete-map-label { display: inline; }
  .footer {
    padding-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right));
  }
  .zoom-controls { gap: 0; }
  #zoom-level { min-width: 32px; }
  .node { min-height: 44px; }
  .node-action { width: 36px; height: 36px; }

  #layout-dialog {
    inset: auto max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) auto;
    max-height: calc(100dvh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
}

@media (min-width: 721px) and (max-width: 1024px) and (not (pointer: coarse)), (min-width: 1025px) and (max-width: 1100px) {
  #export-map .export-label, #edit-node .edit-label, #add-node .add-label { display: none; }
  .toolbar-group-label { margin-inline-end: 0; }
}

@media (min-width: 721px) and (max-width: 820px) and (not (pointer: coarse)) {
  .editor-toolbar { gap: 4px; padding-inline: 8px; }
  .toolbar-group-label { display: none; }
}

@media (max-width: 384px) {
  #add-node { width: 44px; padding: 0; }
  #add-node .add-label { display: none; }
}

@media (max-width: 330px) {
  .toolbar-group-label { display: none; }
}

@media (max-width: 420px) {
  .layout-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 560px) and (max-width: 720px), (pointer: coarse) and (min-width: 560px) and (max-width: 1024px) {
  .editor-toolbar {
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: "title actions tools";
  }
  .editor-tools { border-left: 1px solid var(--edge); padding-left: 4px; }
  #add-node { width: 44px; padding: 0; }
  #add-node .add-label { display: none; }
}

@media (max-height: 380px) {
  body {
    height: auto;
    overflow: auto;
  }
  .workspace { height: max(300px, 100dvh); }
  .editor { grid-template-rows: auto minmax(160px, 1fr); }
}

@media (max-height: 520px) {
  .map-list {
    flex-shrink: 0;
    max-height: 42dvh;
  }
}

@media (display-mode: standalone) {
  [data-action="install"] { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .button { transition: none; }
}
