:root {
  --felt-dark: #1b4332;
  --felt: #2d6a4f;
  --felt-light: #40916c;
  --cream: #f8f4e9;
  --cream-dark: #ece4d0;
  --gold: #d4af37;
  --gold-dark: #b8912b;
  --ink: #1f2a24;
  --danger: #c0392b;
  --brown: #8b5a2b;
  --lightblue: #7ec8e3;
  --pink: #e18aaa;
  --orange: #e08c3e;
  --red: #d64545;
  --yellow: #e8c547;
  --green: #4c9a5b;
  --blue: #3a6fb0;
  --railroad: #333333;
  --utility: #6b6b6b;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Trebuchet MS", "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #0f2e22, #08160f 75%);
  color: var(--cream);
  min-height: 100vh;
  overflow-x: hidden;
}

.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }

/* ---------- Buttons & fields ---------- */
.btn {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 700;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
  font-family: inherit;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: linear-gradient(180deg, var(--gold), var(--gold-dark)); color: #2b1d00; box-shadow: 0 3px 0 #8a6c1e; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn-outline { background: transparent; color: var(--cream); border: 2px solid var(--cream-dark); }
.btn-outline:hover { background: rgba(255,255,255,.08); }
.btn-lg { padding: 14px 28px; font-size: 1.1rem; width: 100%; }
.btn-block { width: 100%; margin-top: 10px; }
.btn-mini { border: 1px solid var(--gold); background: transparent; color: var(--gold); border-radius: 6px; padding: 2px 10px; font-size: .8rem; cursor: pointer; margin-left: 8px; }
.btn-back { background: none; border: none; color: var(--cream-dark); font-size: .95rem; cursor: pointer; padding: 6px 0; }

.field { display: block; margin-bottom: 18px; }
.field span { display: block; margin-bottom: 6px; font-size: .9rem; color: var(--cream-dark); }
.field input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 2px solid var(--felt-light);
  background: rgba(255,255,255,.06); color: var(--cream); font-size: 1.1rem; font-family: inherit;
}
.field input:focus { outline: none; border-color: var(--gold); }

