:root {
  color-scheme: dark;
  --body: #0d161a;
  --surface: #131f24;
  --stage: #0c161a;
  --line: #2b3b41;
  --text: #f4ebd6;
  --muted: #a2b2b2;
  --gold: #efd087;
  --aqua: #72e3e2;
  --lavender: #c8a5ff;
  --sans: "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  font: 14px/1.55 var(--sans);
  color: var(--text);
  background: var(--body);
}

*, *::before, *::after { box-sizing: border-box; }
body { display: flex; flex-direction: column; min-height: 100dvh; margin: 0; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--aqua);
  outline-offset: 3px;
}
h1, h2, p { margin: 0; }

.topbar {
  width: 100%;
  max-width: 1920px;
  margin: 0 auto;
  padding: 15px 32px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 44px; height: 44px; color: var(--gold); }
.brand h1 { font-size: 23px; line-height: 1.25; font-weight: 700; letter-spacing: .11em; }
.brand p { color: var(--muted); font-size: 11px; letter-spacing: .12em; margin-top: 4px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 15px;
  font-weight: 650;
  white-space: nowrap;
}
.primary { color: #201c12; background: var(--gold); }
.primary:hover { background: #ffe3a2; }
.secondary { color: var(--text); background: #17282e; border-color: #3c5055; }
.secondary:hover { background: #20363c; }
.danger { color: #1e1011; background: #f5a0a5; }
.danger:hover { background: #ffb5b9; }
.button:disabled { opacity: .56; cursor: wait; }
.plus { font-size: 18px; line-height: 1; font-weight: 500; }

.search { position: relative; z-index: 4; }
.search form { position: relative; }
.search svg {
  position: absolute; top: 11px; left: 12px; width: 19px; height: 19px;
  stroke: var(--muted); stroke-width: 1.65; pointer-events: none;
}
.search input { width: 100%; padding: 10px 42px 10px 40px; min-height: 42px; }
.search kbd {
  position: absolute; right: 10px; top: 10px; border: 1px solid #3a4d52;
  border-radius: 4px; color: var(--muted); font: 13px/19px ui-monospace, monospace;
  width: 21px; text-align: center; pointer-events: none;
}
.search-results {
  position: absolute; inset: calc(100% + 6px) 0 auto;
  border: 1px solid #41565d; border-radius: 7px; padding: 5px;
  background: #17262c; box-shadow: 0 10px 28px #050b0c99;
}
.search-results p, .link-results p { color: var(--muted); padding: 8px 10px; }
.result {
  display: block; text-align: left; width: 100%; padding: 6px 10px; border: 1px solid transparent;
  border-radius: 4px; color: var(--text); background: transparent; font: 18px/1.3 var(--serif);
}
.result:hover, .result:focus-visible, .result[aria-pressed=true] { background: #23363d; }
.result[aria-pressed=true] { color: var(--gold); border-color: #7f704a; }

.workspace {
  display: grid;
  flex: 1;
  width: 100%;
  max-width: 1920px;
  margin: 0 auto;
  padding: 0 32px 24px;
}
.map-panel {
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface);
}
.map-bar {
  display: grid; grid-template-columns: minmax(156px, 1fr) minmax(180px, 410px) minmax(116px, 1fr);
  align-items: center; gap: 12px; min-height: 58px; padding: 0 15px; border-bottom: 1px solid var(--line);
}
.map-bar > .button { justify-self: end; }
.map-body { display: grid; grid-template-columns: minmax(0, 1fr) 286px; min-height: 440px; }
.map-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 41px; padding: 0 15px; border-top: 1px solid var(--line);
}
.map-footer, .map-count { color: var(--muted); font-size: 12px; }
.map-meta, .map-status { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.dimension { color: var(--gold); font: 600 11px var(--sans); letter-spacing: .04em; }
.map-footer i { width: 6px; height: 6px; background: var(--gold); border-radius: 50%; box-shadow: 0 0 9px #efd08755; }
.map-panel:is(:fullscreen, .is-expanded) { width: 100%; height: 100%; min-height: 0; border: 0; border-radius: 0; }
.map-panel:is(:fullscreen, .is-expanded) .map-body { min-height: 0; }
.map-panel:is(:fullscreen, .is-expanded) .inspector { overflow: auto; }
.map-panel.is-expanded { position: fixed; inset: 0; z-index: 8; }
body:has(.map-panel.is-expanded) { overflow: hidden; }
.tabs { display: flex; gap: 4px; height: 100%; }
.tabs button {
  border: 0; border-bottom: 2px solid transparent; color: var(--muted); background: transparent;
  padding: 0 11px; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-pressed=true] { color: var(--gold); border-bottom-color: var(--gold); }
.stage {
  position: relative; isolation: isolate; overflow: hidden;
  background-color: var(--stage);
  background-image: radial-gradient(ellipse at 52% 45%, #22373c78 0%, #0c161a00 65%),
                    radial-gradient(circle, #58717852 1px, transparent 1px);
  background-size: 100% 100%, 24px 24px;
}
#graph {
  position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab;
  touch-action: none; -webkit-user-select: none; user-select: none;
}
#graph:focus-visible { outline: 2px solid var(--aqua); outline-offset: -3px; }
#graph.is-dragging, #graph.is-dragging .word-node { cursor: grabbing; }
.edge { stroke: var(--gold); stroke-width: 1.25; fill: none; opacity: calc(.66 * var(--depth, 1)); pointer-events: none; }
.edge.is-active { opacity: .88; stroke-width: 1.65; }
.edge.is-dim { opacity: .14; }
.pulse { pointer-events: none; }
.pulse .glow { filter: url(#pulse-glow); opacity: .78; }
.word-node { cursor: grab; opacity: var(--depth, 1); }
.word-node:focus { outline: none; }
.word-node text {
  fill: #eee5cb; font: 20px var(--serif); pointer-events: none;
  paint-order: stroke; stroke: #101a1d; stroke-width: 4px; stroke-linejoin: round;
}
.word-node .core { fill: #f5d18a; }
.word-node .ring { fill: none; stroke: var(--gold); opacity: .32; }
.word-node .halo { fill: url(#node-halo); opacity: .65; }
.word-node.is-hub text { font-size: 25px; }
.word-node.is-active, .word-node:hover, .word-node:focus-visible { opacity: 1; }
.word-node.is-active text, .word-node:hover text { fill: #fff4d5; }
.word-node.is-active .halo, .word-node:hover .halo { opacity: 1; }
.word-node.is-selected .ring { opacity: 1; stroke-width: 1.25; }
.word-node:focus-visible .ring { stroke: var(--aqua); opacity: 1; stroke-width: 1.6; }
.word-node.is-selected .core { fill: #fff3d7; }
.word-node.is-selected text { font-weight: bold; }
.word-node.is-dim { opacity: .32; }
.word-node.is-dim:hover, .word-node.is-dim:focus-visible { opacity: 1; }

.tooltip {
  position: absolute; z-index: 2; pointer-events: none; width: max-content; max-width: min(270px, 90%);
  padding: 10px 13px; border: 1px solid #82724a; border-radius: 6px;
  background: #19262bf5; color: var(--text); box-shadow: 0 8px 25px #050b0c99;
}
.tooltip ul { margin: 0; padding-left: 17px; }
.tooltip li + li { margin-top: 4px; }
.stage-tools { position: absolute; bottom: 14px; right: 14px; display: flex; gap: 8px; }
.map-controls, .stage-button {
  display: flex; align-items: center;
  background: #16262bea; border: 1px solid #40535a; border-radius: 6px;
}
.map-controls button {
  display: grid; place-items: center; color: var(--text); background: transparent; border: 0;
  width: 37px; height: 36px; font: 21px var(--sans);
}
.map-controls button + button { border-left: 1px solid #40535a; }
.map-controls button:first-child { border-radius: 5px 0 0 5px; }
.map-controls button:last-child { border-radius: 0 5px 5px 0; }
.map-controls button:hover, .stage-button:hover:not(:disabled) { background: #253a40; }
.stage-tools svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.6; }
.stage-button { gap: 6px; min-height: 38px; padding: 0 10px; color: var(--text); font-size: 12px; white-space: nowrap; }
.stage-button:disabled { cursor: default; opacity: .5; }
.empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center;
  align-items: center; text-align: center; padding: 24px; pointer-events: none;
}
.empty svg { width: 72px; color: var(--gold); stroke: currentColor; stroke-width: 1; }
.empty svg circle:first-child { opacity: .25; }
.empty h2 { margin-top: 18px; font-size: 24px; }
.empty p { color: var(--muted); margin: 8px 0 20px; }
.empty button { pointer-events: auto; }

.inspector { display: flex; flex-direction: column; min-width: 0; border-left: 1px solid var(--line); }
.inspector > section { padding: 23px 20px; }
.details { min-height: 266px; }
.details h2 { font-size: 18px; }
.details .focus-word {
  font: 38px/1.12 var(--serif); color: var(--gold); overflow-wrap: anywhere;
  margin: 4px 0 10px;
}
.details p { color: var(--muted); margin: 10px 0 17px; }
.details .hint { font-size: 12px; margin: 0; }
.details > .button + .hint { margin-top: 12px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.neighbors { list-style: none; padding: 0; margin: 11px 0 0; max-height: 213px; overflow: auto; }
.neighbors li { display: flex; align-items: center; gap: 7px; border-bottom: 1px solid var(--line); min-height: 37px; }
.neighbor-word {
  min-width: 0; color: var(--text); background: none; border: 0; text-align: left;
  font: 18px var(--serif); padding: 6px 2px; overflow-wrap: anywhere;
}
.neighbor-word:hover { color: var(--gold); }
.neighbor-colors { display: flex; gap: 4px; flex-wrap: wrap; max-width: 52px; flex-shrink: 0; }
.neighbor-colors i, .relation-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--color); }
.quiet {
  padding: 3px 2px; color: var(--muted); border: 0; background: transparent; font-size: 12px;
}
.quiet:hover { color: var(--gold); }
.quiet:disabled { opacity: .45; cursor: default; }
.manage-link { margin-left: auto; flex-shrink: 0; white-space: nowrap; }
.relation-entries { display: grid; gap: 8px; margin-top: 12px; }
.relation-entry { display: grid; grid-template-columns: 7px minmax(0, 1fr) auto auto; align-items: center; gap: 10px; }
.relation-entry select { min-width: 0; }
.remove-relation { color: #f5a0a5; }
.inspector .legend { border-top: 1px solid var(--line); }
.legend-heading { display: flex; align-items: center; justify-content: space-between; gap: 5px; margin-bottom: 16px; }
.legend h2 { font-size: 15px; }
.legend-entry {
  display: flex; align-items: center; gap: 11px; max-width: 100%; padding: 5px 0;
  border: 0; color: var(--text); background: transparent; text-align: left; overflow-wrap: anywhere;
}
.legend-entry:hover span:last-child { color: var(--gold); text-decoration: underline; }
.legend-light {
  display: inline-block; position: relative; width: 37px; min-width: 37px; height: 1px; background: #c5a86a;
}
.legend-light::after {
  content: ""; position: absolute; top: -2px; left: 15px; width: 11px; height: 5px;
  border-radius: 50%; background: var(--color); box-shadow: 0 0 8px var(--color);
}
.legend-note { font-size: 12px; color: var(--muted); margin-top: 15px; }
.storage-panel { margin-top: auto; border-top: 1px solid var(--line); padding: 12px 20px; }
.storage-label {
  color: var(--muted); font-size: 11px; display: flex; align-items: center; gap: 8px;
}
.storage-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.storage-actions:not(:has(button:not([hidden]))) { display: none; }
.status-light { width: 6px; height: 6px; border-radius: 50%; background: #9bd7bb; }

dialog {
  width: min(460px, calc(100% - 28px)); max-height: calc(100% - 28px); overflow: auto;
  padding: 23px; color: var(--text); background: #17262c;
  border: 1px solid #526970; border-radius: 10px; box-shadow: 0 16px 60px #05090bbf;
}
dialog::backdrop { background: #070e13b5; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 17px; }
.dialog-header h2 { font-size: 20px; }
.close {
  width: 34px; height: 34px; border: 0; background: transparent;
  color: var(--muted); border-radius: 5px; font-size: 24px; line-height: 1;
}
.close:hover { color: var(--text); background: #263b42; }
label { display: block; margin: 13px 0 6px; color: var(--text); }
input, select, textarea {
  color: var(--text); border: 1px solid #41555b; border-radius: 6px; background: #0f1c21;
  min-height: 38px; padding: 8px 10px;
}
input::placeholder, textarea::placeholder { color: #9babad; }
dialog input:not([type=color]), dialog select, dialog textarea { width: 100%; }
input[type=color] { width: 68px; padding: 3px; }
textarea { resize: vertical; }
.form-note { margin: 7px 0 0; font-size: 12px; color: var(--muted); }
.error { margin: 9px 0 0; color: #ffb4b7; }
.dialog-actions { display: flex; justify-content: end; gap: 8px; margin-top: 22px; }
.link-results { max-height: 176px; overflow: auto; margin-top: 6px; }
.toast {
  position: fixed; z-index: 6; left: 50%; bottom: 24px; transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 28px); padding: 10px 16px;
  border: 1px solid #7e704f; border-radius: 7px; background: #263339; box-shadow: 0 6px 28px #0008;
}
@media (max-width: 920px) {
  .topbar, .workspace { padding-inline: 18px; }
  .map-body { grid-template-columns: minmax(0, 1fr) 242px; }
  .inspector > section { padding-inline: 15px; }
}
@media (max-width: 680px) {
  .topbar { padding: 12px; }
  .search { grid-row: 2; grid-column: 1 / -1; }
  .workspace { padding: 0 12px 14px; }
  .map-bar { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: 42px auto; gap: 6px; padding-bottom: 8px; }
  .map-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(350px, 58dvh) auto; }
  .map-panel:is(:fullscreen, .is-expanded) .map-body { grid-template-rows: minmax(230px, 56dvh) auto; overflow: auto; }
  .inspector { border-left: 0; border-top: 1px solid var(--line); }
  .details { min-height: 0; }
  .map-bar, .map-footer { padding-inline: 10px; }
  .map-hint { display: none; }
  .tabs button { padding-inline: 6px; }
  .stage-tools { gap: 6px; right: 10px; }
  .stage-button { padding-inline: 8px; }
}
