/* ============================================
   Hog Tally -- "Party Pigs" Design System
   ============================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@700;800&family=Inter:wght@400;600;700&display=swap');

/* --- CSS Custom Properties --- */

:root {
  /* Colors - Light theme */
  --color-primary: #FF6B6B;
  --color-primary-dark: #E55555;
  --color-primary-light: #FFE0E0;
  --color-accent: #4ECDC4;
  --color-accent-dark: #3DBDB5;
  --color-highlight: #FFE66D;
  --color-warning: #FFA726;
  --color-danger: #FF5252;
  --color-bg: #FAFAFA;
  --color-surface: #FFFFFF;
  --color-surface-alt: #F0FFFE;
  --color-text: #2D3436;
  --color-text-muted: #636E72;
  --color-border: #E0E0E0;
  --color-shadow: rgba(0, 0, 0, 0.08);
  --pig-fill: #FFB5B5;

  /* Typography */
  --font-display: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Inter', 'Segoe UI', system-ui, sans-serif;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px var(--color-shadow);
  --shadow-md: 0 4px 12px var(--color-shadow);
  --shadow-lg: 0 8px 24px var(--color-shadow);
}

/* --- Dark Theme --- */

[data-theme="dark"] {
  --color-primary: #FF8A80;
  --color-primary-dark: #FF6B6B;
  --color-primary-light: #3D2020;
  --color-accent: #69F0AE;
  --color-accent-dark: #4ECDC4;
  --color-highlight: #FFE66D;
  --color-warning: #FFB74D;
  --color-danger: #FF5252;
  --color-bg: #1A1A2E;
  --color-surface: #25253E;
  --color-surface-alt: #2D2D4A;
  --color-text: #E8E8F0;
  --color-text-muted: #9999B0;
  --color-border: #3A3A55;
  --color-shadow: rgba(0, 0, 0, 0.3);
  --pig-fill: #FF9E9E;
}

/* --- Reset & Base --- */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* --- Typography --- */

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 1.2;
}

/* --- Layout --- */

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 var(--space-4);
  padding-bottom: env(safe-area-inset-bottom, var(--space-4));
}

.screen {
  display: none;
  min-height: 100dvh;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* --- Buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease-out, opacity 0.15s ease-out, box-shadow 0.15s ease-out;
  -webkit-user-select: none;
  user-select: none;
  min-height: 48px;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.95);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

.btn-accent {
  background: var(--color-accent);
  color: #1a1a2e;
  box-shadow: var(--shadow-sm);
}

.btn-accent:hover:not(:disabled) {
  background: var(--color-accent-dark);
}

.btn-outline {
  background: transparent;
  color: var(--color-text);
  border: 2px solid var(--color-border);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--color-text);
  background: var(--color-surface-alt);
}

.btn-danger {
  background: transparent;
  color: var(--color-danger);
  border: 2px solid var(--color-danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--color-danger);
  color: #fff;
}

.btn-warning {
  background: var(--color-warning);
  color: #fff;
}

.btn-full {
  width: 100%;
}

.btn-lg {
  min-height: 56px;
  font-size: 18px;
  font-weight: 700;
  border-radius: var(--radius-lg);
}

.btn-sm {
  min-height: 36px;
  padding: var(--space-1) var(--space-3);
  font-size: 14px;
}

/* --- Cards --- */

.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}

/* === SETUP SCREEN === */

.setup-screen {
  padding-top: var(--space-12);
  align-items: center;
  gap: var(--space-8);
}

.setup-header {
  text-align: center;
}

.setup-header h1 {
  font-size: 28px;
  color: var(--color-primary);
  margin-bottom: var(--space-1);
}

.setup-header p {
  color: var(--color-text-muted);
  font-size: 16px;
}

.player-slots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  width: 100%;
  max-width: 320px;
}

.player-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.slot-circle {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
  position: relative;
}

.slot-circle:active {
  transform: scale(0.92);
}

.slot-circle.empty {
  border: 3px dashed var(--color-border);
  background: transparent;
  color: var(--color-text-muted);
}

.slot-circle.filled {
  color: #fff;
  box-shadow: var(--shadow-md);
}

.slot-circle .remove-btn {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 12px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
}

.slot-circle.filled .remove-btn {
  display: flex;
}

.slot-name {
  font-size: 13px;
  color: var(--color-text-muted);
  text-align: center;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-name.active {
  color: var(--color-text);
  font-weight: 600;
}

/* Player editor (inline) */
.player-editor {
  width: 100%;
  max-width: 320px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-md);
  display: none;
}

.player-editor.active {
  display: block;
}

.player-editor input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--color-text);
  background: var(--color-bg);
  outline: none;
  margin-bottom: var(--space-3);
}

