:root {
  --bg: #1f1510;
  --bg2: #2b1e16;
  --panel: #33241a;
  --panel2: #3d2b1f;
  --line: #5a4230;
  --text: #f6ecdc;
  --muted: #c9b59a;
  --accent: #d9973a;
  --accent2: #f0b85a;
  --good: #5fbf7a;
  --bad: #e2675a;
  --paper: #f5ecd9;
  --paper2: #eadbbd;
  --ink: #2a1c12;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent2); }
button, input, select { font: inherit; }
.loading { text-align: center; padding: 40px; color: var(--muted); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; background: #170f0b; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-family: Georgia, "Times New Roman", serif; font-weight: 700; font-size: 20px; letter-spacing: .04em; color: var(--accent2); text-decoration: none; }
.topbar-right { display: flex; gap: 8px; align-items: center; }

main { max-width: 1400px; margin: 0 auto; padding: 16px; }
@media (max-width: 979px) { main { padding: 10px 8px; } }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-family: Georgia, serif; font-size: 19px; color: var(--accent2); }
.card h3 { margin: 14px 0 8px; font-size: 15px; color: var(--accent2); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  padding: 9px 14px; border-radius: 8px; cursor: pointer; min-height: 40px; touch-action: manipulation;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1b120c; font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: var(--accent2); }
.btn.danger { border-color: #8a3a32; color: #ffb3a9; }
.btn.small { padding: 4px 9px; min-height: 32px; font-size: 13px; }
.btn.block { width: 100%; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stack > * + * { margin-top: 10px; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], select {
  width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: #1a120d; color: var(--text); min-height: 40px;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent2); outline-offset: 1px; }

.home { display: grid; gap: 16px; grid-template-columns: 1fr; max-width: 980px; margin: 0 auto; }
@media (min-width: 820px) { .home { grid-template-columns: 1.3fr 1fr; } }
.hero { text-align: center; padding: 12px 0 4px; }
.hero h1 { font-family: Georgia, serif; font-size: clamp(30px, 7vw, 46px); margin: 0; color: var(--accent2); letter-spacing: .03em; }
.hero p { margin: 6px 0 0; color: var(--muted); }

.color-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.color-opt { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 7px 4px; border: 1px solid var(--line); border-radius: 8px; background: #1a120d; cursor: pointer; font-size: 12px; text-align: center; color: var(--text); }
.color-opt[aria-pressed=true] { border-color: var(--accent2); box-shadow: 0 0 0 2px var(--accent) inset; }
.color-opt:disabled { opacity: .35; cursor: not-allowed; }
.color-opt .swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid rgba(255,255,255,.8); box-shadow: 0 1px 3px rgba(0,0,0,.45); }

.piece-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.piece-opt { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; border: 1px solid var(--line); border-radius: 8px; background: #1a120d; cursor: pointer; font-size: 12px; text-align: center; color: var(--text); }
.piece-opt[aria-pressed=true] { border-color: var(--accent2); box-shadow: 0 0 0 2px var(--accent) inset; }
.piece-opt:disabled { opacity: .35; cursor: not-allowed; }
.piece-opt .piece { width: 34px; height: 34px; }
svg.piece, svg.piece-sm, svg.token { border-radius: 50%; display: inline-block; flex: none; }
svg.piece-sm { width: 22px; height: 22px; vertical-align: middle; }

.rule { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #1a120d; margin-bottom: 8px; }
.rule input { margin-top: 4px; width: 20px; height: 20px; flex: none; }
.rule strong { display: block; }

.recent a { display: block; padding: 8px 0; border-bottom: 1px solid var(--line); text-decoration: none; }

/* ---------- game layout ---------- */
.game { display: grid; gap: 16px; grid-template-columns: 1fr; }
/* Phones: what you can do now sits above the board; the rest follows below it. */
.turn-top > .card { margin: 0; }
.side > .card:last-child { margin-bottom: 0; }
@media (min-width: 980px) {
  .game { grid-template-columns: minmax(0, 1fr) 380px; grid-template-rows: auto 1fr; align-items: start; }
  .board-shell { position: sticky; top: 64px; grid-column: 1; grid-row: 1 / span 2; min-width: 0; }
  .turn-top { grid-column: 2; grid-row: 1; }
  .side { grid-column: 2; grid-row: 2; }
}
.board-shell { width: 100%; min-width: 0; }
@media (max-width: 979px) { .board-shell { width: calc(100% + 16px); margin: 0 -8px; } }
.board-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 0 0 8px; padding: 0 4px; }
@media (max-width: 979px) { .board-controls { padding: 0 8px; } }
.board-scroll { width: 100%; }
.board-scroll.zoomed { overflow: auto; -webkit-overflow-scrolling: touch; max-height: 78vh; border-radius: 6px; }
.board-wrap { width: 100%; max-width: min(100%, calc(100vh - 120px)); margin: 0 auto; container-type: inline-size; }
@media (max-width: 979px) { .board-wrap { max-width: 100%; } }

.board {
  aspect-ratio: 1 / 1; width: 100%; display: grid; background: #6b4a2f; border: 2px solid #6b4a2f; border-radius: 6px;
  grid-template-columns: 1.65fr repeat(9, 1fr) 1.65fr; grid-template-rows: 1.65fr repeat(9, 1fr) 1.65fr; gap: 1px;
  font-size: max(6.5px, 1.35cqw); color: var(--ink); user-select: none;
}
.space { background: var(--paper); position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; text-align: center; cursor: pointer; padding: 0; line-height: 1.08; }
.space:hover { filter: brightness(1.04); }
.space .band { flex: none; width: 100%; height: 22%; }
.space .nm { padding: 2px 2px 0; font-weight: 600; overflow-wrap: break-word; hyphens: auto; }
.space .nm.nowrap { white-space: nowrap; overflow-wrap: normal; hyphens: none; }
.space .pr { margin-top: auto; padding-bottom: 2px; font-size: .92em; opacity: .8; }
.space.s-left { flex-direction: row-reverse; }
.space.s-left .band, .space.s-right .band { width: 18%; height: 100%; }
.space.s-right { flex-direction: row; }
.space.s-left .txt, .space.s-right .txt { flex: 1; display: flex; flex-direction: column; justify-content: center; height: 100%; min-width: 0; padding: 0 2px; }
.space.s-left .nm, .space.s-right .nm { padding: 0 1px; }
.space.s-left .pr, .space.s-right .pr { margin-top: 1px; padding-bottom: 0; }
.space.s-top { flex-direction: column-reverse; }
.space.s-top .pr { margin-top: 0; margin-bottom: auto; padding-top: 2px; }
.space .txt { display: contents; }
.space.corner { background: var(--paper2); justify-content: center; font-family: Georgia, serif; font-weight: 700; font-size: 1.25em; padding: 4px; }
.space.corner .sub { font-family: system-ui, sans-serif; font-weight: 400; font-size: .72em; opacity: .8; }
.space.card-sp { background: #efe2c4; }
.space.card-sp .icon { font-size: 1.6em; margin-top: 8%; }
.space.tax .icon { font-size: 1.3em; margin-top: 6%; }
.space.owned { padding: max(3px, .6cqw); box-shadow: inset 0 0 0 max(3px, .6cqw) var(--owner-color); }
.space.mortgaged::after { content: "MORTGAGED"; position: absolute; inset: 35% -10% auto; background: rgba(120, 30, 20, .82); color: #fff; font-size: .7em; font-weight: 700; letter-spacing: .05em; transform: rotate(-18deg); padding: 1px 0; }
.bldg { position: absolute; display: flex; gap: 1px; top: 3px; left: 50%; transform: translateX(-50%); }
.space.s-top .bldg { top: auto; bottom: 3px; }
.space.s-left .bldg { left: auto; right: 3px; top: 50%; transform: translateY(-50%); flex-direction: column; }
.space.s-right .bldg { left: 3px; top: 50%; transform: translateY(-50%); flex-direction: column; }
.bldg i { display: block; width: .8em; height: .8em; background: #2e8b3e; border: 1px solid #fff; border-radius: 2px; }
.bldg i.hotel { width: 1.5em; background: #b2271f; }
.tokens { position: absolute; inset: 22% 4% 10%; display: flex; flex-wrap: wrap; gap: 1px; align-content: center; justify-content: center; pointer-events: none; }
.space.corner .tokens { inset: auto 4% 4%; }
svg.token { width: max(12px, 2.9cqw); height: max(12px, 2.9cqw); box-shadow: 0 1px 2px rgba(0,0,0,.6); border: 1.5px solid #fff; }
svg.token.me { outline: 2px solid #111; }
svg.token.jailed { border-style: dashed; border-color: #111; }
.space.here { box-shadow: inset 0 0 0 2px var(--accent); }
.space.owned.here { box-shadow: inset 0 0 0 max(3px, .6cqw) var(--owner-color), inset 0 0 0 max(5px, .95cqw) rgba(255, 255, 255, .55); }

.center { grid-column: 2 / 11; grid-row: 2 / 11; background: radial-gradient(ellipse at center, #f7efdf 0%, #e8d6b4 100%); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2.2%; padding: 4%; text-align: center; overflow: hidden; }
.center .logo { font-family: Georgia, serif; font-weight: 700; font-size: 4.6em; color: #6b3d16; letter-spacing: .06em; line-height: 1; transform: rotate(-4deg); }
.center .tag { font-size: 1.1em; color: #6d5440; letter-spacing: .08em; text-transform: uppercase; }
.center .turnline { font-size: 1.5em; font-weight: 700; }
.center .lastcard { max-width: 80%; background: #fffaf0; border: 1px solid #c9a97a; border-radius: 6px; padding: 2% 3%; font-size: 1.15em; box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.center .lastcard b { display: block; color: #8a4b1a; font-size: .85em; text-transform: uppercase; letter-spacing: .06em; }
.center .pot { font-weight: 700; color: #7a3d0f; font-size: 1.25em; }
.dice { display: flex; gap: 3%; justify-content: center; width: 30%; }
.die { width: 40%; aspect-ratio: 1; background: #fff; border-radius: 16%; border: 1px solid #b89a72; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 9%; box-shadow: 0 2px 4px rgba(0,0,0,.25); }
.die span { border-radius: 50%; background: transparent; margin: 14%; }
.die span.on { background: #4a2a12; }

/* ---------- side panel ---------- */
.side .card, .turn-top .card { padding: 14px; }
.turnbox { border: 3px solid var(--turn-color, var(--accent)); box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.turnbox h2 { margin-bottom: 6px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.turnbox .actions { display: grid; gap: 8px; margin-top: 10px; }
.turn-results { list-style: none; margin: 6px 0 10px; padding: 8px 10px; border-radius: 8px; background: #231811; border: 1px solid var(--line); font-size: 13.5px; }
.turn-results li { padding: 3px 0; border-bottom: 1px dashed rgba(90, 66, 48, .55); }
.turn-results li:last-child { border-bottom: 0; }
.turn-results li.rent-hit { color: #b7f5c6; font-weight: 700; background: rgba(95, 191, 122, .14); border-left: 3px solid var(--good); padding: 4px 6px; margin: 3px -4px; border-radius: 4px; border-bottom: 0; }
.poke-banner { background: rgba(217, 151, 58, .18); border: 1px solid var(--accent); border-left: 4px solid var(--accent2); border-radius: 8px; padding: 8px 10px; margin: 6px 0 8px; color: var(--text); }
.poke-status { background: #231811; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin: 6px 0 8px; color: var(--muted); }
.cash-wrap { display: inline-flex; align-items: baseline; gap: 4px; white-space: nowrap; }
.cash-big { font-size: 26px; font-weight: 800; color: var(--accent2); }
.players .pl { display: flex; align-items: center; gap: 8px; padding: 7px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.players .pl:last-child { border-bottom: 0; }
.players .pl.current { background: rgba(217, 151, 58, .12); border-radius: 6px; }
.players .pl.out { opacity: .45; text-decoration: line-through; }
.players .pl .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .pl .cash { font-weight: 700; }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); margin-left: 4px; }
.badge.warn { color: #ffcf8a; border-color: #8a6a32; }
.propgroup { border-left: 5px solid; padding-left: 8px; margin: 10px 0; }
.propgroup .gname { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.prop { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.prop:last-child { border-bottom: 0; }
.prop .pn { flex: 1 1 140px; min-width: 0; }
.prop .ps { font-size: 12px; color: var(--muted); }
.log { max-height: 320px; overflow: auto; font-size: 13px; }
.log div { padding: 4px 0; border-bottom: 1px solid rgba(90, 66, 48, .5); }
.log div:first-child { color: var(--accent2); }
.chat-list { max-height: 220px; overflow: auto; font-size: 13.5px; margin-bottom: 10px; padding-right: 4px; }
.chat-msg { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; border-bottom: 1px solid rgba(90, 66, 48, .45); }
.chat-msg:last-child { border-bottom: 0; }
.chat-msg .dot { margin-top: 5px; }
.chat-body { flex: 1; min-width: 0; overflow-wrap: break-word; }
.chat-time { font-size: 11px; color: var(--muted); margin-left: 4px; }
.chat-form { display: flex; gap: 6px; }
.chat-form input { flex: 1; min-width: 0; min-height: 36px; padding: 6px 10px; }
.btn.notify-on { border-color: var(--good); }
.notify-box { padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: #1a120d; }
.notify-tip { padding: 10px; border-radius: 8px; border: 1px solid var(--accent); background: #261a11; font-size: 13.5px; }
.trade { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; background: #1a120d; }
.trade .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; font-size: 13px; }
.trade ul { margin: 4px 0; padding-left: 16px; }
.auction-box { border: 1px solid var(--accent); border-radius: 8px; padding: 10px; background: #2a1c12; }
.bidrow { display: flex; gap: 6px; margin-top: 8px; }
.bidrow input { flex: 1; min-width: 0; }
.share { display: flex; gap: 6px; }
.share input { flex: 1; min-width: 0; font-size: 13px; }
.code-big { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 30px; letter-spacing: .2em; color: var(--accent2); font-weight: 800; }
.winner { text-align: center; font-size: 22px; font-family: Georgia, serif; }

/* ---------- modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: flex; align-items: flex-end; justify-content: center; padding: 0; }
@media (min-width: 640px) { .modal-back { align-items: center; padding: 20px; } }
.modal { background: var(--panel); border: 1px solid var(--line); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 14px 14px 0 0; padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { .modal { border-radius: 14px; } }
.modal h2 { margin: 0 0 10px; font-family: Georgia, serif; color: var(--accent2); }
.modal .close { float: right; }
.deed-band { height: 34px; border-radius: 6px 6px 0 0; margin: -4px 0 10px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
table.rent { width: 100%; border-collapse: collapse; font-size: 14px; }
table.rent td { padding: 4px 2px; border-bottom: 1px solid var(--line); }
table.rent td:last-child { text-align: right; font-weight: 600; }
table.rent tr.now td { color: var(--accent2); }
.checklist label { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.checklist input { width: 18px; height: 18px; flex: none; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(140%); background: #111; color: #fff; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); z-index: 80; transition: transform .2s; max-width: 92vw; text-align: center; }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { border-color: var(--bad); }
.conn { font-size: 12px; color: var(--muted); }
.conn.off { color: var(--bad); }
