/* ---------- Design tokens ---------- */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;

  --bg: #f5f5f7;
  --bg-elevated: #ffffff;
  --card: #ffffff;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #98989d;
  --accent: #0071e3;
  --accent-contrast: #ffffff;
  --separator: rgba(0, 0, 0, 0.08);
  --danger: #ff3b30;
  --success: #34c759;

  --radius-xl: 32px;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --shadow-pill: 0 8px 30px rgba(0, 0, 0, 0.18), 0 1px 1px rgba(0, 0, 0, 0.06);
  --shadow-sheet: 0 -8px 40px rgba(0, 0, 0, 0.2);

  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.5);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --card: #1c1c1e;
    --text: #f5f5f7;
    --text-secondary: #98989d;
    --text-tertiary: #6e6e73;
    --separator: rgba(255, 255, 255, 0.1);
    --glass-bg: rgba(28, 28, 30, 0.72);
    --glass-border: rgba(255, 255, 255, 0.08);
    color-scheme: dark;
  }
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  touch-action: manipulation;
  overflow-x: hidden;
}
button { font-family: inherit; }
input { font-family: inherit; }
h1, h2, h3, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
button, a, input, label {
  touch-action: manipulation;
}
button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  background: none;
  border: none;
  appearance: none;
  font: inherit;
  color: inherit;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 20px calc(140px + env(safe-area-inset-bottom));
}

@keyframes screen-enter-right {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
.screen-enter-right {
  animation: screen-enter-right 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}

/* ---------- Home screen ---------- */
.home-header {
  padding: 28px 4px 8px;
  text-align: center;
}
.home-header .logo {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  overflow: hidden;
  margin: 0 auto 14px;
  box-shadow: var(--shadow-card);
}
.home-header .logo img { width: 100%; height: 100%; display: block; object-fit: cover; }
.home-header h1 {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.home-header p {
  color: var(--text-secondary);
  font-size: 16px;
  margin-top: 6px;
}

.game-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 28px;
}
@media (min-width: 520px) {
  .game-grid { grid-template-columns: 1fr 1fr; }
}

.game-tile {
  position: relative;
  border: none;
  text-decoration: none;
  border-radius: var(--radius-xl);
  padding: 26px 22px;
  text-align: left;
  min-height: 168px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  color: #fff;
}
.game-tile:active { transform: scale(0.97); }

.game-tile.tile-golf {
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(255, 255, 255, 0.12), transparent 55%),
    linear-gradient(160deg, #2d5a3d 0%, #1b3a2b 55%, #12261c 100%);
}
.game-tile.tile-farkle {
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(255, 255, 255, 0.12), transparent 55%),
    linear-gradient(160deg, #5b5cf0 0%, #3f3fb0 60%, #2c2c86 100%);
}

.game-tile .tile-icon {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 44px;
  height: 44px;
  opacity: 0.9;
}
.tile-icon img, .tile-icon svg { width: 100%; height: 100%; display: block; }
.tile-icon .icon-img { object-fit: contain; }
.game-tile .tile-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.game-tile .tile-sub {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.78);
}
.game-tile .tile-resume {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.95);
  background: rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  width: fit-content;
  backdrop-filter: blur(6px);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.tile-resume svg { width: 12px; height: 12px; flex-shrink: 0; }

.app-version {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(14px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-tertiary);
  pointer-events: none;
}

