:root {
  color-scheme: light dark;
  --bg: #f4f1ea;
  --panel: #ffffff;
  --text: #1c1c1c;
  --muted: #6b6b6b;
  --border: #ddd6c8;
  --red: #b23a3a;
  --blue: #2f5f8f;
  --tan: #cdb98a;
  --black: #222222;
  --neutral: #e7e2d6;
  --red-light: #f0d6d6;
  --blue-light: #d6e2ef;
  --tan-light: #ede4cd;
  --black-light: #cfcfcf;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#root {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

h1, h2, h3 { margin-top: 0; }

.rooms {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.room-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  text-align: left;
}

.room-card:hover { border-color: #aaa; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-top: 16px;
}

.error-banner {
  background: #f8d7da;
  color: #58151c;
  border: 1px solid #f1aeb5;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 12px;
}

.badge {
  display: inline-block;
  font-size: 0.75em;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 6px;
}
.badge.dim { background: var(--muted); color: white; }

button {
  font: inherit;
  font-size: 1.05em;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid #bbb;
  background: #fff;
  color: #1c1c1c;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}
button:hover:not(:disabled) {
  border-width: 2px;
  border-color: #1c1c1c;
  background: #f0f0f0;
  box-shadow: 0 0 0 3px rgba(28, 28, 28, 0.08);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--text); color: white; border-color: var(--text); }
button.primary:hover:not(:disabled) {
  background: #333;
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(28, 28, 28, 0.25);
}

input[type="text"], select {
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #bbb;
}

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 132px));
  gap: 8px;
  margin-top: 16px;
}

.actions-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.muted { color: var(--muted); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  max-width: 1120px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  margin-top: 0;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-close {
  padding: 4px 10px;
  font-size: 1em;
  line-height: 1;
}

.wordlist-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-wrap: wrap;
}
.wordlist-row:last-child { border-bottom: none; }

.wordlist-row .actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.wordlist-textarea {
  width: 100%;
  min-height: 120px;
  font: inherit;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #bbb;
  resize: vertical;
}

.word-chips {
  display: grid;
  grid-template-columns: repeat(auto-fill, 160px);
  grid-auto-rows: 34px;
  gap: 6px;
  margin: 10px 0;
}

.word-chip {
  display: flex;
  align-items: center;
  gap: 2px;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  background: var(--neutral);
  border-radius: 999px;
  padding: 3px 6px 3px 10px;
  font-size: 0.85em;
  overflow: hidden;
}

.word-chip span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.word-chip button {
  margin-left: auto;
  flex-shrink: 0;
  border: none;
  background: none;
  padding: 0 4px;
  font-size: 1em;
  line-height: 1;
  border-radius: 999px;
}
.word-chip button:hover:not(:disabled) { box-shadow: none; background: rgba(0, 0, 0, 0.1); }

.app-title a { color: inherit; text-decoration: none; }
.app-title a:hover { text-decoration: underline; }

.team-name.red { color: var(--red); }
.team-name.blue { color: var(--blue); }

/* Home */
.room-status { font-weight: 700; font-size: 0.85em; text-transform: uppercase; color: var(--muted); }
.room-card h3 { margin: 4px 0 8px; }
.room-card .team-name { font-weight: 600; }
.room-player { padding-left: 16px; }

/* Choose Player: two invisible columns, a quadrant per seat */
.quadrants {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  max-width: 640px;
}
.quadrant {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 24px;
}
.quadrant-label { font-weight: 600; }
.quadrant input { width: 100%; }
.quadrant input:disabled { background: var(--neutral); color: var(--text); }

/* ConfigView */
.config { max-width: 560px; }
.config-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.config-row label { width: 96px; font-weight: 600; }
.config-row input[type="text"] { flex: 1; min-width: 0; }
.config h3 { margin-top: 20px; }
.players-table { border-collapse: collapse; margin-bottom: 16px; width: 100%; }
.players-table th, .players-table td { border: none; padding: 4px 12px 4px 0; text-align: left; width: 20%; }
.config-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}
.config-footer-left { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-right: auto; }

/* BoardView */
.board-layout {
  display: flex;
  align-items: flex-start;
  gap: 32px;
}
.board-main { flex: 0 1 auto; min-width: 0; }
.board-side { flex: 0 0 240px; padding-top: 52px; }
.board-side section { margin-bottom: 20px; }
.board-side h3 { margin-bottom: 6px; }
.board-greeting { font-size: 1.3em; }

@media (max-width: 760px) {
  .board-layout { flex-direction: column; }
  .board-side { flex-basis: auto; width: 100%; padding-top: 0; }
}

.turn-box {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 2px solid currentColor;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 600;
}
.turn-box.red { color: var(--red); }
.turn-box.blue { color: var(--blue); }

.tile {
  aspect-ratio: 3 / 2;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--neutral);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 600;
  font-size: 0.85em;
  padding: 6px;
  user-select: none;
  overflow-wrap: anywhere;
}
.tile.clickable { cursor: pointer; }
.tile.clickable:hover { border-color: var(--text); }
.tile.selected { outline: 3px solid #f1c40f; outline-offset: -3px; }

.tile.light-red { background: var(--red-light); }
.tile.light-blue { background: var(--blue-light); }
.tile.light-tan { background: var(--tan-light); }
.tile.light-black { background: var(--black-light); }

.tile.dark-red { background: var(--red); color: white; }
.tile.dark-blue { background: var(--blue); color: white; }
.tile.dark-tan { background: var(--tan); color: #3a2f1c; }
.tile.dark-black { background: var(--black); color: white; }
/* Revealed only because the game ended, not guessed during play */
.tile.unguessed { opacity: 0.55; }

.score-row { padding: 2px 0; }
.current-clue { font-size: 1.2em; font-weight: 700; }
.stack-buttons { display: flex; gap: 8px; margin-top: 8px; }
.number-input { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.number-input span { font-weight: 700; }
.number-input input { width: 140px; }
.field-error { color: var(--red); font-size: 0.9em; margin: 6px 0 0; }

.clue-history { border-collapse: collapse; }
.clue-history td { padding: 2px 12px 2px 0; }
