/**
 * General Scoreboard — styles
 * Theme, RWD, Tabs, Numpad slide-up and grid
 */

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  transition: background-color 0.3s, color 0.3s;
}

body.light-mode {
  background: #f0f0f0;
  color: #222;
}

body.dark {
  background: #181c1f;
  color: #f0f0f0;
}

/* App container */
.scoreboard-app {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: 120px; /* space above numpad when open */
  box-sizing: border-box;
}

.scoreboard-heading {
  text-align: center;
  margin-bottom: 24px;
}

.scoreboard-heading h1 {
  font-size: 1.8em;
  margin: 0.5em 0 0.25em;
  color: #1976d2;
}

body.dark .scoreboard-heading h1 {
  color: #90caf9;
}

.subtitle {
  color: #666;
  font-size: 1em;
  margin: 0;
}

body.dark .subtitle {
  color: #bbb;
}

/* Cards */
.card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border: 1px solid #eee;
}

body.dark .card {
  background: #23272a;
  border-color: #333;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.card h2 {
  margin: 0 0 16px;
  font-size: 1.2em;
  color: #1976d2;
}

body.dark .card h2 {
  color: #90caf9;
}

.card h3 {
  margin: 0 0 12px;
  font-size: 1em;
  font-weight: 600;
  color: #444;
}

body.dark .card h3 {
  color: #bbb;
}

/* Buttons */
.btn {
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 1em;
  font-weight: 600;
  border: 2px solid;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.btn-primary {
  background: #1976d2;
  color: #fff;
  border-color: #1976d2;
}

.btn-primary:hover,
.btn-primary:focus-visible {
  background: #1565c0;
  border-color: #1565c0;
  outline: none;
}

.btn-secondary {
  background: transparent;
  color: #1976d2;
  border-color: #1976d2;
}

.btn-secondary:hover,
.btn-secondary:focus-visible {
  background: rgba(25, 118, 210, 0.1);
  outline: none;
}

body.dark .btn-primary {
  background: #90caf9;
  color: #111;
  border-color: #90caf9;
}

body.dark .btn-primary:hover,
body.dark .btn-primary:focus-visible {
  background: #64b5f6;
  border-color: #64b5f6;
}

body.dark .btn-secondary {
  color: #90caf9;
  border-color: #90caf9;
}

body.dark .btn-secondary:hover,
body.dark .btn-secondary:focus-visible {
  background: rgba(144, 202, 249, 0.15);
}

/* Form */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  color: #333;
}

body.dark .form-group label {
  color: #e0e0e0;
}

.form-group input[type="number"],
.form-group input[type="text"],
.form-group select {
  width: 100%;
  max-width: 280px;
  padding: 10px 12px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 1em;
  background: #fff;
  color: #222;
  box-sizing: border-box;
}

body.dark .form-group input,
body.dark .form-group select {
  background: #2c2f33;
  border-color: #444;
  color: #f0f0f0;
}

.form-group input.score-input {
  cursor: pointer;
}

/* Remark input (normal text, not score-input — uses system keyboard) */
.remark-group {
  margin-top: 12px;
}

.remark-input {
  width: 100%;
  max-width: 100%;
  padding: 10px 12px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 1em;
  background: #fff;
  color: #222;
  box-sizing: border-box;
}

body.dark .remark-input {
  background: #2c2f33;
  border-color: #444;
  color: #f0f0f0;
}