/* ---------- Section / cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
}
.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin: 24px 4px 10px;
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: var(--radius-pill);
  padding: 14px 22px;
  font-size: 16px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.btn:active { transform: scale(0.96); }
.btn svg, .btn img { width: 18px; height: 18px; flex-shrink: 0; }
.btn-primary { background: var(--accent); color: #fff; width: 100%; }
.btn-primary:disabled { opacity: 0.4; }
.btn-secondary { background: rgba(120, 120, 128, 0.14); color: var(--text); }
.btn-danger { background: rgba(255, 59, 48, 0.12); color: var(--danger); }
.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(120, 120, 128, 0.14);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  flex-shrink: 0;
}
.btn-icon svg, .btn-icon img { width: 20px; height: 20px; flex-shrink: 0; }
.btn-block { width: 100%; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0 4px;
}
.topbar .title-block { flex: 1; min-width: 0; text-align: center; }
.topbar h1 {
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .subtitle {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ---------- Setup screen ---------- */
.player-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--separator);
  transition: opacity 0.15s ease;
}
.player-row:last-child { border-bottom: none; }
.player-row.dragging { opacity: 0.4; }
.drag-handle {
  border: none;
  background: none;
  color: var(--text-tertiary);
  width: 28px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  touch-action: none;
  cursor: grab;
  margin-left: -6px;
}
.drag-handle svg { width: 18px; height: 18px; }
.player-avatar {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  cursor: pointer;
  overflow: hidden;
}
.avatar-color-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  padding: 0;
  cursor: pointer;
}
.player-row input[type="text"] {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--text);
  outline: none;
  min-width: 0;
}
.player-row .remove-btn {
  border: none;
  background: none;
  color: var(--text-tertiary);
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
}
.player-row .remove-btn svg { width: 18px; height: 18px; display: block; }
.first-player-card { padding: 4px 8px; }
.first-player-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 8px;
  border: none;
  background: none;
  border-bottom: 1px solid var(--separator);
  text-align: left;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.first-player-row:last-child { border-bottom: none; }
.first-player-row:active { background: rgba(120, 120, 128, 0.1); border-radius: var(--radius-sm); }
.first-player-name { flex: 1; }
.pick-for-me-wrap {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}
.pick-for-me-btn {
  padding: 10px 18px;
  font-size: 14px;
}
.pick-for-me-btn svg { width: 15px; height: 15px; }

.add-player-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 4px 4px;
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
  background: none;
  border: none;
  appearance: none;
  white-space: nowrap;
}
.add-player-row svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ---------- Scorecard table ---------- */
.scorecard-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  background: var(--card);
  -webkit-overflow-scrolling: touch;
}
table.scorecard {
  border-collapse: collapse;
  width: 100%;
  font-variant-numeric: tabular-nums;
}
table.scorecard th, table.scorecard td {
  padding: 16px 18px;
  text-align: center;
  font-size: 14px;
  border-bottom: 1px solid var(--separator);
  white-space: nowrap;
}
table.scorecard th.round-col, table.scorecard td.round-col {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--card);
  font-weight: 600;
  z-index: 1;
}
table.scorecard thead th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
table.scorecard tr.totals-row td {
  font-weight: 700;
  font-size: 15px;
  border-bottom: 2px solid var(--separator);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}
table.scorecard tr.totals-row td.round-col {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--card);
}
table.scorecard tr.row-current td.round-col { color: var(--accent); font-weight: 700; }
table.scorecard td.cell-current {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-radius: 8px;
  font-weight: 700;
}
table.scorecard td.cell-empty { color: var(--text-tertiary); }
table.scorecard td.cell-editable { cursor: pointer; }
table.scorecard td.cell-editable:active {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-radius: 8px;
}
table.scorecard th.col-winner, table.scorecard td.col-winner { color: var(--success); }

/* ---------- Standings bar ---------- */
/* Scrolls sideways with the scrollbar hidden; negative margin + matching
   padding lets the pills run under the screen edges. */
.standings-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 10px -20px 18px;
  padding: 0 20px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.standings-bar::-webkit-scrollbar { display: none; }
