/* Aesop — storybook trading terminal */
:root {
  --bg: #16120e;
  --bg2: #1d1813;
  --card: #211b15;
  --card2: #262019;
  --line: #322a20;
  --ink: #ece1cd;
  --ink2: #b3a68d;
  --muted: #7d715c;
  --accent: #e0a458;
  --accent-ink: #2a1f10;
  --up: #8fbf7f;
  --down: #e07a6a;
  --serif: 'Alegreya', 'Georgia', serif;            /* body: made for reading */
  --display: 'Cormorant Garamond', 'Georgia', serif; /* big storybook moments only */
  --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
}
[data-theme="light"] {
  --bg: #f3ead9;
  --bg2: #ede2cd;
  --card: #faf3e4;
  --card2: #f1e7d2;
  --line: #ddcfb4;
  --ink: #2b2314;
  --ink2: #5c5137;
  --muted: #8d8064;
  --accent: #b3752a;
  --accent-ink: #fff6e6;
  --up: #3e7d3a;
  --down: #b0432f;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
}
/* display face is reserved for the big storybook moments */
h1, .welcomeline, .brand .word, .docs h1 { font-family: var(--display); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: var(--mono); font-size: 0.72em; letter-spacing: 0.02em; }

/* ---------- header ---------- */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 26px; gap: 16px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .mark { width: 34px; height: 34px; }
.brand .word { font-size: 26px; font-weight: 600; letter-spacing: 0.01em; }
.brand .word b { color: var(--accent); font-weight: 600; }
.brand small { display: block; font-family: var(--mono); font-size: 10px; color: var(--muted); letter-spacing: 0.08em; }
nav { display: flex; align-items: center; gap: 18px; font-family: var(--mono); font-size: 13px; }
nav a, nav button.linky { color: var(--ink2); background: none; border: 0; cursor: pointer; font-family: var(--mono); font-size: 13px; padding: 0; }
nav a:hover, nav button.linky:hover { color: var(--accent); text-decoration: none; }
.btn {
  background: var(--accent); color: var(--accent-ink); border: 0; cursor: pointer;
  font-family: var(--mono); font-size: 13px; font-weight: 600;
  padding: 9px 16px; border-radius: 999px;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--ink2); border: 1px solid var(--line); }
