:root {
  color-scheme: light;
  --paper: #f5f0e6;
  --paper-strong: #ede4d2;
  --ink: #1a1a1a;
  --ink-muted: #645e54;
  --line: #cfc3ae;
  --red: #9e3425;
  --red-dark: #7d241a;
  --jade: #2b6255;
  --gold: #a66f25;
  --shadow: 0 18px 48px rgb(42 32 17 / 13%);
  --radius: 18px;
  font-family: "Noto Serif SC", "Songti SC", "STSong", Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-height: 100%; background: var(--paper); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 4% 0%, rgb(255 255 255 / 55%), transparent 25rem),
    radial-gradient(circle at 93% 8%, rgb(200 172 117 / 16%), transparent 30rem),
    var(--paper);
}

button, input, select, textarea { font: inherit; }
button { color: inherit; }
a { color: inherit; }

.site-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  gap: 22px;
  min-height: 66px;
  padding: 10px clamp(18px, 5vw, 72px);
  border-bottom: 1px solid rgb(125 95 51 / 20%);
  background: rgb(245 240 230 / 91%);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 9px;
  flex: 0 0 auto;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark { color: var(--red); font-size: 1.42rem; font-weight: 800; letter-spacing: .12em; }
.brand-sub { color: var(--ink-muted); font-family: ui-serif, Georgia, serif; font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; }

.site-nav { display: flex; gap: 5px; align-items: center; flex: 1; }
.site-nav a { padding: 8px 11px; border-radius: 9px; color: var(--ink-muted); font-size: .93rem; text-decoration: none; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--ink); background: rgb(28 25 20 / 7%); }

.button, .icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--ink);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-weight: 650;
  line-height: 1;
  text-decoration: none;
  transition: transform .16s ease, background .16s ease, color .16s ease;
}

.button:hover, .icon-button:hover { transform: translateY(-1px); background: var(--ink); color: var(--paper); }
.button.primary { border-color: var(--red); background: var(--red); color: #fffaf2; }
.button.primary:hover { border-color: var(--red-dark); background: var(--red-dark); }
.button.quiet { border-color: transparent; color: var(--ink-muted); }
.button.danger { border-color: var(--red); color: var(--red); }
.button.small { min-height: 32px; padding: 6px 9px; font-size: .82rem; }
.icon-button { width: 38px; padding: 0; border-color: transparent; font-size: 1.15rem; }

.page-shell { width: min(1440px, calc(100% - 36px)); margin: 0 auto; padding: 36px 0 70px; }

.hero { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 28px; align-items: end; padding: clamp(16px, 4vw, 56px) 0 30px; }
.eyebrow { margin: 0 0 12px; color: var(--red); font-size: .78rem; font-weight: 800; letter-spacing: .16em; }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 820px; margin-bottom: 13px; font-size: clamp(2.05rem, 5vw, 4.1rem); letter-spacing: .04em; line-height: 1.1; }
h2 { margin-bottom: 6px; font-size: 1.3rem; }
h3 { margin-bottom: 7px; font-size: 1rem; }
.hero-copy { max-width: 690px; color: var(--ink-muted); font-size: 1.02rem; line-height: 1.85; }

.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { min-width: 108px; padding: 15px 17px; border: 1px solid var(--line); border-radius: 13px; background: rgb(255 252 246 / 58%); }
.stat strong { display: block; font-size: 1.48rem; line-height: 1.1; }
.stat span { display: block; margin-top: 5px; color: var(--ink-muted); font-size: .78rem; }

.toolbar { display: grid; grid-template-columns: minmax(240px, 1fr) auto auto; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: rgb(255 252 246 / 65%); box-shadow: 0 5px 20px rgb(67 45 13 / 5%); }
.field { display: grid; gap: 6px; }
.field label { color: var(--ink-muted); font-size: .78rem; font-weight: 700; }
.control, input[type="search"], input[type="text"], input[type="password"], .field input:not([type]), select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  color: var(--ink);
  background: #fffdf8;
}
textarea { min-height: 95px; resize: vertical; line-height: 1.55; }
.control:focus, input:focus, select:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgb(158 52 37 / 12%); }

