:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #1f2933;
  --muted: #64707d;
  --line: #d8dee6;
  --accent: #176f8f;
  --accent-soft: #e7f3f6;
  --tag: #9aa3ad;
  --danger: #b3261e;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--ink);
}
body.graphing { overflow: hidden; }
a { color: var(--accent); text-decoration: none; }
[hidden] { display: none !important; }
button, input, select, textarea { font-family: inherit; }

/* ---------- 按鈕、表單 ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 6px; padding: 7px 10px; font-size: 13px; cursor: pointer;
  white-space: nowrap; line-height: 1.2;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-size: 15px; padding: 10px 16px; }
.btn.primary:hover { background: #135d78; color: #fff; }
.btn.primary.sm { font-size: 13px; padding: 7px 12px; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-size: 14px; color: var(--ink); background: #fff;
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }

/* ---------- 登入 ---------- */
.login { max-width: 360px; margin: 12vh auto 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px 26px; }
.login h1 { font-size: 22px; margin: 0 0 4px; }
.login p { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.login .btn.primary { width: 100%; }

/* ---------- 首頁（上傳） ---------- */
.userbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  max-width: 960px; margin: 0 auto; padding: 14px 20px 0; font-size: 13px; color: var(--muted);
}
.userbar .spacer { flex: 1; }
.landing { max-width: 960px; margin: 0 auto; padding: 24px 20px 60px; }
.landing h1 { font-size: 26px; margin: 0 0 6px; }
.landing .lead { color: var(--muted); font-size: 15px; line-height: 1.7; margin: 0 0 22px; }
.drop {
  border: 2px dashed #b9c3cd; border-radius: 12px; background: var(--surface);
  padding: 38px 20px; text-align: center; font-size: 16px; transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .sub { color: var(--muted); font-size: 13px; margin-top: 8px; }
.paste { margin-top: 14px; }
.paste summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.paste textarea {
  width: 100%; min-height: 140px; margin-top: 10px; font: 13px/1.5 ui-monospace, Menlo, monospace;
  border: 1px solid var(--line); border-radius: 8px; padding: 10px; resize: vertical;
}
.paste .row { margin-top: 8px; }
.formats { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 30px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px 18px 16px; }
.card h2 { font-size: 17px; margin: 0 0 4px; }
.card .when { color: var(--muted); font-size: 13px; margin: 0 0 12px; line-height: 1.6; }
.card table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 12px; }
.card th, .card td { text-align: left; padding: 6px 6px; border-bottom: 1px solid #edf0f3; vertical-align: top; line-height: 1.5; }
.card th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.card td code { background: #eef1f4; border-radius: 4px; padding: 1px 5px; font-size: 12px; }
.card .req { color: #e34948; font-size: 11px; margin-left: 4px; }
.card .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.card pre {
  background: #f1f3f6; border-radius: 6px; padding: 10px; font-size: 12px; line-height: 1.55;
  overflow-x: auto; margin: 0 0 12px; white-space: pre;
}
.tips { margin-top: 24px; color: var(--muted); font-size: 13px; line-height: 1.8; }
.tips li { margin-bottom: 2px; }
.tips code { background: #eef1f4; border-radius: 4px; padding: 1px 5px; }

/* ---------- 圖形頁 ---------- */
.header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  background: rgba(255,255,255,0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.topbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 14px; }
.topbar h1 { margin: 0; font-size: 16px; white-space: nowrap; max-width: 30vw; overflow: hidden; text-overflow: ellipsis; }
.topbar .count { color: var(--muted); font-size: 13px; white-space: nowrap; }
.topbar input[type="search"] {
  flex: 1 1 160px; min-width: 140px;
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-size: 14px;
}
.topbar select {
  border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink);
  padding: 7px 8px; font-size: 13px; max-width: 46vw;
}
.topbar .sep { width: 1px; height: 22px; background: var(--line); }
.legend {
  display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; padding: 8px 14px;
  background: rgba(246,247,249,0.9); border-top: 1px solid var(--line);
  scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.legend.wrap { flex-wrap: wrap; max-height: 40vh; overflow-y: auto; }
.legend .chip { flex: 0 0 auto; }
.legend .more { flex: 0 0 auto; border-style: dashed; color: var(--muted); }
.legend.static .chip[data-cat] { cursor: default; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 999px; background: #fff;
  padding: 4px 10px 4px 6px; font-size: 12px; cursor: pointer; user-select: none;
}
.chip i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.chip.collapsed { opacity: 0.55; text-decoration: line-through; }
.chip .n { color: var(--muted); }

#graph { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#graph svg { width: 100%; height: 100%; display: block; cursor: grab; }
#graph svg.dragging { cursor: grabbing; }
#graph .g3d { position: absolute; inset: 0; }
.btn.toggle.on { background: var(--accent-soft); border-color: #b9dfe7; color: var(--accent); font-weight: 600; }
.link { stroke: #c2cad3; stroke-opacity: 0.8; }
.link.tag { stroke: #d5dbe2; stroke-dasharray: 3 3; }
.link.rel { stroke: #b6bfc9; }
.linklabel {
  font-size: 10px; fill: var(--muted); pointer-events: none; text-anchor: middle; opacity: 0;
  paint-order: stroke; stroke: rgba(255,255,255,0.9); stroke-width: 3px; stroke-linejoin: round;
}
.linklabel.show { opacity: 1; }
.node { cursor: pointer; }
.node circle { stroke: #fff; stroke-width: 1.5px; }
.node.center circle { stroke-width: 2.5px; }
.node.center.collapsed circle { stroke-dasharray: 4 3; }
.node text {
  font-size: 11px; fill: var(--ink); pointer-events: none;
  paint-order: stroke; stroke: rgba(255,255,255,0.85); stroke-width: 3px; stroke-linejoin: round;
}
.node.center text { font-size: 13px; font-weight: 700; }
.node.bridge text { font-size: 10px; fill: var(--muted); }
.node.leaf text { opacity: 0; transition: opacity .15s; }
.node.leaf.labeled text, .node.leaf.lit text { opacity: 1; }
.dim { opacity: 0.12; }
.lit circle { stroke: var(--ink); }
.node.hit circle { stroke: #e34948; stroke-width: 3px; }

.panel {
  position: fixed; top: calc(var(--header-h, 96px) + 10px); right: 14px; bottom: 14px; width: 340px; z-index: 21;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 18px; overflow: auto;
  transform: translateX(calc(100% + 20px)); transition: transform .2s ease;
  box-shadow: 0 8px 24px rgba(31,41,51,0.08);
}
.panel.open { transform: none; }
.panel .close { position: absolute; top: 10px; right: 10px; }
.eyebrow { color: var(--accent); font-size: 12px; font-weight: 700; margin-bottom: 8px; }
.panel h2 { margin: 0 0 8px; font-size: 18px; line-height: 1.3; padding-right: 36px; word-break: break-word; }
.panel .meta { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.panel p { line-height: 1.7; margin: 0 0 12px; font-size: 14px; white-space: pre-wrap; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
.tags span { background: #eef1f4; border-radius: 999px; padding: 4px 8px; color: #46515c; font-size: 12px; cursor: pointer; }
.tags span:hover { background: var(--accent-soft); color: var(--accent); }
.panel .primary { display: inline-block; background: var(--accent); color: #fff; border-radius: 6px; padding: 9px 14px; font-size: 14px; }
.related { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.related strong { display: block; font-size: 13px; margin-bottom: 8px; }
.related a { display: block; padding: 6px 0; font-size: 13px; border-bottom: 1px dashed var(--line); color: var(--ink); }
.related a:hover { color: var(--accent); }
.related .cat { color: var(--muted); font-size: 12px; }
.hint {
  position: fixed; left: 14px; bottom: 12px; z-index: 19;
  color: var(--muted); font-size: 12px; background: rgba(255,255,255,0.85);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; max-width: calc(100vw - 28px);
}
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: #2b3540; color: #fff; padding: 12px 16px; border-radius: 8px; font-size: 14px;
  max-width: min(90vw, 560px); line-height: 1.6; box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; pointer-events: auto; }
.toast.error { background: var(--danger); }
.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 15px; padding: 20px; text-align: center; line-height: 1.7; }

/* ---------- 對話框 ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 22px 24px; width: min(92vw, 520px);
  box-shadow: 0 16px 48px rgba(0,0,0,0.18); color: var(--ink);
}
dialog::backdrop { background: rgba(31,41,51,0.35); }
dialog h2 { margin: 0 0 14px; font-size: 18px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.list { border-top: 1px solid var(--line); }
.list .item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.list .item .grow { flex: 1; min-width: 0; }
.list .item .name { font-size: 14px; font-weight: 600; word-break: break-all; }
.list .item .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.list .item.off { opacity: .55; }
.linkbox { display: flex; gap: 6px; margin-top: 10px; }
.linkbox input { flex: 1; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-size: 13px; }
.badge { display: inline-block; border-radius: 999px; padding: 2px 8px; font-size: 11px; background: #eef1f4; color: #46515c; }
.badge.ok { background: #e3f6ec; color: #0f6b3a; }
.badge.bad { background: #fde8e6; color: var(--danger); }

/* ---------- 管理者頁 ---------- */
.admin { max-width: 1100px; margin: 0 auto; padding: 20px; }
.admin h1 { font-size: 22px; margin: 0; }
.tabs { display: flex; gap: 6px; margin: 16px 0; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: none; padding: 10px 14px; font-size: 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; font-size: 13px; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid #edf0f3; vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table td .btn { padding: 4px 8px; font-size: 12px; }
.table .code { font-family: ui-monospace, Menlo, monospace; }
.tablewrap { overflow-x: auto; }
.panelbox { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px; margin-bottom: 16px; }
.panelbox h2 { font-size: 15px; margin: 0 0 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 14px; }

/* ---------- 分享頁 ---------- */
.sharebar { position: fixed; right: 14px; bottom: 12px; z-index: 19; color: var(--muted); font-size: 12px; background: rgba(255,255,255,0.85); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; }

@media (max-width: 720px) {
  .landing { padding: 16px 14px 40px; }
  .formats { grid-template-columns: 1fr; }
  .topbar { gap: 6px; padding: 8px 10px; }
  .topbar h1 { font-size: 14px; }
  .topbar .count { display: none; }
  .topbar input[type="search"] { flex-basis: 100%; padding: 7px 9px; font-size: 13px; }
  .btn { padding: 6px 8px; font-size: 12px; }
  .topbar select { padding: 6px 4px; font-size: 12px; max-width: 34vw; }
  .legend { padding: 6px 10px; }
  .panel { top: auto; left: 10px; right: 10px; bottom: 10px; width: auto; max-height: 55vh;
    transform: translateY(calc(100% + 20px)); }
  .panel.open { transform: none; }
  .hint, .sharebar { display: none; }
}