/* Player chips (replace dropdowns) */
.player-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.player-chip {
  padding: 10px 16px;
  font-size: 0.95em;
  font-weight: 600;
  border: 2px solid #ccc;
  border-radius: 999px;
  background: #fff;
  color: #333;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

body.dark .player-chip {
  background: #2a2e32;
  border-color: #555;
  color: #e0e0e0;
}

.player-chip:hover {
  border-color: #1976d2;
  background: rgba(25, 118, 210, 0.08);
}

body.dark .player-chip:hover {
  border-color: #90caf9;
  background: rgba(144, 202, 249, 0.12);
}

.player-chip.selected {
  border-color: #1976d2;
  background: #1976d2;
  color: #fff;
}

body.dark .player-chip.selected {
  border-color: #90caf9;
  background: #90caf9;
  color: #111;
}

.form-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.form-row .form-group {
  flex: 1;
  min-width: 140px;
}

/* Init section */
.init-section .init-form {
  max-width: 480px;
  margin: 0 auto;
}

.player-names-container {
  margin: 16px 0;
}

.player-names-container .form-group {
  margin-bottom: 10px;
}

#startScoreboardBtn {
  margin-top: 8px;
}

/* Dashboard */
.dashboard-section {
  max-width: 900px;
  margin: 0 auto;
}

