:root {
  --bg: #000;
  --g: #50ef5a;
  --g2: #3cc447;
  --g3: #2a8a33;
  --g4: #174d1c;
  --g5: #0b260e;
  --glow: 0 0 6px rgba(80, 239, 90, .55), 0 0 18px rgba(80, 239, 90, .18);
  --pix: "Silkscreen", "VT323", monospace;
  --mono: "VT323", ui-monospace, monospace;
  --w: 1180px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 64px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--g);
  font-family: var(--mono);
  font-size: 21px;
  line-height: 1.3;
  text-shadow: var(--glow);
  overflow-x: hidden;
  animation: flicker 6s infinite steps(1);
}
::selection { background: var(--g); color: #000; text-shadow: none; }
a { color: inherit; }
img { image-rendering: pixelated; display: block; max-width: 100%; height: auto; }
b { font-weight: normal; color: var(--g); }
.muted { color: var(--g3); }
.hide-sm { }

/* ---------- CRT overlay ---------- */
.crt {
  pointer-events: none;
  position: fixed; inset: 0; z-index: 50;
  background:
    repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0, rgba(0,0,0,0) 2px, rgba(0,0,0,.28) 3px),
    radial-gradient(ellipse at center, rgba(0,0,0,0) 60%, rgba(0,0,0,.65) 100%);
}
.crt::after {
  content: ""; position: absolute; left: 0; right: 0; height: 120px; top: -120px;
  background: linear-gradient(to bottom, rgba(80,239,90,0), rgba(80,239,90,.05), rgba(80,239,90,0));
  animation: roll 7s linear infinite;
}
@keyframes roll { to { transform: translateY(calc(100vh + 240px)); } }
@keyframes flicker {
  0%, 100% { opacity: 1; } 41% { opacity: .97; } 42% { opacity: 1; } 77% { opacity: .985; } 78% { opacity: 1; }
}

/* ---------- boot ---------- */
#boot {
  position: fixed; inset: 0; z-index: 100; background: #000;
  display: flex; flex-direction: column; justify-content: flex-start;
  padding: 8vh 8vw; transition: opacity .6s, visibility .6s;
}
#boot.done { opacity: 0; visibility: hidden; }
#boot pre { margin: 0; font: inherit; font-size: 22px; white-space: pre-wrap; }
.boot-skip { color: var(--g3); animation: blink 1.2s steps(1) infinite; margin-top: 24px; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- nav ---------- */
.nav {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px max(16px, calc((100vw - var(--w)) / 2));
  background: rgba(0,0,0,.88); backdrop-filter: blur(4px);
  border-bottom: 1px dashed var(--g4);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--pix); font-size: 17px; letter-spacing: 1px; }
