/* =============================================
   MORA MARKET — TEYVAT PROPERTY WARS
   Design: Dark imperial gold, map-alive board
   ============================================= */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #070a16;
  --bg2:        #0d1226;
  --bg3:        #131929;
  --gold:       #c9a227;
  --gold-light: #f0cb5a;
  --gold-dim:   #7a6018;
  --text:       #e8e0cc;
  --text-dim:   #8a8070;
  --border:     #2a2d40;
  --glow:       rgba(201,162,39,0.25);

  /* Nation colors */
  --mondstadt:  #4fc3f7;
  --liyue:      #ef9a9a;
  --inazuma:    #ce93d8;
  --sumeru:     #a5d6a7;
  --fontaine:   #80cbc4;
  --natlan:     #ffcc80;
  --snezhnaya:  #b0bec5;
  --special:    #555970;

  --font-display: 'Cinzel', serif;
  --font-deco:    'Cinzel Decorative', serif;
  --font-body:    'Inter', sans-serif;

  --board-size: min(620px, 92vw);
  --cell-size: calc(var(--board-size) / 9);
}

html, body {
  height: 100%;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
}

/* ─── SCREENS ─────────────────────────────── */
.screen { display: none; position: fixed; inset: 0; overflow: auto; }
.screen.active { display: flex; align-items: center; justify-content: center; }

/* ─── LOBBY ───────────────────────────────── */
.lobby-bg {
  position: fixed; inset: 0; z-index: 0;
  background: radial-gradient(ellipse at 30% 20%, rgba(100,80,160,0.18) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 80%, rgba(201,162,39,0.12) 0%, transparent 55%),
              var(--bg);
}
.lobby-content {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; gap: 48px;
  padding: 40px 20px;
  width: 100%; max-width: 800px;
}
.title-block { text-align: center; }
.title-eyebrow {
  font-family: var(--font-body); font-size: 11px; letter-spacing: 4px;
  text-transform: uppercase; color: var(--gold-dim); margin-bottom: 8px;
}
.title-main {
  font-family: var(--font-deco); font-size: clamp(42px, 8vw, 80px);
  color: var(--gold); line-height: 1;
  text-shadow: 0 0 60px rgba(201,162,39,0.4);
}
.title-sub {
  font-family: var(--font-display); font-size: clamp(14px, 3vw, 22px);
  color: var(--text-dim); letter-spacing: 3px; margin-top: 4px;
}
.title-tagline {
  font-family: var(--font-body); font-size: 13px; color: var(--text-dim);
  margin-top: 12px; letter-spacing: 2px; text-transform: uppercase;
}
.lobby-panels {
  display: flex; align-items: center; gap: 0;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; width: 100%; max-width: 620px;
}
.lobby-panel {
  flex: 1; padding: 32px 28px; display: flex; flex-direction: column; gap: 14px;
}
.lobby-panel h2 {
  font-family: var(--font-display); font-size: 15px; letter-spacing: 2px;
  color: var(--gold); text-transform: uppercase;
}
.lobby-divider {
  width: 1px; background: var(--border); align-self: stretch;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 11px; letter-spacing: 2px;
  position: relative; flex-shrink: 0;
}
.lobby-divider::before {
  content: 'or';
  position: absolute; background: var(--bg2);
  padding: 6px 0; color: var(--text-dim); font-size: 10px;
}
.lobby-note {
  font-size: 11px; color: var(--text-dim); letter-spacing: 1px;
  text-align: center;
}

/* ─── INPUTS / BUTTONS ────────────────────── */
input[type="text"] {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 14px;
  color: var(--text); font-family: var(--font-body); font-size: 14px;
  outline: none; transition: border-color 0.2s;
}
input[type="text"]:focus { border-color: var(--gold-dim); }
input[type="text"]::placeholder { color: var(--text-dim); }

.btn-gold {
  background: linear-gradient(135deg, #c9a227, #a07e1a);
  border: none; border-radius: 6px; padding: 11px 20px;
  color: #0d0a02; font-family: var(--font-display); font-size: 13px;
  font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase;
  cursor: pointer; transition: all 0.2s;
}
.btn-gold:hover { filter: brightness(1.15); transform: translateY(-1px); }
.btn-gold:active { transform: translateY(0); }
.btn-gold:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: transparent; border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 18px; color: var(--text-dim);
  font-family: var(--font-body); font-size: 13px; cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--text-dim); color: var(--text); }

