:root {
  --text: #1d2125;
  --muted: #6b7280;
  --line: #d9dde3;
  --bg: #ffffff;
  --panel: #f6f7f9;
  --accent: #2f6db5;
  --danger: #b42318;
  --warn-bg: #fff4d6;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0.2rem 0 0.4rem; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 0.5rem; }
main > section { max-width: 960px; margin: 0 auto; padding: 1rem; }
section.narrow { max-width: 460px; }

.top { display: flex; gap: 1rem; align-items: center; padding: 0.3rem 1rem; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); display: inline-flex; align-items: center; gap: 0.45rem; }
.brand img { width: 2.4em; height: 2.4em; }
.crumb { color: var(--muted); }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
form.inline, .actions form { display: inline; }

button, .button { font: inherit; padding: 0.3rem 0.8rem; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 4px; cursor: pointer; display: inline-block; }
.button { background: #fff; color: var(--accent); }
.button:hover { text-decoration: none; background: #eef3fa; }
button.link { background: none; border: none; color: var(--accent); padding: 0 0.2rem; }
button.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
button.link.danger { border: none; }
input, select, textarea { font: inherit; padding: 0.25rem 0.4rem; border: 1px solid var(--line); border-radius: 4px; max-width: 100%; }
textarea { width: 100%; }
.stack p { margin: 0.4rem 0; }
.stack label { display: block; font-weight: 600; }
.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0.4rem 0; }
.helptext { color: var(--muted); font-size: 0.85em; display: block; }
.errorlist { color: var(--danger); }

table.list { border-collapse: collapse; width: 100%; }
table.list td, table.list th { text-align: left; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.small td { font-family: ui-monospace, monospace; font-size: 0.8rem; white-space: nowrap; }
pre { background: var(--panel); padding: 0.6rem; overflow-x: auto; }
.danger-zone { margin-top: 2rem; }

.messages { list-style: none; margin: 0; padding: 0; }
.messages li { padding: 0.5rem 1rem; background: #e8f1fb; border-bottom: 1px solid var(--line); }
.messages li.error { background: #fde8e7; }
.messages li.warning { background: var(--warn-bg); }
.warn { background: var(--warn-bg); padding: 0.3rem 0.6rem; }
.badge { font-size: 0.75rem; background: #eceff3; border-radius: 3px; padding: 0 0.3rem; color: var(--muted); }
.badge.warn { background: var(--warn-bg); color: #8a5a00; }

/* tree viewer */
body.viewer main { padding: 0; }
.viewer-layout { display: flex; height: calc(100vh - 50px); }
.panel { width: 340px; flex: none; overflow-y: auto; padding: 0.8rem; border-right: 1px solid var(--line); background: var(--panel); }
.panel .box { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 0.4rem 0.6rem; margin: 0.6rem 0; }
.panel summary { font-weight: 600; cursor: pointer; }
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem 0.6rem; margin-top: 0.4rem; }
.settings label { display: flex; flex-direction: column; font-size: 0.85rem; min-width: 0; }
.settings input:not([type=checkbox]), .settings select { width: 100%; }
.settings label.check { flex-direction: row; gap: 0.3rem; align-items: center; grid-column: span 2; }
.settings .row { grid-column: span 2; }
.annotations { padding-left: 1.3rem; margin: 0.4rem 0; }
.annotations li { margin: 0.25rem 0; word-break: break-all; }
.annotations .actions { display: flex; gap: 0.25rem; margin-top: 0.15rem; }
.annotations .actions button.link { border: 1px solid var(--line); border-radius: 3px; background: #fff;
  color: var(--text); font-size: 0.75rem; padding: 0 0.4rem; line-height: 1.5; }
.annotations .actions button.link:hover { border-color: var(--accent); color: var(--accent); }
.annotations .actions button.link.danger { color: var(--danger); }
.annotations .actions button.link.danger:hover { border-color: var(--danger); }
.hidden-item > a { color: var(--muted); text-decoration: line-through; }
.figure { flex: 1; overflow: hidden; background: #fff; cursor: grab; }
.figure svg { width: 100%; height: 100%; display: block; user-select: none; }
.figure:active { cursor: grabbing; }

@media (max-width: 800px) {
  .viewer-layout { flex-direction: column; height: auto; }
  .panel { width: 100%; border-right: none; }
  .figure { height: 80vh; }
}

/* mouse-over highlighting (viewer.js) */
.figure { position: relative; }
.figure svg .hl { stroke: #ff6a00; }
.figure svg path.hl[fill]:not([fill="none"]) { fill: #ffb27a; }
.figure svg text.hl { fill: #ff6a00; font-weight: bold; stroke: none; }
.hover-info { position: absolute; top: 8px; right: 8px; background: rgba(255, 255, 255, 0.92); border: 1px solid var(--line);
  border-radius: 4px; padding: 0.2rem 0.5rem; font-size: 0.85rem; pointer-events: none; max-width: 60%; }

/* "?" marks and their tooltip (help.js) */
.help { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; border-radius: 50%;
  background: #e3e8ef; color: #4b5563; font-size: 10px; font-weight: 700; cursor: help; vertical-align: middle; flex: none; }
.help:hover { background: var(--accent); color: #fff; }
.tip { position: fixed; z-index: 100; max-width: 280px; background: #1f2937; color: #fff; font-size: 0.8rem;
  line-height: 1.35; padding: 0.35rem 0.55rem; border-radius: 5px; pointer-events: none; box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.figure-hint { position: absolute; bottom: 6px; left: 8px; font-size: 0.75rem; color: var(--muted); pointer-events: none; }
.history form { display: inline; }
.history .button { padding: 0.2rem 0.6rem; }
button:disabled, .button:disabled { opacity: 0.4; cursor: default; }
button.button.danger { color: var(--danger); border-color: var(--danger); background: #fff; }

/* movable figure elements, dataset name settings, file editor */
.figure svg [data-move] { cursor: move; }
.figure svg [data-move]:hover text { fill: var(--accent); }
.name-settings { margin: 0.15rem 0 0.3rem; font-size: 0.8rem; }
.name-settings summary { cursor: pointer; color: var(--muted); }
.name-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.3rem 0.5rem; margin-top: 0.3rem; }
.name-form label { display: flex; flex-direction: column; min-width: 0; }
.name-form label.wide { flex: 1 1 100%; }
.name-form label.wide input { width: 100%; }
.name-form label.angle input { width: 5rem; }
.name-form label.check { flex-direction: row; align-items: center; gap: 0.3rem; padding-bottom: 0.3rem; }
.name-form button { padding: 0.2rem 0.7rem; }
textarea.code { font-family: ui-monospace, monospace; font-size: 0.8rem; white-space: pre; tab-size: 12; }

/* node menu (viewer.js) */
.node-menu { position: fixed; z-index: 90; background: #fff; border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.15); padding: 0.3rem; display: flex; flex-direction: column; min-width: 180px; }
.node-menu-title { font-size: 0.8rem; color: var(--muted); padding: 0.15rem 0.4rem 0.3rem; border-bottom: 1px solid var(--line);
  margin-bottom: 0.2rem; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-menu button { background: none; border: none; color: var(--text); text-align: left; padding: 0.3rem 0.4rem; border-radius: 4px; }
.node-menu button:hover { background: #eef3fa; color: var(--accent); }
.node-menu label { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.2rem 0.4rem; cursor: pointer; }
.node-menu input[type=color] { width: 2rem; height: 1.4rem; padding: 0; border: 1px solid var(--line); }

.settings .group-title { grid-column: span 2; font-weight: 600; font-size: 0.85rem; margin-top: 0.4rem;
  padding-top: 0.4rem; border-top: 1px solid var(--line); }
.settings input[type=color] { height: 1.9rem; padding: 0.1rem; }

/* guest mode */
.guest-banner { background: var(--warn-bg); padding: 0.4rem 1rem; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.guest-start { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 0.3rem; align-items: flex-start; }
