:root {
  --bg: #06110d; --bg2: #0a1913; --panel: #0e211a; --panel2: #12291f; --line: #1e3a2d;
  --text: #e6f2ea; --muted: #8fa89a; --accent: #5ce1a0; --accent2: #e8c872;
  --red: #ff6b6b; --blue: #5aa2ff; --violet: #a98bff; --cyan: #4dd0e1; --pink: #ff7ac6; --orange: #ffb347;
  --radius: 14px; --shadow: 0 8px 30px rgba(0,0,0,.35);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: radial-gradient(1200px 600px at 80% -10%, #0f3a28 0%, transparent 60%), radial-gradient(900px 500px at -10% 10%, #0c2a3a 0%, transparent 55%), var(--bg); color: var(--text); line-height: 1.55; min-height: 100vh; }
h1, h2, h3, h4 { font-family: Georgia, "Times New Roman", serif; line-height: 1.2; margin: 0 0 .5em; font-weight: 600; }
h2 { font-size: 1.55rem; } h3 { font-size: 1.2rem; } h4 { font-size: 1rem; }
p { margin: 0 0 .8em; }
a { color: var(--accent); }
u { text-decoration-color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); } .small { font-size: .85rem; }

/* topbar */
.topbar { position: sticky; top: 0; z-index: 50; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; padding: 10px 22px; background: rgba(6,17,13,.88); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { font-size: 1.7rem; color: var(--accent); }
.brand strong { display: block; font-family: Georgia, serif; font-size: 1.1rem; }
.brand small { color: var(--muted); font-size: .72rem; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs button { background: none; border: 0; color: var(--muted); padding: 8px 14px; border-radius: 999px; cursor: pointer; font: inherit; font-size: .9rem; white-space: nowrap; }
.tabs button:hover { color: var(--text); background: var(--panel); }
.tabs button.active { background: var(--accent); color: #04140c; font-weight: 600; }
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.btn { font: inherit; font-size: .88rem; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; transition: .15s; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #04140c; border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; }

main { max-width: 1280px; margin: 0 auto; padding: 22px; }

/* landing */
.landing { display: grid; place-items: center; min-height: 78vh; }
.landing-inner { max-width: 820px; text-align: center; }
.eyebrow { color: var(--accent); font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; }
.landing h1 { font-size: clamp(2.1rem, 5vw, 3.6rem); }
.landing h1 em { color: var(--accent2); font-style: italic; }
.lead { color: #bcd3c6; font-size: 1.08rem; max-width: 680px; margin: 0 auto 1.6em; }
.drop { border: 2px dashed #2c5a45; border-radius: 20px; padding: 38px 20px; background: linear-gradient(180deg, rgba(92,225,160,.06), transparent); cursor: pointer; transition: .2s; }
.drop:hover, .drop.over, .drop:focus-visible { border-color: var(--accent); background: rgba(92,225,160,.12); outline: none; transform: translateY(-2px); }
.drop-icon { font-size: 2.6rem; }
.drop-title { font-size: 1.15rem; margin: .3em 0; }
.drop-sub { color: var(--muted); font-size: .85rem; margin: 0; }
.paste { margin: 18px auto 0; text-align: left; max-width: 640px; }
.paste summary { cursor: pointer; color: var(--muted); text-align: center; }
textarea, input[type=text], input[type=number], select { width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; color: var(--text); padding: 10px; font: inherit; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.row-end { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; align-items: center; }
.row-end input[type=text] { max-width: 260px; }
.feature-grid { list-style: none; padding: 0; margin: 30px 0 14px; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; text-align: left; }
.feature-grid li { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.feature-grid b { display: block; margin-bottom: 4px; }
.feature-grid span { color: var(--muted); font-size: .82rem; }
.fineprint { color: var(--muted); font-size: .78rem; max-width: 620px; margin: 0 auto; }

/* tabs */
.tabpane { display: none; animation: fade .3s; }
.tabpane.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* cards / grid */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card h3 { display: flex; align-items: center; gap: 8px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.section-title { margin: 28px 0 12px; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.section-title small { color: var(--muted); font-family: inherit; font-weight: 400; }
.chart-box { position: relative; height: 320px; }
.chart-box.tall { height: 420px; } .chart-box.short { height: 220px; }

/* hero */
.hero { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center; background: linear-gradient(135deg, #0f2e22, #0b1d2b); border: 1px solid var(--line); border-radius: 20px; padding: 26px; margin-bottom: 18px; }
.hero h2 { font-size: 2rem; margin-bottom: .2em; }
.hero .sub { color: var(--accent2); font-style: italic; margin-bottom: 12px; }
.hero p { color: #c7dccf; max-width: 760px; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; } }
.ring { --v: 70; --c: var(--accent); width: 150px; height: 150px; border-radius: 50%; background: conic-gradient(var(--c) calc(var(--v) * 1%), #1b3529 0); display: grid; place-items: center; position: relative; flex: none; }
.ring::before { content: ""; position: absolute; inset: 11px; background: var(--panel); border-radius: 50%; }
.ring > div { position: relative; text-align: center; }
.ring b { font-size: 2.3rem; font-family: Georgia, serif; display: block; line-height: 1; }
.ring span { font-size: .72rem; color: var(--muted); }
.ring.sm { width: 84px; height: 84px; } .ring.sm::before { inset: 8px; } .ring.sm b { font-size: 1.35rem; }

.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.stat b { display: block; font-size: 1.6rem; font-family: Georgia, serif; color: var(--accent2); }
.stat span { color: var(--muted); font-size: .8rem; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: .78rem; background: #163126; border: 1px solid var(--line); color: #cfe6d8; white-space: nowrap; }
.chip.accent { background: rgba(92,225,160,.15); border-color: var(--accent); color: var(--accent); }
.chip.gold { background: rgba(232,200,114,.14); border-color: var(--accent2); color: var(--accent2); }
.chip.red { background: rgba(255,107,107,.13); border-color: var(--red); color: var(--red); }
.chip.warn { background: rgba(255,179,71,.13); border-color: var(--orange); color: var(--orange); }

.bars { display: grid; gap: 9px; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 190px) 1fr 44px; gap: 10px; align-items: center; font-size: .86rem; }
.bar-row .track { height: 9px; background: #17301f; border-radius: 99px; overflow: hidden; }
.bar-row .track i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), #3ab87b); }
.bar-row .val { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-row.gold .track i { background: linear-gradient(90deg, var(--accent2), #c9962a); }
.bar-row.red .track i { background: linear-gradient(90deg, #ff9b6b, var(--red)); }

/* characters */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; align-items: center; }
.toolbar input[type=search], .toolbar select { max-width: 240px; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; color: var(--text); padding: 9px 12px; font: inherit; }
.toolbar .count { color: var(--muted); margin-left: auto; font-size: .85rem; }
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.char-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px; cursor: pointer; transition: .15s; display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden; }
.char-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--rc, var(--accent)); }
.char-card:hover { transform: translateY(-3px); border-color: var(--rc, var(--accent)); box-shadow: var(--shadow); }
.char-head { display: flex; gap: 12px; align-items: center; }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-family: Georgia, serif; font-weight: 700; font-size: 1.2rem; color: #04140c; background: var(--rc, var(--accent)); flex: none; }
.char-head h4 { margin: 0; font-size: 1.05rem; }
.role-label { color: var(--rc, var(--accent)); font-size: .8rem; font-weight: 600; }
.rep { color: #b6cdbf; font-size: .84rem; margin: 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.drama-row { display: flex; align-items: center; gap: 10px; font-size: .78rem; color: var(--muted); }
.drama-row .track { flex: 1; height: 8px; background: #17301f; border-radius: 99px; overflow: hidden; }
.drama-row .track i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent2), var(--red)); }
.drama-row b { color: var(--text); min-width: 30px; text-align: right; }
.char-foot { display: flex; justify-content: space-between; color: var(--muted); font-size: .76rem; }
.coh { font-size: .74rem; padding: 2px 8px; border-radius: 8px; }
.coh.good { background: rgba(92,225,160,.15); color: var(--accent); }
.coh.mid { background: rgba(255,179,71,.15); color: var(--orange); }
.coh.bad { background: rgba(255,107,107,.15); color: var(--red); }
.coh.na { background: #1b2a24; color: var(--muted); }

/* drawer */
.drawer { position: fixed; inset: 0; z-index: 90; }
.drawer-bg { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.drawer-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(720px, 100%); background: var(--bg2); border-left: 1px solid var(--line); overflow-y: auto; padding: 24px; animation: slide .25s; }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-close { position: sticky; top: 0; float: right; z-index: 3; }
.d-head { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; }
.d-head .avatar { width: 64px; height: 64px; font-size: 1.7rem; }
.d-sec { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }
.d-sec h4 { color: var(--accent2); margin-bottom: 8px; display: flex; gap: 8px; align-items: center; }
.note { display: flex; gap: 8px; font-size: .86rem; margin: 6px 0; }
.note i { font-style: normal; flex: none; }
blockquote { margin: 8px 0; padding: 8px 12px; border-left: 3px solid var(--accent2); background: rgba(232,200,114,.06); font-family: Georgia, serif; font-size: .92rem; color: #dbe9df; border-radius: 0 8px 8px 0; }
blockquote small { display: block; color: var(--muted); font-family: inherit; margin-top: 4px; }
.rel-item { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: .86rem; flex-wrap: wrap; }
.rel-item:last-child { border: 0; }
.rel-item .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.rel-item a { cursor: pointer; text-decoration: none; font-weight: 600; }
.spark { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; align-items: end; height: 54px; }
.spark i { display: block; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 2px; opacity: .85; }

/* relations / graph */
.graph-wrap { position: relative; background: radial-gradient(circle at 50% 50%, #0f2a20, #07140f); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; touch-action: none; }
.graph-wrap svg { width: 100%; height: auto; display: block; max-height: 78vh; }
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; font-size: .78rem; color: var(--muted); margin: 10px 0; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 18px; height: 4px; border-radius: 2px; display: inline-block; }
.legend i.dot { width: 11px; height: 11px; border-radius: 50%; }
.node text { fill: #e6f2ea; font-size: 12px; paint-order: stroke; stroke: #06110d; stroke-width: 3px; pointer-events: none; }
.node circle { cursor: grab; stroke: #06110d; stroke-width: 2; transition: stroke .15s; }
.node.sel circle { stroke: #fff; stroke-width: 3; }
.node.dim, .edge.dim { opacity: .12; }
.edge { transition: opacity .15s; }
.rel-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.rel-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.rel-table td { padding: 8px; border-bottom: 1px dashed var(--line); vertical-align: top; }
.rel-table tr { cursor: pointer; } .rel-table tr:hover td { background: rgba(92,225,160,.05); }

/* timeline */
.rail { display: grid; gap: 3px; align-items: end; }
.rail .col { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 3px; cursor: pointer; min-width: 0; }
.rail .col .ic { font-size: .95rem; line-height: 1; min-height: 1em; text-align: center; }
.rail .col .tb { width: 100%; border-radius: 4px 4px 0 0; min-height: 6px; transition: .15s; opacity: .9; }
.rail .col:hover .tb { opacity: 1; filter: brightness(1.2); }
.rail .col .n { font-size: .62rem; color: var(--muted); }
.phase-legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 12px 0; font-size: .82rem; }
.phase-legend span { display: inline-flex; gap: 6px; align-items: center; }
.phase-legend i { width: 12px; height: 12px; border-radius: 3px; }
.heat { display: grid; gap: 2px; overflow-x: auto; }
.heat .nm { font-size: .78rem; padding-right: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: sticky; left: 0; background: var(--panel); z-index: 1; display: flex; align-items: center; }
.heat .cell { height: 20px; border-radius: 3px; background: rgba(92,225,160, var(--a, 0)); }
.heat .hd { font-size: .62rem; color: var(--muted); text-align: center; }
.tl { position: relative; margin-left: 12px; padding-left: 26px; border-left: 2px solid var(--line); }
.tl-item { position: relative; margin-bottom: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; scroll-margin-top: 90px; }
.tl-item::before { content: ""; position: absolute; left: -35px; top: 18px; width: 16px; height: 16px; border-radius: 50%; background: var(--pc); border: 3px solid var(--bg); }
.tl-item.flash { outline: 2px solid var(--accent2); }
.tl-head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-bottom: 8px; }
.tl-head h4 { margin: 0; font-size: 1.02rem; }
.pill { font-size: .72rem; padding: 2px 9px; border-radius: 99px; background: var(--pc); color: #04140c; font-weight: 700; }
.meter { display: flex; align-items: center; gap: 8px; font-size: .76rem; color: var(--muted); }
.meter .track { width: 90px; height: 7px; background: #17301f; border-radius: 99px; overflow: hidden; }
.meter .track i { display: block; height: 100%; background: linear-gradient(90deg, #3ab87b, var(--orange), var(--red)); }
.mini-av { width: 26px; height: 26px; font-size: .75rem; display: inline-grid; place-items: center; border-radius: 50%; color: #04140c; background: var(--rc, var(--accent)); font-weight: 700; margin-right: -6px; border: 2px solid var(--panel); }
.tl-ms { background: rgba(232,200,114,.1); border: 1px solid rgba(232,200,114,.35); padding: 4px 10px; border-radius: 8px; font-size: .8rem; color: var(--accent2); display: inline-block; margin: 2px 4px 2px 0; }

/* literary */
.crit { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; padding: 12px 0; border-bottom: 1px dashed var(--line); }
.crit:last-child { border: 0; }
.crit .t { font-weight: 600; } .crit .w { color: var(--muted); font-size: .76rem; }
.crit .score { font-family: Georgia, serif; font-size: 1.4rem; text-align: right; }
.crit .track { grid-column: 1 / -1; height: 8px; background: #17301f; border-radius: 99px; overflow: hidden; }
.crit .track i { display: block; height: 100%; border-radius: 99px; }
.crit .why { grid-column: 1 / -1; color: var(--muted); font-size: .82rem; }
.crit .tip { grid-column: 1 / -1; color: var(--orange); font-size: .82rem; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; font-size: .86rem; }
.kv span:nth-child(odd) { color: var(--muted); } .kv span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }
.disclaimer { background: rgba(255,179,71,.08); border: 1px solid rgba(255,179,71,.3); border-radius: 10px; padding: 10px 14px; font-size: .82rem; color: #e8c99a; margin-top: 14px; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(2,8,5,.8); backdrop-filter: blur(4px); padding: 16px; }
.loading-card, .modal { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 26px; width: min(480px, 100%); box-shadow: var(--shadow); }
.loading-card { text-align: center; }
.spinner { width: 46px; height: 46px; border: 4px solid #1d3d2e; border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 14px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 8px; background: #17301f; border-radius: 99px; overflow: hidden; margin-top: 12px; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .25s; }
.modal label { display: block; margin: 12px 0; font-size: .86rem; color: var(--muted); }
.modal label textarea, .modal label input { margin-top: 5px; }
.err { background: rgba(255,107,107,.1); border: 1px solid var(--red); color: #ffb3b3; padding: 12px 16px; border-radius: 10px; margin: 14px auto; max-width: 640px; text-align: left; }

@media (max-width: 640px) {
  main { padding: 12px; }
  .g2 { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 90px 1fr 38px; }
  .topbar { padding: 8px 12px; }
  .brand small { display: none; }
  .drawer-panel { padding: 16px; }
}

@media print {
  body { background: #fff; color: #111; }
  .topbar, .drawer, .overlay, .toolbar, #landing { display: none !important; }
  .tabpane { display: block !important; page-break-inside: avoid; margin-bottom: 20px; }
  .card, .stat, .char-card, .tl-item, .d-sec, .hero { background: #fff !important; color: #111 !important; border-color: #ccc !important; box-shadow: none !important; }
  .muted, .rep, .why { color: #444 !important; }
  .hero p, .hero .sub { color: #333 !important; }
  .graph-wrap { background: #fff; }
  .node text { fill: #000; stroke: #fff; }
}
