:root {
  --bg: #f4ecd8;
  --panel: #ffffff;
  --ink: #1c2b22;
  --dim: #6b7a70;
  --green: #0b3d24;
  --green-light: #14653d;
  --gold: #c9972a;
  --red: #c0392b;
  --border: #e2d6b8;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  overscroll-behavior-y: contain;
}
button, input { font-family: inherit; }
#app { min-height: 100%; display: flex; flex-direction: column; }
.hidden { display: none !important; }

.screen { display: none; flex: 1; flex-direction: column; min-height: 100vh; }
.screen.active { display: flex; }

/* ---- Buttons / inputs ---- */
.btn {
  border: none; border-radius: 12px; padding: 14px 18px;
  font-size: 16px; font-weight: 700; cursor: pointer;
  min-height: 48px; touch-action: manipulation;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--green); color: #fff; }
.btn-secondary { background: var(--gold); color: #2b2005; }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; color: var(--green); border: 2px solid var(--green); }
.btn-big { width: 100%; padding: 16px; font-size: 17px; }
.btn-tiny { padding: 8px 12px; font-size: 13px; min-height: 36px; background: rgba(255,255,255,0.15); color: #fff; border-radius: 8px; }
.input {
  width: 100%; padding: 13px 14px; border-radius: 10px; border: 2px solid var(--border);
  font-size: 16px; background: #fff; color: var(--ink); margin-bottom: 14px;
}
.input:focus { outline: none; border-color: var(--green-light); }
.code-input { text-transform: uppercase; letter-spacing: 4px; font-weight: 700; text-align: center; margin-bottom: 0; }
.error-text { color: var(--red); font-size: 14px; min-height: 18px; margin-top: 8px; }
.dim { color: var(--dim); font-size: 14px; }

/* ---- Landing ---- */
.landing-wrap {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  padding: 28px 24px calc(28px + var(--safe-b));
  max-width: 480px; margin: 0 auto; width: 100%;
}
.logo { font-size: 34px; line-height: 1.05; color: var(--green); margin: 0 0 8px; letter-spacing: 1px; }
.tag { color: var(--dim); margin-bottom: 28px; font-size: 15px; }
.divider { display: flex; align-items: center; gap: 10px; margin: 18px 0; color: var(--dim); font-size: 13px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.join-code-form { display: flex; gap: 10px; }
.join-code-form .code-input { flex: 1; }

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-t)) 14px 10px;
  background: var(--green); color: #fff; position: sticky; top: 0; z-index: 20;
}
.game-code { font-weight: 700; letter-spacing: 3px; font-size: 15px; }
.pot-indicator { margin-left: auto; font-size: 13px; background: rgba(255,255,255,0.15); padding: 6px 10px; border-radius: 8px; }