.btn-danger {
  background: rgba(239,154,154,0.08);
  border: 1px solid rgba(239,154,154,0.45);
  border-radius: 6px;
  padding: 10px 18px;
  color: #ef9a9a;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-danger:hover { border-color: #ef9a9a; background: rgba(239,154,154,0.14); transform: translateY(-1px); }
.btn-danger:active { transform: translateY(0); }
.btn-danger:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

button, input { -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }


/* Player icon uploader */
.avatar-picker {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: rgba(255,255,255,0.025);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.avatar-preview {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(201,162,39,0.22), rgba(79,195,247,0.12));
  border: 2px solid rgba(201,162,39,0.35);
  color: var(--gold);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  box-shadow: 0 0 18px rgba(201,162,39,0.08);
}
.avatar-preview img,
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.avatar-controls {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  align-items: center;
}
.avatar-controls input[type="file"] { display: none; }
.avatar-label,
.avatar-clear {
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  transition: all .2s;
}
.avatar-label {
  background: rgba(201,162,39,0.12);
  border: 1px solid rgba(201,162,39,0.38);
  color: var(--gold-light);
  font-family: var(--font-display);
  letter-spacing: .8px;
  text-transform: uppercase;
}
.avatar-label:hover { background: rgba(201,162,39,0.18); }
.avatar-clear {
  background: transparent;
  border: 1px solid rgba(239,154,154,0.38);
  color: #ef9a9a;
  font-family: var(--font-body);
}
.avatar-help {
  flex-basis: 100%;
  color: var(--text-dim);
  font-size: 10px;
  line-height: 1.35;
}
.waiting-avatar,
.pc-avatar,
.go-avatar {
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--avatar-color, var(--gold));
  color: #070a16;
  font-family: var(--font-display);
  font-weight: 800;
  border: 1px solid rgba(255,255,255,0.18);
}
.waiting-avatar { width: 28px; height: 28px; font-size: 12px; }
.pc-avatar { width: 34px; height: 34px; font-size: 14px; }
.go-avatar { width: 26px; height: 26px; font-size: 11px; }
.avatar-fallback { text-shadow: none; }


