:root {
  /* 3D view (read by view.js and render.js) */
  --sky: #dce5e9;
  --ground: #eef0e7;
  --ground-out: #d7dbd1;
  --grid: #8a948d;
  --grid-major: #4f5a54;
  --edge: #e0782a;
  --path: #24303a;
  --sel: #ff7a1a;
  --route: #2f6fe0;
  --draft: #0fa3b6;
  --node: #4b5a63;
  --end: #1d8a73;
  --junction: #7b4fd6;
  --handle: #ff7a1a;
  --hover: #2f6fe0;
  /* interface */
  --bg: #fbfbf8;
  --raised: #ffffff;
  --text: #1d262c;
  --muted: #69757b;
  --line: #e0e3dc;
  --accent: #ff7a1a;
  --danger: #c2372b;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 30, 35, .08), 0 4px 14px rgba(20, 30, 35, .08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.4 Barlow, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }

#app { display: grid; grid-template-columns: minmax(0, 1fr) 320px; height: 100vh; }
#main { display: grid; grid-template-rows: minmax(0, 1fr) 170px; min-width: 0; border-right: 1px solid var(--line); }
#view { position: relative; overflow: hidden; user-select: none; }
#view canvas { display: block; touch-action: none; }

/* Toolbar */
#toolbar {
  position: absolute; left: 12px; top: 12px; display: flex; flex-direction: column; gap: 2px; padding: 5px;
  background: var(--raised); border-radius: 10px; box-shadow: var(--shadow);
}
#toolbar hr { border: 0; border-top: 1px solid var(--line); margin: 3px 2px; }
#toolbar button {
  position: relative; width: 38px; height: 38px; display: grid; place-items: center; border: 0; border-radius: 7px;
  background: none; cursor: pointer; color: var(--text);
}
#toolbar button:hover { background: #f0f2ee; }
#toolbar button.on { background: var(--text); color: #fff; }
#toolbar svg { width: 20px; height: 20px; fill: currentColor; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#toolbar svg [fill="none"] { fill: none; }
#toolbar kbd { position: absolute; right: 3px; bottom: 1px; font: 600 9px Barlow, sans-serif; opacity: .55; }

#hint {
  position: absolute; left: 66px; top: 12px; right: 12px; max-width: 760px; padding: 7px 11px; border-radius: var(--radius);
  background: rgba(255, 255, 255, .86); box-shadow: var(--shadow); color: var(--muted); font-size: 13px; pointer-events: none;
}
#hint b { color: var(--text); font-weight: 600; }
#legend {
  position: absolute; left: 66px; top: 52px; display: flex; gap: 10px; padding: 5px 10px; border-radius: var(--radius);
  background: rgba(255, 255, 255, .86); font-size: 12px; color: var(--muted); pointer-events: none;
}
#legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
#status {
  position: absolute; left: 12px; bottom: 10px; right: 12px; display: flex; justify-content: space-between; gap: 16px;
  font-size: 12px; color: var(--muted); pointer-events: none;
}
#status > span { background: rgba(255, 255, 255, .8); padding: 2px 8px; border-radius: 6px; }
#status > span:empty { display: none; }
#stSave { pointer-events: auto; }
#stSave.warn { color: var(--danger); }
#debug { position: absolute; right: 12px; top: 64px; padding: 4px 8px; border-radius: 6px; background: rgba(0, 0, 0, .7); color: #fff; font: 12px ui-monospace, monospace; }
#tip {
  position: absolute; padding: 3px 7px; border-radius: 5px; background: var(--text); color: #fff; font-size: 12px; pointer-events: none;
  white-space: nowrap;
}
#box { position: absolute; border: 1px solid var(--sel); background: rgba(255, 122, 26, .08); pointer-events: none; }
#toast {
  position: absolute; left: 50%; bottom: 40px; transform: translate(-50%, 20px); max-width: min(560px, 90%); padding: 9px 14px;
  border-radius: var(--radius); background: var(--text); color: #fff; font-size: 13px; opacity: 0; transition: .2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Help */
