:root {
  --accent: #DB6A41;
  --accent-ink: #B4502B;
  --ink: #2A2420;
  --ink-2: #6B5F55;
  --ink-3: #9A8D82;
  --paper: #FBF6EF;
  --paper-2: #F3EADF;
  --line: rgba(42, 36, 32, .12);
  --glass: rgba(251, 246, 239, .86);
  --shadow: 0 10px 30px rgba(60, 40, 20, .14), 0 2px 6px rgba(60, 40, 20, .08);
  --sea: #A9CFD3;
  --r: 18px;
  --side-w: 360px;
  --font: "Bricolage Grotesque", "Noto Sans TC", system-ui, sans-serif;
  --body: "Noto Sans TC", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #F3EADF; --ink-2: #C9BBAE; --ink-3: #94877B;
    --paper: #221D1A; --paper-2: #2D2622;
    --line: rgba(243, 234, 223, .14);
    --glass: rgba(34, 29, 26, .86);
    --shadow: 0 10px 30px rgba(0, 0, 0, .4);
    --accent-ink: #F08A63;
  }
}
:root[data-theme="dark"] {
  --ink: #F3EADF; --ink-2: #C9BBAE; --ink-3: #94877B;
  --paper: #221D1A; --paper-2: #2D2622;
  --line: rgba(243, 234, 223, .14);
  --glass: rgba(34, 29, 26, .86);
  --shadow: 0 10px 30px rgba(0, 0, 0, .4);
  --accent-ink: #F08A63;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--sea); color: var(--ink); font-family: var(--body); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app { position: fixed; inset: 0; }
#stage { position: absolute; inset: 0; touch-action: none; }
#stage canvas { display: block; }
.eyebrow { font: 500 11px/1 var(--mono); letter-spacing: .14em; color: var(--accent-ink); text-transform: uppercase; }
.glass { background: var(--glass); backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2); }

/* brand */
.brand { position: absolute; top: 16px; left: 16px; display: flex; gap: 14px; align-items: center; padding: 12px 18px 12px 16px; border-radius: var(--r); background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow); z-index: 5; }
.brand .mark { font: 800 26px/.86 var(--font); color: var(--accent); text-decoration: none; letter-spacing: -.02em; display: flex; flex-direction: column; }
.brand .mark span { color: var(--ink); }
.brand-r h1 { margin: 0; font: 700 17px/1.2 var(--body); letter-spacing: .04em; }
.brand-r p { margin: 4px 0 0; font: 500 12px/1 var(--font); color: var(--ink-2); }
.brand-r em { font-style: normal; background: var(--accent); color: #fff; padding: 2px 6px; border-radius: 4px; margin-right: 4px; }

/* hero */
.hero-note { position: absolute; left: 24px; bottom: 120px; max-width: 360px; z-index: 2; pointer-events: none; color: #22303A; transition: opacity .4s; }
.hero-note .number { font: 800 120px/.8 var(--font); color: var(--accent); letter-spacing: -.04em; }
.hero-note h2 { margin: 10px 0 8px; font: 700 28px/1.1 var(--font); letter-spacing: -.01em; }
.hero-note p { margin: 0; font-size: 14px; line-height: 1.55; opacity: .8; }
#app.night .hero-note { color: #F3EADF; }
#app.focused .hero-note { opacity: 0; }

/* toolbar */
.toolbar { position: absolute; top: 16px; right: calc(var(--side-w) + 32px); display: flex; gap: 8px; z-index: 5; transition: right .35s; }
#app.side-closed .toolbar { right: 16px; }
.toolbar button { display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px; border: 0; border-radius: 12px; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow); font-weight: 500; font-size: 14px; }
.toolbar button:hover { color: var(--accent-ink); }
.toolbar #help { width: 40px; justify-content: center; padding: 0; }
.ico { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* sidebar */
.sidebar { position: absolute; top: 16px; right: 16px; bottom: 16px; width: var(--side-w); display: flex; flex-direction: column; border-radius: var(--r); background: var(--glass); backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2); box-shadow: var(--shadow); z-index: 6; transition: transform .35s cubic-bezier(.2,.8,.2,1), opacity .3s; overflow: hidden; }
#app.side-closed .sidebar { transform: translateX(calc(100% + 24px)); opacity: 0; pointer-events: none; }
.side-head { position: relative; padding: 22px 22px 12px; border-bottom: 1px solid var(--line); }
.side-head h2 { margin: 10px 0 6px; font: 800 26px/1.1 var(--font); letter-spacing: -.01em; }
.side-lead { margin: 0 0 14px; font-size: 13px; line-height: 1.55; color: var(--ink-2); }
.side-close { position: absolute; top: 16px; right: 16px; width: 32px; height: 32px; border: 0; border-radius: 10px; background: transparent; color: var(--ink-2); }
.side-close:hover { background: var(--paper-2); }
.search { width: 100%; height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); font: 14px var(--body); }
.side-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 12px; }
.side-tabs button { height: 38px; border: 1px solid var(--line); border-radius: 12px; background: transparent; font-weight: 500; font-size: 14px; }
.side-tabs button.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.tree { flex: 1; overflow-y: auto; padding: 8px 10px 16px; overscroll-behavior: contain; }
.side-foot { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 12px 22px 16px; border-top: 1px solid var(--line); font-size: 13px; }
.side-foot a { color: var(--ink-2); text-decoration: none; }
.side-foot a:hover { color: var(--accent-ink); }
.sheet-handle { display: none; }