.player-editor input:focus {
  border-color: var(--color-primary);
}

.icon-picker {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding-bottom: var(--space-2);
  -webkit-overflow-scrolling: touch;
}

.icon-option {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  color: var(--color-text-muted);
  background: var(--color-surface-alt);
}

.icon-option:active {
  transform: scale(0.9);
}

.icon-option.selected {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-light);
}

.add-more-slot .slot-circle {
  width: 52px !important;
  height: 52px !important;
}

.setup-actions {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.setup-footer {
  display: flex;
  justify-content: center;
}

/* === GAME SCREEN === */

.game-screen {
  padding-top: var(--space-3);
  gap: var(--space-3);
  padding-bottom: var(--space-4);
}

/* Top bar */
.game-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) 0;
}

.game-topbar .btn {
  min-height: 36px;
  font-size: 14px;
}

/* Scoreboard */
.scoreboard {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.score-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  transition: box-shadow 0.2s, transform 0.2s;
}

.score-card.active-turn {
  box-shadow: 0 0 0 2px var(--color-primary), var(--shadow-md);
  transform: scale(1.02);
}

.score-card.eliminated {
  opacity: 0.4;
  text-decoration: line-through;
}

.score-card .player-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  font-size: 14px;
}

.score-card .player-name {
  flex: 1;
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-card .player-score {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  min-width: 40px;
  text-align: right;
}

.score-card .trophy-icon {
  display: none;
  color: var(--color-highlight);
  margin-left: var(--space-1);
}

.score-card.has-trophy .trophy-icon {
  display: inline;
}

/* Scoreboard expandable section */
.scoreboard-expandable {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.scoreboard-expandable.open {
  /* max-height set dynamically by JS */
}

.scoreboard-expandable .score-card {
  margin: 0;
}

/* Scoreboard toggle / collapsed summary */
.score-dots.hidden {
  display: none;
}

.scoreboard-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  color: var(--color-text-muted);
  font-size: 13px;
}

.scoreboard-toggle:active {
  opacity: 0.7;
}

.score-dots {
  display: flex;
  gap: var(--space-1);
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.score-dot {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.score-dot .dot-score {
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.score-dot.eliminated {
  opacity: 0.3;
}

.toggle-chevron {
  display: flex;
  align-items: center;
  color: var(--color-text-muted);
}

.toggle-label {
  font-size: 13px;
  color: var(--color-text-muted);
}

/* Turn banner */
.turn-banner {
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  text-align: center;
  color: #fff;
  position: relative;
  overflow: hidden;
}

.turn-banner .turn-player {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  opacity: 0.9;
}

.turn-banner .turn-total {
  font-family: var(--font-display);
  font-size: 42px;
  font-weight: 800;
  line-height: 1.1;
}

.turn-banner .turn-label {
  font-size: 13px;
  opacity: 0.7;
}

/* Score pop animation */
@keyframes scorePop {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.score-pop {
  animation: scorePop 0.3s ease-out;
}

/* === PRO MODE === */

.quick-scores {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
}

.quick-scores .btn-score {
  background: var(--color-surface);
  color: var(--color-text);
  border: 2px solid var(--color-border);
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  border-radius: var(--radius-md);
  min-height: 52px;
}

.quick-scores .btn-score:active:not(:disabled) {
  border-color: var(--color-accent);
  background: var(--color-surface-alt);
}

.quick-scores-doubles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}

.custom-score-row {
  display: flex;
  gap: var(--space-2);
}

.custom-score-row input {
  flex: 1;
  min-width: 0;
  padding: var(--space-3);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text);
  background: var(--color-surface);
  text-align: center;
  outline: none;
  font-variant-numeric: tabular-nums;
}

.custom-score-row input:focus {
  border-color: var(--color-accent);
}

.custom-score-row input::placeholder {
  color: var(--color-text-muted);
  font-weight: 400;
}

/* Action buttons row */
.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-2);
}

.action-row .btn {
  font-size: 14px;
  font-weight: 700;
}

.footer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
}

/* === STANDARD MODE === */

.pig-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.pig-card {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-2) var(--space-3);
  text-align: center;
  height: 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.pig-card .pig-svg-display {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pig-card .pig-position-name {
  font-size: 12px;
}

.pig-card.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.pig-card .pig-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.position-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}

.position-buttons .btn-position {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  min-height: 72px;
}

.position-buttons .btn-position:active {
  transform: scale(0.95);
}

.position-buttons .btn-position.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.position-buttons .btn-position .pig-svg-mini {
  width: 40px;
  height: 40px;
}

/* === WINNER MODAL === */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 100;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-8) var(--space-6);
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-height: 90dvh;
  overflow-y: auto;
}