.btn.danger { background: var(--down); color: #fff; }

/* ---------- layout ---------- */
.wrap { max-width: 1460px; margin: 0 auto; padding: 22px 26px 60px; }
.grid { display: grid; grid-template-columns: minmax(340px, 1fr) minmax(480px, 1.15fr); gap: 26px; }
@media (max-width: 980px) { .grid { grid-template-columns: 1fr; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.card h3 { margin: 0 0 12px; font-size: 20px; font-weight: 600; }
.klabel { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.14em; color: var(--muted); text-transform: uppercase; }

/* ---------- hero / gimmick ---------- */
.gimmick { margin: 6px 0 18px; }
.gimmick .quote { font-size: 19px; font-style: italic; }
.gimmick .quote em { color: var(--accent); font-style: italic; }
.hpwrap { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.hpbar { flex: 1; height: 16px; background: var(--bg2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; position: relative; }
.hpfill { height: 100%; background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 70%, var(--down))); transition: width 0.8s ease; border-radius: 999px; }
.hplabel { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--mono); font-size: 10px; color: var(--accent-ink); font-weight: 700; mix-blend-mode: normal; }
[data-theme="light"] .hplabel { color: #3a2a10; }
.countdown { font-family: var(--mono); font-size: 14px; color: var(--accent); min-width: 52px; text-align: right; }
.chapterlabel { font-family: var(--mono); font-size: 10px; color: var(--muted); letter-spacing: 0.1em; margin-top: 4px; }

.hero { text-align: center; padding: 34px 0 10px; }
.hero .bigname { font-size: 72px; font-weight: 600; color: var(--accent); line-height: 1; margin: 0; }
.hero .sub { font-family: var(--mono); font-size: 12px; letter-spacing: 0.32em; color: var(--ink2); margin-top: 10px; text-transform: uppercase; }
.hero .subtag { font-style: italic; color: var(--muted); margin-top: 6px; font-size: 16px; }
.paperbadge {
  display: inline-block; margin-top: 12px; font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em;
  color: var(--ink2); border: 1px dashed var(--line); padding: 4px 12px; border-radius: 999px;
}

/* ---------- trades ---------- */
.recent { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; }
.recent .klabel { margin-top: 4px; }
.tradeline { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 13px; flex-wrap: wrap; }
.side { font-weight: 700; padding: 1px 7px; border-radius: 5px; font-size: 11px; }
.side.BUY { color: var(--up); background: color-mix(in srgb, var(--up) 14%, transparent); }
.side.SELL { color: var(--down); background: color-mix(in srgb, var(--down) 14%, transparent); }
.tsym { color: var(--accent); font-weight: 600; }
.tmc { color: var(--muted); }
.tago { color: var(--muted); font-size: 11px; white-space: nowrap; }
.tradelog { max-height: 420px; overflow-y: auto; display: flex; flex-direction: column; gap: 7px; margin-top: 4px; padding-right: 4px; }
.tradelog .row { display: flex; align-items: center; gap: 10px; font-family: var(--mono); font-size: 12.5px; }
.tradelog .row .tago { width: 64px; flex-shrink: 0; }
.pnltag { font-size: 11px; font-weight: 700; }
.pnltag.up { color: var(--up); } .pnltag.down { color: var(--down); }

/* ---------- portfolio ---------- */
.portrow { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.portval { font-size: 44px; font-weight: 600; font-family: var(--serif); }
.portchg { font-family: var(--mono); font-size: 14px; font-weight: 700; }
.portchg.up { color: var(--up); } .portchg.down { color: var(--down); }
.portsol { font-family: var(--mono); font-size: 13px; color: var(--ink2); }

.holdings { display: flex; flex-direction: column; margin-top: 6px; }
.holding { display: grid; grid-template-columns: 1fr auto auto auto; gap: 14px; align-items: center; padding: 9px 4px; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 13px; }
.holding:first-child { border-top: 0; }
.holding .sym { color: var(--ink); font-weight: 600; font-family: var(--serif); font-size: 16px; }
.holding .sym a { color: inherit; }
.holding .amt { color: var(--muted); font-size: 12px; }
.holding .usd { font-weight: 600; }
.holding .sharepct { color: var(--muted); width: 52px; text-align: right; }
.holding .hpnl { font-size: 11px; font-weight: 700; }
.showall { width: 100%; margin-top: 8px; background: var(--card2); border: 1px solid var(--line); color: var(--ink2); border-radius: 8px; padding: 8px; cursor: pointer; font-family: var(--mono); font-size: 12px; }

/* ---------- chart ---------- */
.chartwrap { position: relative; }
#chart { width: 100%; height: 240px; display: block; }
.charttip {
  position: absolute; pointer-events: none; display: none;
  background: var(--card2); border: 1px solid var(--line); border-radius: 8px;
  font-family: var(--mono); font-size: 11.5px; padding: 6px 10px; color: var(--ink);
  white-space: nowrap; z-index: 5;
}

/* ---------- stats ---------- */
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.stat { background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.stat .v { font-size: 24px; font-weight: 600; margin-top: 4px; }
.stat .v small { font-size: 13px; color: var(--muted); }
.stat .v.up { color: var(--up); } .stat .v.down { color: var(--down); }

/* ---------- thoughts ---------- */
.thoughts { display: flex; flex-direction: column; gap: 14px; max-height: 640px; overflow-y: auto; padding-right: 6px; }
.thought { border-left: 2px solid var(--line); padding: 2px 0 2px 14px; }
.thought.kind-BUY { border-color: var(--up); }
.thought.kind-SELL { border-color: var(--down); }
.thought.kind-CHAPTER { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); border-radius: 0 8px 8px 0; padding: 8px 10px 8px 14px; }
.thought.kind-REC { border-color: #9d7fd4; }
.thought .meta { display: flex; gap: 10px; align-items: center; font-family: var(--mono); font-size: 10.5px; color: var(--muted); letter-spacing: 0.08em; }
.thought .meta .kind { color: var(--accent); font-weight: 700; }
.thought .meta .sym { color: var(--ink2); }
.thought .txt { margin-top: 4px; font-size: 15px; }
.thought .outcome { margin-top: 6px; font-family: var(--mono); font-size: 11.5px; color: var(--ink2); background: var(--card2); border: 1px solid var(--line); display: inline-block; padding: 3px 10px; border-radius: 999px; }

.halted { background: color-mix(in srgb, var(--down) 12%, transparent); border: 1px solid var(--down); color: var(--ink); border-radius: 10px; padding: 10px 14px; font-family: var(--mono); font-size: 12.5px; margin-bottom: 14px; display: none; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: none; place-items: center; z-index: 100; padding: 20px; }
.modal.open { display: grid; }
.modal .box { background: var(--card); border: 1px solid var(--line); border-radius: 16px; max-width: 640px; width: 100%; padding: 26px 28px; max-height: 86vh; overflow-y: auto; }
.modal h2 { margin: 0 0 6px; color: var(--accent); }
.modal .steps { margin: 14px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 12px; }
.modal .steps li { display: flex; gap: 12px; }
.modal .steps .n { font-family: var(--mono); color: var(--accent); font-weight: 700; }
input, textarea, select {
  background: var(--bg2); border: 1px solid var(--line); color: var(--ink);
  border-radius: 8px; padding: 10px 12px; font-family: var(--mono); font-size: 13px; width: 100%;
}
input:focus, textarea:focus { outline: 1px solid var(--accent); }
.formrow { margin-top: 12px; }
.formrow label { display: block; font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: 0.1em; margin-bottom: 5px; text-transform: uppercase; }
.formmsg { margin-top: 10px; font-family: var(--mono); font-size: 12.5px; min-height: 18px; }
.formmsg.ok { color: var(--up); } .formmsg.err { color: var(--down); }

footer { border-top: 1px solid var(--line); padding: 18px 26px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-family: var(--mono); font-size: 12px; color: var(--muted); }

/* ---------- fables page ---------- */
.fablegrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; margin-top: 20px; }
.fable { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; display: flex; flex-direction: column; gap: 8px; }
.fable h4 { margin: 0; font-size: 21px; color: var(--accent); font-weight: 600; }
.fable .fmeta { font-family: var(--mono); font-size: 11px; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; }
.fable .story { font-size: 14.5px; color: var(--ink2); }
.fable .moral { font-style: italic; border-top: 1px dashed var(--line); padding-top: 10px; margin-top: 4px; }
.fable .moral b { color: var(--accent); font-style: normal; font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; }
.fable .pnl { font-family: var(--mono); font-weight: 700; font-size: 15px; }

/* ---------- docs page ---------- */
.docs { max-width: 860px; margin: 0 auto; }
.docs h1 { font-size: 42px; color: var(--accent); margin: 30px 0 6px; }
.docs h2 { font-size: 28px; margin: 40px 0 10px; }
.docs .eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: 0.2em; color: var(--muted); margin-top: 40px; text-transform: uppercase; }
.docs p { color: var(--ink2); font-size: 16px; }
.docs table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 13px; margin: 14px 0; }
.docs td { padding: 9px 10px; border-top: 1px solid var(--line); }
.docs td:last-child { text-align: right; color: var(--accent); font-weight: 600; }
.docs .cardrow { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin: 18px 0; }
.docs code { background: var(--card2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: 13px; font-family: var(--mono); color: var(--accent); }
.docs pre { background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; font-size: 12.5px; overflow-x: auto; font-family: var(--mono); color: var(--ink2); }

/* ---------- race ---------- */
:root { --tortoise: #199e70; --hare: #c98500; --fox: #9085e9; --aesop: #e0a458; }

/* ---------- fullscreen campfire background ---------- */
#bgStage { position: fixed; inset: 0; z-index: 0; background: radial-gradient(ellipse at 50% 68%, #241408 0%, #120c06 45%, #070503 100%); }
#bgStage canvas { display: block; width: 100%; height: 100%; }
#bgStage .vignette { position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 62%, transparent 30%, rgba(7,5,3,0.55) 78%, rgba(7,5,3,0.9) 100%); }
body.has-bg { background: transparent; }
body.has-bg header, body.has-bg .wrap, body.has-bg footer, .firehero { position: relative; z-index: 1; }
body.has-bg header { background: color-mix(in srgb, var(--bg) 55%, transparent); border-bottom-color: color-mix(in srgb, var(--line) 60%, transparent); }
body.has-bg .card { background: color-mix(in srgb, var(--card) 84%, transparent); backdrop-filter: blur(10px); }
body.has-bg footer { background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(10px); }
body.has-bg.no3d #bgStage canvas, body.has-bg.no3d #bgStage .vignette { display: none; }

.firehero { height: 88vh; min-height: 480px; display: flex; flex-direction: column; justify-content: space-between; align-items: center; padding: 6vh 20px 18px; }
.firehero .stagetoggle { position: absolute; top: 14px; right: 18px; }
.welcome { text-align: center; max-width: 780px; }
.welcomeline { font-size: clamp(30px, 4.6vw, 52px); font-weight: 600; color: #f4e9d3; text-shadow: 0 2px 24px rgba(0,0,0,0.85), 0 0 60px rgba(224,164,88,0.25); line-height: 1.15; }
.welcome .sub { margin-top: 16px; text-shadow: 0 1px 8px rgba(0,0,0,0.9); }
.welcome .subtag { text-shadow: 0 1px 8px rgba(0,0,0,0.9); color: #cdbfa4; }
.herofoot { text-align: center; max-width: 860px; }
.stagehint { font-family: var(--mono); font-size: 10px; color: color-mix(in srgb, var(--muted) 80%, transparent); letter-spacing: 0.1em; margin-top: 12px; }
.caption { font-style: italic; font-size: clamp(15px, 1.8vw, 19px); color: #f0e6d2; text-shadow: 0 2px 10px rgba(0,0,0,0.95); min-height: 26px; }
.firehero.collapsed { height: 30vh; min-height: 240px; }
@media (max-width: 700px) { .firehero { height: 62vh; } }

.racercard { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: var(--card2); position: relative; overflow: hidden; }
.racercard .rank { position: absolute; top: 10px; right: 14px; font-family: var(--mono); font-size: 22px; color: var(--muted); font-weight: 700; }
.racercard.lead { border-color: color-mix(in srgb, var(--rc) 60%, var(--line)); }
.racercard .rname { display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 600; }
.racercard .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--rc); flex-shrink: 0; }
.racercard .motto { font-style: italic; color: var(--muted); font-size: 13px; margin-top: 2px; }
.racercard .rval { font-size: 27px; font-weight: 600; margin-top: 8px; }
.racercard .rchg { font-family: var(--mono); font-size: 13px; font-weight: 700; }
.racercard .rmeta { font-family: var(--mono); font-size: 11px; color: var(--ink2); margin-top: 6px; display: flex; gap: 12px; flex-wrap: wrap; }
.racercard .rhp { height: 6px; background: var(--bg2); border-radius: 999px; margin-top: 10px; overflow: hidden; }
.racercard .rhp > div { height: 100%; background: var(--rc); border-radius: 999px; transition: width 0.8s ease; }
.racercard .benched { font-family: var(--mono); font-size: 10px; color: var(--down); letter-spacing: 0.1em; margin-top: 6px; }
.racegrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }

.agenttag { font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; padding: 1px 8px; border-radius: 999px; color: #16120e; }
.agenttag.tortoise { background: var(--tortoise); } .agenttag.hare { background: var(--hare); }
.agenttag.fox { background: var(--fox); } .agenttag.aesop { background: var(--aesop); }
.thought.agent-tortoise { border-color: var(--tortoise); }
.thought.agent-hare { border-color: var(--hare); }
.thought.agent-fox { border-color: var(--fox); }
.thought.agent-aesop { border-color: var(--aesop); background: color-mix(in srgb, var(--aesop) 5%, transparent); border-radius: 0 8px 8px 0; }
.feedfilter { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.feedfilter button { background: var(--card2); border: 1px solid var(--line); color: var(--ink2); font-family: var(--mono); font-size: 11px; padding: 4px 12px; border-radius: 999px; cursor: pointer; }
.feedfilter button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }

.votebox { display: flex; flex-direction: column; gap: 8px; }
.voterow { display: grid; grid-template-columns: 92px 1fr auto auto; gap: 10px; align-items: center; font-family: var(--mono); font-size: 12px; }
.voterow .vbar { height: 12px; background: var(--bg2); border-radius: 999px; overflow: hidden; }
.voterow .vbar > div { height: 100%; border-radius: 999px; transition: width 0.6s ease; }
.voterow button { background: var(--card2); border: 1px solid var(--line); color: var(--ink2); font-family: var(--mono); font-size: 10px; padding: 3px 10px; border-radius: 999px; cursor: pointer; }
.voterow button.mine { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }

.holdgroup { margin-top: 10px; }
.holdgroup .ghead { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; color: var(--ink2); margin: 12px 0 4px; text-transform: uppercase; }
.holdgroup .ghead .dot { width: 9px; height: 9px; border-radius: 50%; }

.treasury { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.treasury .tval { font-size: 30px; font-weight: 600; color: var(--accent); }

.prooflist { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.proofrow { border: 1px solid var(--line); background: var(--card2); border-radius: 10px; padding: 10px 14px; font-family: var(--mono); font-size: 12px; display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.proofrow .k { color: var(--muted); }
code.api { background: var(--card2); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; font-family: var(--mono); font-size: 12px; color: var(--accent); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }
.thought.kind-PRIZE { border-left-width: 3px; background: color-mix(in srgb, #e8c34a 7%, transparent); border-radius: 0 8px 8px 0; padding: 8px 10px 8px 14px; }
.thought.kind-PRIZE .kind { color: #e8c34a; }
.thought.kind-LEVEL { border-left-width: 3px; background: color-mix(in srgb, var(--accent) 8%, transparent); border-radius: 0 8px 8px 0; padding: 8px 10px 8px 14px; }
.thought.kind-LEVEL .kind { color: var(--accent); }
