:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #121417;
  --muted: #606770;
  --border: #d7dce1;
  --called: #111827;
  --called-text: #ffffff;
  --accent: #1d4ed8;
  --danger: #b42318;

  --bingo-b: #2563eb;
  --bingo-i: #dc2626;
  --bingo-n: #15803d;
  --bingo-g: #facc15;
  --bingo-o: #7e22ce;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

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

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: .55;
}

.participant-shell {
  max-width: 844px;
  margin: 0 auto;
  padding: 10px 12px 12px;
}

.recent-section h1 {
  margin: 0 0 6px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.recent-numbers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.recent-number {
  min-height: 82px;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.recent-number.primary {
  border-width: 3px;
}

.recent-number.bingo-b,
.recent-number.bingo-i,
.recent-number.bingo-n,
.recent-number.bingo-g,
.recent-number.bingo-o {
  color: #fff;
}

.recent-number.bingo-b {
  background: var(--bingo-b);
  border-color: var(--bingo-b);
}

.recent-number.bingo-i {
  background: var(--bingo-i);
  border-color: var(--bingo-i);
}

.recent-number.bingo-n {
  background: var(--bingo-n);
  border-color: var(--bingo-n);
}

.recent-number.bingo-g {
  background: var(--bingo-g);
  border-color: var(--bingo-g);
}

.recent-number.bingo-o {
  background: var(--bingo-o);
  border-color: var(--bingo-o);
}

.recent-letter {
  font-size: 22px;
  font-weight: 800;
}

.recent-value {
  font-size: 48px;
  line-height: 1;
  font-weight: 900;
}

.recent-empty {
  color: var(--muted);
  font-size: 28px;
  font-weight: 700;
}

.board-section {
  margin-top: 10px;
}

.bingo-board {
  display: grid;
  grid-template-columns: 42px repeat(15, minmax(0, 1fr));
  gap: 3px;
}

.board-letter,
.board-number {
  min-width: 0;
  height: 42px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}

.board-letter {
  color: #fff;
  font-size: 22px;
}

.board-letter.bingo-b {
  background: var(--bingo-b);
}

.board-letter.bingo-i {
  background: var(--bingo-i);
}

.board-letter.bingo-n {
  background: var(--bingo-n);
}

.board-letter.bingo-g {
  background: var(--bingo-g);
}

.board-letter.bingo-o {
  background: var(--bingo-o);
}

.board-number {
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: 16px;
}

.board-number.called {
  color: #fff;
}

.board-number.called.bingo-b {
  background: var(--bingo-b);
  border-color: var(--bingo-b);
}

.board-number.called.bingo-i {
  background: var(--bingo-i);
  border-color: var(--bingo-i);
}

.board-number.called.bingo-n {
  background: var(--bingo-n);
  border-color: var(--bingo-n);
}

.board-number.called.bingo-g {
  background: var(--bingo-g);
  border-color: var(--bingo-g);
}

.board-number.called.bingo-o {
  background: var(--bingo-o);
  border-color: var(--bingo-o);
}

.participant-board {
  min-width: 760px;
}

.board-section {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px;
}

.login-card h1 {
  margin-top: 0;
}

.login-card form {
  display: grid;
  gap: 10px;
}

.login-card label {
  font-weight: 700;
}

.login-card input,
.number-entry-row input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 18px;
  background: #fff;
}

.login-card button,
.number-entry-row button,
.secondary-button,
.danger-button {
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 800;
}

.login-card button,
.number-entry-row button {
  background: var(--accent);
  color: #fff;
}

.error-message {
  color: var(--danger);
  font-weight: 700;
}

.caller-page {
  padding: 24px;
}

.caller-shell {
  max-width: 1180px;
  margin: 0 auto;
}

.caller-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.caller-header h1 {
  margin: 2px 0 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: 13px;
}

.caller-entry,
.caller-recent,
.history-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 22px;
}

.caller-entry label {
  display: block;
  font-weight: 800;
  margin-bottom: 8px;
}

.number-entry-row {
  display: grid;
  grid-template-columns: 180px auto;
  gap: 10px;
  align-items: stretch;
}

.caller-message {
  min-height: 1.25em;
  margin-bottom: 0;
  font-weight: 700;
}

.caller-recent h2,
.caller-shell section > h2 {
  margin-top: 0;
}

.recent-numbers.compact {
  max-width: 560px;
  margin-bottom: 12px;
}

.recent-numbers.compact .recent-number {
  min-height: 70px;
}

.recent-numbers.compact .recent-value {
  font-size: 38px;
}

.secondary-button {
  background: #e5e7eb;
  color: #111827;
}

.danger-button {
  background: var(--danger);
  color: #fff;
}

.caller-board {
  grid-template-columns: 42px repeat(15, minmax(38px, 1fr));
  overflow-x: auto;
}

.history-section {
  margin-top: 28px;
}

.history-controls {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}

.history-controls label {
  display: block;
  font-weight: 800;
  margin-bottom: 7px;
}

.history-controls input {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 11px 12px;
  min-height: 44px;
  font-size: 16px;
}

.history-message {
  min-height: 1.25em;
  color: var(--muted);
  font-weight: 700;
}