.result-meta { display: flex; justify-content: space-between; gap: 18px; align-items: center; margin: 26px 0 15px; color: var(--ink-muted); font-size: .9rem; }
.result-meta strong { color: var(--ink); }

.groups { display: grid; gap: 30px; }
.group-section { scroll-margin-top: 92px; }
.group-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 13px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.group-heading h2 { margin: 0; }
.group-count { color: var(--ink-muted); font-size: .86rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 12px; }

.character-card {
  position: relative;
  display: grid;
  min-height: 156px;
  padding: 17px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: inherit;
  background: rgb(255 253 248 / 82%);
  cursor: pointer;
  text-align: left;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.character-card::after { position: absolute; inset: auto -18px -25px auto; width: 80px; height: 80px; border: 1px solid rgb(158 52 37 / 14%); border-radius: 50%; content: ""; }
.character-card:hover { z-index: 1; transform: translateY(-3px); border-color: rgb(158 52 37 / 52%); box-shadow: var(--shadow); }
.character-card h3 { padding-right: 22px; font-size: 1.09rem; }
.alias { min-height: 20px; overflow: hidden; color: var(--ink-muted); font-size: .82rem; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.card-footer { align-self: end; margin-top: 12px; }
.heaven { display: block; margin-bottom: 8px; color: var(--jade); font-size: .75rem; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { display: inline-flex; align-items: center; min-height: 22px; padding: 2px 7px; border: 1px solid rgb(42 98 85 / 33%); border-radius: 99px; color: var(--jade); font-family: ui-sans-serif, system-ui, sans-serif; font-size: .68rem; line-height: 1; }
.chip.warm { border-color: rgb(166 111 37 / 35%); color: #815617; }
.chip.gray { border-color: rgb(100 94 84 / 25%); color: var(--ink-muted); }

.empty-state { padding: 48px 24px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--ink-muted); text-align: center; }

dialog { width: min(760px, calc(100% - 28px)); max-height: min(88vh, 900px); padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 20px; color: var(--ink); background: #fbf7ee; box-shadow: 0 25px 90px rgb(30 20 7 / 35%); }
dialog::backdrop { background: rgb(21 18 12 / 48%); backdrop-filter: blur(3px); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 21px 24px 15px; border-bottom: 1px solid var(--line); }
.dialog-title { margin: 0; font-size: 1.38rem; }
.dialog-body { max-height: calc(88vh - 83px); padding: 21px 24px 25px; overflow: auto; }
.detail-kicker { margin: 0 0 10px; color: var(--red); font-size: .76rem; font-weight: 800; letter-spacing: .08em; }
.detail-copy { white-space: pre-line; color: #3f3b34; line-height: 1.8; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; margin: 18px 0; }
.detail-box { padding: 11px; border: 1px solid var(--line); border-radius: 10px; background: rgb(255 255 255 / 42%); }
.detail-box span { display: block; margin-bottom: 4px; color: var(--ink-muted); font-size: .73rem; }
.detail-box strong { font-size: .92rem; word-break: break-word; }
.detail-section { margin-top: 22px; }
.detail-section > h3 { padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.section-heading h3 { margin: 0; }
.relation-editor-section { padding-top: 2px; }
.relation-list { display: grid; gap: 8px; }
.relation-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 10px; border: 1px solid rgb(128 107 76 / 20%); border-radius: 10px; background: rgb(255 255 255 / 36%); }
.relation-direction { color: var(--ink-muted); font-family: ui-sans-serif, system-ui, sans-serif; font-size: .72rem; }
.relation-target { min-width: 0; border: 0; color: var(--ink); background: none; cursor: pointer; font-weight: 800; text-align: left; }
.relation-target:hover { color: var(--red); text-decoration: underline; }
.relation-type { color: var(--jade); font-size: .77rem; text-align: right; }
.relation-statement { display: flex; min-width: 0; flex-wrap: wrap; align-items: baseline; gap: 5px; }
.relation-arrow { color: var(--jade); font-size: .78rem; }
.relation-actions { display: flex; gap: 5px; }
.relation-actions .button { padding: 4px 7px; font-size: .68rem; }
.relation-story, .relation-row > .provenance { grid-column: 1 / -1; margin: 0; color: var(--ink-muted); font-size: .82rem; line-height: 1.55; }
.classification-list { display: grid; gap: 7px; }
.classification-row { display: flex; align-items: baseline; gap: 8px; padding: 8px 10px; border: 1px solid rgb(95 120 157 / 25%); border-radius: 9px; background: rgb(95 120 157 / 7%); }
.classification-row > span { min-width: 36px; color: var(--ink-muted); font-size: .72rem; }
.provenance { margin: 9px 0 0; color: var(--ink-muted); font-size: .78rem; line-height: 1.55; }
.provenance a { color: var(--jade); }
.source-list { display: grid; gap: 7px; padding-left: 18px; color: var(--ink-muted); font-size: .83rem; line-height: 1.5; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 9px; margin-top: 21px; }
.admin-tools { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 18px; }
.notice { margin: 13px 0; padding: 10px 12px; border-left: 3px solid var(--gold); border-radius: 0 8px 8px 0; color: #5f512f; background: rgb(166 111 37 / 10%); font-size: .84rem; line-height: 1.55; }
.notice.error { border-color: var(--red); color: #7d241a; background: rgb(158 52 37 / 10%); }

.toast-region { position: fixed; z-index: 100; right: 18px; bottom: 18px; display: grid; gap: 8px; max-width: min(410px, calc(100vw - 36px)); }
.toast { padding: 11px 14px; border: 1px solid var(--line); border-left: 4px solid var(--jade); border-radius: 10px; background: #fffdf8; box-shadow: var(--shadow); font-size: .88rem; line-height: 1.45; }
.toast.error { border-left-color: var(--red); }

.startup-help {
  position: fixed;
  z-index: 999;
  inset: 50% auto auto 50%;
  display: grid;
  gap: 10px;
  width: min(560px, calc(100% - 34px));
  padding: 22px 24px;
  transform: translate(-50%, -50%);
  border: 1px solid var(--line);
  border-left: 5px solid var(--red);
  border-radius: 16px;
  background: #fffdf8;
  box-shadow: 0 25px 90px rgb(30 20 7 / 32%);
  line-height: 1.7;
}
.startup-help strong { font-size: 1.08rem; }
.startup-help span { color: var(--ink-muted); }
.startup-help code { padding: 2px 5px; border-radius: 5px; color: var(--red-dark); background: var(--paper-strong); font-family: Consolas, monospace; }

.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.graph-page { overflow: hidden; color: #e8f1fb; background: #02050b; }
.graph-page .site-header { border-bottom-color: rgb(132 190 208 / 14%); color: #dce8f5; background: rgb(3 8 16 / 82%); box-shadow: 0 8px 30px rgb(0 0 0 / 28%); }
.graph-page .brand, .graph-page .site-nav a:hover, .graph-page .site-nav a[aria-current="page"] { color: #f2f7ff; }
.graph-page .brand-mark { color: #8de8e2; text-shadow: 0 0 18px rgb(85 226 217 / 42%); }
.graph-page .brand-sub, .graph-page .site-nav a, .graph-page #admin-button { color: #9fb1c7; }
.graph-page .site-nav a:hover, .graph-page .site-nav a[aria-current="page"] { background: rgb(125 224 218 / 10%); }
.graph-page .button { border-color: rgb(151 190 210 / 38%); color: #dce8f5; background: rgb(7 17 28 / 86%); backdrop-filter: blur(10px); }
.graph-page .button:hover { border-color: #79e6df; color: #061018; background: #79e6df; }
.graph-page .button.primary { border-color: #65d7d0; color: #061018; background: #65d7d0; }
.graph-page .button.primary:hover { border-color: #a4fff7; background: #a4fff7; }
.graph-shell { position: fixed; inset: 66px 0 0; background: #02050b; }
.graph-canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.graph-canvas.panning, .graph-canvas.linking { cursor: grabbing; }
.graph-toolbar { position: fixed; z-index: 15; top: 80px; left: clamp(12px, 3vw, 34px); right: clamp(12px, 3vw, 34px); display: flex; align-items: center; gap: 10px; pointer-events: none; }
.graph-toolbar > * { pointer-events: auto; }
.graph-search-wrap { position: relative; width: min(440px, calc(100vw - 180px)); }
.graph-page .graph-search { min-height: 43px; padding-inline: 14px 42px; border-color: rgb(137 195 214 / 30%); color: #edf7ff; background: rgb(4 12 21 / 92%); box-shadow: 0 8px 28px rgb(0 0 0 / 30%), inset 0 0 24px rgb(83 192 199 / 4%); backdrop-filter: blur(12px); }
.graph-search::placeholder { color: #7d91a8; }
.graph-search:focus { border-color: #79e6df; box-shadow: 0 0 0 3px rgb(121 230 223 / 13%), 0 8px 28px rgb(0 0 0 / 30%); }
.search-results { position: absolute; top: calc(100% + 7px); left: 0; right: 0; display: grid; max-height: min(50vh, 370px); overflow: auto; border: 1px solid rgb(137 195 214 / 24%); border-radius: 12px; color: #dce8f5; background: rgb(4 11 20 / 96%); box-shadow: 0 18px 50px rgb(0 0 0 / 48%); backdrop-filter: blur(14px); }
.search-result { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; width: 100%; padding: 10px 12px; border: 0; border-bottom: 1px solid rgb(128 107 76 / 15%); background: transparent; cursor: pointer; text-align: left; }
.search-result:hover { background: rgb(121 230 223 / 9%); }
.search-result span { color: #8da3b9; font-size: .76rem; }
.graph-toolbar-actions { display: flex; gap: 7px; margin-left: auto; }
.graph-legend { position: fixed; z-index: 12; bottom: 18px; left: clamp(12px, 3vw, 34px); display: flex; flex-wrap: wrap; gap: 10px; max-width: min(750px, calc(100vw - 180px)); padding: 9px 12px; border: 1px solid rgb(137 195 214 / 18%); border-radius: 12px; color: #91a5ba; background: rgb(4 11 20 / 72%); box-shadow: 0 8px 28px rgb(0 0 0 / 30%); backdrop-filter: blur(12px); font-family: ui-sans-serif, system-ui, sans-serif; font-size: .73rem; }
.legend-dot { display: inline-block; width: 9px; height: 9px; margin-right: 3px; border-radius: 50%; vertical-align: -1px; }
.legend-dot.person { background: #9debe4; box-shadow: 0 0 8px #79e6df; }
.legend-dot.org { border: 1px solid #f4d38b; background: #f4d38b; box-shadow: 0 0 8px rgb(244 211 139 / 70%); }
.legend-line { display: inline-block; width: 19px; margin-right: 3px; border-top: 1px solid #5f789d; vertical-align: 3px; }
.legend-line.historical { border-top-style: dashed; border-color: #f2c879; }
.legend-line.user { border-top-style: dashed; border-color: #79e6df; }
.legend-line.organizational { border-top-width: 1px; border-color: #5f789d; }
.graph-panel { position: fixed; z-index: 16; top: 78px; right: 18px; bottom: 18px; display: flex; width: min(390px, calc(100vw - 36px)); transform: translateX(calc(100% + 26px)); overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: #fbf7ee; box-shadow: var(--shadow); transition: transform .23s ease; }
.graph-panel.open { transform: translateX(0); }
.graph-panel-content { width: 100%; overflow: auto; }
.graph-panel .dialog-header { position: sticky; top: 0; z-index: 1; background: #fbf7ee; }
.graph-panel .dialog-body { max-height: none; padding-bottom: 25px; }
.graph-panel .detail-grid { grid-template-columns: 1fr; }
.graph-help { position: fixed; z-index: 12; top: 140px; left: clamp(12px, 3vw, 34px); max-width: 270px; padding: 12px 14px; border: 1px solid rgb(137 195 214 / 18%); border-radius: 12px; color: #8fa4ba; background: rgb(4 11 20 / 82%); box-shadow: 0 8px 28px rgb(0 0 0 / 25%); backdrop-filter: blur(10px); font-size: .8rem; line-height: 1.6; }
.graph-help strong { color: #dce8f5; }
.graph-status { position: fixed; z-index: 12; right: 20px; bottom: 20px; color: #7890a8; font-family: ui-sans-serif, system-ui, sans-serif; font-size: .75rem; pointer-events: none; }
.graph-page .toast { border-color: rgb(137 195 214 / 24%); border-left-color: #79e6df; color: #dce8f5; background: rgb(4 11 20 / 94%); box-shadow: 0 12px 38px rgb(0 0 0 / 42%); }
.graph-page dialog, .graph-page .graph-panel { --ink: #e5edf7; --ink-muted: #93a5b8; --line: rgb(137 195 214 / 20%); --red: #79e6df; --red-dark: #a4fff7; --jade: #8ccfff; --gold: #f4d38b; color: #e5edf7; background: rgb(5 12 22 / 96%); box-shadow: 0 24px 80px rgb(0 0 0 / 55%); }
.graph-page dialog::backdrop { background: rgb(0 3 9 / 68%); backdrop-filter: blur(4px); }
.graph-page .graph-panel .dialog-header { background: rgb(5 12 22 / 96%); }
.graph-page .detail-copy { color: #b8c6d5; }
.graph-page .detail-box, .graph-page .relation-row { background: rgb(126 181 206 / 5%); }
.graph-page .relation-target { color: #e5edf7; }
.graph-page .notice { color: #ddc890; background: rgb(244 211 139 / 8%); }
.graph-page input[type="text"], .graph-page input[type="password"], .graph-page .field input:not([type]), .graph-page select, .graph-page textarea { border-color: rgb(137 195 214 / 22%); color: #e5edf7; background: #07101c; }
.graph-page .icon-button { color: #b7c5d5; }
.graph-page .graph-context-menu { border-color: rgb(137 195 214 / 22%); color: #e5edf7; background: rgb(5 12 22 / 96%); }
.graph-page .graph-context-menu button:hover { background: rgb(121 230 223 / 9%); }
.graph-context-menu { position: fixed; z-index: 30; display: none; min-width: 152px; padding: 5px; border: 1px solid var(--line); border-radius: 10px; background: #fffdf8; box-shadow: var(--shadow); }
.graph-context-menu.open { display: block; }
.graph-context-menu button { width: 100%; padding: 8px 9px; border: 0; border-radius: 6px; background: transparent; cursor: pointer; text-align: left; }
.graph-context-menu button:hover { background: var(--paper-strong); }
.node-count { color: var(--ink-muted); font-size: .8rem; }

@media (max-width: 720px) {
  .graph-shell { inset: 58px 0 0; }
  .graph-toolbar { top: 68px; }
  .graph-toolbar-actions .button:not(.primary) { display: none; }
  .graph-search-wrap { width: calc(100vw - 146px); }
  .graph-help { display: none; }
  .graph-legend { bottom: 9px; left: 9px; max-width: calc(100vw - 18px); }
  .graph-status { display: none; }
  .graph-panel { top: 67px; right: 8px; bottom: 8px; width: calc(100vw - 16px); }
}

@media (max-width: 720px) {
  .site-header { gap: 6px; padding-inline: 10px; }
  .brand-sub { display: none; }
  .brand-mark { font-size: 1.08rem; letter-spacing: .08em; }
  .site-nav { min-width: 0; justify-content: center; gap: 8px; }
  .site-nav a { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 6px; font-size: .78rem; white-space: nowrap; }
  .site-header #admin-button { flex: 0 0 auto; min-height: 44px; padding-inline: 7px; font-size: .76rem; }
  .page-shell { width: min(100% - 24px, 1440px); padding-top: 20px; }
  .hero { grid-template-columns: 1fr; gap: 20px; padding-top: 20px; }
  .toolbar { grid-template-columns: 1fr; }
  .detail-grid, .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .cards { grid-template-columns: 1fr; }
  .dialog-header, .dialog-body { padding-inline: 17px; }
}

@media (max-width: 359px) {
  .site-header { gap: 3px; padding-inline: 7px; }
  .brand-mark { font-size: 1rem; letter-spacing: .05em; }
  .site-nav { gap: 4px; }
  .site-nav a { padding-inline: 4px; font-size: .72rem; }
  .site-header #admin-button { padding-inline: 5px; font-size: .72rem; }
}