.modal h2 {
  font-size: 24px;
  color: var(--color-primary);
  margin-bottom: var(--space-2);
}

.modal .winner-score {
  font-size: 48px;
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--color-highlight);
  text-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.modal .standings {
  list-style: none;
  margin: var(--space-4) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.modal .standings li {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-alt);
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.modal .standings .rank {
  font-size: 14px;
  color: var(--color-text-muted);
  min-width: 24px;
}

.modal .standings .name {
  flex: 1;
  text-align: left;
}

.modal .standings .final-score {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.modal .modal-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

/* Trophy animation */
@keyframes trophyBounce {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-8px) rotate(-5deg); }
  75% { transform: translateY(-4px) rotate(5deg); }
}

.trophy-anim {
  font-size: 48px;
  display: inline-block;
  animation: trophyBounce 0.8s ease-in-out;
}

/* === SETTINGS BOTTOM SHEET === */

.bottom-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: none;
  z-index: 90;
}

.bottom-sheet-overlay.active {
  display: block;
}

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-4) var(--space-4) var(--space-8);
  max-height: 80dvh;
  overflow-y: auto;
  z-index: 91;
  transform: translateY(100%);
  transition: transform 0.3s ease-out;
  box-shadow: 0 -4px 24px var(--color-shadow);
}

.bottom-sheet.active {
  transform: translateY(0);
}

.bottom-sheet .drag-handle {
  width: 40px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--color-border);
  margin: 0 auto var(--space-4);
}

.bottom-sheet h3 {
  font-size: 18px;
  margin-bottom: var(--space-3);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
}

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