/* ─── WAITING ROOM ────────────────────────── */
#screen-waiting { flex-direction: column; }
.waiting-content {
  display: flex; flex-direction: column; align-items: center; gap: 32px;
  padding: 48px 24px; max-width: 480px; width: 100%;
}
.waiting-header { text-align: center; }
.waiting-header h2 {
  font-family: var(--font-display); font-size: 12px; letter-spacing: 3px;
  color: var(--text-dim); text-transform: uppercase; margin-bottom: 12px;
}
.room-code-display {
  font-family: var(--font-display); font-size: 48px; letter-spacing: 10px;
  color: var(--gold); text-shadow: 0 0 30px var(--glow);
}
.waiting-hint { font-size: 12px; color: var(--text-dim); margin-top: 8px; }
.waiting-players {
  display: flex; flex-wrap: wrap; gap: 12px; justify-content: center;
  min-height: 60px;
}
.waiting-player-chip {
  padding: 7px 14px 7px 8px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 30px; font-size: 14px; display: flex; align-items: center; gap: 8px;
}
.waiting-player-chip .pip { display: none; }
.waiting-status { font-size: 12px; color: var(--text-dim); letter-spacing: 1px; }
.waiting-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* ─── GAME LAYOUT ─────────────────────────── */
#screen-game { display: none; }
#screen-game.active {
  display: flex; align-items: stretch; justify-content: flex-start;
  overflow: hidden;
}
.game-layout {
  display: flex; width: 100%; height: 100vh; overflow: hidden;
}
.board-section {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: var(--bg);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.board-wrap { position: relative; width: var(--board-size); height: var(--board-size); }
.board {
  width: var(--board-size); height: var(--board-size);
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  border: 2px solid var(--gold-dim);
  border-radius: 4px;
  background: var(--bg2);
  overflow: hidden;
  position: relative;
}

/* Board center overlay */
.board-center {
  position: absolute;
  top: calc(var(--cell-size));
  left: calc(var(--cell-size));
  width: calc(var(--board-size) - 2 * var(--cell-size));
  height: calc(var(--board-size) - 2 * var(--cell-size));
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  gap: 16px; pointer-events: none;
}
.board-center-logo {
  text-align: center;
  opacity: 0.18;
}
.bcl-top {
  font-family: var(--font-display); font-size: 11px; letter-spacing: 3px;
  color: var(--gold); text-transform: uppercase;
}
.bcl-mid { font-size: 32px; color: var(--gold); line-height: 1.2; }
.bcl-bot {
  font-family: var(--font-display); font-size: 8px; letter-spacing: 2px;
  color: var(--gold-dim); text-transform: uppercase;
}
.center-action {
  pointer-events: all;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: rgba(7,10,22,0.9); border: 1px solid var(--border);
  border-radius: 10px; padding: 18px 22px;
}
.center-action.hidden { display: none; }
.center-msg { font-size: 12px; color: var(--text-dim); text-align: center; letter-spacing: 1px; }
.dice-row { display: flex; gap: 12px; }
.die {
  width: 42px; height: 42px; border-radius: 8px;
  background: var(--bg3); border: 2px solid var(--border);
  font-family: var(--font-display); font-size: 20px;
  color: var(--gold); display: flex; align-items: center; justify-content: center;
  transition: all 0.3s;
}
.die.rolling { animation: dieRoll 0.5s ease-in-out; }
@keyframes dieRoll {
  0%,100% { transform: rotate(0deg); }
  25% { transform: rotate(-20deg) scale(1.1); }
  75% { transform: rotate(20deg) scale(1.1); }
}

/* ─── BOARD CELLS ─────────────────────────── */
.cell {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  font-size: 6px; text-align: center; cursor: default;
  transition: background 0.2s;
  border: 1px solid rgba(255,255,255,0.04);
  padding: 1px;
}
.cell.corner {
  font-size: 6px; font-family: var(--font-display);
  justify-content: center;
}
.cell-nation-bar {
  height: 4px; width: 100%; flex-shrink: 0;
  border-radius: 1px; margin-bottom: 1px;
}
.cell-name {
  font-family: var(--font-display); font-size: 5.6px;
  line-height: 1.2; color: var(--text);
  overflow: hidden; word-break: break-word;
  padding: 0 1px;
}
.cell-price { font-size: 5px; color: var(--gold-dim); margin-top: 1px; }
.cell.special-card { background: rgba(85,89,112,0.15); }
.cell.tax-space { background: rgba(200,50,50,0.08); }
.cell.travel-space { background: rgba(60,100,200,0.1); }
.cell.utility-space { background: rgba(50,150,100,0.1); }
.cell.free-space { background: rgba(50,200,50,0.06); }
.cell.jail-space { background: rgba(200,100,50,0.1); }

/* Token dots on cells */
.cell-tokens { display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; min-height: 11px; z-index: 2; }
.token-dot {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.82);
  transition: transform 0.28s cubic-bezier(.34,1.56,.64,1), opacity 0.2s, box-shadow 0.28s;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #080a12;
  font-family: var(--font-display);
  font-size: 7px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 1px rgba(255,255,255,0.4);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.65), 0 0 8px rgba(0,0,0,0.55);
}
.token-dot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.token-avatar { border-color: rgba(255,255,255,0.9); }
.token-dot.current-token {
  transform: scale(1.22);
  border-color: var(--gold-light);
  box-shadow: 0 0 0 2px rgba(7,10,22,0.85), 0 0 14px rgba(240,203,90,0.9);
  animation: currentTokenPulse 1.15s ease-in-out infinite;
}
.token-moving-hidden { opacity: 0.18; transform: scale(0.72); }
.token-landed { animation: tokenLanded 0.9s ease both; }
.travel-token {
  position: absolute;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--gold-light);
  z-index: 40;
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: #070a16;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 900;
  transform: translate(-50%, -50%) scale(1.15);
  transition: left 165ms ease, top 165ms ease, transform 165ms ease, opacity 165ms ease;
  box-shadow: 0 0 0 3px rgba(7,10,22,0.75), 0 0 22px rgba(240,203,90,0.95), 0 10px 22px rgba(0,0,0,0.55);
}
.travel-token img { width: 100%; height: 100%; object-fit: cover; display: block; }
.travel-token-arrived { opacity: 0; transform: translate(-50%, -50%) scale(1.65); }