.segmented { display: flex; gap: 8px; }
.segmented button {
  flex: 1; padding: 10px; border-radius: 8px; border: 2px solid var(--felt-light);
  background: rgba(255,255,255,.04); color: var(--cream); cursor: pointer; font-weight: 700;
}
.segmented button.active { background: var(--gold); color: #2b1d00; border-color: var(--gold); }

.hint { font-size: .82rem; color: #b9c9bf; line-height: 1.5; }

/* ---------- Home ---------- */
.home-wrap {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px;
}
.logo { font-size: 2.4rem; margin: 0; letter-spacing: 2px; color: var(--gold); text-shadow: 0 2px 0 #6b4e00; }
.logo-sub { display: block; font-size: .8rem; letter-spacing: 6px; color: var(--cream-dark); margin-top: 4px; }
.tagline { color: var(--cream-dark); margin: 14px 0 34px; }
.home-actions { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 320px; }

/* ---------- Panel (create/join/lobby) ---------- */
.panel {
  max-width: 420px; margin: 0 auto; padding: 28px 20px 40px;
}
.panel h2 { color: var(--gold); margin: 14px 0 20px; }

.room-code-box {
  background: rgba(255,255,255,.06); border: 2px dashed var(--gold); border-radius: 12px;
  padding: 14px; text-align: center; font-size: 1rem; margin-bottom: 10px;
}
#lobby-roomcode { font-size: 1.6rem; font-weight: 800; letter-spacing: 6px; color: var(--gold); }

.lobby-players { display: flex; flex-direction: column; gap: 10px; margin: 18px 0; }
.lobby-player-card {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(255,255,255,.06); border-radius: 10px; padding: 12px 14px;
}
.lobby-player-card .tag { font-size: .75rem; padding: 2px 8px; border-radius: 12px; background: var(--felt-light); }
.lobby-player-card .tag.ai { background: #5a3d8a; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(20,20,20,.92); color: #fff; padding: 10px 18px; border-radius: 10px;
  z-index: 999; font-size: .95rem; box-shadow: 0 4px 14px rgba(0,0,0,.4); transition: opacity .25s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

/* ---------- Game layout ---------- */
.game-layout {
  display: flex; gap: 16px; padding: 12px; max-width: 1400px; margin: 0 auto; align-items: flex-start;
  flex-wrap: wrap; justify-content: center;
}
.board-wrap { flex: 0 0 auto; }
.board {
  display: grid; grid-template-columns: repeat(11, minmax(46px, 64px)); grid-template-rows: repeat(11, minmax(46px, 64px));
  background: var(--felt); border-radius: 14px; padding: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
  border: 4px solid var(--felt-dark);
}
.tile {
  position: relative; background: var(--cream); color: var(--ink); border-radius: 4px;
  border: 1px solid rgba(0,0,0,.15); font-size: .58rem; display: flex; flex-direction: column;
  align-items: center; justify-content: flex-end; overflow: hidden; padding: 3px 2px 4px;
  text-align: center; line-height: 1.15;
}
.tile .band { position: absolute; top: 0; left: 0; right: 0; height: 14px; }
.tile .tname { font-weight: 700; margin-top: 2px; word-break: break-all; }
.tile .tprice { color: #555; font-size: .55rem; }
.tile.corner { font-size: .62rem; justify-content: center; font-weight: 800; background: var(--cream-dark); }
.tile.special { justify-content: center; }
.tile .icon { font-size: 1.1rem; }

.tile .tokens { position: absolute; bottom: 2px; left: 2px; right: 2px; display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; }
.token-dot {
  width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; font-size: .5rem; color: #fff; font-weight: 800;
}

.tile.owned { box-shadow: inset 0 0 0 3px var(--owner-color, transparent); }
.tile .house-marks { position: absolute; top: 15px; left: 0; right: 0; display: flex; justify-content: center; gap: 1px; }
.house-mark { width: 6px; height: 6px; background: #2e7d32; border-radius: 1px; }
.hotel-mark { width: 10px; height: 7px; background: #b71c1c; border-radius: 1px; }

.board-center {
  grid-column: 2 / 11; grid-row: 2 / 11; background: var(--felt-dark); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 6px;
  border: 2px solid var(--felt-light);
}
.board-center .center-title { font-size: 1.8rem; color: var(--gold); font-weight: 800; letter-spacing: 3px; }
.board-center .center-sub { color: var(--cream-dark); font-size: .85rem; }

/* group color bands */
.band.brown{background:var(--brown)} .band.lightblue{background:var(--lightblue)}
.band.pink{background:var(--pink)} .band.orange{background:var(--orange)}
.band.red{background:var(--red)} .band.yellow{background:var(--yellow)}
.band.green{background:var(--green)} .band.blue{background:var(--blue)}

/* ---------- Side panel ---------- */
.side-panel { width: 340px; max-width: 92vw; display: flex; flex-direction: column; gap: 12px; }
.panel-block { background: rgba(255,255,255,.05); border-radius: 12px; padding: 14px; border: 1px solid rgba(255,255,255,.08); }
.panel-block h3 { margin: 0 0 10px; color: var(--gold); font-size: .95rem; letter-spacing: 1px; }

.players-list { display: flex; flex-direction: column; gap: 8px; }
.player-card { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,.04); }
.player-card.current { background: rgba(212,175,55,.18); box-shadow: 0 0 0 2px var(--gold) inset; }
.player-card.bankrupt { opacity: .4; text-decoration: line-through; }
.player-avatar { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; color: #fff; flex-shrink: 0; }
.player-meta { flex: 1; min-width: 0; }
.player-name { font-size: .9rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-cash { font-size: .82rem; color: #cfe8d8; }
.player-badges { display: flex; gap: 4px; }
.badge-jail { font-size: .65rem; background: var(--danger); padding: 1px 5px; border-radius: 6px; }

.turn-info { font-size: .95rem; margin-bottom: 10px; min-height: 22px; }
.dice-area { display: flex; gap: 10px; justify-content: center; margin-bottom: 12px; }
.dice {
  width: 48px; height: 48px; background: var(--cream); color: var(--ink); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; font-size: 1.4rem; font-weight: 800;
  box-shadow: 0 3px 0 #8f8a78;
}
.dice.rolling { animation: shake .4s ease; }
@keyframes shake { 0%,100%{transform:rotate(0)} 25%{transform:rotate(-12deg)} 75%{transform:rotate(12deg)} }

.action-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.action-buttons .btn { flex: 1 1 auto; min-width: 100px; }

.log-list { max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; font-size: .8rem; color: #d8e6dd; }
.log-list div { padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,.06); }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center;
  z-index: 500; padding: 16px;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--cream); color: var(--ink); border-radius: 16px; padding: 24px; max-width: 380px; width: 100%;
  box-shadow: 0 20px 50px rgba(0,0,0,.5);
}
.modal-card h3 { margin-top: 0; color: var(--felt-dark); }
.buy-details { font-size: .95rem; line-height: 1.7; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-actions .btn { flex: 0 0 auto; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .game-layout { flex-direction: column; align-items: center; }
  .side-panel { width: 100%; max-width: 640px; }
  .board { grid-template-columns: repeat(11, minmax(30px, 8.5vw)); grid-template-rows: repeat(11, minmax(30px, 8.5vw)); }
  .tile { font-size: .5rem; }
  .board-center .center-title { font-size: 1.1rem; }
}
