:root {
  --bg: #0a101d;
  --panel: #111a2b;
  --panel-2: #162136;
  --line: #22304a;
  --line-2: #2d3e5e;
  --text: #dfe7f3;
  --muted: #8b9ab3;
  --dim: #5d6d88;
  --gold: #e3b448;
  --gold-2: #f0cb73;
  --good: #3fbf7f;
  --bad: #ec5f56;
  --warn: #e7a03c;
  --info: #5aa9e6;
  --radius: 10px;
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef1f6; --panel: #ffffff; --panel-2: #f5f7fb; --line: #d9dfea; --line-2: #c6cfdf;
    --text: #18223a; --muted: #56647e; --dim: #8592a8; --gold: #a97a10; --gold-2: #8a6208;
    --good: #19865a; --bad: #c8392f; --warn: #b26a0e; --info: #2a74b8;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold); }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.gold { color: var(--gold); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.2; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* controls */
.btn { min-height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--gold); color: #1a1405; border-color: var(--gold); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--gold-2); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.on { background: var(--good); border-color: var(--good); color: #04180e; font-weight: 600; }
input[type=text], input[type=password], input[type=number], select, textarea {
  min-height: 36px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--bg); width: 100%;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
input[type=range] { width: 100%; accent-color: var(--gold); height: 28px; }
input:disabled, select:disabled { opacity: .55; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.stack { display: grid; gap: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { min-height: 34px; padding: 0 12px; background: transparent; border: 0; border-right: 1px solid var(--line-2); cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button.sel { background: var(--gold); color: #1a1405; font-weight: 600; }
.seg button:disabled { cursor: not-allowed; opacity: .6; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.panel.tight { padding: 10px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap; }
.tag.boom { color: var(--good); border-color: var(--good); }
.tag.normal { color: var(--info); border-color: var(--info); }
.tag.slowdown { color: var(--warn); border-color: var(--warn); }
.tag.crisis { color: var(--bad); border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.tag.bot { color: var(--info); border-color: var(--info); }
.tag.red { color: var(--bad); border-color: var(--bad); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
td.r, th.r { text-align: right; }
.scroll-x { overflow-x: auto; }

/* home */
.home { max-width: 1040px; margin: 0 auto; padding: 40px 20px 60px; }
.hero { display: grid; gap: 8px; margin-bottom: 28px; }
.hero h1 { font-size: clamp(30px, 6vw, 52px); letter-spacing: -.02em; }
.hero h1 span { color: var(--gold); }
.hero p { color: var(--muted); max-width: 680px; font-size: 16px; margin: 0; }
.feature-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin-top: 18px; }
.feature { padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.feature b { display: block; margin-bottom: 2px; }
.rooms td { white-space: nowrap; }
details.how summary { cursor: pointer; color: var(--gold); min-height: 34px; display: flex; align-items: center; }
details.how li { margin-bottom: 4px; }

/* layout: lobby + game */
.topbar { display: flex; align-items: center; gap: 14px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.brand img { width: 22px; height: 22px; }
.topbar .spacer { flex: 1; }
.kv { display: grid; line-height: 1.15; }
.kv small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.kv b { font-family: var(--mono); font-weight: 600; }
.timer { font-family: var(--mono); font-size: 20px; font-weight: 700; min-width: 64px; }
.timer.low { color: var(--bad); }
.wrap { max-width: 1500px; margin: 0 auto; padding: 16px; }
.lobby-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; }
.game-grid { display: grid; grid-template-columns: 180px minmax(0, 1fr) 360px; gap: 14px; padding: 14px; max-width: 1700px; margin: 0 auto; }
.side-nav { display: grid; gap: 4px; align-content: start; position: sticky; top: 72px; }
.side-nav button { text-align: left; min-height: 38px; border-radius: 8px; border: 1px solid transparent; background: transparent; padding: 0 10px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.side-nav button:hover { background: var(--panel); }
.side-nav button.sel { background: var(--panel); border-color: var(--gold); color: var(--gold); }
.side-nav .who { font-size: 11px; color: var(--muted); max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-nav .who.me { color: var(--good); }
.rightcol { display: grid; gap: 12px; align-content: start; }

/* bank cards in lobby */
.bank-card { border-left: 4px solid var(--c, var(--gold)); align-content: start; }
.member { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.member:last-child { border-bottom: 0; }
.divmap { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 6px; margin-top: 8px; }
.divmap label { font-size: 12px; color: var(--muted); display: grid; gap: 2px; }
.divmap select { min-height: 32px; padding: 2px 6px; font-size: 13px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.kpi { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.kpi small { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.kpi b { font-family: var(--mono); font-size: 20px; }
.kpi i { font-style: normal; font-size: 12px; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.bar > span { display: block; height: 100%; background: var(--gold); }

/* sliders */
.slider { display: grid; grid-template-columns: 120px 1fr 64px; gap: 10px; align-items: center; padding: 4px 0; }
.slider .val { font-family: var(--mono); text-align: right; }
.slider .lbl small { display: block; color: var(--muted); font-size: 11px; }
.locked { padding: 8px 12px; border-radius: 8px; background: var(--panel-2); border: 1px dashed var(--line-2); color: var(--muted); font-size: 13px; margin-bottom: 10px; }

/* dilemma */
.dilemma { border: 1px solid var(--gold); }
.dilemma .opt { display: grid; gap: 2px; width: 100%; text-align: left; padding: 10px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer; margin-top: 8px; }
.dilemma .opt:hover { border-color: var(--gold); }
.dilemma .opt.sel { border-color: var(--good); box-shadow: inset 3px 0 0 var(--good); }
.dilemma .opt small { color: var(--muted); }
.voters { font-size: 12px; color: var(--muted); }

/* feed + chat */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px -4px 10px; }
.tabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; padding: 6px 10px; min-height: 34px; cursor: pointer; color: var(--muted); }
.tabs button.sel { color: var(--text); border-color: var(--gold); }
.feed { max-height: 300px; overflow-y: auto; display: grid; gap: 6px; align-content: start; font-size: 13px; }
.feed .item { padding: 6px 8px; border-radius: 6px; background: var(--panel-2); border-left: 3px solid var(--line-2); }
.feed .item.good { border-color: var(--good); color: var(--text); }
.feed .item.bad { border-color: var(--bad); color: var(--text); }
.feed .q { font-family: var(--mono); font-size: 11px; color: var(--dim); margin-right: 6px; }
.chatlog { max-height: 260px; overflow-y: auto; display: grid; gap: 4px; font-size: 13px; align-content: start; }
.chatlog b { color: var(--gold); }
.chatlog .team b { color: var(--info); }
.advisor-log { max-height: 340px; overflow-y: auto; display: grid; gap: 8px; font-size: 13px; }
.advisor-log .q { color: var(--gold); }
.advisor-log .a { white-space: pre-wrap; background: var(--panel-2); padding: 8px; border-radius: 8px; }
.botnote { font-size: 12px; color: var(--muted); font-style: italic; margin-top: 2px; }

/* modal + toasts */
.modal-back { position: fixed; inset: 0; background: rgba(3, 6, 14, .72); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; max-width: 760px; width: 100%; max-height: 90vh; overflow-y: auto; padding: 20px; }
.modal header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 60; width: min(92vw, 460px); }
.toast { background: var(--panel-2); border: 1px solid var(--gold); padding: 10px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); animation: pop .2s ease-out; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.pnl-row { display: grid; grid-template-columns: 140px 1fr 70px; align-items: center; gap: 8px; font-size: 13px; padding: 2px 0; }
.pnl-bar { height: 10px; position: relative; background: var(--line); border-radius: 2px; }
.pnl-bar span { position: absolute; top: 0; bottom: 0; border-radius: 2px; }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart text { fill: var(--muted); font: 10px var(--mono); }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); }
.stars { color: var(--gold); letter-spacing: 2px; }
.end-hero { text-align: center; padding: 20px; }
.end-hero h1 { font-size: 34px; }
.report li { margin-bottom: 3px; }
.deal-table td, .deal-table th { padding: 5px 6px; font-size: 13px; }
.deal-table select { min-height: 30px; padding: 2px 4px; width: auto; }
.deal-table tr.flag td { background: color-mix(in srgb, var(--bad) 8%, transparent); }
.deal-table tr.on td { background: color-mix(in srgb, var(--gold) 9%, transparent); }
.mobile-only { display: none; }

@media (max-width: 1180px) {
  .game-grid { grid-template-columns: 160px minmax(0, 1fr); }
  .rightcol { grid-column: 1 / -1; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
}
@media (max-width: 860px) {
  .lobby-grid { grid-template-columns: 1fr; }
  .game-grid { grid-template-columns: 1fr; padding: 10px; }
  .side-nav { position: static; grid-auto-flow: column; overflow-x: auto; grid-auto-columns: max-content; }
  .side-nav .who { display: none; }
  .slider { grid-template-columns: 92px 1fr 52px; }
  .topbar { gap: 10px; padding: 8px 10px; }
  .hide-sm { display: none; }
  .pnl-row { grid-template-columns: 110px 1fr 60px; }
}