.dashboard-actions {
  margin-bottom: 20px;
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.session-list-item {
  position: relative;
  display: block;
  width: 100%;
  padding: 16px 20px;
  padding-top: 14px;
  text-align: left;
  border-radius: 12px;
  border: 2px solid #e0e0e0;
  background: #fff;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}

body.dark .session-list-item {
  background: #2a2e32;
  border-color: #444;
}

.session-list-item-settled {
  border-color: #2e7d32;
}

body.dark .session-list-item-settled {
  border-color: #81c784;
}

.session-list-item-badge {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 0.8em;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: #2e7d32;
  color: #fff;
}

body.dark .session-list-item-badge {
  background: #388e3c;
  color: #fff;
}

.session-list-item:hover {
  border-color: #1976d2;
  background: linear-gradient(90deg, rgba(25, 118, 210, 0.08) 0%, rgba(25, 118, 210, 0.02) 100%);
  box-shadow: inset 4px 0 0 #1976d2;
}

body.dark .session-list-item:hover {
  border-color: #90caf9;
  background: linear-gradient(90deg, rgba(144, 202, 249, 0.12) 0%, transparent 100%);
  box-shadow: inset 4px 0 0 #90caf9;
}

.session-list-item-name {
  font-weight: 600;
  font-size: 1.1em;
  margin-bottom: 4px;
  color: #1976d2;
}

body.dark .session-list-item-name {
  color: #90caf9;
}

.session-list-item-meta {
  font-size: 0.9em;
  color: #666;
}

body.dark .session-list-item-meta {
  color: #999;
}

.session-list-empty {
  padding: 24px 20px;
  text-align: center;
  color: #666;
  font-size: 1em;
}

body.dark .session-list-empty {
  color: #999;
}

/* Main section header (current session) */
.main-section-header {
  margin-bottom: 20px;
}

.scoreboard-heading-inline {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  text-align: left;
  margin-bottom: 0;
}

.session-title {
  font-size: 1.4em;
  margin: 0;
  color: #1976d2;
}

body.dark .session-title {
  color: #90caf9;
}

.btn-icon-text {
  padding: 8px 14px;
  font-size: 0.95em;
}

.btn-danger {
  color: #c62828;
  border-color: #c62828;
}

.btn-danger:hover {
  background: rgba(198, 40, 40, 0.1);
}

body.dark .btn-danger {
  color: #ef5350;
  border-color: #ef5350;
}

body.dark .btn-danger:hover {
  background: rgba(239, 83, 80, 0.15);
}

/* Player cards */
.players-section .players-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.players-section .players-header h2 {
  margin: 0;
}

.player-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.player-card {
  padding: 16px;
  border-radius: 10px;
  border: 2px solid #e0e0e0;
  background: linear-gradient(145deg, #fafafa 0%, #f5f7fa 100%);
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}

body.dark .player-card {
  background: linear-gradient(145deg, #2a2e32 0%, #25282c 100%);
  border-color: #444;
}

.player-card:hover {
  border-color: #90caf9;
  box-shadow: 0 2px 12px rgba(25, 118, 210, 0.12);
}

body.dark .player-card:hover {
  border-color: #64b5f6;
  box-shadow: 0 2px 12px rgba(144, 202, 249, 0.15);
}

.player-card-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.player-card-name {
  font-weight: 600;
  color: #333;
  flex: 1;
  min-width: 0;
}

body.dark .player-card-name {
  color: #e0e0e0;
}

.player-card-edit-name-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  color: #666;
  font-size: 0.95em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.player-card-edit-name-btn:hover {
  border-color: #1976d2;
  background: rgba(25, 118, 210, 0.08);
  color: #1976d2;
}

body.dark .player-card-edit-name-btn {
  background: #2a2e32;
  border-color: #555;
  color: #aaa;
}

body.dark .player-card-edit-name-btn:hover {
  border-color: #90caf9;
  background: rgba(144, 202, 249, 0.12);
  color: #90caf9;
}

.player-card-score {
  font-size: 1.5em;
  font-weight: 700;
  color: #1565c0;
  letter-spacing: 0.02em;
}

body.dark .player-card-score {
  color: #90caf9;
}

.player-card-score.positive {
  color: #2e7d32;
}

body.dark .player-card-score.positive {
  color: #81c784;
}

.player-card-score.negative {
  color: #c62828;
}

body.dark .player-card-score.negative {
  color: #ef5350;
}

.player-card-score.score-update {
  animation: scoreFlash 0.4s ease;
}

@keyframes scoreFlash {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); opacity: 0.9; }
  100% { transform: scale(1); }
}

/* Tabs */
.tabs-container {
  overflow: hidden;
}

.tabs-header {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
  border-bottom: 2px solid #e0e0e0;
  padding-bottom: 0;
}

body.dark .tabs-header {
  border-bottom-color: #444;
}

.tab-btn {
  padding: 10px 14px;
  font-size: 0.95em;
  font-weight: 600;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  background: transparent;
  color: #666;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

body.dark .tab-btn {
  color: #999;
}

.tab-btn:hover {
  color: #1976d2;
}

body.dark .tab-btn:hover {
  color: #90caf9;
}

.tab-btn.active {
  color: #1976d2;
  border-bottom-color: #1976d2;
}

body.dark .tab-btn.active {
  color: #90caf9;
  border-bottom-color: #90caf9;
}

/* HK Mahjong tab accent */
.tab-btn[data-mode="e"].active {
  color: #e65100;
  border-bottom-color: #ff9800;
}

body.dark .tab-btn[data-mode="e"].active {
  color: #ffb74d;
  border-bottom-color: #ffb74d;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Mode forms */
.mode-losers,
.mode-winners {
  margin: 16px 0;
}

.mode-losers .form-group,
.mode-winners .form-group {
  margin-bottom: 12px;
}

.mode-a-form .btn,
.mode-b-form .btn,
.mode-c-form .btn,
.mode-d-form .btn,
.mode-e-form .btn {
  margin-top: 8px;
}

/* Win type label + rules hint on one line */
.mode-e-form .form-group:has(.mode-e-rules-hint) > label {
  display: inline;
}
.mode-e-rules-hint {
  display: inline;
  margin-left: 6px;
  cursor: help;
  font-size: 1rem;
  opacity: 0.75;
  color: #666;
  font-style: normal;
}
body.dark .mode-e-rules-hint {
  color: #aaa;
}

/* Who's playing this hand? (Select 4) - when session has >4 players */
.mode-e-playing-hint {
  font-size: 0.9rem;
  color: #666;
  margin: 4px 0 8px;
}
body.dark .mode-e-playing-hint {
  color: #aaa;
}
.mode-e-playing-chips .player-chip.selected {
  border-color: #f57c00;
  background: rgba(245, 124, 0, 0.2);
}
body.dark .mode-e-playing-chips .player-chip.selected {
  border-color: #ffb74d;
  background: rgba(255, 183, 77, 0.2);
}
.mode-e-playing-count {
  font-size: 0.9rem;
  margin-top: 6px;
  color: #666;
}
body.dark .mode-e-playing-count {
  color: #aaa;
}
.mode-e-playing-count.mode-e-playing-ok {
  font-weight: 600;
  color: #2e7d32;
}
body.dark .mode-e-playing-count.mode-e-playing-ok {
  color: #81c784;
}

.mode-e-win-type {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.mode-e-radio-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 999px;
  border: 2px solid #ccc;
  background: #fff;
  color: #333;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.mode-e-radio-label input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.mode-e-radio-label:hover {
  border-color: #1976d2;
  background: rgba(25, 118, 210, 0.08);
}

.mode-e-radio-label:has(input:checked) {
  border-color: #1976d2;
  background: #1976d2;
  color: #fff;
}

body.dark .mode-e-radio-label {
  background: #2a2e32;
  border-color: #555;
  color: #e0e0e0;
}

body.dark .mode-e-radio-label:hover {
  border-color: #90caf9;
  background: rgba(144, 202, 249, 0.12);
}

body.dark .mode-e-radio-label:has(input:checked) {
  border-color: #90caf9;
  background: #90caf9;
  color: #111;
}

/* Mode E panel: light warm accent */
#panelE .mode-e-form {
  padding: 12px 0 0;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(255, 152, 0, 0.06) 0%, transparent 120%);
}

body.dark #panelE .mode-e-form {
  background: linear-gradient(180deg, rgba(255, 183, 77, 0.08) 0%, transparent 120%);
}

/* Mode E mahjong stats - fun cards */
.mode-e-stats {
  margin-top: 20px;
  padding: 16px;
  background: linear-gradient(145deg, rgba(255, 152, 0, 0.06) 0%, rgba(255, 193, 7, 0.04) 100%);
  border-radius: 14px;
  border: 1px dashed rgba(255, 152, 0, 0.35);
}
body.dark .mode-e-stats {
  background: linear-gradient(145deg, rgba(255, 183, 77, 0.08) 0%, rgba(255, 152, 0, 0.04) 100%);
  border-color: rgba(255, 183, 77, 0.4);
}
.mode-e-stats-title {
  margin: 0 0 14px 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: #e65100;
  letter-spacing: 0.02em;
}
body.dark .mode-e-stats-title {
  color: #ffb74d;
}
.mode-e-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.mode-e-stat-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  transition: transform 0.2s, box-shadow 0.2s;
}
.mode-e-stat-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.mode-e-stat-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}
.mode-e-stat-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mode-e-stat-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  opacity: 0.9;
}
.mode-e-stat-value {
  font-size: 0.9rem;
  line-height: 1.3;
}
.mode-e-stat-value strong {
  font-weight: 700;
  opacity: 0.95;
}
/* Crown champion - gold */
.mode-e-stat-wins {
  border-color: #f9a825;
  background: linear-gradient(135deg, #fffde7 0%, #fff8e1 100%);
  color: #f57f17;
}
body.dark .mode-e-stat-wins {
  border-color: #ffb300;
  background: linear-gradient(135deg, rgba(255, 193, 7, 0.15) 0%, rgba(255, 152, 0, 0.1) 100%);
  color: #ffb74d;
}
/* Self-draw king - green */
.mode-e-stat-selfdraw {
  border-color: #66bb6a;
  background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
  color: #2e7d32;
}
body.dark .mode-e-stat-selfdraw {
  border-color: #81c784;
  background: linear-gradient(135deg, rgba(129, 199, 132, 0.2) 0%, rgba(102, 187, 106, 0.1) 100%);
  color: #a5d6a7;
}
/* Fish of the day - warm orange/red */
.mode-e-stat-discard {
  border-color: #ff8a65;
  background: linear-gradient(135deg, #fbe9e7 0%, #ffccbc 100%);
  color: #bf360c;
}
body.dark .mode-e-stat-discard {
  border-color: #ffab91;
  background: linear-gradient(135deg, rgba(255, 138, 101, 0.2) 0%, rgba(255, 171, 145, 0.1) 100%);
  color: #ffab91;
}
/* Pack master - purple */
.mode-e-stat-baau {
  border-color: #ba68c8;
  background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%);
  color: #6a1b9a;
}
body.dark .mode-e-stat-baau {
  border-color: #ce93d8;
  background: linear-gradient(135deg, rgba(186, 104, 200, 0.2) 0%, rgba(206, 147, 216, 0.1) 100%);
  color: #e1bee7;
}

/* History Log */
.history-section .history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.history-section .history-header h2 {
  margin: 0;
}

.history-list {
  max-height: 280px;
  overflow-y: auto;
  padding: 8px 0;
  border-radius: 10px;
  background: linear-gradient(180deg, #f5f7fa 0%, #f0f2f5 100%);
  border: 1px solid #e8eaed;
}

body.dark .history-list {
  background: linear-gradient(180deg, #1e2226 0%, #1a1e21 100%);
  border-color: #333;
}

.history-item {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px 12px;
  padding: 10px 12px;
  margin-bottom: 6px;
  border-radius: 8px;
  border-left: 4px solid #1976d2;
  background: #fff;
  font-size: 0.9em;
  line-height: 1.4;
  transition: background 0.2s, border-left-color 0.2s;
}

.history-item:nth-child(odd) {
  background: #f8fafc;
}

body.dark .history-item {
  background: #2a2e32;
  border-left-color: #90caf9;
}

body.dark .history-item:nth-child(odd) {
  background: #24282c;
}

.history-item:last-child {
  margin-bottom: 0;
}

.history-item-time {
  font-weight: 600;
  color: #666;
  margin-right: 8px;
}

body.dark .history-item-time {
  color: #aaa;
}

.history-item-message {
  flex: 1;
  min-width: 0;
  color: #222;
}

body.dark .history-item-message {
  color: #e0e0e0;
}

.history-item-message .history-msg-positive {
  color: #2e7d32;
  font-weight: 700;
}

body.dark .history-item-message .history-msg-positive {
  color: #81c784;
}

.history-item-message .history-msg-negative {
  color: #c62828;
  font-weight: 700;
}

body.dark .history-item-message .history-msg-negative {
  color: #ef5350;
}

.history-item-remark {
  width: 100%;
  margin-top: 4px;
  font-size: 0.9em;
  color: #1976d2;
}

body.dark .history-item-remark {
  color: #90caf9;
}

.history-item-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.history-item-edit-btn,
.history-item-delete-btn {
  box-sizing: border-box;
  line-height: 1.25;
}

/* Icon-only buttons for history row - compact on mobile */
.history-item-icon-btn {
  padding: 8px 10px;
  font-size: 1.1em;
  font-weight: 600;
  min-width: 40px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

.history-item-icon-btn span {
  line-height: 1;
  pointer-events: none;
}

.history-item-edit-btn {
  background: transparent;
  border-color: #7b1fa2;
  color: #7b1fa2;
}

.history-item-edit-btn:hover,
.history-item-edit-btn:focus-visible {
  background: rgba(123, 31, 162, 0.1);
  outline: none;
}

.history-item-delete-btn {
  background: transparent;
}

body.dark .history-item-edit-btn {
  border-color: #ce93d8;
  color: #ce93d8;
}

body.dark .history-item-edit-btn:hover,
body.dark .history-item-edit-btn:focus-visible {
  background: rgba(206, 147, 216, 0.15);
}

body.dark .history-item-delete-btn {
  background: transparent;
}

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

.history-list:empty::before,
.history-list .history-empty::before {
  content: attr(data-empty);
  display: block;
  padding: 16px;
  text-align: center;
  color: #999;
  font-size: 0.95em;
}

body.dark .history-list .history-empty {
  color: #666;
}

/* Main actions */
.main-actions {
  margin-top: 24px;
  text-align: center;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 500;
  z-index: 10000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  animation: toastIn 0.25s ease;
}

body.light-mode .toast {
  background: #333;
  color: #fff;
}

body.dark .toast {
  background: #90caf9;
  color: #111;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ---------- Custom Numpad ---------- */
.numpad-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}

.numpad-overlay[hidden] {
  display: none;
}

.numpad-overlay.is-open {
  pointer-events: auto;
}

.numpad-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.numpad-overlay.is-open .numpad-backdrop {
  opacity: 1;
}

.numpad-panel {
  position: relative;
  width: 100%;
  max-width: 400px;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  transform: translateY(100%);
  transition: transform 0.3s ease-out;
  background: #f5f5f5;
}

body.dark .numpad-panel {
  background: #2a2e32;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
}

.numpad-overlay.is-open .numpad-panel {
  transform: translateY(0);
}

/* Quick buttons */
.numpad-quick {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.numpad-quick-btn {
  flex: 1;
  min-width: 64px;
  padding: 10px 12px;
  font-size: 0.95em;
  font-weight: 600;
  border: 2px solid #ccc;
  border-radius: 8px;
  background: #fff;
  color: #333;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

body.dark .numpad-quick-btn {
  background: #3a3e42;
  border-color: #555;
  color: #f0f0f0;
}

.numpad-quick-btn:active {
  transform: scale(0.97);
  background: #e0e0e0;
  border-color: #1976d2;
}

body.dark .numpad-quick-btn:active {
  background: #4a4e52;
  border-color: #90caf9;
}

/* Numpad grid */
.numpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.numpad-key {
  min-height: 52px;
  padding: 12px;
  font-size: 1.4em;
  font-weight: 600;
  border: 2px solid #ddd;
  border-radius: 10px;
  background: #fff;
  color: #222;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

body.dark .numpad-key {
  background: #3a3e42;
  border-color: #555;
  color: #f0f0f0;
}

.numpad-key:hover {
  background: #f0f0f0;
  border-color: #1976d2;
}

body.dark .numpad-key:hover {
  background: #4a4e52;
  border-color: #90caf9;
}

.numpad-key:active {
  transform: scale(0.97);
  background: #e0e0e0;
  border-color: #1976d2;
}

body.dark .numpad-key:active {
  background: #5a5e62;
  border-color: #90caf9;
}

.numpad-backspace,
.numpad-enter {
  font-size: 1.2em;
}

.numpad-enter {
  background: #1976d2;
  color: #fff;
  border-color: #1976d2;
}

body.dark .numpad-enter {
  background: #90caf9;
  color: #111;
  border-color: #90caf9;
}

.numpad-enter:active {
  background: #1565c0;
}

body.dark .numpad-enter:active {
  background: #64b5f6;
}

/* RWD */
@media (max-width: 640px) {
  .scoreboard-app {
    padding: 12px;
    padding-bottom: 100px;
  }

  .scoreboard-heading h1 {
    font-size: 1.5em;
  }

  .player-cards {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .tabs-header {
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox: hide scrollbar */
    -ms-overflow-style: none; /* IE/Edge: hide scrollbar */
  }

  .tabs-header::-webkit-scrollbar {
    display: none; /* Chrome/Safari: hide scrollbar */
  }

  .tab-btn {
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 0.9em;
  }

  .form-group input[type="number"],
  .form-group input[type="text"],
  .form-group select {
    max-width: none;
  }

  .numpad-key {
    min-height: 48px;
    font-size: 1.25em;
  }

  .numpad-quick-btn {
    min-width: 56px;
    padding: 8px 10px;
    font-size: 0.9em;
  }
}

@media (min-width: 641px) {
  .numpad-key {
    min-height: 56px;
  }
}

/* ---------- Zero-sum error modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  padding: 20px;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

body.dark .modal-content {
  background: #2a2e32;
}

.modal-content .form-select {
  width: 100%;
  max-width: 280px;
  padding: 8px 12px;
  font-size: 1rem;
  border-radius: 8px;
  border: 1px solid #ccc;
  background: #fff;
}
body.dark .modal-content .form-select {
  background: #2a2e32;
  border-color: #555;
  color: #e0e0e0;
}

.history-edit-mode-e {
  margin-bottom: 12px;
}
.history-edit-mode-e .form-group {
  margin-bottom: 10px;
}
.history-edit-mode-e .player-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Add player modal: quick-pick chips */
.add-player-recent-chips {
  max-height: 140px;
  overflow-y: auto;
  margin-bottom: 4px;
}
.add-player-recent-chips .player-chip {
  cursor: pointer;
}

/* Init form: quick fill chips */
.init-quick-fill-group {
  margin-bottom: 12px;
}
.init-quick-fill-chips {
  max-height: 100px;
  overflow-y: auto;
}
.init-quick-fill-chips .player-chip {
  cursor: pointer;
}

.modal-content.modal-error {
  border: 2px solid #c62828;
}

body.dark .modal-content.modal-error {
  border-color: #ef5350;
}

.modal-message {
  margin: 0 0 20px;
  font-size: 1.05em;
  line-height: 1.5;
  color: #222;
}

body.dark .modal-message {
  color: #e0e0e0;
}

/* ---------- Settlement (View C) ---------- */
.settlement-section {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: 80px;
}

.settlement-card {
  margin-bottom: 20px;
}

.settlement-card h2 {
  margin: 0 0 16px;
}

.settlement-leaderboard {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settlement-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #eee;
}

body.dark .settlement-row {
  border-bottom-color: #444;
}

.settlement-row:last-child {
  border-bottom: none;
}

.settlement-rank {
  flex-shrink: 0;
  width: 28px;
  font-weight: 700;
  color: #666;
}

body.dark .settlement-rank {
  color: #999;
}

.settlement-row.winner {
  background: linear-gradient(90deg, rgba(46, 125, 50, 0.08) 0%, transparent 100%);
  border-radius: 8px;
  padding-left: 12px;
  margin: 0 -12px;
  padding-right: 12px;
}

body.dark .settlement-row.winner {
  background: linear-gradient(90deg, rgba(129, 199, 132, 0.12) 0%, transparent 100%);
}

.settlement-row.winner .settlement-rank {
  color: #2e7d32;
}

body.dark .settlement-row.winner .settlement-rank {
  color: #81c784;
}

.settlement-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
}

.settlement-net {
  flex-shrink: 0;
  font-weight: 700;
  font-size: 1.1em;
}

.settlement-net.positive {
  color: #2e7d32;
}

body.dark .settlement-net.positive {
  color: #81c784;
}

.settlement-net.negative {
  color: #c62828;
}

body.dark .settlement-net.negative {
  color: #ef5350;
}

.settlement-bar-wrap {
  flex: 0 1 120px;
  height: 12px;
  background: #e0e0e0;
  border-radius: 999px;
  overflow: hidden;
}

body.dark .settlement-bar-wrap {
  background: #444;
}

.settlement-bar {
  height: 100%;
  border-radius: 999px;
  min-width: 0;
  transition: width 0.3s ease;
}

.settlement-bar.positive {
  background: #2e7d32;
}

body.dark .settlement-bar.positive {
  background: #81c784;
}

.settlement-bar.negative {
  background: #c62828;
}

body.dark .settlement-bar.negative {
  background: #ef5350;
}

.settlement-stats {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #eee;
  font-size: 0.95em;
  color: #666;
}

body.dark .settlement-stats {
  border-top-color: #444;
  color: #999;
}

.settlement-plan {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settlement-plan-item {
  padding: 10px 12px;
  border-radius: 8px;
  border-left: 4px solid #1976d2;
  background: #f5f5f5;
  font-size: 0.95em;
}

body.dark .settlement-plan-item {
  background: #2a2e32;
  border-left-color: #90caf9;
}

.settlement-plan-empty {
  color: #666;
  font-style: italic;
}

body.dark .settlement-plan-empty {
  color: #999;
}

.settlement-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}
