:root {
  --ink: #17201e;
  --muted: #66726f;
  --paper: #f5f3ec;
  --surface: #fffdf7;
  --line: #dcdad1;
  --green: #154e43;
  --green-2: #267565;
  --mint: #dcece5;
  --amber: #a85f19;
  --amber-bg: #fff0d8;
  --red: #9d3f35;
  --red-bg: #f8e0dc;
  --violet: #69588f;
  --violet-bg: #ebe5f5;
  --shadow: 0 12px 40px rgba(25, 35, 31, .08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--paper); min-height: 100vh; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.pw-topbar {
  position: sticky; top: 0; z-index: 20; height: 82px; display: grid;
  grid-template-columns: 170px minmax(210px, 1fr) minmax(330px, 520px) auto;
  align-items: center; gap: 24px; padding: 12px 24px; color: white;
  background: #113c34; border-bottom: 1px solid rgba(255,255,255,.14);
}
.pw-brand { display: flex; align-items: center; gap: 9px; color: white; text-decoration: none; font-weight: 750; }
.pw-brand img { width: 34px; height: 34px; object-fit: contain; }
.pw-brand small { display: block; margin-top: 2px; color: #a7d0c6; font-size: 9px; font-weight: 600; letter-spacing: .02em; }
.pw-title-block h1 { margin: 2px 0 0; font-family: Georgia, serif; font-size: 22px; font-weight: 500; }
.pw-kicker { display: block; font-size: 10px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; color: #74a99d; }
.pw-topbar .pw-kicker { color: #a7d0c6; }
.pw-protein-form label { display: block; margin-bottom: 5px; color: #b8d6cf; font-size: 10px; text-transform: uppercase; letter-spacing: .1em; }
.pw-protein-form > div { display: flex; }
.pw-protein-form input { flex: 1; min-width: 0; height: 38px; padding: 0 12px; border: 1px solid rgba(255,255,255,.28); border-right: 0; border-radius: 7px 0 0 7px; color: white; background: rgba(255,255,255,.08); text-transform: uppercase; }
.pw-protein-form button { padding: 0 16px; border: 0; border-radius: 0 7px 7px 0; color: #123b33; background: #d5e9e2; font-weight: 750; }
.pw-owner-button { padding: 9px 12px; color: white; border: 1px solid rgba(255,255,255,.3); border-radius: 7px; background: transparent; }
.pw-owner-button.authenticated { color: #113c34; background: #d5e9e2; border-color: #d5e9e2; }

.pw-rail { position: fixed; top: 82px; bottom: 0; left: 0; width: 340px; display: flex; flex-direction: column; background: #f9f7f1; border-right: 1px solid var(--line); }
.pw-rail-head { display: flex; align-items: end; justify-content: space-between; padding: 22px 18px 12px; }
.pw-rail-head h2 { margin: 3px 0 0; font: 500 24px/1.1 Georgia, serif; }
.pw-count { min-width: 42px; padding: 5px 8px; text-align: center; border-radius: 999px; background: var(--mint); color: var(--green); font-weight: 800; font-size: 12px; }
.pw-filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; padding: 0 18px 9px; }
.pw-filter-grid input { grid-column: 1 / -1; }
.pw-filter-grid #candidate-scope { grid-column: 1 / -1; border-color: #8eafa6; color: var(--green); font-weight: 750; }
.pw-scope-status { grid-column: 1 / -1; margin-top: -2px; color: var(--muted); font-size: 10px; line-height: 1.35; }
.pw-external-refresh { grid-column: 1 / -1; border: 1px solid #789e94; border-radius: 7px; padding: 8px 10px; color: var(--green); background: #edf5f2; font-weight: 800; cursor: pointer; }
.pw-external-refresh:hover:not(:disabled) { border-color: var(--green); background: #e1eee9; }
.pw-external-refresh:disabled { cursor: not-allowed; opacity: .55; }
.pw-external-refresh-status { grid-column: 1 / -1; color: var(--muted); font-size: 10px; line-height: 1.4; }
.pw-filter-grid input, .pw-filter-grid select { width: 100%; min-width: 0; height: 36px; padding: 0 9px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: white; font-size: 12px; }
.pw-rail-note { margin: 0 18px 10px; padding: 8px 10px; border-left: 2px solid #8aa89f; color: var(--muted); background: #eef3ef; font-size: 11px; line-height: 1.4; }
.pw-candidate-list { flex: 1; overflow: auto; padding: 0 10px 12px; }
.pw-candidate { width: 100%; display: grid; grid-template-columns: 36px 1fr auto; gap: 8px; align-items: center; padding: 11px 9px; border: 1px solid transparent; border-bottom-color: #e5e2da; background: transparent; text-align: left; }
.pw-candidate:hover { background: white; }
.pw-candidate.selected { border-color: #8eafa6; border-radius: 8px; background: white; box-shadow: 0 4px 18px rgba(28,65,55,.07); }
.pw-rank { color: #8a938f; font: 650 12px/1 ui-monospace, monospace; }
.pw-symbol { display: block; font-weight: 800; letter-spacing: .03em; }
.pw-candidate-meta { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.pw-status-dot { width: 9px; height: 9px; border-radius: 50%; background: #b8bfbc; }
.pw-status-dot.painted { background: var(--violet); box-shadow: 0 0 0 3px var(--violet-bg); }
.pw-status-dot.in_progress { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-bg); }
.pw-load-more { margin: 9px 18px 16px; padding: 10px; color: var(--green); border: 1px solid #9dbbb3; border-radius: 7px; background: white; font-weight: 750; }

.pw-main { margin-left: 340px; padding: 26px clamp(20px, 3vw, 46px) 60px; }
.pw-hero { display: flex; justify-content: space-between; align-items: center; gap: 20px; min-height: 96px; }
.pw-hero h2 { margin: 6px 0 5px; font: 500 clamp(25px, 3vw, 38px)/1.1 Georgia, serif; }
.pw-hero p { max-width: 760px; margin: 0; color: var(--muted); line-height: 1.5; }
.pw-hero-actions { display: flex; gap: 8px; flex: none; }
.pw-secondary, .pw-paint { padding: 10px 14px; border-radius: 7px; font-weight: 750; }
.pw-secondary { border: 1px solid var(--line); color: var(--ink); background: var(--surface); }
.pw-paint { border: 1px solid var(--green); color: white; background: var(--green); }
.pw-paint:disabled { cursor: not-allowed; opacity: .45; }
.pw-badges { display: flex; flex-wrap: wrap; gap: 5px; }
.pw-badge { padding: 4px 7px; border-radius: 5px; font-size: 10px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.pw-badge.observed { color: #135343; background: #dcefe7; }
.pw-badge.derived { color: #365b77; background: #e0ebf3; }
.pw-badge.hypothesis { color: var(--violet); background: var(--violet-bg); }
.pw-badge.contradiction { color: var(--red); background: var(--red-bg); }
.pw-badge.unknown { color: #6c665f; background: #ebe8e2; }

.pw-benchmark { display: flex; align-items: center; gap: 10px; margin: 14px 0 18px; padding: 11px 14px; border: 1px solid #d1dcd7; border-radius: 8px; color: #38534c; background: #edf3ef; font-size: 12px; }
.pw-benchmark strong { color: var(--green); }
.pw-spinner { width: 15px; height: 15px; border: 2px solid #bdd1ca; border-top-color: var(--green); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.pw-map-card, .pw-details { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.pw-section-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.pw-section-head h3 { margin: 3px 0 0; font: 500 20px/1.2 Georgia, serif; }
.pw-map-legend { display: flex; flex-wrap: wrap; gap: 13px; color: var(--muted); font-size: 10px; }
.pw-map-legend span { display: flex; align-items: center; gap: 5px; }
.pw-map-legend i { width: 22px; height: 3px; border-radius: 4px; background: var(--green-2); }
.pw-map-legend .derived { background: #6285a0; border-top: 1px dashed white; }
.pw-map-legend .unknown { background: #aaa59d; }
.pw-map-legend .chain { background: var(--amber); }
.pw-map { height: 430px; position: relative; overflow: hidden; background: radial-gradient(circle at center, #fff 0, #fffdf7 72%); }
.pw-map svg { width: 100%; height: 100%; }
.pw-map .node text { fill: var(--ink); font-size: 11px; font-weight: 750; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.pw-chain-strip { display: flex; gap: 8px; overflow-x: auto; padding: 10px 12px 13px; border-top: 1px solid var(--line); background: #faf8f2; }
.pw-chain-chip { flex: 0 0 min(320px, 78vw); padding: 9px 10px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: white; text-align: left; }
.pw-chain-chip:hover, .pw-chain-chip.active { border-color: var(--amber); box-shadow: 0 3px 12px rgba(168,95,25,.12); }
.pw-chain-chip strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 700 11px ui-monospace, monospace; }
.pw-chain-chip span { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.pw-relationship-summary { border-color: #9cb8ae; background: #f4faf7; }
.pw-role-term { display: inline-block; margin: 2px 4px 2px 0; padding: 3px 6px; border-radius: 999px; color: #365b77; background: #e6f0f6; font-size: 10px; }
.pw-empty { display: grid; place-items: center; height: 100%; min-height: 100px; padding: 28px; color: #828b88; text-align: center; }

.pw-details { margin-top: 18px; overflow: hidden; }
.pw-tabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); background: #f7f5ef; }
.pw-tabs button { flex: none; padding: 13px 15px; border: 0; border-bottom: 2px solid transparent; color: var(--muted); background: transparent; font-size: 12px; font-weight: 750; }
.pw-tabs button[aria-selected="true"] { color: var(--green); border-bottom-color: var(--green); background: white; }
.pw-tab-panel { min-height: 270px; padding: 20px; }
.pw-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.pw-card { padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.pw-card h4 { margin: 0 0 7px; font-size: 13px; }
.pw-card p { margin: 6px 0; color: #43504c; font-size: 12px; line-height: 1.55; }
.pw-card ul, .pw-card ol { margin: 7px 0; padding-left: 19px; color: #43504c; font-size: 12px; line-height: 1.55; }
.pw-card a { color: var(--green-2); }
.pw-publications { display: flex; flex-wrap: wrap; gap: 6px; margin: 9px 0 6px; }
.pw-publications a { display: inline-flex; align-items: center; padding: 4px 7px; border: 1px solid #cfe0da; border-radius: 999px; background: #f3faf7; font-size: 11px; font-weight: 700; text-decoration: none; }
.pw-publications a:hover { border-color: var(--green-2); background: #e7f5ef; }
.pw-source-id { display: inline-block; margin: 2px 3px 2px 0; padding: 2px 5px; border-radius: 4px; color: #52615d; background: #edf0ee; font: 10px ui-monospace, monospace; }
.pw-callout { padding: 11px 13px; border-left: 3px solid var(--amber); color: #71471f; background: var(--amber-bg); font-size: 12px; line-height: 1.5; }
.pw-hypothesis-card { border-color: #cfc3e2; background: #fdfbff; }
.pw-hypothesis-card h4 { color: var(--violet); }

.pw-dialog { width: min(610px, calc(100vw - 30px)); padding: 0; border: 0; border-radius: 12px; background: transparent; box-shadow: 0 30px 100px rgba(0,0,0,.28); }
.pw-dialog::backdrop { background: rgba(12, 24, 20, .58); backdrop-filter: blur(3px); }
.pw-dialog-card { position: relative; padding: 25px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.pw-dialog-card h2 { margin: 4px 0 12px; font: 500 25px Georgia, serif; }
.pw-dialog-card p { color: var(--muted); line-height: 1.5; }
.pw-dialog-card label { display: block; margin-bottom: 5px; font-size: 12px; font-weight: 750; }
.pw-dialog-card input { width: 100%; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px; }
.pw-dialog-close { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border: 0; border-radius: 50%; background: #ebe9e2; font-size: 20px; }
.pw-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.pw-form-error { min-height: 18px; color: var(--red) !important; font-size: 12px; }
.pw-price { margin: 13px 0; padding: 13px; border-radius: 8px; color: var(--green); background: var(--mint); font-size: 22px; font-weight: 800; }
.pw-toast { position: fixed; right: 22px; bottom: 22px; z-index: 100; max-width: 390px; padding: 12px 15px; border-radius: 8px; color: white; background: #173e35; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(8px); transition: .2s; }
.pw-toast.show { opacity: 1; transform: none; }

@media (max-width: 900px) {
  .pw-topbar { height: auto; grid-template-columns: auto 1fr auto; gap: 10px; }
  .pw-title-block { display: none; }
  .pw-protein-form { grid-column: 1 / -1; grid-row: 2; }
  .pw-rail { position: static; width: auto; height: 390px; border-right: 0; border-bottom: 1px solid var(--line); }
  .pw-main { margin-left: 0; }
  .pw-hero { align-items: flex-start; flex-direction: column; }
}