.node { width: 100%; display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; padding: 12px; border: 0; border-radius: 12px; background: transparent; text-align: left; }
.node:hover, .node.active { background: var(--paper-2); }
.node .num { font: 500 12px var(--mono); color: var(--c, var(--accent)); }
.node .t { font: 700 15px/1.25 var(--font); }
.node .z { display: block; font: 400 12px/1.4 var(--body); color: var(--ink-2); margin-top: 2px; }
.node .n { font: 500 12px var(--mono); color: var(--ink-3); }
.hits { margin: -4px 0 6px 56px; padding: 0; list-style: none; }
.hits li { font-size: 12.5px; line-height: 1.45; color: var(--ink-2); padding: 3px 0; }
.hits mark { background: color-mix(in srgb, var(--accent) 25%, transparent); color: inherit; border-radius: 3px; }
.bridge-row { width: 100%; display: block; padding: 12px; border: 0; border-radius: 12px; background: transparent; text-align: left; }
.bridge-row:hover { background: var(--paper-2); }
.bridge-row .ends { display: flex; align-items: center; gap: 8px; font: 700 14px/1.3 var(--font); }
.bridge-row .ends i { flex: 0 0 18px; height: 2px; background: linear-gradient(90deg, var(--ca), var(--cb)); border-radius: 2px; }
.bridge-row .lbl { display: block; font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.empty { padding: 24px 12px; color: var(--ink-3); font-size: 14px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }

/* detail card */
.card { position: absolute; left: 16px; top: 112px; bottom: 112px; width: min(420px, calc(100vw - 32px)); overflow-y: auto; padding: 26px 26px 22px; border-radius: var(--r); background: var(--glass); backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2); box-shadow: var(--shadow); z-index: 7; animation: rise .35s cubic-bezier(.2,.8,.2,1); }
.card[hidden] { display: none; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
.card .close { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; border: 0; border-radius: 10px; background: var(--paper-2); font-size: 20px; line-height: 1; }
.card .swatch { width: 44px; height: 6px; border-radius: 3px; background: var(--c); margin-bottom: 14px; }
.card h2 { margin: 8px 0 2px; font: 800 30px/1.05 var(--font); letter-spacing: -.015em; padding-right: 36px; }
.card .zh { font: 500 15px var(--body); color: var(--ink-2); }
.card .blurb { font-size: 14.5px; line-height: 1.7; margin: 16px 0; }
.card h3 { margin: 22px 0 8px; font: 500 11px/1 var(--mono); letter-spacing: .14em; color: var(--ink-3); text-transform: uppercase; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); text-decoration: none; font-size: 13px; font-weight: 500; }
.chip:hover { border-color: var(--accent); color: var(--accent-ink); }
.papers { list-style: none; margin: 0; padding: 0; }
.papers li { padding: 10px 0; border-top: 1px solid var(--line); }
.papers a { display: block; color: var(--ink); text-decoration: none; font-size: 14px; line-height: 1.45; font-weight: 500; }
.papers a:hover { color: var(--accent-ink); }
.papers .v { display: block; margin-top: 3px; font: 500 11.5px/1.4 var(--mono); color: var(--ink-3); }