/* Property owned indicator */
.cell.owned-indicator::after {
  content: '';
  position: absolute; top: 0; right: 0;
  width: 4px; height: 4px; border-radius: 50%;
  background: currentColor;
}

/* Ownership + active-space visibility */
.cell.owned-cell { box-shadow: inset 0 0 0 2px var(--owner-ring); }
.cell.active-glow {
  outline: 2px solid var(--gold-light);
  outline-offset: -3px;
  box-shadow: inset 0 0 0 2px rgba(240,203,90,0.35), 0 0 20px rgba(240,203,90,0.55), inset 0 0 14px rgba(201,162,39,0.28);
  animation: activeSpacePulse 1.35s ease-in-out infinite;
  z-index: 3;
}
.cell.owned-cell.active-glow {
  box-shadow: inset 0 0 0 2px var(--owner-ring), 0 0 22px rgba(240,203,90,0.65), inset 0 0 16px rgba(201,162,39,0.35);
}
.cell.move-trail {
  outline: 1px solid rgba(240,203,90,0.5);
  outline-offset: -2px;
  background-image: radial-gradient(circle at center, rgba(240,203,90,0.22), transparent 62%);
}
.cell.landing-pulse { animation: landingPulse 1.05s ease both; }
@keyframes currentTokenPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.25); }
}
@keyframes tokenLanded {
  0% { transform: scale(0.8); }
  35% { transform: scale(1.45); }
  100% { transform: scale(1); }
}
@keyframes activeSpacePulse {
  0%, 100% { outline-color: rgba(240,203,90,0.82); }
  50% { outline-color: rgba(255,244,180,1); }
}
@keyframes landingPulse {
  0% { box-shadow: 0 0 0 0 rgba(240,203,90,0.95), inset 0 0 18px rgba(240,203,90,0.35); }
  70% { box-shadow: 0 0 0 12px rgba(240,203,90,0), inset 0 0 22px rgba(240,203,90,0.45); }
  100% { box-shadow: 0 0 0 0 rgba(240,203,90,0), inset 0 0 0 rgba(240,203,90,0); }
}

/* ─── SIDEBAR ─────────────────────────────── */
.sidebar {
  width: 300px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--bg2); overflow: hidden;
}
.sidebar-players {
  padding: 12px; display: flex; flex-direction: column; gap: 8px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.player-card {
  padding: 10px 12px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  transition: all 0.3s;
}
.player-card.active-turn {
  border-color: var(--gold-dim);
  box-shadow: 0 0 12px rgba(201,162,39,0.2);
}
.player-card.bankrupt { opacity: 0.4; }
.pc-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.pc-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.pc-name { font-family: var(--font-display); font-size: 12px; letter-spacing: 1px; flex: 1; }
.pc-turn-badge {
  font-size: 9px; background: var(--gold); color: #000;
  padding: 2px 6px; border-radius: 10px; font-weight: 700; letter-spacing: 1px;
}
.pc-stats { display: flex; gap: 10px; flex-wrap: wrap; }
.pc-stat { font-size: 10px; color: var(--text-dim); }
.pc-stat span { color: var(--gold); font-weight: 600; }

.game-controls {
  margin: 10px 12px 0;
  padding: 12px;
  background: rgba(239,154,154,0.04);
  border: 1px solid rgba(239,154,154,0.22);
  border-radius: 10px;
  flex-shrink: 0;
}
.game-controls .btn-danger { width: 100%; }
.game-controls-note {
  margin-top: 8px;
  color: var(--text-dim);
  font-size: 10px;
  line-height: 1.35;
  text-align: center;
}

/* Property + Event Modals */
.property-modal, .event-modal {
  margin: 12px; padding: 18px;
  background: var(--bg3); border: 1px solid var(--gold-dim);
  border-radius: 10px; flex-shrink: 0;
}
.property-modal.hidden, .event-modal.hidden { display: none; }

.pm-nation {
  font-size: 10px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 4px; font-family: var(--font-display);
}
.pm-name {
  font-family: var(--font-display); font-size: 16px; color: var(--text);
  margin-bottom: 12px; line-height: 1.3;
}
.pm-price-row, .pm-rent-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; margin-bottom: 6px; color: var(--text-dim);
}
.mora-val { font-family: var(--font-display); color: var(--gold); font-size: 15px; }
.pm-owner-row { font-size: 11px; color: var(--text-dim); margin: 8px 0; min-height: 16px; }
.pm-actions { display: flex; gap: 8px; margin-top: 12px; }
.pm-actions .btn-gold, .pm-actions .btn-secondary { flex: 1; }

