:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-dim: #6b6b6b;
  --border: #d8d8dc;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --danger: #c62828;
  --header-bg: #eef1f8;
  --sticky-shadow: rgba(0, 0, 0, 0.08);
  --accent-tint: #e8f0fe;
  --accent-shadow: rgba(47, 111, 237, 0.35);
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --surface: #232429;
    --text: #f0f0f0;
    --text-dim: #a0a0a8;
    --border: #3a3b42;
    --accent: #5b8dfa;
    --accent-text: #0c0c0d;
    --header-bg: #26283a;
    --sticky-shadow: rgba(0, 0, 0, 0.4);
    --accent-tint: #22304d;
    --accent-shadow: rgba(91, 141, 250, 0.4);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: 1rem;
}

button {
  min-height: 44px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 600;
}

button.danger {
  color: var(--danger);
  border-color: var(--danger);
}

input[type="text"],
input[type="number"],
select,
textarea {
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}

.view {
  padding: 0.75rem;
  padding-bottom: 4rem;
  max-width: 900px;
  margin: 0 auto;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 0.75rem;
}

/* History list's game card: the delete button is pinned to the top-right
   corner (taken out of flow) so a long game name wraps around it onto a
   second line instead of pushing the button off to the right and wrapping
   the whole row. */
.game-card {
  position: relative;
}

.game-card-name {
  display: block;
  padding-right: 2.75rem;
  margin-bottom: 0.25rem;
}

.game-card-delete {
  position: absolute;
  top: 1rem;
  right: 1rem;
  min-height: 32px;
  min-width: 32px;
  padding: 0;
}

.muted {
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* Score grid: horizontal scroll allowed, sticky first column + header row.
   max-height + overflow-y makes this box its OWN scrollport — without a
   bounded height, "position: sticky" on the header has nothing to stick
   within once the page itself needs to scroll, so it just scrolls away. */
.grid-scroll {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 65vh;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

table.score-grid {
  border-collapse: collapse;
  width: 100%;
}

table.score-grid th,
table.score-grid td {
  padding: 0.3rem 0.4rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.score-grid thead th {
  position: sticky;
  top: 0;
  background: var(--header-bg);
  z-index: 2;
  box-shadow: 0 2px 0 var(--sticky-shadow);
}

table.score-grid th:first-child,
table.score-grid td:first-child {
  position: sticky;
  left: 0;
  background: var(--header-bg);
  z-index: 1;
  text-align: left;
  font-weight: 600;
}

table.score-grid thead th:first-child {
  z-index: 3;
}

table.score-grid input[type="number"] {
  min-height: 36px;
  width: 3.8rem;
  text-align: center;
  padding: 0.2rem;
}

/* Shared by any score-grid variant whose cell needs two inputs plus a
   computed per-hand total stacked vertically (Canasta's Base/Cards,
   Diminishing Bridge's Bid/Tricks). */
.stacked-cell {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.15rem;
  padding: 0.15rem 0;
}

.stacked-line {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.stacked-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  width: 1.6rem;
  text-align: right;
  flex-shrink: 0;
}

.stacked-cell input[type="number"] {
  width: 3.4rem;
  min-height: 30px;
  padding: 0.15rem;
  font-size: 0.9rem;
}

.stacked-hand-total {
  font-weight: 700;
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  padding-top: 0.15rem;
  margin-top: 0.05rem;
  text-align: center;
}

.stacked-cell-readout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.05rem;
  font-size: 0.85rem;
  line-height: 1.3;
}

.stacked-cell-readout .stacked-hand-total {
  margin-top: 0.1rem;
}

/* Diminishing Bridge's "Hand" column: round number, cards dealt, and the
   per-mistake point cost, stacked in the sticky first column. */
.hand-cell-detail {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
}

.hand-cell-detail .hand-cell-sub {
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--text-dim);
  white-space: nowrap;
}

.reorder-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.markdown-body {
  line-height: 1.5;
}

.markdown-body :first-child {
  margin-top: 0;
}

.markdown-body :last-child {
  margin-bottom: 0;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.25rem;
  margin: 0.5rem 0;
}

.markdown-body li {
  margin-bottom: 0.25rem;
}

.markdown-body code {
  background: var(--header-bg);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  font-size: 0.9em;
}

.reorder-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.reorder-btn {
  min-height: 36px;
  min-width: 36px;
  padding: 0;
  line-height: 1;
  font-size: 0.85rem;
  border-radius: 6px;
  flex-shrink: 0;
}

.reorder-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

table.score-grid tfoot td {
  font-weight: 700;
  border-top: 2px solid var(--border);
  border-bottom: none;
  position: sticky;
  bottom: 0;
  background: var(--surface);
  z-index: 2;
  box-shadow: 0 -2px 0 var(--sticky-shadow);
}

table.score-grid tfoot td:first-child {
  z-index: 3;
  background: var(--header-bg);
}

table.score-grid td.leader {
  color: var(--accent);
}

.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

/* Invisible click-catcher behind a "⋮" dropdown (not a full modal — no
   backdrop tint, no centering). Sits below the dropdown's own z-index but
   above everything else, so the first click outside the menu is absorbed by
   this instead of also reaching whatever button/link happens to be there —
   it just closes the menu instead of closing it AND activating that control. */
.menu-scrim {
  position: fixed;
  inset: 0;
  z-index: 9;
}

.dialog-panel {
  max-width: 420px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

.group-option {
  cursor: pointer;
  transition: background-color 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.group-option:active {
  background: var(--accent-tint);
}

.player-name-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.player-name-row input {
  flex: 1;
  min-width: 0;
}

.player-name-row button {
  flex-shrink: 0;
}

.name-preset-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  align-items: center;
}

.name-preset-row input {
  flex: 1;
  min-width: 0;
}

.name-preset-row select {
  flex-shrink: 0;
  width: auto;
  max-width: 40%;
}

.group-option.selected {
  background: var(--accent-tint);
  border-color: var(--accent);
  box-shadow: 0 4px 12px var(--accent-shadow);
}

header {
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 20;
}
