:root {
  --bg: #f5f0e8;
  --panel: #fffdf8;
  --text: #1a1a1a;
  --muted: #555;
  --accent: #2a6b4f;
  --accent-light: #e8f3ed;
  --border: #d4cbb8;
  --card-bg: #fff;
  --selected: #ffe08a;
  --red: #c0392b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

header {
  text-align: center;
  padding: 1.5rem 1rem 0.5rem;
}

h1 { margin: 0; font-size: 2rem; }
.subtitle { color: var(--muted); margin: 0.25rem 0 0; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
}

.panel {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

.hidden { display: none; }

label {
  display: block;
  margin-bottom: 0.75rem;
  font-weight: bold;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-weight: normal;
  margin-bottom: 1rem;
  cursor: pointer;
}

.checkbox-label input {
  margin-top: 0.25rem;
}

input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.6rem 0.75rem;
  font-size: 1.1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
}

#room-code {
  font-family: "Menlo", "Consolas", monospace;
  letter-spacing: 0.12em;
  min-width: 10ch;
  width: auto;
  max-width: 100%;
}

.row {
  display: flex;
  gap: 0.75rem;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.row label { flex: 1; min-width: 200px; }

button {
  padding: 0.65rem 1.1rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

button:hover { background: var(--accent-light); }
button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button.primary:hover { filter: brightness(1.1); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.status {
  color: var(--muted);
  min-height: 1.5rem;
  font-weight: bold;
}

.connection-status {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: bold;
}

.connection-status.connected {
  color: var(--accent);
}

.connection-status.connecting {
  color: var(--muted);
}

.connection-status.error {
  color: #8b2500;
}

.error-status {
  color: #8b2500;
  font-weight: bold;
  min-height: 0;
}

#player-list { padding-left: 1.25rem; }

.hand-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.hand-header h3 { margin: 0; }

#btn-sort-toggle {
  font-size: 0.95rem;
  padding: 0.4rem 0.75rem;
}

.game-header {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

#discard-area {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.discard-slot {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
}

#players-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.player-chip {
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: #eee;
  font-size: 0.95rem;
}

.player-chip.current {
  background: var(--accent);
  color: #fff;
  font-weight: bold;
}

.card-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 80px;
}

.card {
  padding: 0.5rem 0.65rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  cursor: pointer;
  user-select: none;
  min-width: 52px;
  text-align: center;
  font-size: 1rem;
}

.card.red { color: var(--red); }
.card.selected { background: var(--selected); border-color: #c9a000; }
.card.wild { font-weight: bold; }
.card.readonly { cursor: default; }
.card.card-compact {
  min-width: 42px;
  padding: 0.3rem 0.45rem;
  font-size: 0.85rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
}

#log {
  max-height: 200px;
  overflow-y: auto;
  padding-left: 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.meld-group {
  margin-bottom: 0.5rem;
  padding: 0.5rem;
  background: var(--accent-light);
  border-radius: 8px;
  border: 2px solid transparent;
}

.meld-group.interactive {
  cursor: pointer;
}

.meld-header {
  font-weight: bold;
  font-size: 0.95rem;
  margin-bottom: 0.35rem;
}

.meld-cards {
  min-height: 0;
}

.opponent-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  background: #fff;
}

.opponent-panel.current-turn {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.opponent-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

.opponent-name {
  font-weight: bold;
  font-size: 1.05rem;
}

.opponent-stats {
  color: var(--muted);
  font-size: 0.95rem;
}

.opponent-melds {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.no-melds {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0;
}

.meld-group.building {
  background: #fff8e1;
  border-color: #e6c200;
}

.meld-group.red-threes-meld {
  background: #fde8e8;
  border-color: #e8a0a0;
}

.meld-group.undoable {
  cursor: pointer;
}

.meld-group.selected-meld {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.dev-tools {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}

.dev-tools h3 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.hint {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0 0 0.75rem;
}

select {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

#btn-save-game {
  margin-left: auto;
}

.score-summary {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}

.score-summary th,
.score-summary td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.score-summary tr.round-winner td {
  font-weight: bold;
  background: var(--accent-light);
}

.score-summary tr.series-winner td {
  background: #e8f5e9;
}

.finished-actions {
  margin-top: 1rem;
  gap: 0.5rem;
}

.video-section {
  max-width: 1100px;
  margin: 0 auto 1rem;
  padding: 1rem 1.5rem;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
}

.video-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.video-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.video-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.video-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.video-tile {
  position: relative;
  background: #1a1a1a;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 4 / 3;
}

.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #111;
}

.video-tile .tile-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
}

.video-tile.local .tile-name {
  background: linear-gradient(transparent, rgba(42, 107, 79, 0.85));
}

.video-tile .tile-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ccc;
  font-size: 2rem;
  background: #2a2a2a;
}