.em-type {
  font-size: 10px; letter-spacing: 3px; text-transform: uppercase;
  margin-bottom: 6px;
}
.em-type.gossip { color: #ef9a9a; }
.em-type.contract { color: #a5d6a7; }
.em-title {
  font-family: var(--font-display); font-size: 15px; margin-bottom: 10px;
  line-height: 1.3; color: var(--text);
}
.em-desc { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; line-height: 1.5; }
.em-effect {
  font-size: 13px; font-weight: 600; margin-bottom: 14px;
  padding: 8px 10px; border-radius: 6px; background: var(--bg2);
}
.em-effect.negative { color: #ef9a9a; border-left: 2px solid #ef9a9a; }
.em-effect.positive { color: #a5d6a7; border-left: 2px solid #a5d6a7; }
.em-effect.neutral { color: var(--text-dim); border-left: 2px solid var(--border); }

/* Game Log */
.game-log-wrap {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  min-height: 0;
}
.log-header {
  font-family: var(--font-display); font-size: 11px; letter-spacing: 2px;
  color: var(--text-dim); text-transform: uppercase;
  padding: 10px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.game-log {
  flex: 1; overflow-y: auto; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.game-log::-webkit-scrollbar { width: 3px; }
.game-log::-webkit-scrollbar-track { background: transparent; }
.game-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.log-entry {
  font-size: 11px; color: var(--text-dim); line-height: 1.4;
  padding: 5px 8px; border-radius: 4px;
  border-left: 2px solid var(--border);
  animation: logIn 0.3s ease;
}
.log-entry.log-buy { border-left-color: var(--gold-dim); }
.log-entry.log-rent { border-left-color: #ef9a9a; }
.log-entry.log-event { border-left-color: #ce93d8; }
.log-entry.log-system { border-left-color: var(--border); opacity: 0.6; }
.log-entry.log-tax { border-left-color: #ffcc80; }
.log-name { font-weight: 600; }
@keyframes logIn {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ─── GAME OVER ────────────────────────────── */
#screen-gameover { flex-direction: column; }
.gameover-content {
  text-align: center; padding: 48px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 20px;
}
.go-eyebrow {
  font-size: 11px; letter-spacing: 4px; text-transform: uppercase; color: var(--text-dim);
}
.go-winner {
  font-family: var(--font-deco); font-size: clamp(32px, 7vw, 60px);
  color: var(--gold); text-shadow: 0 0 40px var(--glow);
}
.go-sub { font-size: 14px; color: var(--text-dim); letter-spacing: 2px; }
.go-standings {
  display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 360px;
}
.go-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 6px; font-size: 14px; gap: 12px;
}
.go-player { display: inline-flex; align-items: center; gap: 9px; min-width: 0; }
.go-row:first-child { border-color: var(--gold-dim); }

/* ─── UTILITY ─────────────────────────────── */
.hidden { display: none !important; }

/* ─── RESPONSIVE / MOBILE PLAYABILITY ───────── */
@media (max-width: 900px) {
  :root {
    --board-size: min(560px, 94vw);
  }

  .game-layout {
    flex-direction: column;
    height: 100dvh;
  }

  .board-section {
    flex: 0 0 auto;
    min-height: 0;
    padding: 12px 10px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar {
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
  }

  .sidebar-players {
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .player-card {
    min-width: 180px;
    scroll-snap-align: start;
  }
}

@media (max-width: 700px) {
  :root {
    --board-size: min(96vw, 390px);
  }

  html, body {
    overflow: hidden;
  }

  .screen.active {
    align-items: stretch;
    justify-content: flex-start;
  }

  #screen-lobby.active,
  #screen-waiting.active,
  #screen-gameover.active {
    align-items: center;
    justify-content: center;
  }

  #screen-game.active {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .game-layout {
    min-height: 100dvh;
    height: auto;
    overflow: visible;
  }

  .board-section {
    position: sticky;
    top: 0;
    z-index: 2;
    background: linear-gradient(180deg, var(--bg) 0%, rgba(7,10,22,0.96) 100%);
    padding: max(8px, env(safe-area-inset-top)) 6px 8px;
  }

  .board-wrap,
  .board {
    max-width: 100%;
  }

  .board {
    border-width: 1px;
  }

  .cell {
    font-size: 5px;
    padding: 0;
  }

  .cell-name {
    font-size: 4.6px;
    line-height: 1.08;
  }

  .cell-price {
    font-size: 4.4px;
  }

  .cell-nation-bar {
    height: 3px;
  }

  .cell-tokens {
    min-height: 10px;
    gap: 1px;
  }

  .token-dot {
    width: 12px;
    height: 12px;
    border-width: 1.5px;
    font-size: 6px;
  }

  .travel-token {
    width: 22px;
    height: 22px;
  }

  .board-center {
    gap: 8px;
  }

  .board-center-logo {
    display: none;
  }

  .center-action {
    width: min(210px, calc(var(--board-size) - 110px));
    gap: 8px;
    padding: 10px 12px;
    border-radius: 9px;
    background: rgba(7,10,22,0.94);
  }

  .center-msg {
    font-size: 11px;
    line-height: 1.3;
    letter-spacing: 0.2px;
  }

  .dice-row {
    gap: 8px;
  }

  .die {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  #btn-roll,
  #btn-end-turn,
  .center-action .btn-gold,
  .center-action .btn-secondary {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    font-size: 11px;
  }

  .sidebar {
    min-height: 46dvh;
    max-height: none;
    overflow: visible;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .sidebar-players {
    position: relative;
    padding: 10px 10px 8px;
    border-top: 1px solid rgba(255,255,255,0.04);
  }

  .sidebar-players::after {
    content: 'Swipe players →';
    flex: 0 0 auto;
    align-self: center;
    color: var(--text-dim);
    font-size: 10px;
    opacity: 0.65;
    padding-right: 8px;
  }

  .player-card {
    min-width: 166px;
    padding: 9px 10px;
  }

  .game-controls {
    margin: 8px 10px 0;
    padding: 10px;
  }

  .game-controls .btn-danger {
    min-height: 42px;
    font-size: 11px;
  }

  .pc-name {
    font-size: 11px;
    letter-spacing: .5px;
  }

  .pc-stats {
    gap: 7px;
  }

  .pc-stat {
    font-size: 9.5px;
  }

  .property-modal,
  .event-modal {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 10;
    margin: 0;
    max-height: min(55dvh, 360px);
    overflow-y: auto;
    padding: 16px;
    border-radius: 16px;
    box-shadow: 0 -18px 50px rgba(0,0,0,0.45);
  }

  .property-modal::before,
  .event-modal::before {
    content: '';
    display: block;
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: rgba(232,224,204,0.22);
    margin: 0 auto 12px;
  }

  .pm-name,
  .em-title {
    font-size: 15px;
  }

  .pm-actions {
    flex-direction: column;
  }

  .pm-actions .btn-gold,
  .pm-actions .btn-secondary,
  .event-modal .btn-gold {
    width: 100%;
    min-height: 44px;
  }

  .game-log-wrap {
    min-height: 210px;
  }

  .game-log {
    max-height: 260px;
    overflow-y: auto;
  }

  .lobby-content {
    gap: 28px;
    padding: 28px 16px;
  }

  .lobby-panels {
    flex-direction: column;
    max-width: 420px;
  }

  .lobby-panel {
    width: 100%;
    padding: 24px 20px;
  }

  .lobby-divider {
    width: 100%;
    height: 1px;
  }

  .lobby-divider::before {
    padding: 0 10px;
  }

  input[type="text"],
  .lobby-panel .btn-gold,
  .waiting-actions .btn-gold {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }


  .avatar-picker {
    width: 100%;
    padding: 9px;
  }

  .avatar-preview {
    width: 48px;
    height: 48px;
  }

  .avatar-label,
  .avatar-clear {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
  }

  .pc-avatar {
    width: 30px;
    height: 30px;
  }

  .waiting-avatar {
    width: 26px;
    height: 26px;
  }

  .room-code-display {
    font-size: clamp(30px, 11vw, 44px);
    letter-spacing: clamp(4px, 1.7vw, 9px);
  }
}

@media (max-width: 380px) {
  :root {
    --board-size: min(98vw, 350px);
  }

  .board-section {
    padding-left: 3px;
    padding-right: 3px;
  }

  .cell-name {
    font-size: 4.1px;
  }

  .cell-price {
    font-size: 4px;
  }

  .center-action {
    width: 175px;
    padding: 8px 9px;
  }

  .die {
    width: 32px;
    height: 32px;
  }

  .token-dot {
    width: 10px;
    height: 10px;
  }
}

@media (max-height: 680px) and (max-width: 700px) {
  :root {
    --board-size: min(92vw, 330px);
  }

  .board-section {
    position: relative;
  }

  .game-log {
    max-height: 190px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  #screen-game.active {
    overflow: hidden;
  }

  .game-layout {
    flex-direction: row;
    height: 100dvh;
    overflow: hidden;
  }

  :root {
    --board-size: min(94vh, 52vw);
  }

  .board-section {
    position: relative;
    flex: 1 1 auto;
    border-right: 1px solid var(--border);
    border-bottom: none;
    padding: 6px;
  }

  .sidebar {
    width: min(44vw, 330px);
    height: 100dvh;
    overflow: hidden;
  }

  .sidebar-players {
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 40dvh;
  }

  .sidebar-players::after {
    content: none;
  }

  .player-card {
    min-width: 0;
  }

  .game-controls {
    margin: 8px;
  }

  .property-modal,
  .event-modal {
    position: static;
    margin: 8px;
    max-height: 38dvh;
    border-radius: 10px;
  }

  .property-modal::before,
  .event-modal::before {
    content: none;
  }
}

/* ==========================================================
   EXPANDED FUN SYSTEMS + MOBILE POLISH
   ========================================================== */
.role-select-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--text-dim);
  text-transform: uppercase;
}
.role-select,
.trade-panel select,
.role-panel select,
.trade-panel input,
.auction-modal input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  outline: none;
}
.role-select:focus,
.trade-panel select:focus,
.role-panel select:focus,
.trade-panel input:focus,
.auction-modal input:focus { border-color: var(--gold-dim); }

.waiting-player-chip-plus {
  align-items: center;
  gap: 10px;
}
.waiting-player-chip-plus em {
  font-size: 10px;
  color: var(--gold-dim);
  font-style: normal;
  margin-left: 2px;
}
.waiting-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--gold-dim);
  flex-shrink: 0;
}

.game-status,
.objective-panel,
.auction-modal,
.trade-offer-modal,
.role-panel,
.trade-panel,
.my-assets {
  margin: 10px 12px 0;
  padding: 12px;
  background: rgba(19,25,41,0.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  flex-shrink: 0;
}
.panel-title {
  font-family: var(--font-display);
  color: var(--gold);
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.game-status p,
.objective-panel p,
.auction-modal p,
.trade-offer-modal p,
.role-panel p,
.trade-panel p,
.my-assets p {
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-dim);
  margin-top: 4px;
}
.game-status b,
.objective-panel b,
.auction-modal b,
.trade-offer-modal b,
.role-panel b,
.my-assets b {
  color: var(--text);
  font-size: 12px;
}
.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}
.meta-grid div {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}
.meta-grid b {
  display: block;
  color: var(--text-dim);
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.meta-grid span {
  color: var(--gold);
  font-family: var(--font-display);
  font-size: 13px;
}
.global-event-card {
  border-left: 2px solid var(--gold);
  padding: 8px 10px;
  background: rgba(201,162,39,0.06);
  border-radius: 6px;
}
.global-event-card.muted {
  border-left-color: var(--border);
  background: rgba(255,255,255,0.03);
}
.bonus-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
  font-size: 10px;
  color: var(--text-dim);
}
.bonus-row span,
.status-badges span {
  display: inline-flex;
  padding: 3px 7px;
  border: 1px solid var(--gold-dim);
  border-radius: 999px;
  color: var(--gold-light);
  background: rgba(201,162,39,0.08);
}

.pc-name small {
  display: block;
  font-family: var(--font-body);
  font-size: 9px;
  color: var(--gold-dim);
  letter-spacing: 1px;
  margin-top: 2px;
  text-transform: uppercase;
}
.pc-stats-plus { margin-bottom: 6px; }
.rep-meter {
  height: 5px;
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}
.rep-meter i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #ef9a9a, #f0cb5a, #a5d6a7);
  border-radius: inherit;
  transition: width 0.3s ease;
}
.status-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 7px;
}
.status-badges span { font-size: 9px; padding: 2px 6px; }
.pc-bankrupt {
  margin-top: 6px;
  font-size: 10px;
  color: #ef9a9a;
  letter-spacing: 2px;
}

.objective-status {
  display: inline-flex;
  margin-top: 8px;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(201,162,39,0.09);
  color: var(--gold-light);
  font-size: 10px;
}
.objective-status.done { background: rgba(165,214,167,0.12); color: #a5d6a7; }

.auction-actions,
.inline-actions {
  display: flex;
  gap: 7px;
  margin-top: 10px;
}
.auction-actions input { flex: 1; min-width: 0; }
.auction-actions button,
.inline-actions button { flex: 1; }
.auction-modal small,
.role-panel small,
.my-assets small {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 6px;
  line-height: 1.35;
}

.trade-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.trade-panel .panel-title { margin-bottom: 0; }
.asset-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.asset-row:first-of-type { border-top: none; }
.asset-row div { min-width: 0; }
.asset-row b {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.btn-mini {
  background: transparent;
  border: 1px solid var(--gold-dim);
  border-radius: 999px;
  color: var(--gold-light);
  padding: 6px 8px;
  font-size: 10px;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-mini:disabled {
  opacity: .4;
  cursor: not-allowed;
}
.maxed {
  color: #a5d6a7;
  font-size: 10px;
}
.upgrade-chip {
  position: absolute;
  top: 3px;
  right: 3px;
  z-index: 3;
  padding: 1px 3px;
  border-radius: 4px;
  background: rgba(201,162,39,0.95);
  color: #0d0a02;
  font-family: var(--font-body);
  font-size: 6px;
  font-weight: 800;
}
.log-entry.log-rep { border-left-color: #80cbc4; }
.log-entry.log-role { border-left-color: #a5d6a7; }
.log-entry.log-upgrade { border-left-color: var(--gold-light); }
.log-entry.log-trade { border-left-color: #4fc3f7; }
.log-entry.log-auction { border-left-color: #ffcc80; }
.log-entry.log-objective { border-left-color: #a5d6a7; color: #c8f7ca; }
.log-entry.log-global { border-left-color: #ce93d8; color: #e9d0f1; }
.log-entry.log-loan { border-left-color: #b0bec5; }

.fx-layer {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  overflow: hidden;
}
.fx-bubble {
  position: fixed;
  left: 50%;
  top: 16%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--gold-dim);
  background: rgba(7,10,22,0.92);
  color: var(--gold-light);
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 2px;
  box-shadow: 0 0 30px rgba(201,162,39,0.2);
  animation: fxBubble 1.35s ease forwards;
}
@keyframes fxBubble {
  0% { opacity: 0; transform: translate(-50%, 16px) scale(.9); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -28px) scale(.96); }
}
.fx-confetti {
  position: fixed;
  top: 14%;
  width: 6px;
  height: 10px;
  border-radius: 2px;
  background: var(--gold-light);
  animation: fxConfetti .9s ease forwards;
}
.fx-confetti:nth-child(3n) { background: #ce93d8; }
.fx-confetti:nth-child(4n) { background: #80cbc4; }
.fx-confetti:nth-child(5n) { background: #ef9a9a; }
@keyframes fxConfetti {
  to { transform: translate(var(--dx), 180px) rotate(540deg); opacity: 0; }
}

@media (max-width: 700px) {
  .role-select { font-size: 12px; min-height: 42px; }
  .game-status,
  .objective-panel,
  .auction-modal,
  .trade-offer-modal,
  .role-panel,
  .trade-panel,
  .my-assets {
    margin: 8px 10px 0;
    padding: 11px;
  }
  .sidebar {
    overflow-y: auto;
  }
  .sidebar-players {
    overflow-x: auto;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(210px, 78vw);
  }
  .player-card { min-width: 0; }
  .asset-row b { max-width: 54vw; }
  .auction-actions,
  .inline-actions { flex-wrap: wrap; }
  .auction-actions input { min-width: 120px; }
  .fx-bubble { top: 10%; width: max-content; max-width: 86vw; text-align: center; }
}
