:root {
  --regime: #2f9e44;
  --bg: #f4efe4; --paper: #fffdf7; --ink: #1f1d1a; --muted: #6b665c; --line: #d9d1c1; --cell: #fbf8f0;
  --shadow: 0 2px 10px rgba(0,0,0,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #17161a; --paper: #222127; --ink: #ece9e2; --muted: #a29d93; --line: #3a3842; --cell: #2a2930; color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #17161a; --paper: #222127; --ink: #ece9e2; --muted: #a29d93; --line: #3a3842; --cell: #2a2930; color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100vh; transition: background .6s; background: linear-gradient(180deg, color-mix(in srgb, var(--regime) 14%, var(--bg)), var(--bg) 40%); }
button { font: inherit; border: 1px solid var(--line); background: var(--paper); color: var(--ink); padding: .5em 1em; border-radius: 8px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--regime); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--regime); border-color: var(--regime); color: #fff; font-weight: 600; }
button.big { font-size: 1.1em; padding: .6em 1.4em; }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: .3em; }
input, select { font: inherit; padding: .4em .6em; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); }
em { font-style: normal; font-size: .75em; background: var(--line); border-radius: 4px; padding: 0 .35em; color: var(--muted); }
em.warn { background: #ffe066; color: #5c4400; }
.row { display: flex; gap: .5em; align-items: center; flex-wrap: wrap; margin: .5em 0; }
h1, h2, h3, h4 { margin: .3em 0; line-height: 1.15; }
.tok { display: inline-grid; place-items: center; width: 1.6em; height: 1.6em; border-radius: 50%; font-size: .9em; box-shadow: 0 1px 3px rgba(0,0,0,.35); border: 2px solid #fff; flex: none; }
.chip { display: inline-block; width: .8em; height: .8em; border-radius: 2px; margin-right: 2px; }

/* Home / lobby */
.home { max-width: 820px; margin: 0 auto; padding: 32px 16px; }
.home h1 { font-size: 2.6em; letter-spacing: -.02em; }
.tag { color: var(--muted); font-size: 1.1em; }
.regime-strip { display: flex; flex-wrap: wrap; gap: 6px; margin: 1em 0; }
.regime-strip span { background: var(--c); color: #fff; padding: .25em .7em; border-radius: 99px; font-size: .9em; cursor: help; }
.field { display: flex; flex-direction: column; gap: 4px; max-width: 320px; margin: 1em 0; font-weight: 600; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
.card p { color: var(--muted); margin-top: 0; }
#code { width: 6em; }
.rules { margin-top: 24px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 12px 18px; }
.rules summary { cursor: pointer; font-weight: 600; }
.code { font-family: ui-monospace, monospace; background: var(--regime); color: #fff; padding: 0 .3em; border-radius: 8px; letter-spacing: .1em; }
.plist { list-style: none; padding: 0; }
.plist li { display: flex; align-items: center; gap: .6em; padding: .5em; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 6px; }
.settings { display: flex; gap: 1em; flex-wrap: wrap; margin: 1em 0; }
.settings input { width: 5em; }

/* Game layout */
.game { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; padding: 12px; max-width: 1400px; margin: 0 auto; align-items: start; }
@media (max-width: 900px) { .game { grid-template-columns: 1fr; padding: 8px; } }
.board {
  --s: min(calc(100vw - 340px), calc(100vh - 24px), 960px);
  width: var(--s); height: var(--s); display: grid; gap: 2px; margin: 0 auto;
  grid-template-columns: 1.45fr repeat(7, 1fr) 1.45fr; grid-template-rows: 1.45fr repeat(7, 1fr) 1.45fr;
  background: var(--line); border: 3px solid color-mix(in srgb, var(--regime) 60%, var(--ink)); border-radius: 10px; overflow: hidden;
  font-size: calc(var(--s) / 75); transition: border-color .6s;
}
@media (max-width: 900px) { .board { --s: min(calc(100vw - 16px), 720px); font-size: calc(var(--s) / 62); } .sp .ic { font-size: 1.3em; } }
.sp { background: var(--cell); position: relative; padding: 2px 3px; display: flex; flex-direction: column; align-items: center; text-align: center; cursor: pointer; overflow: hidden; min-width: 0; }
.sp:hover { outline: 2px solid var(--regime); outline-offset: -2px; z-index: 1; }
.sp.mine { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--ink) 25%, transparent); }
.sp .band { position: absolute; left: 0; right: 0; top: 0; height: 1.5em; }
.sp.left .band { top: 0; bottom: 0; left: auto; right: 0; width: 1.5em; height: auto; }
.sp.right .band { top: 0; bottom: 0; left: 0; right: auto; width: 1.5em; height: auto; }
.sp.top .band { top: auto; bottom: 0; }
.sp.bottom:has(.band) { padding-top: 1.7em; }
.sp.top:has(.band) { padding-bottom: 1.7em; }
.sp.left:has(.band) { padding-right: 1.8em; }
.sp.right:has(.band) { padding-left: 1.8em; }
.sp .nm { font-weight: 600; font-size: 1em; line-height: 1.05; word-break: break-word; hyphens: auto; }
.sp .ic { display: block; font-size: 1.6em; line-height: 1.2; }
.sp.corner .nm { font-size: 1.2em; margin: auto 0 0; }
.sp.corner .ic { font-size: 2.6em; }
.sp .pr { font-size: .95em; color: var(--muted); margin-top: auto; }
.sp .own { display: inline-grid; place-items: center; width: 1.8em; height: 1.8em; border-radius: 50%; border: 1px solid #fff; }
.sp .houses { font-size: .8em; letter-spacing: -.3em; }
.sp .tower { font-size: 1.4em; }
.sp .toks { position: absolute; inset: auto 0 18% 0; display: flex; flex-wrap: wrap; justify-content: center; pointer-events: none; }
.sp .toks .tok { width: 2.2em; height: 2.2em; font-size: 1.1em; margin: -2px; }
.sp .toks .tok.now { animation: bob 1s infinite alternate; }
@keyframes bob { to { transform: translateY(-4px); } }
.t-gotojail, .t-jail { background: color-mix(in srgb, #e03131 8%, var(--cell)); }
.t-ballot { background: color-mix(in srgb, var(--regime) 18%, var(--cell)); }

.center { grid-row: 2 / 9; grid-column: 2 / 9; background: var(--paper); display: flex; flex-direction: column; align-items: center; padding: 2.2em; gap: .8em; font-size: 1.25em; min-height: 0; }
.regime-banner { display: flex; gap: .8em; align-items: center; background: var(--regime); color: #fff; padding: .7em 1em; border-radius: 12px; width: 100%; transition: background .6s; }
.r-icon { font-size: 2.6em; line-height: 1; }
.r-name { font-weight: 800; font-size: 1.4em; letter-spacing: -.01em; }
.r-blurb { font-size: .85em; opacity: .92; }
.meta { display: flex; gap: .4em 1.2em; flex-wrap: wrap; justify-content: center; color: var(--muted); font-size: .9em; }
.meta b { color: var(--ink); }
.dice { font-size: 3.4em; line-height: 1; min-height: 1em; letter-spacing: .05em; }
.actions { display: flex; gap: .6em; flex-wrap: wrap; justify-content: center; align-items: center; min-height: 2.6em; }
.actions button { font-size: 1em; }
.offer { width: 100%; text-align: center; font-weight: 600; }
.hint, .waiting { color: var(--muted); font-size: .85em; }
.log { flex: 1; min-height: 0; width: 100%; overflow-y: auto; font-size: .85em; border-top: 1px solid var(--line); padding-top: .4em; color: var(--muted); }
.log div:last-child { color: var(--ink); font-weight: 600; }
@media (max-width: 600px) { .center { padding: 1em; font-size: 1.35em; } .r-blurb { display: none; } }

/* Side panel */
.side { display: flex; flex-direction: column; gap: 12px; }
.side h3 { font-size: .8em; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.pl { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; margin-bottom: 6px; }
.pl.turn { border-color: var(--regime); box-shadow: 0 0 0 2px color-mix(in srgb, var(--regime) 35%, transparent); }
.pl.out { opacity: .45; }
.pl-top { display: flex; align-items: center; gap: .4em; flex-wrap: wrap; }
.pl-top .cash { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.pl-sub { color: var(--muted); font-size: .82em; margin: 2px 0; }
.trade { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; font-size: .9em; margin-bottom: 6px; }
.side-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Modals */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal { background: var(--paper); border-radius: 16px; padding: 20px 22px; max-width: 560px; width: 100%; max-height: 90vh; overflow: auto; position: relative; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal .x { position: absolute; top: 8px; right: 8px; border: none; font-size: 1.4em; padding: 0 .4em; background: none; }
.band.big { color: #fff; padding: .3em .6em; border-radius: 6px; font-weight: 700; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
.rents { width: 100%; border-collapse: collapse; margin: .6em 0; }
.rents td { padding: .2em 0; border-bottom: 1px dashed var(--line); }
.rents td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.note { color: var(--muted); font-size: .9em; }
.cands { display: grid; gap: 8px; margin: 12px 0; }
.cand { display: block; border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px 10px 38px; position: relative; cursor: pointer; }
.cand input { position: absolute; left: 12px; top: 14px; accent-color: var(--c); }
.cand:has(input:checked) { border-color: var(--c); background: color-mix(in srgb, var(--c) 10%, var(--paper)); }
.cand-h { font-weight: 700; color: var(--c); }
.cand-b { font-size: .88em; color: var(--muted); }
.don { display: flex; align-items: center; gap: .5em; flex-wrap: wrap; margin: 8px 0 12px; }
.don input { flex: 1; min-width: 120px; }
.status { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 12px; font-size: .9em; color: var(--muted); }
.vs { display: inline-flex; align-items: center; gap: 4px; }
.vs.done { color: var(--ink); }
.trade-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 12px 0; }
.trade-grid input[type=number] { width: 7em; }
.pick { display: flex; align-items: center; gap: 4px; font-size: .92em; padding: 2px 0; }
.final li { display: flex; align-items: center; gap: .5em; padding: .2em 0; }
.final li span:last-child { margin-left: auto; font-weight: 700; }
.hist { font-size: .9em; color: var(--muted); }

/* Regime change overlay */
.banner-overlay { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 82%, transparent); animation: fadein .35s ease-out, fadeout .6s ease-in 3.6s forwards; cursor: pointer; padding: 16px; }
.banner-in { text-align: center; color: #fff; animation: slam .55s cubic-bezier(.2,1.6,.4,1); max-width: 560px; }
.b-cause { text-transform: uppercase; letter-spacing: .3em; font-weight: 700; opacity: .9; }
.b-icon { font-size: 7em; line-height: 1.1; }
.b-name { font-size: 3.2em; font-weight: 900; letter-spacing: -.02em; line-height: 1; }
.b-blurb { margin-top: .8em; font-size: 1.1em; }
@keyframes fadein { from { opacity: 0; } }
@keyframes fadeout { to { opacity: 0; visibility: hidden; } }
@keyframes slam { from { transform: scale(2.4) rotate(-6deg); opacity: 0; } }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 150%); background: var(--ink); color: var(--bg); padding: .7em 1.2em; border-radius: 10px; transition: transform .25s; z-index: 40; max-width: calc(100vw - 32px); box-shadow: var(--shadow); }
#toast.show { transform: translate(-50%, 0); }
#toast.bad { background: #c92a2a; color: #fff; }
body.offline::before { content: 'Reconnecting to server…'; position: fixed; top: 0; left: 0; right: 0; background: #f59f00; color: #000; text-align: center; padding: 4px; z-index: 50; font-size: .9em; }
body[data-regime=communism] .board { background: #8f1d1d; }
body[data-regime=anarchy] .sp:nth-child(3n) { transform: rotate(-.6deg); }
