:root {
  --bg: #f2efe7;
  --panel: #fffdf8;
  --ink: #1e2430;
  --muted: #5e6777;
  --accent: #2a6df4;
  --shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
  --red: #df3f3f;
  --green: #2fa55c;
  --yellow: #e4b62a;
  --blue: #3f6ee8;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  background: linear-gradient(180deg, #ece7db 0%, #e4efe9 100%);
  color: var(--ink);
  touch-action: manipulation;
}

body {
  overflow: hidden;
}

#app {
  width: 100%;
  height: 100%;
}

.screen {
  display: none;
  width: 100%;
  height: 100%;
  padding: 16px;
}

.screen.active {
  display: flex;
}

.card {
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
  border: 2px solid rgba(0, 0, 0, 0.08);
}

#startScreen {
  align-items: center;
  justify-content: center;
}

.setup-card {
  width: min(900px, 92vw);
  padding: 28px;
}

.setup-card h1 {
  margin: 0 0 8px;
  font-size: 2.2rem;
}

.subtitle {
  margin: 0 0 24px;
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-weight: 700;
}

select,
button {
  font: inherit;
}

select {
  padding: 14px 16px;
  border-radius: 12px;
  border: 2px solid #cfd6e4;
  background: #fff;
  min-height: 52px;
}

.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 12px;
  border: 2px solid #d8deea;
  border-radius: 14px;
  padding: 14px;
  background: #fbfcff;
}

.checkbox-row input {
  width: 22px;
  height: 22px;
}

.actions {
  margin-top: 24px;
  display: flex;
  justify-content: center;
}

.primary-btn,
.secondary-btn {
  min-height: 56px;
  padding: 0 24px;
  border: none;
  border-radius: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.primary-btn:active,
.secondary-btn:active {
  transform: scale(0.98);
}

.primary-btn {
  background: var(--accent);
  color: #fff;
}

.secondary-btn {
  background: #e8edf7;
  color: var(--ink);
}

#gameScreen {
  flex-direction: column;
  gap: 12px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  gap: 16px;
}

.status-main {
  display: flex;
  gap: 12px;
  align-items: stretch;
  flex-wrap: wrap;
}

.turn-pill,
.status-item {
  background: #f5f7fb;
  border: 2px solid #dbe2ee;
  border-radius: 14px;
  padding: 10px 14px;
  min-width: 120px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.turn-pill span,
.status-item span {
  font-size: 0.82rem;
  color: var(--muted);
}

.turn-pill strong,
.status-item strong {
  font-size: 1.02rem;
}

.top-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 12px;
  min-height: 0;
  flex: 1;
}

.board-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-height: 0;
}

#boardCanvas {
  width: min(100%, calc(100vh - 190px));
  height: auto;
  aspect-ratio: 1 / 1;
  background: #f8f4ea;
  border-radius: 18px;
  border: 3px solid #d5c9aa;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.05);
}

.sidebar {
  padding: 16px;
  overflow: auto;
}

.sidebar h2 {
  margin-top: 0;
}

.player-stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.player-card {
  border-radius: 14px;
  border: 2px solid #dbe2ee;
  padding: 12px;
  background: #fbfcff;
}

.player-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(42, 109, 244, 0.12);
}

.player-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.color-chip {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.2);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  margin: 4px 0;
  color: var(--muted);
  font-weight: 700;
}

.legend {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 2px dashed #dbe2ee;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-weight: 700;
  color: var(--muted);
}

.dot {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}

.dot.safe {
  background: #fff;
  border: 3px solid #333;
}

.dot.barrier {
  background: #444;
}

.dot.selectable {
  background: #7c5cff;
}

@media (max-width: 1100px) {
  .game-layout {
    grid-template-columns: 1fr 260px;
  }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .screen,
  .screen.active {
    height: auto;
    min-height: 100%;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  #boardCanvas {
    width: min(100%, 90vw);
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button {
    flex: 1;
  }
}
