:root {
  --paper: #f4f1ea;
  --ink: #211f1b;
  --muted: #7a7468;
  --accent: #ad431f;
  --panel: rgba(252, 250, 245, .82);
  --panel-border: rgba(33, 31, 27, .09);
  --font: Inter, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 50% -12%, #fbf8f1 0%, #f3efe6 52%, #ebe6da 100%);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#svg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: default;
}
#svg.tool-create { cursor: crosshair; }
#svg.panning { cursor: grabbing; }
#svg.pan-ready { cursor: grab; }
#preview { pointer-events: none; }

/* ---------- chrome ---------- */

.brand {
  position: fixed;
  top: 18px;
  left: 22px;
  pointer-events: none;
  line-height: 1;
}
.brand .mark {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-style: italic;
  font-size: 21px;
  letter-spacing: -.01em;
}
.brand .sub {
  margin-top: 5px;
  font-size: 9px;
  letter-spacing: .17em;
  text-transform: uppercase;
  color: var(--muted);
}

.tools, .actions, .zoombar, .hint, .menu {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 10px 30px rgba(56, 44, 22, .10), 0 1px 2px rgba(56, 44, 22, .05);
  backdrop-filter: blur(14px) saturate(1.25);
  -webkit-backdrop-filter: blur(14px) saturate(1.25);
}

.tools {
  position: fixed;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 7px;
  border-radius: 15px;
  max-height: calc(100vh - 150px);
  overflow: auto;
  scrollbar-width: none;
}
.tools::-webkit-scrollbar { display: none; }

.tools .divider {
  height: 1px;
  margin: 4px 6px;
  background: rgba(33, 31, 27, .12);
  flex: none;
}

.actions {
  position: fixed;
  top: 16px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  border-radius: 13px;
}

.zoombar {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  border-radius: 13px;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0;
}

.ibtn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #5b554b;
  transition: background .14s, color .14s;
}
.ibtn:hover { background: rgba(33, 31, 27, .06); color: var(--ink); }
.ibtn:active { background: rgba(33, 31, 27, .1); }
.ibtn:disabled { opacity: .3; cursor: default; background: none; }
.ibtn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

.tool {
  width: 38px;
  height: 36px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: #5b554b;
  transition: background .14s, color .14s;
}
.tool svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { background: rgba(33, 31, 27, .06); color: var(--ink); }
.tool.active {
  background: var(--ink);
  color: #f7f3ea;
  box-shadow: 0 2px 6px rgba(33, 31, 27, .25);
}

.btn {
  height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 12.5px;
  letter-spacing: .01em;
  color: #524c42;
  transition: background .14s, color .14s;
}
.btn:hover { background: rgba(33, 31, 27, .06); color: var(--ink); }
.btn:active { background: rgba(33, 31, 27, .1); }
.btn.on { background: var(--ink); color: #f7f3ea; box-shadow: 0 2px 6px rgba(33, 31, 27, .25); }

.sep {
  width: 1px;
  height: 18px;
  margin: 0 4px;
  background: rgba(33, 31, 27, .12);
  flex: none;
}

.zoomlabel {
  min-width: 50px;
  height: 32px;
  border-radius: 8px;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: #5b554b;
}
.zoomlabel:hover { background: rgba(33, 31, 27, .06); }

.hint {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  max-width: calc(100vw - 260px);
  padding: 8px 15px;
  border-radius: 999px;
  font-size: 11.5px;
  letter-spacing: .005em;
  color: #6d6658;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .2s, border-color .2s;
}
.hint.warn { color: var(--accent); border-color: rgba(173, 67, 31, .35); }

.menu {
  position: fixed;
  z-index: 40;
  min-width: 208px;
  padding: 6px;
  border-radius: 12px;
  background: #fffdf8;
}
.menu .head {
  padding: 9px 10px 4px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #8a8272;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 12.5px;
  color: #3b372f;
}
.menu button:hover { background: #f2eee3; }
.menu button span {
  display: block;
  margin-top: 2px;
  font-size: 10.5px;
  color: #746d5f;
}
.menu hr {
  border: 0;
  border-top: 1px solid rgba(33, 31, 27, .08);
  margin: 5px 6px;
}

/* ---------- inline editor ---------- */

.edit {
  position: fixed;
  z-index: 60;
  transform: none;
  padding: 7px 9px;
  border: 1.5px solid var(--accent);
  border-radius: 9px;
  background: #fffdf8;
  box-shadow: 0 6px 22px rgba(56, 44, 22, .16);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  resize: none;
  overflow: hidden;
  outline: none;
}

/* ---------- diagram ---------- */

#world .node { cursor: default; }

#nodes .node.loop, #nodes .auto-loop { cursor: pointer; }

#nodes .node:hover .hit { fill: rgba(33, 31, 27, .045); }

#nodes .hit { fill: transparent; }

#links .link { cursor: pointer; }

@media (max-width: 820px) {
  .hint { display: none; }
  .brand .sub { display: none; }
  .actions .btn { padding: 0 8px; }
}