.setting-label {
  font-weight: 600;
  font-size: 15px;
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--color-border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-track {
  background: var(--color-accent);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(24px);
}

/* Threshold stepper */
.threshold-stepper {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.threshold-stepper .value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 40px;
  text-align: center;
}

.threshold-stepper .btn {
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  font-size: 18px;
  border-radius: var(--radius-full);
}

/* History list */
.history-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.history-item {
  padding: var(--space-3);
  background: var(--color-surface-alt);
  border-radius: var(--radius-sm);
}

.history-item .date {
  font-size: 12px;
  color: var(--color-text-muted);
}

.history-item .winner-line {
  font-weight: 700;
  font-size: 15px;
}

.history-item .others {
  font-size: 13px;
  color: var(--color-text-muted);
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.stat-card {
  background: var(--color-surface-alt);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  text-align: center;
}

.stat-card .stat-value {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
  color: var(--color-primary);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--color-text-muted);
}

/* === RESUME PROMPT === */

.resume-banner {
  background: var(--color-surface-alt);
  border: 2px solid var(--color-accent);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  display: none;
  align-items: center;
  gap: var(--space-3);
}

.resume-banner.active {
  display: flex;
}

.resume-banner .resume-text {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
}

.resume-banner .resume-actions {
  display: flex;
  gap: var(--space-2);
}

/* === DRAG & REORDER === */

/* -- Setup slot reorder -- */

/* Reorder mode: tap-to-swap */
.player-slot.reorder-slot .slot-circle.filled {
  border: 2px dashed var(--color-text-muted);
  cursor: pointer;
}

.player-slot.swap-selected .slot-circle {
  border: 3px solid var(--color-accent) !important;
  box-shadow: 0 0 0 4px rgba(78, 205, 196, 0.3);
  transform: scale(1.05);
}

.score-card.swap-selected {
  border: 3px solid var(--color-accent) !important;
  box-shadow: 0 0 0 4px rgba(78, 205, 196, 0.3);
  transform: scale(1.02);
}

.player-slot {
  transition: transform 0.2s ease-out;
}

/* -- Scoreboard reorder -- */

.score-card {
  transition: transform 0.2s ease-out, box-shadow 0.2s ease-out, opacity 0.2s ease-out;
}

.score-card.reorderable {
  cursor: pointer;
}

.reorder-arrows {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

.btn-arrow {
  width: 28px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0;
  touch-action: manipulation;
}

.btn-arrow:active {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.btn-arrow.invisible {
  visibility: hidden;
}

.score-card .drag-handle {
  display: flex;
  align-items: center;
  padding: var(--space-1);
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.scoreboard.edit-mode .score-card {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-md);
}

.scoreboard.edit-mode .score-card.active-turn {
  box-shadow: none;
  transform: none;
}

/* Inline edit inputs in edit mode */
.score-card .edit-name {
  flex: 1;
  min-width: 0;
  border: none;
  border-bottom: 2px solid var(--color-border);
  background: transparent;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  padding: var(--space-1) var(--space-1);
  outline: none;
  border-radius: 0;
}

.score-card .edit-name:focus {
  border-bottom-color: var(--color-primary);
}

.score-card .edit-score {
  width: 56px;
  min-width: 0;
  border: none;
  border-bottom: 2px solid var(--color-border);
  background: transparent;
  font-family: var(--font-body);
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
  text-align: right;
  padding: var(--space-1) var(--space-1);
  outline: none;
  border-radius: 0;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

.score-card .edit-score::-webkit-inner-spin-button,
.score-card .edit-score::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.score-card .edit-score:focus {
  border-bottom-color: var(--color-primary);
}

/* === CONFIRM DIALOG === */

.confirm-dialog {
  padding: var(--space-6);
  max-width: 320px;
}

.confirm-dialog h2 {
  font-size: 20px;
  margin-bottom: var(--space-2);
}

.confirm-icon {
  font-size: 40px;
  margin-bottom: var(--space-3);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.modal-overlay.active .modal {
  animation: modalIn 0.2s ease-out;
}

/* === MODE SELECTOR (Settings) === */

.mode-selector {
  display: flex;
  gap: var(--space-1);
  background: var(--color-surface-alt);
  border-radius: var(--radius-md);
  padding: 2px;
}

.mode-selector .btn {
  min-height: 32px;
  padding: var(--space-1) var(--space-3);
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  border: none;
}

.mode-selector .btn.active {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* === ONBOARDING === */

.onboarding-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-6);
}

.onboarding-slides {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 360px;
  overflow: hidden;
  position: relative;
}

.onboarding-slide {
  display: none;
  text-align: center;
  padding: var(--space-4);
}

.onboarding-slide.active {
  display: block;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.onboarding-emoji {
  font-size: 64px;
  margin-bottom: var(--space-4);
}

.onboarding-slide h2 {
  font-size: 24px;
  color: var(--color-primary);
  margin-bottom: var(--space-3);
}

.onboarding-slide p {
  font-size: 16px;
  color: var(--color-text-muted);
  line-height: 1.6;
}

.onboarding-dots {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
}

.onboarding-dots .dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--color-border);
  transition: background 0.2s, transform 0.2s;
}

.onboarding-dots .dot.active {
  background: var(--color-primary);
  transform: scale(1.3);
}

.onboarding-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 360px;
}

/* === ACCESSIBILITY === */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

*:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (prefers-contrast: high) {
  :root {
    --color-border: #888;
    --color-text-muted: #555;
  }
}

/* === RESPONSIVE === */

/* Mobile compact: fit game screen without scrolling */
@media (max-width: 480px) {
  .game-screen {
    gap: var(--space-2);
  }

  .game-topbar {
    padding: var(--space-1) 0;
  }

  .turn-banner {
    padding: var(--space-2) var(--space-3);
  }

  .turn-banner .turn-player {
    font-size: 14px;
  }

  .turn-banner .turn-total {
    font-size: 32px;
  }

  .turn-banner .turn-label {
    font-size: 11px;
  }

  .pig-card {
    height: 70px;
    padding: var(--space-1) var(--space-2);
  }

  .pig-card .pig-svg-display {
    height: 32px;
  }

  .pig-card .pig-label {
    font-size: 9px;
  }

  .pig-card .pig-position-name {
    font-size: 11px;
  }

  .position-buttons .btn-position {
    min-height: 60px;
    padding: var(--space-1);
    font-size: 10px;
  }

  .position-buttons .btn-position .pig-svg-mini {
    width: 32px;
    height: 32px;
  }

  .quick-scores .btn-score {
    min-height: 44px;
    font-size: 16px;
  }

  .action-row .btn {
    font-size: 13px;
    min-height: 42px;
  }

  .btn-sm {
    min-height: 32px;
    font-size: 13px;
  }

  .score-card {
    padding: var(--space-1) var(--space-2);
  }

  .score-card .player-icon {
    width: 30px;
    height: 30px;
  }

  .score-card .player-name {
    font-size: 14px;
  }

  .score-card .player-score {
    font-size: 18px;
  }
}

@media (max-width: 360px) {
  .app {
    padding: 0 var(--space-2);
  }

  .setup-header h1 {
    font-size: 24px;
  }

  .slot-circle {
    width: 60px;
    height: 60px;
  }

  .turn-banner .turn-total {
    font-size: 28px;
  }
}

@media (min-width: 768px) {
  .app {
    max-width: 560px;
    padding: 0 var(--space-6);
  }

  .setup-screen {
    padding-top: var(--space-12);
  }

  .player-slots {
    max-width: 400px;
    gap: var(--space-6);
  }

  .slot-circle {
    width: 84px;
    height: 84px;
  }
}
