:root {
  --bg: #16181c;
  --card: #1e2026;
  --row: #1f2228;
  --row-hover: #262a31;
  --raise: #2a2e36;
  --line: #2c3038;
  --text: #f2f3f5;
  --dim: #a0a6b0;
  --faint: #8a909b;
  --blue: #4f7cff;
  --blue-hover: #6a8fff;
  --violet: #a35cff;
  --green: #3fbf6f;
  --green-bg: rgb(63 191 111 / 0.14);
  --red: #f05454;
  --red-bg: rgb(240 84 84 / 0.14);
  --amber: #e7b84b;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, Menlo, monospace;
  --r: 10px;
  --r-lg: 14px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--bg); scrollbar-color: var(--line) var(--bg); }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
/* tabular figures only where numbers align; on body they space out hyphens in market titles */
.num, .stats dd, .rows dd, .big, .vbox, .whale .val, .px, .side, .meta, .ev .body { font-variant-numeric: tabular-nums; }
::selection { background: var(--blue); color: #fff; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-decoration-color: var(--faint); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 6px; }
h1, h2, p, dl, dd { margin: 0; }
ul, ol { list-style: none; margin: 0; padding: 0; }
.muted { color: var(--dim); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.cap { font: 600 12px/1 var(--font); letter-spacing: 0.06em; text-transform: uppercase; color: var(--dim); margin-bottom: 12px; }
svg.i { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* shell */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 28px; height: 60px; padding: 0 24px; background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { font: 700 18px/1 var(--font); letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.top nav { display: flex; gap: 20px; height: 100%; }
.top nav a { display: flex; align-items: center; gap: 6px; color: var(--dim); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.top nav a:hover { color: var(--text); text-decoration: none; }
.top nav a[aria-current] { color: var(--text); border-bottom-color: var(--text); }
.live { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--green); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
body.stale .live { color: var(--amber); }
body.stale .px { opacity: 0.55; }
/* while a page loads in place, the content dims instead of flashing white */
body[aria-busy="true"] main { opacity: 0.6; transition: opacity 120ms 80ms; }

.layout { display: grid; grid-template-columns: 248px minmax(0, 1fr) 320px; min-height: calc(100vh - 60px); }
.whales, .feed { min-width: 0; position: sticky; top: 60px; align-self: start; height: calc(100vh - 60px); overflow-y: auto; padding: 20px 16px; }
.whales { border-right: 1px solid var(--line); }
.feed { border-left: 1px solid var(--line); }
main { padding: 24px 28px 48px; min-width: 0; }

/* whale rail */
.add-whale { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 20px; width: 100%; }
.whale { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; padding: 10px 12px; border-radius: var(--r); transition: background 150ms; }
.whale:hover { background: var(--row); text-decoration: none; }
.whale[aria-current] { background: var(--row-hover); }
.whale .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.whale .val { font-weight: 600; }
.whale .sub { grid-column: 1 / -1; color: var(--dim); font-size: 12px; }
.whale .err { grid-column: 1 / -1; color: var(--red); font-size: 12px; }

/* profile */
.profile { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px; min-width: 0; }
.who-top { display: flex; align-items: center; gap: 14px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.avatar { display: grid; place-items: center; flex: none; width: 56px; height: 56px; border-radius: 50%; background: linear-gradient(135deg, var(--blue), var(--violet)); font: 700 22px/1 var(--font); color: #fff; }
.who-name { display: grid; gap: 2px; min-width: 0; }
h1 { font: 600 22px/1.2 var(--font); letter-spacing: -0.01em; overflow-wrap: anywhere; }
.who-name a { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.unfollow { margin-left: auto; }
.unfollow .btn:hover { color: var(--red); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 18px 0; text-align: center; border-bottom: 1px solid var(--line); }
.stats div { display: grid; gap: 2px; }
.stats dd { font: 600 18px/1.2 var(--font); }
.stats dt { color: var(--dim); font-size: 12px; }
.rows { display: grid; gap: 8px; padding-top: 14px; font-size: 13px; }
.rows div { display: flex; justify-content: space-between; }
.rows dt { color: var(--dim); }
.rows dd { font-weight: 600; }
.pnlcard { display: flex; flex-direction: column; }
.pnl-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.lbl { color: var(--dim); font-size: 13px; font-weight: 500; }
.range { display: flex; gap: 2px; }
.range a { padding: 4px 10px; border-radius: 6px; color: var(--dim); font-size: 12px; font-weight: 600; }
.range a:hover { color: var(--text); text-decoration: none; }
.range a[aria-current] { color: var(--blue); background: rgb(79 124 255 / 0.15); }
.big { font: 600 30px/1.1 var(--font); letter-spacing: -0.01em; margin-top: 8px; color: var(--green); }
.big.neg { color: var(--red); }
.period { font-size: 12px; margin-bottom: 8px; }
.chart { display: block; width: 100%; height: 120px; margin-top: auto; }
.chart-empty { margin-top: auto; padding: 32px 0; text-align: center; }
.error { color: var(--red); margin-top: 8px; }
.empty { padding: 48px 0; color: var(--dim); text-align: center; }

/* whale-level alerts */
.whale-alerts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 24px; }
.whale-alerts .lbl { margin-right: 4px; }

/* controls */
.btn, .chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: var(--r); border: 1px solid var(--line); background: var(--card); color: var(--text); font: 500 14px/1 var(--font); cursor: pointer; text-decoration: none; transition: background 150ms, border-color 150ms, color 150ms; }
.btn:hover, .chip:hover { background: var(--row-hover); text-decoration: none; }
.btn:active, .chip:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--blue-hover); }
.btn.ghost { background: none; border-color: transparent; color: var(--dim); }
.btn.ghost:hover { color: var(--text); background: var(--row-hover); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { padding: 0; width: 36px; justify-content: center; }
.chip { border-radius: 999px; color: var(--dim); }
.chip[aria-pressed="true"] { border-color: var(--blue); color: var(--blue); background: rgb(79 124 255 / 0.12); }
form.inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
label { display: inline-flex; align-items: center; gap: 8px; color: var(--dim); font-size: 13px; }
input, select { min-height: 36px; padding: 0 12px; border-radius: var(--r); border: 1px solid var(--line); background: var(--card); color: var(--text); font: 14px var(--font); caret-color: var(--blue); }
input:hover, select:hover { border-color: var(--faint); }
input:focus-visible, select:focus-visible { outline: none; border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
input:user-invalid { border-color: var(--red); }
input[type="number"] { width: 100px; }
input::placeholder { color: var(--faint); }

/* toolbar */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.seg { display: flex; gap: 2px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; }
.seg a { padding: 7px 14px; border-radius: 8px; color: var(--dim); font-weight: 600; white-space: nowrap; }
.seg a:hover { color: var(--text); text-decoration: none; }
.seg a[aria-current] { background: var(--raise); color: var(--text); }
.seg .n { color: var(--faint); font-weight: 500; }
.search { flex: 1; position: relative; }
.search svg { position: absolute; left: 12px; color: var(--faint); pointer-events: none; }
.search input { width: 100%; min-height: 44px; padding-left: 38px; border-radius: 12px; }
.sort select { min-height: 44px; border-radius: 12px; font-weight: 600; }

/* positions */
table.positions { width: 100%; border-collapse: separate; border-spacing: 0 6px; }
.positions th { text-align: left; font: 600 12px/1 var(--font); letter-spacing: 0.06em; text-transform: uppercase; color: var(--dim); padding: 8px 14px; white-space: nowrap; }
.positions td { padding: 12px 14px; background: var(--row); vertical-align: middle; transition: background 150ms; }
.positions td:first-child { border-radius: var(--r) 0 0 var(--r); }
.positions td:last-child { border-radius: 0 var(--r) var(--r) 0; }
.positions tbody tr:hover td { background: var(--row-hover); }
.positions tbody tr { scroll-margin-top: 80px; }
.positions tbody tr:is(:target, .hit) td { background: rgb(79 124 255 / 0.12); }
.num { text-align: right; white-space: nowrap; }
th.num { text-align: right; }
.market { font-size: 14px; line-height: 1.35; font-weight: 500; }
.mk { display: flex; gap: 12px; align-items: center; }
.mk:hover { text-decoration: none; }
.mk:hover .q { text-decoration: underline; text-decoration-color: var(--faint); }
.ic { flex: none; width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--raise); }
.mt { display: grid; gap: 5px; min-width: 0; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--dim); font-size: 12px; font-weight: 400; }
.side { display: inline-block; padding: 3px 7px; border-radius: 6px; font: 600 12px/1.1 var(--font); background: var(--green-bg); color: var(--green); }
.side[data-o="no"] { background: var(--red-bg); color: var(--red); }
/* named outcomes (teams, candidates) carry no direction, so they stay neutral */
.side:not([data-o="yes"], [data-o="no"]) { background: var(--raise); color: var(--text); }
.price { white-space: nowrap; }
.px { display: inline-block; font-weight: 500; transition: opacity 200ms; }
.px.up { color: var(--green); }
.px.dn { color: var(--red); }
.px.flip { animation: tick 480ms var(--ease); }
@keyframes tick { from { transform: translateY(35%); opacity: 0; } }
s.was { color: var(--faint); font-size: 12px; text-decoration-color: currentColor; margin-right: 6px; }
.vbox { display: grid; justify-items: end; gap: 2px; }
.vbox .v { font-weight: 600; font-size: 14px; }
.pnl { color: var(--green); }
.pnl.neg { color: var(--red); }
.vbox .pnl { font-size: 12px; }
.act { font-weight: 600; color: var(--green); }
.act.sell { color: var(--red); }
.activity .when { white-space: nowrap; }

/* inline alert editor */
.bell { width: 56px; text-align: right; position: relative; }
.alert-pop summary { list-style: none; position: relative; color: var(--dim); }
.alert-pop summary::-webkit-details-marker { display: none; }
.alert-pop summary.on { color: var(--blue); border-color: rgb(79 124 255 / 0.5); }
.alert-pop .count { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; border-radius: 999px; background: var(--blue); color: #fff; font: 600 12px/18px var(--font); text-align: center; }
.alert-pop[open] summary { background: var(--row-hover); color: var(--blue); }
.pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 4; width: 320px; padding: 16px; display: grid; gap: 12px; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: 0 16px 40px rgb(0 0 0 / 0.5); animation: pop 180ms var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }
.pop-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.pop-head div { display: grid; gap: 2px; }
.pop-head strong { font-weight: 600; line-height: 1.35; }
.pop-head .muted { font-size: 12px; }
.pop .close { flex: none; }
.pop form.inline { justify-content: space-between; color: var(--text); font-size: 14px; }
.new-alert { display: grid; gap: 10px; }
.pop form.inline ~ .new-alert { border-top: 1px solid var(--line); padding-top: 12px; }
.new-alert label { display: grid; gap: 4px; font-size: 12px; }
.new-alert select, .new-alert input { width: 100%; }

/* feed */
.events { display: grid; gap: 8px; }
.ev a { display: grid; gap: 4px; padding: 12px 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); transition: background 150ms; }
.ev a:hover { background: var(--row-hover); text-decoration: none; }
.ev .when { color: var(--dim); font-size: 12px; }
.ev strong { font-weight: 600; }
.ev .body { color: var(--dim); font-size: 13px; }
.ev[data-kind="whale_sell"] strong, .ev[data-kind="whale_exit"] strong { color: var(--red); }
.ev[data-kind="whale_new"] strong { color: var(--green); }
.ev[data-kind^="price"] strong, .ev[data-kind="big_trade"] strong { color: var(--blue); }
.episode { display: grid; gap: 6px; margin-top: 4px; }
.episode .track { display: block; height: 6px; border-radius: 999px; background: var(--raise); }
.episode .bar { display: block; height: 6px; border-radius: 999px; background: var(--faint); }
.episode .bar.open { background: var(--red); }

/* alerts page, add page */
h1 + p.muted { max-width: 75ch; margin: 6px 0 24px; }
form.add { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin: 16px 0 8px; }
form.add label { display: grid; gap: 6px; }
form.add label:first-child { flex: 1 1 440px; }
form.add input[name="wallet"] { width: 100%; font-family: var(--mono); }
main > h2.cap { margin-top: 40px; }
.suggest { display: grid; gap: 6px; margin-top: 12px; }
.suggest li { display: grid; grid-template-columns: minmax(120px, 200px) 1fr auto; gap: 16px; align-items: center; padding: 10px 14px; border-radius: var(--r); background: var(--row); }
.suggest .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* loading */
.skeleton { display: grid; gap: 6px; margin-bottom: 12px; }
.skeleton .row { height: 68px; border-radius: var(--r); background: var(--row); animation: breathe 1.4s ease-in-out infinite alternate; }
@keyframes breathe { to { background: var(--row-hover); } }

.to-feed { display: none; }

/* login */
.logout { margin-left: 4px; }
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(400px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 32px 28px; }
.auth-card .brand { margin-bottom: 20px; }
.auth-card h1 { margin-bottom: 20px; }
.auth-card form { display: grid; gap: 16px; }
.auth-card label { display: grid; gap: 6px; font-size: 13px; }
.auth-card input { width: 100%; min-height: 44px; }
.auth-card .btn { justify-content: center; min-height: 44px; }
.auth-card .error { margin: 0; }
.auth-card .hint { margin-top: 20px; font-size: 12px; }
.auth-card code { font-family: var(--mono); color: var(--text); }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 220px minmax(0, 1fr); }
  .feed { grid-column: 1 / -1; grid-row: 1; position: static; height: auto; border-left: 0; border-bottom: 1px solid var(--line); padding: 16px 24px; }
  .events { grid-auto-flow: column; grid-auto-columns: minmax(260px, 320px); overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 4px; }
  .ev { scroll-snap-align: start; }
  .profile { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .top { gap: 16px; padding: 0 16px; }
  .top nav .lbl { display: none; }
  .live { font-size: 0; gap: 0; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .feed { padding: 12px 16px; }
  .events { grid-auto-columns: 86%; }
  .whales { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; }
  .whales .cap { display: none; }
  .whales ul { display: flex; gap: 8px; overflow-x: auto; }
  .whales li { flex: none; }
  .whale { grid-template-columns: auto auto; padding: 8px 12px; background: var(--row); }
  .whale .sub { display: none; }
  .add-whale { display: none; }
  .feed:not(:has(.ev)) { display: none; }
  main { padding: 16px 16px 40px; }
  .card { padding: 16px; }
  .toolbar { flex-wrap: wrap; }
  .search { flex-basis: 100%; order: 3; }
  table.positions, .positions tbody, .positions tr, .positions td { display: block; }
  .positions thead { display: none; }
  .positions tr { display: grid; grid-template-columns: 1fr auto auto; gap: 10px 12px; align-items: center; padding: 14px; margin-bottom: 8px; border-radius: var(--r); background: var(--row); }
  .positions td, .positions tbody tr:hover td { padding: 0; background: none; border-radius: 0; }
  .positions tbody tr:is(:target, .hit) { background: rgb(79 124 255 / 0.12); }
  .positions tbody tr:is(:target, .hit) td { background: none; }
  .positions td.market { grid-column: 1 / -1; }
  .positions td.avg { display: none; }
  .positions td.price { grid-row: 2; grid-column: 1; text-align: left; }
  .positions td.price .px { font-size: 15px; font-weight: 600; }
  .positions td.value { grid-row: 2; grid-column: 2; }
  .positions td.bell { grid-row: 2; grid-column: 3; width: auto; }
  .positions:not(:has(.bell)) tr { grid-template-columns: 1fr auto; }
  .to-feed { display: grid; gap: 2px; position: sticky; bottom: 12px; z-index: 3; order: 9; margin: 0 0 16px; padding: 10px 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); box-shadow: 0 8px 24px rgb(0 0 0 / 0.45); }
  .to-feed:hover { text-decoration: none; }
  .to-feed .when { color: var(--dim); font-size: 12px; }
  .to-feed strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #main { display: flex; flex-direction: column; }
  .pop { position: fixed; left: 16px; right: 16px; top: auto; bottom: 16px; width: auto; }
  .suggest li { grid-template-columns: 1fr auto; }
  .suggest li .muted { grid-column: 1; font-size: 12px; }
  .suggest li form { grid-row: 1 / 3; grid-column: 2; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