/* hud */
.hud { position: absolute; left: 50%; bottom: 16px; transform: translateX(calc(-50% - var(--side-w) / 2 - 8px)); display: flex; gap: 8px; z-index: 5; transition: transform .35s; }
#app.side-closed .hud { transform: translateX(-50%); }
.seg { display: flex; padding: 4px; gap: 2px; border-radius: 14px; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow); }
.seg button { display: inline-flex; align-items: center; gap: 6px; height: 36px; min-width: 36px; padding: 0 9px; justify-content: center; border: 0; border-radius: 10px; background: transparent; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.seg svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* dock */
.dock { position: absolute; left: 50%; bottom: 72px; transform: translateX(calc(-50% - var(--side-w) / 2 - 8px)); display: flex; gap: 6px; z-index: 4; transition: transform .35s; }
#app.side-closed .dock { transform: translateX(-50%); }
.dock button { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--paper); background: var(--c); box-shadow: var(--shadow); color: #fff; font: 500 11px var(--mono); transition: transform .2s; }
.dock button:hover, .dock button.active { transform: translateY(-4px) scale(1.08); }

/* labels */
#labels { position: absolute; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
#labels.off { display: none; }
.lbl3d { position: absolute; left: 0; top: 0; display: flex; align-items: center; gap: 7px; padding: 6px 12px 6px 8px; border-radius: 999px; background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: 0 4px 14px rgba(40, 30, 20, .16); font: 700 13px/1 var(--font); white-space: nowrap; pointer-events: auto; cursor: pointer; border: 0; color: var(--ink); will-change: transform; transition: opacity .25s; }
.lbl3d .dot { width: 9px; height: 9px; }
.lbl3d small { font: 400 11px var(--body); color: var(--ink-2); }
.lbl3d.dim { opacity: .35; }

/* mascot */
.mascot { position: absolute; right: calc(var(--side-w) + 32px); bottom: 16px; display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 8px; border-radius: 999px; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow); font-size: 13px; z-index: 4; transition: right .35s; max-width: 280px; white-space: nowrap; }
.mascot #mascot-text { overflow: hidden; text-overflow: ellipsis; }
#app.side-closed .mascot { right: 16px; }
.mascot .face { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; flex: none; }

/* intro + loading */
.intro { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(40, 30, 20, .25); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); z-index: 20; padding: 16px; }
.intro[hidden] { display: none; }
.intro-box { width: min(460px, 100%); padding: 28px; border-radius: 22px; background: var(--paper); box-shadow: var(--shadow); }
.intro-box h2 { margin: 14px 0 10px; font: 800 26px/1.15 var(--font); }
.intro-box p { margin: 0; font-size: 14.5px; line-height: 1.7; color: var(--ink-2); }
.intro-actions { display: flex; justify-content: space-between; margin-top: 24px; }
.intro-actions button { height: 42px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: transparent; font-weight: 500; }
.intro-actions .next { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.loading { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; background: var(--paper); z-index: 30; transition: opacity .6s; }
.loading h2 { margin: 0; font: 800 96px/1 var(--font); color: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.loading p { margin: 10px 0 0; color: var(--ink-2); font-size: 14px; }
.loading.done { opacity: 0; pointer-events: none; }
@keyframes pulse { 50% { transform: scale(.9); opacity: .6; } }
.noscript { position: absolute; inset: auto 16px 16px; padding: 16px; background: var(--paper); border-radius: 12px; z-index: 40; }
.fallback .hud, .fallback .dock, .fallback .hero-note { display: none; }

/* phones: index becomes a bottom sheet */
@media (max-width: 760px) {
  :root { --side-w: 0px; }
  .brand { top: 12px; left: 12px; padding: 9px 12px; gap: 10px; }
  .brand .mark { font-size: 19px; }
  .brand-r h1 { font-size: 14px; }
  .brand-r p { font-size: 11px; }
  .toolbar { top: 76px; left: 12px; right: auto !important; }
  .toolbar button { height: 36px; font-size: 13px; padding: 0 12px; }
  .toolbar #help { width: 36px; }
  .hero-note { display: none; }
  .sidebar { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 62vh; border-radius: 22px 22px 0 0; }
  #app.side-closed .sidebar { transform: translateY(calc(100% - 0px)); }
  .sheet-handle { display: block; width: 100%; height: 22px; border: 0; background: transparent; padding: 8px 0; }
  .sheet-handle i { display: block; width: 40px; height: 5px; margin: 0 auto; border-radius: 3px; background: var(--ink-3); }
  .side-head { padding-top: 6px; }
  .side-head h2 { font-size: 21px; }
  .card { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 52vh; border-radius: 22px 22px 0 0; z-index: 8; }
  .card h2 { font-size: 24px; }
  .hud { bottom: 12px; transform: translateX(-50%) !important; }
  .hud .tg span { display: none; }
  .lbl3d { font-size: 11.5px; padding: 5px 9px 5px 7px; }
  .lbl3d small { display: none; }
  .dock { bottom: 66px; transform: translateX(-50%) !important; }
  .dock button { width: 30px; height: 30px; }
  .mascot { display: none; }
  #app:not(.side-closed) .hud, #app:not(.side-closed) .dock { visibility: hidden; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
