:root {
  --bg: #1b1410; --panel: #2a1f18; --panel2: #33261d; --ink: #f6ead7; --muted: #bfa98d; --line: #4a3727;
  --gold: #e0a526; --gold-ink: #2a1a05; --red: #e0614a; --green: #6cc483; --blue: #6aa7e6; --violet: #a98be0;
  --parch: #f3e3c3;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 Inter, system-ui, sans-serif; }
h1, h2, .day { font-family: Cinzel, Georgia, serif; }
button, input, select { font: inherit; }
button { border: 0; border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 600; color: var(--ink); background: var(--panel2); transition: transform .08s, filter .15s; }
button:hover { filter: brightness(1.15); } button:active { transform: translateY(1px); }
button.primary { background: linear-gradient(180deg, #f0bd45, #c98b14); color: var(--gold-ink); }
button.ghost { background: transparent; border: 1px solid var(--line); }
button:disabled { opacity: .5; cursor: progress; }

.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; padding: 12px 20px; background: linear-gradient(180deg, #120d0a, #1b1410); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand h1 { margin: 0; font-size: 24px; letter-spacing: .04em; color: var(--gold); }
.brand .tag { color: var(--muted); font-size: 12px; }
.clock { text-align: center; }
.day { font-size: 22px; } .day b { color: var(--gold); }
.events { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; min-height: 22px; }
.events span { background: #4a1f15; color: #ffcfbf; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.controls { display: flex; gap: 8px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.chain { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: #173525; color: var(--green); text-decoration: none; font-weight: 700; }
.chain.mock { background: #3a2f22; color: var(--muted); }

.stage { position: relative; min-height: 420px; background: url(/art/bazaar.webp) center 30% / cover no-repeat; display: flex; align-items: flex-end; padding: 124px 16px 16px; } /* the top strip is kept for the rumor pill and the Palace card */
.stage::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(27,20,16,0) 35%, rgba(27,20,16,.85) 85%, var(--bg)); pointer-events: none; }
.rumor { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 2; background: rgba(20,12,8,.82); border: 1px solid var(--gold); color: var(--parch); padding: 8px 18px; border-radius: 999px; font-style: italic; box-shadow: 0 6px 30px rgba(0,0,0,.4); animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(224,165,38,.15); } }
.stalls { position: relative; z-index: 1; width: 100%; display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }

.stall { position: relative; background: rgba(42,31,24,.92); border: 1px solid var(--line); border-top: 4px solid var(--c); border-radius: 14px; padding: 10px; display: grid; grid-template-columns: 64px 1fr; gap: 10px; backdrop-filter: blur(4px); transition: transform .3s, filter .5s; }
.stall.me { box-shadow: 0 0 0 2px var(--gold), 0 10px 30px rgba(224,165,38,.25); }
.stall.bankrupt { filter: grayscale(.9) brightness(.7); }
.stall.bankrupt .portrait::after { content: ''; position: absolute; inset: -6px; background: url(/art/ruin.webp) center/contain no-repeat; opacity: .9; }
.portrait { position: relative; width: 64px; height: 64px; border-radius: 12px; background: var(--parch) center/cover; border: 2px solid var(--c); }
.stall h3 { margin: 0; font-size: 14px; font-family: Cinzel, serif; }
.stall .nw { font-size: 20px; font-weight: 700; } .stall .nw small { font-size: 11px; color: var(--muted); font-weight: 500; }
.pnl.up { color: var(--green); } .pnl.down { color: var(--red); }
.stance { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: rgba(255,255,255,.08); text-transform: uppercase; letter-spacing: .04em; }
.stance.corner { background: #5a1d14; color: #ffb4a3; } .stance.hoard { background: #4a3a0e; color: #ffd978; } .stance.undercut { background: #123a4a; color: #9bd9ff; }
.stance.premium { background: #33215a; color: #d4c0ff; } .stance.liquidate { background: #444; color: #ddd; }
.brain { display: inline-block; margin-left: 4px; font-size: 10.5px; font-weight: 600; color: #e9d3ff; background: rgba(169,139,224,.18); border: 1px solid rgba(169,139,224,.35); padding: 0 7px; border-radius: 999px; white-space: nowrap; }
.dots { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #d4c0ff; animation: blink 1s infinite; vertical-align: middle; }
@keyframes blink { 50% { opacity: .2; } }
.bark { grid-column: 1 / -1; position: relative; background: var(--parch); color: #3a2614; border-radius: 10px; padding: 6px 10px; font-size: 12.5px; font-style: italic; min-height: 34px; }
.bark::before { content: ''; position: absolute; top: -6px; left: 24px; border: 6px solid transparent; border-top: 0; border-bottom-color: var(--parch); }
.bark.thinking { opacity: .6; } .bark.thinking::after { content: ' …thinking'; font-style: normal; color: #8a6a44; }
.charter { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 6px; font-size: 11px; color: var(--muted); }
.charter a { color: var(--muted); text-decoration: none; border-bottom: 1px dotted; } .charter a:hover { color: var(--gold); }
.takeover { grid-column: 1 / -1; }
.owned { grid-column: 1 / -1; font-size: 12px; color: var(--gold); text-align: center; }
.flash { animation: flash .9s; } @keyframes flash { 30% { transform: translateY(-4px) scale(1.02); } }

.grid { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 16px; padding: 16px 20px 32px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; min-width: 0; }
.panel h2 { margin: 0 0 10px; font-size: 16px; color: var(--parch); } .panel h2 small { font-family: Inter; font-size: 11px; color: var(--muted); font-weight: 500; }
.goods { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.good { background: var(--panel2); border-radius: 12px; padding: 10px; display: grid; grid-template-columns: 44px 1fr; gap: 8px; align-items: center; }
.good img { width: 44px; height: 44px; border-radius: 10px; }
.good .p { font-size: 18px; font-weight: 700; } .good .d { font-size: 12px; margin-left: 6px; }
.good canvas { grid-column: 1 / -1; width: 100%; height: 46px; }
.share { grid-column: 1 / -1; display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: #221911; }
.share i { display: block; height: 100%; }
.good .meta { grid-column: 1 / -1; display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }

.order { display: flex; gap: 8px; }
.order input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: #1d1510; color: var(--ink); }
.reply { margin-top: 8px; padding: 8px 12px; border-left: 3px solid var(--gold); background: #1d1510; border-radius: 6px; font-size: 13px; }
.reply b { color: var(--gold); }
.stances { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 12px 0 8px; }
.stances button { font-size: 12px; padding: 7px 6px; text-transform: capitalize; }
.stances button.on { background: var(--gold); color: var(--gold-ink); }
.row { display: flex; gap: 12px; align-items: center; font-size: 12px; color: var(--muted); }
.row .grow { flex: 1; display: flex; gap: 8px; align-items: center; } .row input[type=range] { flex: 1; accent-color: var(--gold); }
.row select { background: #1d1510; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 10px; min-height: 18px; }
#race { width: 100%; display: block; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--muted); } .legend i { display: inline-block; width: 10px; height: 3px; margin-right: 4px; vertical-align: middle; }

.feeds { display: grid; grid-template-rows: 1fr 1fr; gap: 12px; }
.feed ol { list-style: none; margin: 0; padding: 0; max-height: 210px; overflow: auto; font-size: 12.5px; }
.feed li { padding: 5px 0; border-bottom: 1px solid #3a2b1f; color: var(--muted); }
.feed li b { color: var(--ink); font-weight: 600; }
.feed li.kind-event { color: #ffcfbf; } .feed li.kind-rumor { color: var(--parch); font-style: italic; } .feed li.kind-bankrupt, .feed li.kind-error { color: var(--red); } .feed li.kind-takeover { color: var(--gold); }
.feed li a { color: var(--blue); text-decoration: none; font-family: ui-monospace, monospace; font-size: 11px; }
.feed li .k { display: inline-block; min-width: 54px; font-size: 10px; text-transform: uppercase; font-weight: 700; color: var(--green); }

dialog { background: var(--panel); color: var(--ink); border: 1px solid var(--gold); border-radius: 18px; max-width: 520px; padding: 22px 26px; }
dialog::backdrop { background: rgba(10,6,4,.7); backdrop-filter: blur(3px); }
dialog h2 { color: var(--gold); margin-top: 0; } dialog li { margin: 6px 0; } .muted { color: var(--muted); font-size: 12.5px; }

@media (max-width: 1100px) { .stalls { grid-template-columns: repeat(3, 1fr); } .grid { grid-template-columns: 1fr 1fr; } .feeds { grid-column: 1 / -1; } }
@media (max-width: 700px) {
  .topbar { grid-template-columns: 1fr; text-align: center; } .controls { justify-content: center; }
  .stalls { grid-template-columns: 1fr 1fr; } .grid { grid-template-columns: 1fr; padding: 12px 16px; } .goods { grid-template-columns: 1fr; }
  .stage { min-height: 300px; padding: 0 16px 12px; }
}

/* ---------- v2: season, palace, deals, end screen ---------- */
.day small { font-size: 14px; color: var(--muted); }
.season { width: 160px; height: 4px; margin: 4px auto 6px; background: #3a2b1f; border-radius: 4px; overflow: hidden; }
.season i { display: block; height: 100%; background: linear-gradient(90deg, #c98b14, #f0bd45); transition: width .4s; }
.table-banner { padding: 7px 20px; font-size: 12.5px; background: #2b2118; color: var(--muted); border-bottom: 1px solid var(--line); }
.table-banner.live { background: #13261b; color: #b8e6c6; }
.table-banner a, .foot a { color: inherit; }
.palace { position: absolute; top: 16px; right: 20px; z-index: 3; display: flex; gap: 10px; align-items: center; max-width: 380px; background: rgba(20,12,8,.88); border: 1px solid var(--gold); border-radius: 14px; padding: 10px 12px; box-shadow: 0 8px 30px rgba(0,0,0,.45); font-size: 13px; }
.palace img { width: 46px; height: 46px; border-radius: 10px; }
.palace .reward { color: var(--gold); font-weight: 800; font-size: 16px; margin-right: 8px; }
.palace .claimed { font-size: 12px; color: var(--parch); }
.palace .bar { height: 5px; background: #3a2b1f; border-radius: 4px; margin-top: 4px; overflow: hidden; width: 160px; }
.palace .bar i { display: block; height: 100%; background: var(--green); }
.stall.clickable { cursor: pointer; }
.stall.clickable:hover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(0,0,0,.35), 0 0 0 1px var(--c); }
.stall.vassal { box-shadow: inset 0 0 0 1px var(--gold); }
.stall.vassal .portrait { border-style: dashed; }
.crowns { color: var(--gold); font-size: 12px; letter-spacing: 1px; }
.portrait.big { width: 72px; height: 72px; border-color: var(--c, var(--gold)); }
#deal { width: min(460px, calc(100vw - 32px)); }
.deal-head { display: flex; gap: 12px; align-items: center; }
.deal-head h2 { margin: 0; }
.deal-head form { margin-left: auto; }
.close { padding: 4px 10px; }
.tabs { display: flex; gap: 6px; margin: 14px 0 10px; }
.tabs button { flex: 1; font-size: 12.5px; }
.tabs button.on { background: var(--gold); color: var(--gold-ink); }
.deal-form { display: grid; gap: 8px; }
.deal-form label { display: grid; grid-template-columns: 110px 1fr; align-items: center; font-size: 13px; color: var(--muted); }
.deal-form input, .deal-form select { background: #1d1510; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.deal-reply { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--parch); color: #3a2614; font-style: italic; }
.deal-reply.no { border-left: 4px solid var(--red); } .deal-reply.yes { border-left: 4px solid var(--green); }
.deal-reply button { margin-left: 8px; font-style: normal; color: #3a2614; border-color: #b08b5a; padding: 4px 10px; }
#end { width: min(560px, calc(100vw - 32px)); text-align: center; }
#end h2 { font-size: 26px; }
.standings { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13px; }
.standings th, .standings td { padding: 6px; border-bottom: 1px solid var(--line); text-align: left; }
.standings tr.me td { color: var(--gold); font-weight: 700; }
.end-actions { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.foot { padding: 0 20px 24px; font-size: 12px; color: var(--muted); }
.feed li.kind-palace { color: var(--gold); } .feed li.kind-deal { color: #d4c0ff; } .feed li.kind-loan { color: var(--muted); }
@media (max-width: 700px) { .palace { position: static; margin: 10px 0; max-width: none; } .stage { padding-top: 56px;  flex-direction: column; align-items: stretch; justify-content: flex-end; } }

/* who's who + moods */
#rivals { width: min(680px, calc(100vw - 32px)); max-height: 86vh; }
.rival { display: grid; grid-template-columns: 76px 1fr; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.rival h3 { margin: 0 0 4px; font-family: Cinzel, serif; color: var(--c); }
.rival p { margin: 4px 0; font-size: 13px; }
.lessons { font-size: 12.5px; margin-top: 6px; } .lessons ul { margin: 4px 0 0; padding-left: 18px; color: var(--parch); }
.mood { font-family: Inter, sans-serif; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 1px 7px; border-radius: 999px; background: rgba(255,255,255,.08); color: var(--muted); vertical-align: middle; }
.mood.warm { background: #173525; color: var(--green); } .mood.cold { background: #3a1b14; color: #ffb4a3; } .mood.wary { background: #3a300f; color: #ffd978; }
.feed li .d { display: inline-block; min-width: 48px; font-size: 11px; color: var(--muted); font-weight: 600; }
.feed li .ic { display: inline-block; width: 20px; }
.feed li a { margin-left: 4px; }

/* decisions + coach */
.decision { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -62%); z-index: 4; width: min(520px, calc(100% - 32px)); background: rgba(20,12,8,.94); border: 1px solid var(--gold); border-radius: 16px; padding: 14px 18px; box-shadow: 0 16px 50px rgba(0,0,0,.6); animation: pop .25s ease-out; }
.decision.kind-bankrupt { border-color: var(--red); } .decision.kind-palace { border-color: var(--gold); } .decision.kind-rumor { border-color: #c9a46a; }
.decision .dt { font-family: Cinzel, serif; font-size: 17px; color: var(--parch); }
.decision .dt .muted { font-family: Inter, sans-serif; font-size: 11px; }
.decision p { margin: 8px 0 12px; color: var(--ink); }
.decision .da { display: flex; gap: 8px; flex-wrap: wrap; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -55%) scale(.96); } }
.coach { padding: 8px 20px; font-size: 13px; background: #2d2414; color: #ffe2a6; border-bottom: 1px solid var(--line); }
.coach button { margin-left: 8px; padding: 3px 10px; font-size: 12px; color: #ffe2a6; }
.ap { font-size: 11.5px; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.good .p small { font-size: 11px; color: var(--muted); font-weight: 500; }

.upgrades { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); margin: -2px 0 10px; }
.upgrades button { font-size: 12px; padding: 4px 10px; }
.perk { font-size: 11px; margin-left: 3px; }

.chips { grid-column: 1 / -1; display: flex; gap: 4px; flex-wrap: wrap; }
.chip { font-size: 10.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,.07); color: var(--muted); white-space: nowrap; animation: chip-in .3s ease-out; }
/* tones are prefixed: a bare .good would pick up the market board's .good card (display: grid) */
.chip.tone-bad { background: #3a1b14; color: #ffb4a3; } .chip.tone-good { background: #173525; color: #a9e5bb; } .chip.tone-warn { background: #3a300f; color: #ffd978; }
@keyframes chip-in { from { opacity: 0; transform: scale(.9); } }

/* ---------- v4: the Magnate, the Guild, rats ---------- */
.magnate { padding: 10px 20px; background: linear-gradient(90deg, #3a130d, #2a1a10); border-bottom: 1px solid #a3402c; font-size: 13px; display: grid; gap: 6px; }
.magnate.coming, .magnate.gone { display: block; background: #2b2118; border-bottom-color: var(--line); color: var(--parch); }
.magnate.monopoly { background: linear-gradient(90deg, #3a2a0d, #2a1a10); border-bottom-color: var(--gold); }
.magnate b { color: var(--gold); }
.magnate .mh { font-size: 14px; }
.magnate .patience { display: flex; gap: 10px; align-items: center; }
.magnate .patience .bar { flex: 0 1 320px; height: 10px; background: #1a0f0b; border: 1px solid #a3402c; border-radius: 6px; overflow: hidden; }
.magnate .patience .bar i { display: block; height: 100%; background: linear-gradient(90deg, #e0614a, #f0bd45); transition: width .5s; }
.magnate .mrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.magnate .ally { color: var(--green); } .magnate .no { color: var(--muted); text-decoration: line-through; }
.magnate .hits { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.hit { color: var(--red); font-style: normal; font-weight: 700; }
.guild { display: inline-flex; gap: 6px; align-items: center; color: var(--parch); }
button.danger { border-color: var(--red); color: #ffcfbf; }
.feed li.kind-magnate { color: #ffb38f; } .feed li.kind-guild { color: var(--blue); }
.decision.kind-magnate { border-color: #a3402c; }

.magnate .bar.share i { background: linear-gradient(90deg, #a3402c, #e0614a); }
.heal { color: var(--green); font-style: normal; font-weight: 700; }
.owned.held { color: #ffb38f; }
.goodwill { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--muted); }
.goodwill i { flex: 1; height: 4px; background: #3a2b1f; border-radius: 4px; overflow: hidden; }
.goodwill b { display: block; height: 100%; background: #e07a9a; }

/* ---------- v5: story scenes ---------- */
.scene { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; padding: 0 16px 9vh;
  background: linear-gradient(180deg, #000 0, #000 9vh, rgba(10,6,4,.55) 9vh, rgba(10,6,4,.55) calc(100% - 9vh), #000 calc(100% - 9vh)), url(/art/bazaar.webp) center / cover; animation: fadein .35s ease-out; }
.scene[hidden] { display: none; }
.scene-card { width: min(760px, 100%); margin-bottom: 4vh; background: rgba(20,12,8,.92); border: 1px solid var(--gold); border-radius: 18px; padding: 18px 22px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.scene-who { display: flex; align-items: center; gap: 14px; }
.scene-who b { font-family: Cinzel, serif; font-size: 20px; color: var(--gold); }
#sceneLine { font-size: 18px; line-height: 1.5; min-height: 3em; margin: 12px 0 14px; color: var(--parch); }
.scene-ctrl { display: flex; gap: 10px; align-items: center; } .scene-ctrl .grow { flex: 1; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 600px) { #sceneLine { font-size: 16px; } .scene { padding-bottom: 6vh; } }

/* the hidden attribute always wins over a display set by a class (e.g. .palace { display: flex }) */
[hidden] { display: none !important; }

/* ---------- v6: motion ---------- */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.fx-float { position: fixed; transform: translate(-50%, 0); font-weight: 800; font-size: 20px; text-shadow: 0 2px 8px rgba(0,0,0,.8); animation: fx-rise 1.6s ease-out forwards; white-space: nowrap; }
.fx-float.up { color: #8be0a2; } .fx-float.down { color: #ff8a73; }
.fx-float.big { font-size: 28px; }
@keyframes fx-rise { 0% { opacity: 0; transform: translate(-50%, 8px) scale(.8); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.08); } 100% { opacity: 0; transform: translate(-50%, -64px) scale(1); } }
.fx-tick { animation: fx-tick .5s ease-out; display: inline-block; } @keyframes fx-tick { 40% { transform: scale(1.35); color: #fff3c4; } }
.fx-hit { animation: fx-hit .45s ease-out; } @keyframes fx-hit { 30% { box-shadow: inset 0 0 0 2px #e0614a, 0 0 30px rgba(224,97,74,.45); } }
.fx-shake { animation: fx-shake .6s ease-in-out; } @keyframes fx-shake { 15%, 55% { transform: translateX(-6px); } 35%, 75% { transform: translateX(6px); } }
.fx-glow { animation: fx-glow 1.2s ease-out; } @keyframes fx-glow { 30% { box-shadow: inset 0 0 0 2px var(--gold), 0 0 40px rgba(240,189,69,.4); } }
.fx-crown { animation: fx-crown 1.2s ease-out; } @keyframes fx-crown { 25% { transform: translateY(-6px) scale(1.03); box-shadow: 0 0 0 2px var(--gold), 0 0 40px rgba(240,189,69,.55); } }
.fx-fall { animation: fx-fall 1s ease-out; } @keyframes fx-fall { 20% { transform: rotate(-1.5deg) translateY(4px); filter: saturate(.3); } 60% { transform: rotate(1deg); } }
/* the bazaar breathes: a slow drift of the backdrop */
.stage { animation: stage-drift 60s ease-in-out infinite alternate; }
@keyframes stage-drift { from { background-position: 48% 28%; } to { background-position: 54% 34%; } }
.goodwill b, .palace .bar i, .season i { transition: width .6s ease; }
@media (prefers-reduced-motion: reduce) { .stage { animation: none; } .fx-float { display: none; } }
.scene-card { animation: card-up .45s cubic-bezier(.2,.8,.2,1); } @keyframes card-up { from { opacity: 0; transform: translateY(24px); } }
.fx-speak { animation: fx-speak .4s cubic-bezier(.2,.8,.2,1); } @keyframes fx-speak { from { transform: scale(.82) rotate(-3deg); opacity: .4; } }