#help { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(30, 40, 45, .25); }
#help[hidden] { display: none; }
.help-card { width: min(640px, 92%); max-height: 90%; overflow: auto; padding: 22px 24px; border-radius: 12px; background: var(--raised); box-shadow: var(--shadow); }
.help-card h2 { margin: 0 0 4px; font-size: 20px; }
.help-card h3 { margin: 14px 0 6px; font-size: 13px; text-transform: none; color: var(--muted); font-weight: 600; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.help-card dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: 13px; }
.help-card dt { font-weight: 600; white-space: nowrap; }
.help-card dd { margin: 0; color: var(--muted); }

/* Profile */
#profileWrap { position: relative; border-top: 1px solid var(--line); background: var(--raised); min-height: 0; }
#profile { position: absolute; inset: 0; display: block; }
#profileEmpty { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 13px; padding: 0 20px; text-align: center; }
#profileEmpty[hidden] { display: none; }

/* Panel */
#panel { overflow-y: auto; background: var(--bg); display: flex; flex-direction: column; }
#panel section { padding: 14px 16px; border-bottom: 1px solid var(--line); }
#panel h2 { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
#panel footer { margin-top: auto; padding: 10px 16px; }
.title-input {
  width: 100%; padding: 4px 6px; margin: -4px -6px 2px; border: 1px solid transparent; border-radius: 6px; background: none;
  font-size: 18px; font-weight: 600;
}
.title-input:hover { border-color: var(--line); }
.title-input:focus { outline: none; border-color: var(--accent); background: var(--raised); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
p { margin: 6px 0; }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.btns button, .inline button, details button, .note button {
  padding: 5px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--raised); cursor: pointer;
}
.btns button:hover, .inline button:hover, details button:hover { border-color: #c9cec6; }
button.primary { background: var(--text); border-color: var(--text); color: #fff; }
button.primary:hover { background: #2e3c46; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; padding: 0; color: var(--route); text-decoration: underline; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
.help-card button.primary { margin-top: 14px; padding: 7px 16px; border-radius: 7px; border: 0; cursor: pointer; }

details { margin-top: 10px; }
summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details[open] summary { margin-bottom: 8px; }
.field { display: grid; gap: 3px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.field select { padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--raised); color: var(--text); }

.kv { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.xyz { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0; }
.xyz.two { grid-template-columns: 1fr 1fr; }
.xyz label, .inline label { display: grid; gap: 2px; font-size: 11px; color: var(--muted); }
input[type=number] {
  width: 100%; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--raised); color: var(--text);
  font-variant-numeric: tabular-nums;
}
input:focus, select:focus { outline: 2px solid rgba(255, 122, 26, .35); border-color: var(--accent); }
.inline { display: flex; align-items: end; gap: 6px; margin: 6px 0; }
.inline label { flex: 1; }
.seg3 { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; margin: 8px 0 2px; }
.seg3 button { flex: 1; padding: 5px 0; border: 0; background: var(--raised); cursor: pointer; }
.seg3 button + button { border-left: 1px solid var(--line); }
.seg3 button.on { background: var(--text); color: #fff; }

.list { list-style: none; margin: 8px 0 0; padding: 0; }
.list li.muted { padding: 4px 0; font-size: 13px; }
#worldList { border: 1px solid var(--line); border-radius: var(--radius); background: var(--raised); max-height: 260px; overflow: auto; }
#worldList li + li { border-top: 1px solid var(--line); }
#worldList li.muted { padding: 8px 10px; }
.wl-open { display: grid; gap: 1px; width: 100%; padding: 7px 10px; border: 0; background: none; text-align: left; cursor: pointer; }
.wl-open:hover { background: #f4f5f1; }
.wl-open span { font-size: 12px; color: var(--muted); }
#worldList li.on .wl-open b::after { content: ' (open)'; font-weight: 400; color: var(--muted); }

.route { padding: 8px 10px; margin: 0 -10px; border-radius: var(--radius); cursor: pointer; }
.route:hover { background: #f2f3ef; }
.route.on { background: var(--raised); box-shadow: inset 3px 0 0 var(--route), var(--shadow); cursor: default; }
.route .rname { font-weight: 600; }
.route input.rname { width: 100%; padding: 2px 5px; margin: -3px -6px 0; border: 1px solid var(--line); border-radius: 5px; background: var(--raised); }
.route .rmeta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.route .btns { margin-top: 6px; }
.route .btns button { padding: 3px 8px; font-size: 13px; }
.note { padding: 8px 10px; border-radius: var(--radius); background: #e8f6f8; font-size: 13px; margin-bottom: 8px; }
