:root {
  --bg: #f3f7fb;
  --card: #ffffff;
  --ink: #1d2a39;
  --muted: #5f6d7c;
  --primary: #1677ff;
  --primary-dark: #0f5fca;
  --success: #1aaf5d;
  --danger: #d64545;
  --warning: #ffb020;
  --border: #d7e0ea;
  --shadow: 0 16px 35px rgba(13, 35, 67, 0.12);
  --radius: 18px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Arial, sans-serif;
  background: linear-gradient(180deg, #eef5ff 0%, #f8fbff 100%);
  color: var(--ink);
}

button, select, input {
  font: inherit;
}

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

.setup-card {
  width: min(1100px, calc(100% - 32px));
  margin: 24px auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 28px;
}

h1, h2, h3, p { margin-top: 0; }
.subtitle { color: var(--muted); margin-bottom: 22px; }
.setup-row { margin-bottom: 20px; }
label { display: block; font-weight: 700; margin-bottom: 8px; }
select, input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
}

.player-forms {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
}

.player-form {
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 16px;
  background: #fbfdff;
}

.player-form h3 { margin-bottom: 12px; }
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.avatar-option {
  border: 3px solid transparent;
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  background: #fff;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.avatar-option:hover { transform: translateY(-2px); box-shadow: 0 10px 20px rgba(0,0,0,.08); }
.avatar-option.selected { border-color: var(--primary); }
.avatar-option.disabled { opacity: .35; cursor: not-allowed; filter: grayscale(0.7); }
.avatar-option img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }

.setup-actions { margin-top: 24px; display: flex; justify-content: flex-end; }
.primary-btn, .secondary-btn, .ghost-btn {
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  font-weight: 700;
  cursor: pointer;
}
.primary-btn { background: var(--primary); color: white; }
.primary-btn:hover { background: var(--primary-dark); }
.secondary-btn { background: var(--success); color: white; }
.ghost-btn { background: #edf3fb; color: var(--ink); }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  background: rgba(255,255,255,.9);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}
.topbar p { color: var(--muted); margin-bottom: 0; }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.dice-display {
  width: 54px; height: 54px; display: grid; place-items: center;
  background: #fff; border-radius: 16px; border: 1px solid var(--border);
  font-size: 28px; box-shadow: var(--shadow);
}

.game-layout {
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 20px;
  padding: 20px;
}
.sidebar { display: grid; gap: 18px; align-content: start; }
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.players-panel { display: grid; gap: 12px; }
.player-card {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fbfdff;
}
.player-card.active { border-color: var(--primary); box-shadow: inset 0 0 0 2px rgba(22,119,255,.12); }
.player-card.bankrupt { opacity: .5; }
.player-card img, .winner-avatar {
  width: 56px; height: 56px; border-radius: 50%; object-fit: cover; border: 3px solid white; box-shadow: 0 6px 14px rgba(0,0,0,.12);
}
.player-stats { font-size: 14px; color: var(--muted); }
.player-name-line { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }

.message-panel {
  min-height: 180px;
  max-height: 350px;
  overflow: auto;
  display: grid;
  gap: 8px;
}
.message-item {
  padding: 10px 12px;
  border-radius: 12px;
  background: #f5f8fc;
  border: 1px solid #e8eef5;
  color: #33455a;
}

.board-wrapper {
  position: relative;
  min-height: 760px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 14px;
}
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(7, 1fr);
  gap: 8px;
  min-height: 730px;
}

.cell {
  position: relative;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.cell.corner { min-height: 96px; }
.cell-header {
  height: 10px;
  border-radius: 999px;
  margin-bottom: 6px;
}
.cell-title { font-size: 12px; font-weight: 800; line-height: 1.15; }
.cell-type, .cell-price { font-size: 11px; color: var(--muted); }
.cell-owner { font-size: 10px; color: var(--primary-dark); font-weight: 700; }
.tokens {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.token {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}

.board-center {
  position: absolute;
  inset: 25% 25%;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.center-card {
  width: min(100%, 340px);
  background: linear-gradient(160deg, #ffffff 0%, #edf5ff 100%);
  border-radius: 28px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 28px;
  text-align: center;
}
.center-card .small { color: var(--muted); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(18, 25, 35, 0.55);
  display: grid;
  place-items: center;
  z-index: 30;
}
.modal-card {
  background: white;
  border-radius: 26px;
  padding: 28px;
  width: min(460px, calc(100% - 24px));
  text-align: center;
  box-shadow: var(--shadow);
}

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #ecf3ff;
  color: var(--primary-dark);
}

@media (max-width: 1080px) {
  .game-layout { grid-template-columns: 1fr; }
  .board-wrapper { min-height: 620px; }
  .board { min-height: 580px; }
}

@media (max-width: 720px) {
  .setup-card { padding: 18px; }
  .avatar-grid { grid-template-columns: repeat(3, 1fr); }
  .topbar { padding: 14px; }
  .board { grid-template-columns: repeat(6, 1fr); grid-template-rows: auto; min-height: auto; }
  .board-wrapper { min-height: auto; }
  .board-center { position: static; inset: auto; margin-top: 14px; }
  .cell { min-height: 102px; }
}
