:root {
  --bg: #f4f2ee;
  --text: #222;
  --muted: #666;
  --accent: #2d6a4f;
  --accent-contrast: #ffffff;
  --border: #ccc;
  --error: #c0392b;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

.app-header {
  position: relative;
  padding: 0.6rem;
  text-align: center;
  background: var(--accent);
  color: var(--accent-contrast);
}

.app-header h1 {
  margin: 0;
  font-size: 1.2rem;
}

.leave-btn {
  position: absolute;
  top: 50%;
  right: 0.6rem;
  transform: translateY(-50%);
  min-height: auto;
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.15);
  color: var(--accent-contrast);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.leave-btn.hidden {
  display: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0.4rem 0.5rem 0;
}

.view.hidden {
  display: none;
}

.hidden {
  display: none;
}

.card {
  background: none;
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 0;
}

.card h2 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}

.leave-confirm {
  border: 1px solid var(--error);
  padding: 0.6rem;
  margin: 0.5rem 0;
}

.leave-confirm p {
  margin-top: 0;
}

.card h3 {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

input {
  display: block;
  width: 100%;
  margin-top: 0.2rem;
  padding: 0.5rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
}

button {
  font-size: 1rem;
  padding: 0.6rem 0.9rem;
  border-radius: 4px;
  border: 1px solid transparent;
  min-height: 40px;
  cursor: pointer;
  margin: 0.2rem 0.2rem 0.2rem 0;
}

button.primary {
  background: var(--accent);
  color: var(--accent-contrast);
  width: 100%;
}

button.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.secondary {
  background: none;
  color: var(--text);
  border-color: var(--border);
}

button.hidden {
  display: none;
}

.error-text {
  color: var(--error);
  min-height: 1.2em;
  font-size: 0.9rem;
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
}

.level-cards {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.6rem;
}

.level-cards.hidden {
  display: none;
}

.level-card {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.level-card.selected {
  border: 2px solid var(--accent);
  padding: calc(0.45rem - 1px) calc(0.6rem - 1px);
}

.code-display {
  font-size: 1.8rem;
  font-weight: bold;
  letter-spacing: 0.2em;
  text-align: center;
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin: 0.4rem 0;
}

.player-list,
.log-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.player-list li {
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.player-list li:last-child {
  border-bottom: none;
}

.score-positive {
  color: var(--accent);
}

.score-negative {
  color: var(--error);
}

.player-score-detail {
  font-size: 0.8rem;
  color: var(--muted);
}

.response-badge {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.78rem;
  font-weight: bold;
  width: fit-content;
  padding: 0.05rem 0.4rem;
  border-radius: 4px;
}

.response-badge.responded {
  color: #1c6b3d;
  border: 1px solid #1c6b3d;
}

.response-badge.waiting {
  color: #9a5b00;
  border: 1px solid #9a5b00;
}

.log-list li {
  padding: 0.15rem 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.turn-indicator {
  font-weight: bold;
  text-align: center;
  margin: 0 0 0.3rem;
}

.dice-card {
  text-align: center;
  padding: 0.4rem 0;
}

.board-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.board-card-header h3 {
  margin: 0;
  flex-shrink: 0;
}

.player-hud {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  overflow-x: auto;
  min-width: 0;
}

.hud-chip {
  min-width: 1.4em;
  padding: 0.1rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-weight: bold;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  white-space: nowrap;
  flex-shrink: 0;
}

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

.hud-players {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.hud-player-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.1rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.75rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.hud-player-chip.mine {
  border-color: var(--accent);
}

.hud-player-chip .score-positive,
.hud-player-chip .score-negative {
  font-weight: bold;
}

.hud-color-dot {
  width: 0.85em;
  height: 0.85em;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5rem;
  font-weight: bold;
  color: #fff;
}

.dice-row {
  display: flex;
  justify-content: center;
  gap: 0.35rem;
  margin: 0.3rem 0;
}

.die {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: #fff;
  border: 2px solid transparent;
  cursor: pointer;
  user-select: none;
}

.joker-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #000;
  color: #fff;
  font-size: 0.6rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #fff;
}

.die.small .joker-badge {
  width: 13px;
  height: 13px;
  font-size: 0.5rem;
  top: -4px;
  right: -4px;
}

.die.number-die {
  background: #555;
}

.die.disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.die.selected {
  border-color: #000;
  transform: scale(1.1);
}

.die.small {
  width: 30px;
  height: 30px;
  font-size: 0.8rem;
  opacity: 0.55;
  cursor: default;
}

.dice-row-split {
  justify-content: space-between;
  align-items: flex-end;
  gap: 0.6rem;
  flex-wrap: nowrap;
}

.dice-subgroup {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.dice-subgroup-used {
  margin-left: auto;
  padding-left: 0.5rem;
  border-left: 1px dashed var(--border);
}

.dice-used-label {
  margin: 0.2rem 0 0;
  font-size: 0.65rem;
  color: var(--muted);
  text-align: right;
}

.dice-hint {
  margin: 0.2rem 0;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

.joker-picker {
  margin: 0.4rem 0;
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.joker-picker.hidden {
  display: none;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem;
  margin-top: 0.3rem;
}

.action-row button {
  flex: 1 1 auto;
  min-width: 45%;
}

.board-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.2rem;
}

.board-grid {
  --cell: 38px;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows: repeat(var(--rows), var(--cell));
  gap: 3px;
  width: max-content;
}

.cell {
  position: relative;
  border-radius: 4px;
  width: var(--cell);
  height: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell.start-col {
  outline: 3px solid #2b2f33;
  outline-offset: -3px;
}

.cell.selectable {
  cursor: pointer;
  outline: 2px dashed rgba(0, 0, 0, 0.5);
  outline-offset: -3px;
}

.cell.pending {
  outline: 3px solid #000;
  outline-offset: -3px;
}

.cell .star {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell, 38px) * 0.8);
  line-height: 1;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

.cell .checkmark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  color: rgba(0, 0, 0, 0.85);
  font-size: calc(var(--cell, 38px) * 1.05);
  line-height: 1;
  pointer-events: none;
}

.board-column-labels {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell, 38px));
  gap: 3px;
  margin-top: 0.2rem;
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  width: max-content;
}

.board-column-labels .start-col {
  font-weight: bold;
  color: var(--accent);
}

.board-column-points {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell, 38px));
  gap: 3px;
  text-align: center;
  font-size: 0.65rem;
  color: var(--muted);
  width: max-content;
}

.points-high {
  margin-top: 0.1rem;
  font-weight: bold;
}

.points-low {
  margin-bottom: 0.2rem;
}

.points-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7em;
  height: 1.7em;
  border-radius: 50%;
  color: #fff;
}

.points-badge.mine {
  background: var(--accent);
}

.points-badge.other {
  background: var(--error);
}

.final-scores {
  padding-left: 1.2rem;
}

.final-scores li {
  margin-bottom: 0.5rem;
}