.sword { width: 11px; height: 22px; fill: var(--g); filter: drop-shadow(0 0 4px rgba(80,239,90,.7)); }
.brand:hover .sword { animation: swing .5s ease-in-out; }
@keyframes swing { 30% { transform: rotate(-18deg); } 70% { transform: rotate(12deg); } }
.nav nav { display: flex; gap: 18px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.nav nav a { text-decoration: none; color: var(--g2); white-space: nowrap; position: relative; }
.nav nav a:hover, .nav nav a.active { color: var(--g); }
.nav nav a.active::before { content: ">"; position: absolute; left: -11px; }

/* ---------- hero ---------- */
.hero { position: relative; max-width: var(--w); margin: 0 auto; padding: 28px 16px 12px; text-align: center; }
#embers { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
.hero > *:not(canvas) { position: relative; z-index: 1; }
.title { margin: 0 auto; max-width: 1020px; }
.title img { width: 100%; mix-blend-mode: screen; animation: glowpulse 4s ease-in-out infinite; }
.castle img, .portrait img { mix-blend-mode: screen; }
.title.glitch img { animation: glitch .28s steps(2) 1; }
@keyframes glowpulse {
  0%, 100% { filter: brightness(1) contrast(1.05); }
  50% { filter: brightness(1.35) contrast(1.1); }
}
@keyframes glitch {
  0% { transform: translate(3px, -1px); clip-path: inset(10% 0 55% 0); }
  50% { transform: translate(-4px, 1px); clip-path: inset(50% 0 12% 0); }
  100% { transform: none; clip-path: none; }
}
.subtitle { font-family: var(--pix); font-size: 17px; letter-spacing: 1px; margin: 6px auto 4px; min-height: 1.4em; max-width: 820px; }
.cursor { animation: blink 1s steps(1) infinite; }
.ca[hidden] { display: none; }
.ca { color: var(--g3); font-size: 18px; margin: 6px 0 18px; }
.ca span { color: var(--g2); word-break: break-all; }

.btn, .seg button {
  font: inherit; font-size: 17px; color: var(--g); background: transparent;
  border: 1px solid var(--g3); padding: 1px 10px; cursor: pointer; text-shadow: inherit;
}
.btn:hover, .seg button:hover { background: var(--g5); }
.btn.small { font-size: 15px; padding: 0 8px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button.on { background: var(--g); color: #000; text-shadow: none; border-color: var(--g); }

.castle { position: relative; margin-top: 4px; }
.castle img { width: 100%; }
#sky { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* ---------- now strip ---------- */
.now { border-top: 1px dashed var(--g4); border-bottom: 1px dashed var(--g4); background: rgba(11,38,14,.35); }
.ticker { overflow: hidden; white-space: nowrap; border-bottom: 1px dashed var(--g4); padding: 6px 0; mask-image: linear-gradient(to right, transparent, #000 6%, #000 94%, transparent); }
.ticker-track { display: inline-block; animation: marquee 45s linear infinite; }
.ticker-track span { margin-right: 38px; }
.ticker-track .dn { color: var(--g3); }
@keyframes marquee { to { transform: translateX(-50%); } }
.now-bar { max-width: var(--w); margin: 0 auto; padding: 6px 16px; display: flex; align-items: center; gap: 22px; flex-wrap: wrap; color: var(--g2); font-size: 19px; }
.tick-meter { flex: 1; min-width: 80px; height: 10px; border: 1px solid var(--g3); position: relative; }
#tick-fill { position: absolute; inset: 1px auto 1px 1px; background: repeating-linear-gradient(90deg, var(--g) 0 6px, transparent 6px 8px); width: 0; }
.live { display: inline-flex; align-items: center; gap: 6px; color: var(--g); font-family: var(--pix); font-size: 14px; }
.live i { width: 8px; height: 8px; background: var(--g); display: inline-block; animation: blink 1s steps(1) infinite; box-shadow: var(--glow); }

/* ---------- party ---------- */
.party-section { max-width: var(--w); margin: 0 auto; padding: 22px 16px 10px; }
.featuring { text-align: center; font-family: var(--pix); font-size: 20px; font-weight: 400; margin: 6px 0 22px; letter-spacing: 1px; }
.dots::after { content: "..."; animation: dots 1.6s steps(4) infinite; display: inline-block; overflow: hidden; vertical-align: bottom; width: 0; }
@keyframes dots { to { width: 1.9em; } }
.party { display: grid; grid-template-columns: 1fr minmax(240px, 300px) 1fr; gap: 28px; align-items: start; }
.col { display: grid; gap: 28px; }

.card { position: relative; opacity: 0; transform: translateY(14px); transition: opacity .6s, transform .6s; }
.card.in { opacity: 1; transform: none; }
.portrait { position: relative; overflow: hidden; border: 1px solid var(--g4); cursor: pointer; }
.portrait img { width: 100%; transition: filter .3s, transform .6s; }
.portrait:hover img { filter: brightness(1.15) drop-shadow(0 0 6px rgba(80,239,90,.5)); transform: scale(1.03); }
.portrait::after {
  content: ""; position: absolute; left: 0; right: 0; height: 30%; top: -30%;
  background: linear-gradient(to bottom, transparent, rgba(80,239,90,.18), transparent);
  animation: sweep 5s linear infinite; animation-delay: var(--d, 0s);
}
@keyframes sweep { to { top: 110%; } }
.portrait .rank {
  position: absolute; top: 8px; left: 8px; background: #000; border: 1px solid var(--g);
  font-family: var(--pix); font-size: 13px; padding: 1px 6px;
}
.portrait .flash {
  position: absolute; inset: 0; background: var(--g); opacity: 0; pointer-events: none; mix-blend-mode: screen;
}
.portrait .flash.go { animation: flash .7s ease-out; }
@keyframes flash { 0% { opacity: .45; } 100% { opacity: 0; } }
.portrait .bubble {
  position: absolute; right: 8px; bottom: 8px; max-width: 72%;
  background: #000; border: 1px solid var(--g); padding: 3px 8px; font-size: 17px; line-height: 1.15;
  opacity: 0; transform: translateY(6px); transition: opacity .3s, transform .3s; text-align: left;
}
.portrait .bubble.show { opacity: 1; transform: none; }
.card h3 { font-family: var(--pix); font-weight: 400; font-size: 17px; letter-spacing: 1.5px; text-align: center; margin: 8px 0 0; }
.card .cls { text-align: center; color: var(--g3); margin: 0 0 8px; font-size: 18px; }
.card .row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card .eq { font-size: 34px; line-height: 1; }
.card .pnl { font-size: 22px; }
.dn { color: var(--g3) !important; }
.card canvas.spark { width: 100%; height: 44px; display: block; margin: 6px 0 4px; }
.card .meter { font-size: 17px; color: var(--g2); white-space: nowrap; overflow: hidden; }
.card .thought { margin: 6px 0 0; font-size: 18px; color: var(--g2); min-height: 2.6em; }
.card .thought::before { content: "> "; color: var(--g); }
.card .holds { font-size: 17px; color: var(--g3); margin-top: 2px; min-height: 1.3em; }

.standings { border: 1px dashed var(--g3); padding: 14px 14px 10px; position: sticky; top: 72px; }
.standings h3 { font-family: var(--pix); font-weight: 400; font-size: 15px; text-align: center; margin: 0 0 12px; letter-spacing: 1px; }
.standings ol { list-style: none; margin: 0; padding: 0; position: relative; }
.standings li {
  display: grid; grid-template-columns: 26px 1fr auto; gap: 6px; align-items: baseline;
  padding: 6px 0; border-bottom: 1px dotted var(--g4); transition: transform .5s ease;
}
.standings li .n { font-family: var(--pix); font-size: 14px; }
.standings li .v { text-align: right; }
.standings li .v small { display: block; font-size: 16px; }
.standings li.lead .nm::after { content: " \2654"; }
.purse { margin-top: 12px; font-size: 18px; }
.purse div { display: flex; justify-content: space-between; color: var(--g2); }
.scroll-art { font: inherit; font-size: 14px; line-height: 1.15; color: var(--g3); margin: 14px 0 0; overflow: hidden; text-align: center; }

/* ---------- blocks ---------- */
.block { max-width: var(--w); margin: 0 auto; padding: 44px 16px 18px; border-top: 1px dashed var(--g4); }
.block h2 { font-family: var(--pix); font-weight: 400; font-size: 24px; margin: 0; letter-spacing: 1px; }
.block h2::before { content: "\2694  "; font-size: 18px; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.reveal { opacity: 0; transform: translateY(20px); transition: opacity .8s, transform .8s; }
.reveal.in { opacity: 1; transform: none; }
.note { color: var(--g3); font-size: 18px; }
.lead { color: var(--g2); max-width: 780px; }

.chart-wrap { position: relative; border: 1px solid var(--g4); background: rgba(11,38,14,.25); }
#race-chart { width: 100%; height: 360px; display: block; cursor: crosshair; }
.tip {
  position: absolute; pointer-events: none; background: #000; border: 1px solid var(--g);
  padding: 4px 8px; font-size: 17px; line-height: 1.2; display: none; white-space: nowrap; z-index: 2;
}

.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 19px; }
.tbl th { text-align: left; color: var(--g3); font-weight: 400; border-bottom: 1px solid var(--g3); padding: 4px 10px 4px 0; }
.tbl td { padding: 5px 10px 5px 0; border-bottom: 1px dotted var(--g4); white-space: nowrap; }
.tbl tr.up td.px { animation: upflash 1s; }
.tbl tr.down td.px { animation: dnflash 1s; }
@keyframes upflash { 0% { background: rgba(80,239,90,.35); } 100% { background: transparent; } }
@keyframes dnflash { 0% { background: rgba(23,77,28,.8); } 100% { background: transparent; } }
.tbl canvas { width: 120px; height: 22px; display: block; }
.tbl .empty td { color: var(--g3); }

.ledger-grid { display: grid; grid-template-columns: 260px 1fr; gap: 26px; }
.ledger-stats { border: 1px dashed var(--g3); padding: 12px; font-size: 19px; }
.ledger-stats img { border: 1px solid var(--g4); margin-bottom: 8px; }
.ledger-stats div { display: flex; justify-content: space-between; color: var(--g2); }
.ledger-stats div b { color: var(--g); }

.rules { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.rule { border: 1px solid var(--g4); padding: 14px 16px; transition: border-color .3s, background .3s; }
.rule:hover { border-color: var(--g); background: rgba(11,38,14,.4); }
.rule h3 { font-family: var(--pix); font-weight: 400; font-size: 16px; margin: 0 0 8px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.rule h3 span { color: var(--g3); font-family: var(--mono); font-size: 18px; }
.rule p { margin: 0 0 8px; color: var(--g2); }
.rule ul { margin: 0; padding-left: 0; list-style: none; }
.rule li::before { content: "+ "; color: var(--g3); }

.log { height: 440px; overflow-y: auto; border: 1px solid var(--g4); padding: 8px 12px; font-size: 19px; background: rgba(11,38,14,.2); scrollbar-color: var(--g3) transparent; }
.log .e { display: grid; grid-template-columns: 84px 80px 1fr; gap: 10px; padding: 3px 0; border-bottom: 1px dotted var(--g5); }
.log .e.new { animation: newrow 1.4s ease-out; }
@keyframes newrow { 0% { background: rgba(80,239,90,.25); } 100% { background: transparent; } }
.log .t { color: var(--g3); }
.log .who { font-family: var(--pix); font-size: 14px; padding-top: 3px; }
.log .act b { background: var(--g); color: #000; text-shadow: none; padding: 0 5px; margin-right: 6px; }
.log .act b.sell { background: transparent; color: var(--g); border: 1px solid var(--g); }
.log .act i { color: var(--g2); font-style: normal; display: block; }

.lore { max-width: 780px; color: var(--g2); }

.foot { text-align: center; padding: 36px 16px 50px; border-top: 1px dashed var(--g4); margin-top: 30px; }
.follow { font-size: 22px; margin: 6px 0 4px; }
.follow a { text-decoration: none; border-bottom: 1px dashed var(--g2); }
.follow a:hover { background: var(--g); color: #000; text-shadow: none; }
.quest { font-family: var(--pix); font-size: 20px; letter-spacing: 2px; animation: blink 1.6s steps(1) infinite; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .party { grid-template-columns: 1fr 1fr; }
  .standings { grid-column: 1 / -1; order: -1; position: static; }
  .col { display: contents; }
}
@media (max-width: 720px) {
  body { font-size: 19px; }
  .nav { flex-direction: column; align-items: flex-start; gap: 4px; padding: 8px 16px; }
  .nav nav { width: 100%; gap: 14px; }
  .party { grid-template-columns: 1fr; }
  .rules { grid-template-columns: 1fr; }
  .ledger-grid { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .subtitle { font-size: 14px; }
  #race-chart { height: 260px; }
  .log .e { grid-template-columns: 64px 1fr; }
  .log .act { grid-column: 1 / -1; }
  html { scroll-padding-top: 90px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .card, .reveal { opacity: 1; transform: none; }
}