.history-games {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.history-game-button {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  padding: 12px 14px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.history-game-button strong {
  font-size: 16px;
}

.history-game-button span {
  color: var(--muted);
  font-size: 14px;
}

.history-viewer {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.history-viewer h3 {
  margin: 0 0 4px;
}

.history-viewer-details {
  margin: 0 0 14px;
  color: var(--muted);
  font-weight: 700;
}

#confirmDialog {
  border: 0;
  border-radius: 14px;
  width: min(430px, calc(100% - 32px));
  padding: 22px;
}

#confirmDialog::backdrop {
  background: rgb(0 0 0 / .45);
}

#confirmDialog h2 {
  margin-top: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

@media (max-width: 700px) {
  .caller-page {
    padding: 14px;
  }

  .number-entry-row {
    grid-template-columns: 1fr;
  }

  .participant-shell {
    padding: 10px;
  }

  .recent-number {
    min-height: 70px;
  }

  .recent-letter {
    font-size: 18px;
  }

  .recent-value {
    font-size: 38px;
  }
}


@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #111318;
    --panel: #1b1f26;
    --text: #f3f4f6;
    --muted: #a8afb9;
    --border: #3a414c;
    --called: #f3f4f6;
    --called-text: #111318;
    --accent: #3b82f6;
    --danger: #dc2626;

    --bingo-b: #2563eb;
    --bingo-i: #dc2626;
    --bingo-n: #15803d;
    --bingo-g: #facc15;
    --bingo-o: #7e22ce;
  }

  body {
    background: var(--bg);
    color: var(--text);
  }

  .board-number,
  .login-card,
  .caller-entry,
  .caller-recent,
  .history-section,
  .recent-number,
  .history-game-button {
    background: var(--panel);
    color: var(--text);
  }

  .login-card input,
  .number-entry-row input,
  .history-controls input {
    background: #252a33;
    color: var(--text);
    border-color: var(--border);
  }

  .secondary-button {
    background: #343a45;
    color: var(--text);
  }

  #confirmDialog {
    background: var(--panel);
    color: var(--text);
  }

  .recent-empty,
  .history-game-button span,
  .history-viewer-details,
  .history-message,
  .eyebrow,
  .recent-section h1 {
    color: var(--muted);
  }
}


/* ===== Game type and pattern display ===== */

.game-type-panel,
.participant-game-type {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.game-type-panel {
  padding: 16px 18px;
  margin-bottom: 22px;
}

.participant-game-type {
  padding: 12px 14px;
  margin-bottom: 10px;
}

.game-type-copy {
  min-width: 0;
}

.game-type-copy h1,
.game-type-copy h2 {
  margin: 2px 0 4px;
}

.participant-game-type h1 {
  font-size: 24px;
}

.game-type-rule {
  margin: 4px 0 0;
  color: var(--muted);
  font-weight: 650;
  line-height: 1.3;
}

.pattern-grid {
  flex: 0 0 auto;
  width: 92px;
  height: 92px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 3px;
}

.pattern-grid span {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--panel);
}

.pattern-grid span.pattern-active {
  background: var(--accent);
  border-color: var(--accent);
}

.pattern-grid span.pattern-free {
  box-shadow: inset 0 0 0 2px var(--text);
}

.new-game-options {
  margin-top: 18px;
}

.new-game-options > label {
  display: block;
  margin-bottom: 7px;
  font-weight: 800;
}

.new-game-options select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

.dialog-pattern-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.dialog-pattern-preview > div:first-child {
  flex: 1;
}

.dialog-pattern-preview .pattern-grid {
  width: 76px;
  height: 76px;
}

@media (max-width: 700px) {
  .participant-game-type {
    align-items: center;
  }

  .participant-game-type h1 {
    font-size: 21px;
  }

  .participant-game-type .pattern-grid {
    width: 78px;
    height: 78px;
  }

  .game-type-rule {
    font-size: 14px;
  }
}

@media (prefers-color-scheme: dark) {
  .game-type-panel,
  .participant-game-type {
    background: var(--panel);
    color: var(--text);
  }

  .new-game-options select {
    background: #252a33;
    color: var(--text);
    border-color: var(--border);
  }

  .pattern-grid span {
    background: #252a33;
  }

  .pattern-grid span.pattern-active {
    background: var(--accent);
    border-color: var(--accent);
  }
}


/* ===== G column yellow/gold contrast ===== */

.recent-number.bingo-g,
.board-letter.bingo-g,
.board-number.called.bingo-g {
  color: #111827;
}


/* ===== Archived game pattern ===== */

.history-pattern {
  width: 92px;
  height: 92px;
  margin: 10px 0 16px;
}

@media (max-width: 700px) {
  .history-pattern {
    width: 78px;
    height: 78px;
  }
}

/* ===== Participant portrait board: fit full board to screen ===== */

@media (max-width: 700px) {
  .board-section {
    overflow-x: visible;
  }

  .participant-board {
    min-width: 0;
    width: 100%;
    grid-template-columns: 28px repeat(15, minmax(0, 1fr));
    gap: 2px;
  }

  .participant-board .board-letter,
  .participant-board .board-number {
    height: 28px;
    border-radius: 4px;
  }

  .participant-board .board-letter {
    font-size: 15px;
  }

  .participant-board .board-number {
    font-size: 11px;
  }
}

/* ===== Caller portrait board: fit full board to screen ===== */

@media (max-width: 700px) {
  .caller-board {
    width: 100%;
    overflow-x: visible;
    grid-template-columns: 28px repeat(15, minmax(0, 1fr));
    gap: 2px;
  }

  .caller-board .board-letter,
  .caller-board .board-number {
    height: 28px;
    border-radius: 4px;
  }

  .caller-board .board-letter {
    font-size: 15px;
  }

  .caller-board .board-number {
    font-size: 11px;
  }
}