.standing-pill {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--radius-pill);
  padding: 9px 16px;
  color: #fff;
  font: inherit;
}
.standing-pill {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.standing-pill.is-tappable { cursor: pointer; transition: transform 0.12s ease; }
.standing-pill.is-tappable:active { transform: scale(0.96); }
.standing-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.standing-score {
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- Turn / entry card ---------- */
.turn-card {
  border-radius: var(--radius-xl);
  padding: 24px;
  color: #fff;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}
.turn-card .eyebrow {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.75;
}
.turn-card .player-name {
  font-size: 28px;
  font-weight: 700;
  margin-top: 4px;
  letter-spacing: -0.01em;
}
.turn-card .round-label {
  font-size: 14px;
  opacity: 0.85;
  margin-top: 2px;
}

.quick-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 18px;
}
.quick-buttons button {
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
}
.quick-buttons button.active {
  background: #fff;
  color: #1d1d1f;
}

.keypad-display {
  text-align: center;
  font-size: 44px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin: 18px 0 16px;
  min-height: 52px;
}
.keypad {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
}
.keypad-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.keypad-key {
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 20px;
  font-weight: 600;
  padding: 16px 0;
  border-radius: var(--radius-md);
}
.keypad-key:active { background: rgba(255, 255, 255, 0.26); }
.keypad-key.keypad-func {
  background: rgba(255, 255, 255, 0.24);
  font-size: 18px;
}

.turn-card .btn-enter {
  width: 100%;
  background: #fff;
  color: #1d1d1f;
  border: none;
  border-radius: var(--radius-pill);
  padding: 15px;
  font-size: 16px;
  font-weight: 700;
}
.turn-card .btn-enter:active { transform: scale(0.98); }
.turn-card .btn-farkle {
  width: 100%;
  margin-top: 10px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  padding: 13px;
  font-size: 14px;
  font-weight: 700;
}
.turn-card .btn-farkle:active { background: rgba(255, 255, 255, 0.24); }

/* ---------- Golf theme ---------- */
/* Flat color on both html and body (not a gradient, and no fixed attachment)
   — html covers the safe-area strip behind the notch/status bar, which
   Safari paints from <html>'s background rather than <body>'s, and a plain
   flat fill there can't visually "stick" the way a fixed-attachment gradient
   band does when the page scrolls underneath it. */
html.theme-golf, body.theme-golf {
  background: #0f2318;
}
body.theme-golf {
  --bg: #0f2318;
  --bg-elevated: #16311f;
  --card: #f3ecd8;
  --text: #f5f1e4;
  --text-secondary: #c9b896;
  --accent: #b8843b;
  --separator: rgba(0, 0, 0, 0.08);
  --glass-bg: rgba(22, 40, 28, 0.72);
  --glass-border: rgba(255, 255, 255, 0.1);
  color-scheme: dark;
}
body.theme-golf .topbar,
body.theme-golf .btn-icon-label { color: #f5f1e4; }
body.theme-golf .btn-icon {
  background: rgba(255, 255, 255, 0.1);
  color: #f5f1e4;
}
body.theme-golf table.scorecard { color: #3b2a17; }
body.theme-golf .card {
  color: #3b2a17;
  --text: #3b2a17;
  --text-secondary: #7a6a49;
  --text-tertiary: #a8926a;
  --separator: rgba(59, 42, 23, 0.12);
}
body.theme-golf table.scorecard th.round-col, body.theme-golf table.scorecard td.round-col { background: #f3ecd8; }
body.theme-golf table.scorecard tr.totals-row td.round-col { background: #f3ecd8; }
body.theme-golf table.scorecard thead th { color: #7a6a49; }
body.theme-golf table.scorecard td.cell-current { background: rgba(184, 132, 59, 0.24); }
body.theme-golf .section-title { color: #c9b896; }
body.theme-golf .empty-state { color: #cdbf9c; }
body.theme-golf .empty-state .btn-secondary { background: rgba(255,255,255,0.12); color: #f5f1e4; }

/* ---------- Farkle theme ---------- */
html.theme-farkle {
  background: #f2f2f5;
}
body.theme-farkle {
  --bg: #f2f2f5;
  --card: #ffffff;
  --accent: #5b5cf0;
}
@media (prefers-color-scheme: dark) {
  body.theme-farkle { --bg: #000000; --card: #1c1c1e; }
  html.theme-farkle { background: #000000; }
}
body.theme-farkle table.scorecard td.cell-current { background: rgba(91, 92, 240, 0.14); }

/* ---------- Winner banner ---------- */
.winner-banner {
  border-radius: var(--radius-xl);
  padding: 26px 22px;
  text-align: center;
  color: #fff;
  background: linear-gradient(160deg, #34c759, #1f8a3b);
  box-shadow: var(--shadow-card);
}
.winner-banner .trophy { display: flex; justify-content: center; }
.winner-banner .trophy svg { width: 56px; height: auto; }
.winner-banner h2 { font-size: 22px; font-weight: 700; margin-top: 6px; }
.winner-banner p { margin-top: 4px; opacity: 0.9; font-size: 14px; }
.winner-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.winner-action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  padding: 12px;
  font-size: 14px;
  font-weight: 700;
}
.winner-action-btn:active { background: rgba(255, 255, 255, 0.3); }
.winner-action-btn:disabled { opacity: 0.6; }
.winner-action-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}
.empty-state .icon { font-size: 40px; margin-bottom: 10px; }

/* ---------- Bottom pill nav (Apple Music style) ---------- */
.pill-nav-wrap {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  /* Left/right reuse the same expression as bottom (rather than a plain
     fixed value) so the pill's side margins render numerically equal to
     its bottom margin, home-indicator inset included. */
  padding: 0 calc(6px + env(safe-area-inset-bottom)) calc(6px + env(safe-area-inset-bottom));
  pointer-events: none;
  z-index: 40;
}
.pill-nav {
  pointer-events: auto;
  width: 100%;
  max-width: 560px;
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-pill);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px;
  min-height: 58px;
  transition: transform 0.15s ease;
}
.pill-nav:active { transform: scale(0.99); }
.pill-nav .pill-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  flex-shrink: 0;
}
.pill-nav .pill-avatar svg, .pill-nav .pill-avatar .icon-img { width: 20px; height: 20px; object-fit: contain; }
.pill-nav .pill-info {
  flex: 1;
  min-width: 0;
  text-align: left;
}
.pill-nav .pill-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill-nav .pill-sub {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill-nav .pill-rules-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: rgba(120, 120, 128, 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text);
}
.pill-nav .pill-rules-btn svg { width: 19px; height: 19px; }
.pill-nav.is-idle .pill-title { color: var(--text-secondary); font-weight: 500; }

/* ---------- Expandable sheet ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg-elevated);
  border-radius: 28px 28px 0 0;
  box-shadow: var(--shadow-sheet);
  z-index: 51;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sheet.open { transform: translateY(0); }
.sheet .sheet-handle {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--separator);
  margin: 10px auto 4px;
  flex-shrink: 0;
}
.sheet .sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 20px 12px;
  flex-shrink: 0;
}
.sheet .sheet-header h2 { font-size: 17px; font-weight: 700; }
.sheet-body {
  padding: 0 20px 24px;
  overflow-y: auto;
}
.sheet-body.rules-body {
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
}
.sheet-body.rules-body h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin: 18px 0 8px;
}
.sheet-body.rules-body h3:first-child { margin-top: 0; }
.sheet-body.rules-body ul { padding-left: 18px; list-style: disc; }
.sheet-body.rules-body li { margin-bottom: 6px; }
.sheet-body.rules-body .note {
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-secondary);
  font-style: italic;
}

/* ---------- Confirm dialog ---------- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 24px;
}
.confirm-box {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 22px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-card);
}
.confirm-box h3 { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.confirm-box p { font-size: 14px; color: var(--text-secondary); margin-bottom: 16px; }
.confirm-box .confirm-actions { display: flex; gap: 10px; }
.confirm-box .confirm-actions .btn { flex: 1; padding: 12px; font-size: 15px; }

.new-game-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.new-game-actions .btn { width: 100%; padding: 13px; font-size: 15px; }
.new-game-cancel {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  padding: 6px;
}

.edit-score-box { max-width: 340px; }
.edit-score-box .keypad-display { color: var(--text); }
.edit-score-box .keypad-key {
  background: rgba(120, 120, 128, 0.14);
  color: var(--text);
}
.edit-score-box .keypad-key:active { background: rgba(120, 120, 128, 0.24); }
.edit-score-box .keypad-key.keypad-func { background: rgba(120, 120, 128, 0.22); }
#edit-score-remove {
  margin-top: 14px;
  background: none;
  border: none;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(28, 28, 30, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 500;
  z-index: 70;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Score entry / edit player dialogs ---------- */
.score-dialog-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  text-align: left;
}
.score-dialog-head h3 {
  flex: 1;
  min-width: 0;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.score-dialog-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.dialog-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(120, 120, 128, 0.18);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.dialog-icon-btn svg { width: 16px; height: 16px; }
.hole-picker {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
}
.hole-chip {
  height: 34px;
  border-radius: 10px;
  background: rgba(120, 120, 128, 0.14);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  padding: 0;
}
.hole-chip.filled { color: var(--text); background: rgba(120, 120, 128, 0.28); }
.hole-chip.active { background: var(--accent); color: #fff; }
.is-tappable { cursor: pointer; }
.row-edit-icon { color: var(--text-tertiary); display: flex; margin-left: 4px; }
.row-edit-icon svg { width: 16px; height: 16px; }
table.scorecard td.cell-tappable { cursor: pointer; }

.edit-player-box { max-width: 340px; }
.edit-player-preview { display: flex; justify-content: center; margin: 12px 0; }
.player-avatar.big { width: 64px; height: 64px; font-size: 24px; cursor: default; }
.dialog-input {
  width: 100%;
  border: none;
  outline: none;
  border-radius: 12px;
  background: rgba(120, 120, 128, 0.18);
  color: var(--text);
  font-size: 16px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.swatch-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}
.swatch {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  padding: 0;
  cursor: pointer;
}
.swatch.selected { box-shadow: 0 0 0 2px var(--bg-elevated), 0 0 0 4px var(--text); }
.swatch-custom {
  background: conic-gradient(#ff375f, #ff9f0a, #ffd60a, #34c759, #64d2ff, #0071e3, #bf5af2, #ff375f);
  overflow: hidden;
}
.swatch-custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

/* ---------- Entry card header + hole chips ---------- */
.turn-head { display: flex; align-items: flex-start; gap: 12px; }
.turn-head-text { flex: 1; min-width: 0; }
.turn-edit-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.turn-edit-btn:active { background: rgba(255, 255, 255, 0.34); }
.turn-edit-btn svg { width: 17px; height: 17px; }
.turn-holes {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
  margin-top: 14px;
}
.turn-hole {
  height: 32px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.75);
  font-size: 14px;
  font-weight: 600;
  padding: 0;
}
.turn-hole.filled { background: rgba(255, 255, 255, 0.26); color: #fff; }
.turn-hole.active { background: #fff; color: #1d1d1f; }

/* ---------- Game Library ---------- */
.game-tile.tile-library {
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(255, 255, 255, 0.12), transparent 55%),
    linear-gradient(160deg, #f0567a 0%, #c23a6b 55%, #7a2a5e 100%);
}
@media (min-width: 520px) {
  .game-grid .tile-library { grid-column: 1 / -1; }
}

.home-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 8px;
}
.see-all {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  margin-right: 4px;
}
.recent-row {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  margin: 0 -20px;
  padding: 4px 20px 8px;
  scrollbar-width: none;
}
.recent-row::-webkit-scrollbar { display: none; }
.recent-card {
  flex: 0 0 148px;
  height: 118px;
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 2px;
  color: #fff;
  text-decoration: none;
  position: relative;
  box-shadow: var(--shadow-card);
  background: linear-gradient(140deg, color-mix(in srgb, var(--c) 92%, white), color-mix(in srgb, var(--c) 60%, black));
  transition: transform 0.18s ease;
}
.recent-card:active { transform: scale(0.97); }
.recent-glyph { position: absolute; top: 12px; left: 14px; font-size: 24px; line-height: 1; }
.recent-title { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-sub { font-size: 12px; font-weight: 600; opacity: 0.8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.lib-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 0 14px;
  height: 44px;
  border-radius: var(--radius-pill);
  background: rgba(120, 120, 128, 0.14);
  color: var(--text-secondary);
}
.lib-search svg { width: 18px; height: 18px; flex-shrink: 0; }
.lib-search input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 16px;
  color: var(--text);
}
.lib-filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 12px -20px 0;
  padding: 2px 20px 4px;
  scrollbar-width: none;
}
.lib-filters::-webkit-scrollbar { display: none; }
.lib-chip, .lib-players {
  flex-shrink: 0;
  border: none;
  border-radius: var(--radius-pill);
  padding: 8px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  background: rgba(120, 120, 128, 0.14);
  color: var(--text);
}
.lib-chip.active, .lib-players.active { background: var(--accent); color: #fff; }
.lib-players { appearance: none; -webkit-appearance: none; padding-right: 14px; }

.lib-section-title { display: flex; justify-content: space-between; }
.lib-count { color: var(--text-tertiary); font-variant-numeric: tabular-nums; }
.lib-card { padding: 4px 6px 4px 16px; }
.lib-row {
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--separator);
}
.lib-row:last-child { border-bottom: none; }
.lib-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  color: inherit;
  text-decoration: none;
}
.lib-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 28%;
  color: #fff;
  font-weight: 700;
  line-height: 1;
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 88%, white), var(--c));
}
.lib-icon svg, .lib-icon .icon-img { width: 52%; height: 52%; object-fit: contain; }
.lib-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lib-name { font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.lib-tagline, .lib-meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-tagline { font-size: 14px; color: var(--text-secondary); }
.lib-meta { font-size: 12px; color: var(--text-tertiary); }
.lib-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: var(--c);
  color: #fff;
}
.lib-badge.done { background: rgba(120, 120, 128, 0.18); color: var(--text-secondary); }
.lib-info {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lib-info svg { width: 22px; height: 22px; }
.lib-empty { text-align: center; padding: 60px 20px; color: var(--text-secondary); }

/* ---------- Setup guide ---------- */
.guide-card { padding: 4px 16px; }
.setup-guide summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  cursor: pointer;
}
.setup-guide summary::-webkit-details-marker { display: none; }
.guide-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.guide-icon svg { width: 17px; height: 17px; }
.guide-head { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.guide-title { font-size: 16px; font-weight: 500; color: var(--text); }
.guide-sub { font-size: 14px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.guide-chevron { width: 18px; height: 18px; color: var(--text-tertiary); transition: transform 0.2s ease; }
.guide-chevron svg { width: 100%; height: 100%; }
.setup-guide[open] .guide-chevron { transform: rotate(180deg); }
.guide-body {
  padding: 4px 0 16px 44px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}
.guide-eyebrow {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin: 14px 0 4px;
}
.guide-body > .guide-eyebrow:first-child { margin-top: 0; }
.guide-deal {
  padding: 10px 12px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  margin-bottom: 8px;
}
.guide-deal .guide-eyebrow { margin-top: 0; }
.guide-deal-main { font-size: 16px; font-weight: 700; }
.guide-deal-detail { color: var(--text-secondary); }
.guide-others { display: grid; gap: 3px; font-size: 13px; }
.guide-others div { display: grid; grid-template-columns: 92px 1fr; gap: 8px; }
.guide-others div span:first-child { color: var(--text-secondary); }
.guide-list, .guide-steps { margin: 0; padding-left: 18px; }
.guide-list { list-style: disc; }
.guide-steps { list-style: decimal; }
.guide-list li, .guide-steps li { margin-bottom: 4px; }
.guide-list li::marker, .guide-steps li::marker { color: var(--accent); font-weight: 700; }
.rules-guide {
  background: rgba(120, 120, 128, 0.1);
  border-radius: var(--radius-md);
  padding: 0 14px;
  margin-bottom: 8px;
}
/* Rules-sheet headings mustn't restyle the guide's own text. */
.sheet-body.rules-body .rules-guide ul, .sheet-body.rules-body .rules-guide ol { padding-left: 18px; }

/* ---------- Game options (library setup) ---------- */
.options-card { padding: 4px 16px; }
.option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  font-size: 16px;
  border-bottom: 1px solid var(--separator);
}
.option-row:last-child { border-bottom: none; }
.option-row input {
  width: 110px;
  text-align: right;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}
.segmented {
  display: inline-flex;
  padding: 2px;
  border-radius: 10px;
  background: rgba(120, 120, 128, 0.14);
}
.segmented button {
  border: none;
  background: none;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 8px;
  color: var(--text);
}
.segmented button.active { background: var(--card); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
.options-footer { font-size: 13px; color: var(--text-secondary); margin: 8px 6px 0; line-height: 1.45; }

.pill-nav .pill-avatar.pill-glyph { font-size: 18px; }

/* ---------- Library game theme (accent comes from the game's color) ---------- */
html.theme-library { background: #f2f2f5; }
body.theme-library { --bg: #f2f2f5; --card: #ffffff; }
@media (prefers-color-scheme: dark) {
  body.theme-library { --bg: #000000; --card: #1c1c1e; }
  html.theme-library { background: #000000; }
}
body.theme-library table.scorecard td.cell-current { background: color-mix(in srgb, var(--accent) 14%, transparent); }