/* ---- Lobby ---- */
.lobby-wrap { padding: 20px; max-width: 480px; margin: 0 auto; width: 100%; }
.lobby-slots { display: flex; flex-direction: column; gap: 10px; margin: 16px 0 22px; }
.lobby-slot { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--panel); border-radius: 12px; border: 2px solid var(--border); }
.lobby-slot.empty { opacity: 0.5; border-style: dashed; }
.reclaim-btn { margin-left: auto; background: var(--bg); color: var(--green); border: 2px solid var(--border); }
.slot-avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; color: #fff; flex-shrink: 0; }
.slot-name { font-weight: 600; }
.field-label { display: block; font-size: 13px; font-weight: 700; color: var(--dim); margin-bottom: 6px; margin-top: 4px; }
.token-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.token-opt {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px;
  border-radius: 10px; border: 2px solid var(--border); background: #fff; cursor: pointer; font-size: 22px;
}
.token-opt.selected { border-color: var(--green); background: #e8f3ec; }
.token-opt.taken { opacity: 0.3; pointer-events: none; }
.token-opt .tname { font-size: 10px; color: var(--dim); font-weight: 600; }

/* ---- Turn banner ---- */
.turn-banner {
  padding: 10px 14px; font-size: 14px; font-weight: 700; text-align: center;
  background: #fff3d6; color: #6b4e00; border-bottom: 2px solid var(--border);
}
.turn-banner.yours { background: var(--green); color: #fff; }

/* ---- Board ---- */
.board-wrap { padding: 10px; }
.board {
  display: grid; grid-template-columns: repeat(11, 1fr); grid-template-rows: repeat(11, 1fr);
  aspect-ratio: 1 / 1; width: 100%; max-width: 620px; margin: 0 auto;
  background: var(--green); border-radius: 8px; padding: 3px; gap: 2px;
}
.tile {
  background: #fdfaf1; border-radius: 3px; position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  font-size: 6.5px; line-height: 1.1; text-align: center; padding: 1px; cursor: pointer;
}
.tile .bar { position: absolute; top: 0; left: 0; right: 0; height: 22%; }
.tile .tname {
  font-weight: 700; padding: 1px; width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile.corner .tname { white-space: normal; text-overflow: clip; }
.tile .tprice { color: var(--dim); font-size: 5.5px; white-space: nowrap; }
.tile .owner-dot { position: absolute; bottom: 2px; right: 2px; width: 6px; height: 6px; border-radius: 50%; border: 1px solid #fff; }
.tile .houses { position: absolute; top: 24%; left: 0; right: 0; display: flex; justify-content: center; gap: 1px; }
.tile .houses span { width: 4px; height: 4px; background: #2e7d32; border-radius: 1px; }
.tile .houses span.hotel { width: 6px; height: 5px; background: #c0392b; border-radius: 1px; }
.tile.corner { font-size: 7.5px; font-weight: 800; justify-content: center; background: #eee6cf; }
.tile .tokens { position: absolute; top: 1px; left: 1px; display: flex; flex-wrap: wrap; gap: 1px; max-width: 90%; }
.tile .tok { font-size: 7px; }
.tile.mortgaged { background: #ddd; }
.tile.mortgaged .tname { text-decoration: line-through; }
.center-info {
  grid-column: 2 / 11; grid-row: 2 / 11; background: var(--green-light); border-radius: 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; gap: 6px;
}
.center-info .cgame { letter-spacing: 3px; font-size: 13px; opacity: 0.8; }
.dice-row { display: flex; gap: 8px; }
.die {
  width: 34px; height: 34px; background: #fff; border-radius: 7px; color: #222;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 18px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.center-info .cmsg { font-size: 12px; text-align: center; padding: 0 14px; opacity: 0.9; }

/* ---- Player strip ---- */
.player-strip { display: flex; gap: 8px; padding: 0 10px 10px; overflow-x: auto; }
.player-card {
  flex: 0 0 auto; min-width: 108px; background: var(--panel); border-radius: 10px; padding: 8px 10px;
  border: 2px solid var(--border); position: relative;
}
.player-card.current { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(201,151,42,0.3); }
.player-card.bankrupt { opacity: 0.4; }
.player-card .pname { font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 4px; }
.player-card .pcash { font-size: 15px; font-weight: 800; color: var(--green); }
.player-card .pmeta { font-size: 11px; color: var(--dim); }

/* ---- Tabs ---- */
.tabbar {
  display: flex; position: sticky; bottom: 0; background: var(--panel); border-top: 2px solid var(--border);
  padding-bottom: var(--safe-b); z-index: 20; margin-top: auto;
}
.tab-btn {
  flex: 1; border: none; background: transparent; padding: 12px 4px; font-size: 13px; font-weight: 700;
  color: var(--dim); position: relative; cursor: pointer;
}
.tab-btn.active { color: var(--green); }
.tab-btn .badge {
  position: absolute; top: 4px; right: 20%; background: var(--red); color: #fff; font-size: 10px;
  min-width: 16px; height: 16px; border-radius: 8px; display: flex; align-items: center; justify-content: center; padding: 0 3px;
}
.tabpane { display: none; padding: 12px 14px 20px; flex: 1; }
.tabpane.active { display: block; }

/* ---- Action panel ---- */
.action-panel { display: flex; flex-direction: column; gap: 10px; }
.action-card { background: var(--panel); border: 2px solid var(--border); border-radius: 12px; padding: 14px; }
.action-card h3 { margin: 0 0 8px; font-size: 16px; }
.action-card p { margin: 0 0 12px; font-size: 14px; color: var(--dim); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---- Properties panel ---- */
.group-block { margin-bottom: 14px; }
.group-title { font-size: 12px; font-weight: 800; text-transform: uppercase; color: var(--dim); margin-bottom: 6px; }
.prop-row {
  display: flex; align-items: center; gap: 10px; background: var(--panel); border: 2px solid var(--border);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 6px;
}
.prop-row .pcolor { width: 8px; align-self: stretch; border-radius: 4px; flex-shrink: 0; }
.prop-row .pinfo { flex: 1; min-width: 0; }
.prop-row .pinfo .pn { font-weight: 700; font-size: 14px; }
.prop-row .pinfo .ps { font-size: 12px; color: var(--dim); }
.prop-row .pactions { display: flex; gap: 6px; }
.prop-row .pactions .btn { padding: 8px 10px; font-size: 12px; min-height: 34px; }

/* ---- Trade panel ---- */
.trade-card { background: var(--panel); border: 2px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.trade-card h4 { margin: 0 0 8px; font-size: 14px; }
.trade-side { font-size: 13px; margin-bottom: 6px; }
.trade-side b { color: var(--green); }
select.input { appearance: none; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; max-height: 140px; overflow-y: auto; }
.chip {
  padding: 6px 10px; border-radius: 16px; border: 2px solid var(--border); font-size: 12px; cursor: pointer; background: #fff;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip .cdot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; border: 1px solid rgba(0,0,0,0.15); }
.chip.selected { background: var(--green); color: #fff; border-color: var(--green); }
.chip.selected .cdot { border-color: rgba(255,255,255,0.7); }

/* ---- Log ---- */
.log-panel { display: flex; flex-direction: column-reverse; gap: 6px; }
.log-line { font-size: 13px; padding: 8px 10px; background: var(--panel); border-radius: 8px; border: 1px solid var(--border); }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-card {
  background: #fff; width: 100%; max-width: 480px; border-radius: 16px 16px 0 0;
  padding: 20px 20px calc(20px + var(--safe-b)); max-height: 82vh; overflow-y: auto;
}
.modal-card h2 { margin: 0 0 4px; font-size: 19px; }
.modal-card .rent-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13px; }
.modal-card .rent-table td { padding: 4px 0; border-bottom: 1px solid var(--border); }
.modal-card .rent-table td:last-child { text-align: right; font-weight: 700; }
.modal-close { display: block; text-align: center; padding: 10px; color: var(--dim); font-weight: 700; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: calc(70px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  background: #1c2b22; color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 13px; z-index: 200;
  max-width: 88%; text-align: center; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

@media (min-width: 560px) {
  .lobby-wrap, .landing-wrap { padding-left: 0; padding-right: 0; }
}
