/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: #000;
  color: #000;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* App Layout - No sidebars, just top/bottom toolbars */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-width: 500px;
  margin: 0 auto;
  box-shadow: 0 0 40px rgba(0,0,0,0.5);
}

/* Toolbars */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: #1a1a1a;
  padding: 8px;
  gap: 8px;
  flex-shrink: 0;
}

.toolbar-top {
  padding-top: max(8px, env(safe-area-inset-top));
}

.toolbar-bottom {
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  height: 44px;
  padding: 0 8px;
  border: none;
  border-radius: 8px;
  background: #333;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}

.toolbar-btn:hover {
  background: #444;
}

.toolbar-btn:active {
  transform: scale(0.95);
  background: #555;
}

.toolbar-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.toolbar-btn:disabled:active {
  transform: none;
}

.toolbar-btn svg {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.sort-label {
  display: inline;
}

/* Player List */
.player-list {
  flex: 1;
  min-height: 0; /* Critical for flex scroll */
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* Player Row Wrapper - for swipe/drag */
.player-row-wrapper {
  position: relative;
  overflow: hidden;
  flex-shrink: 0; /* Prevent shrinking - enable scroll */
}

.player-row-wrapper.dragging {
  z-index: 100;
  opacity: 0.9;
}

.player-row-wrapper.dragging .player-row {
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

/* Swipe Edit Background (right swipe) */
.swipe-edit-bg {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 120px;
  background: #0074D9;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.swipe-edit-bg svg {
  width: 32px;
  height: 32px;
}

/* Swipe Delete Background (left swipe) */
.swipe-delete-bg {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 120px;
  background: #dc3545;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.swipe-delete-bg svg {
  width: 32px;
  height: 32px;
}

/* Player Row */
.player-row {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  align-items: center;
  padding: 8px 12px;
  min-height: 60px;
  gap: 8px;
  cursor: default;
  transition: transform 0.2s ease-out;
  border-top: 3px solid rgba(255,255,255,0.2);
  border-bottom: 3px solid rgba(0,0,0,0.3);
  z-index: 1;
  background-color: inherit;
}

/* Drag Handle */
.drag-handle {
  width: 24px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.4;
  cursor: grab;
  touch-action: none;
}

.drag-handle:active {
  cursor: grabbing;
  opacity: 0.7;
}

.drag-handle svg {
  width: 20px;
  height: 20px;
}

.player-name {
  font-size: 1.4rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Score display - shows running total */
.score-display {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 60px;
  justify-content: flex-end;
  flex-shrink: 0;
}

.score-delta {
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s;
  white-space: nowrap;
}

.score-delta.visible {
  opacity: 0.7;
}

.player-score {
  font-size: 1.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-btn {
  width: 50px;
  height: 50px;
  border: none;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
  color: inherit;
  font-size: 2rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, transform 0.1s;
  line-height: 1;
  padding-bottom: 2px; /* Visual adjustment for +/- glyphs */
}

.score-btn:hover {
  background: rgba(0, 0, 0, 0.35);
}

.score-btn:active {
  transform: scale(0.95);
  background: rgba(0, 0, 0, 0.45);
}

/* Score Animation */
.player-score.bump {
  animation: bump 0.15s ease-out;
}

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

/* Edit Modal */
.edit-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  z-index: 100;
  box-sizing: border-box;
}

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

.edit-modal-content {
  background: #2a2a2a;
  border-radius: 16px;
  padding: 16px;
  width: 100%;
  max-width: 360px;
  box-sizing: border-box;
}

/* Color Picker - reordered for better distinction */
.color-picker {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.color-swatch {
  aspect-ratio: 1;
  border: 3px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s, box-shadow 0.1s;
}

/* Make black and white swatches more visible */
.color-swatch[data-color="#111111"] {
  border-color: #555;
}

.color-swatch[data-color="#FFFFFF"] {
  border-color: #ccc;
}

.color-swatch:hover {
  transform: scale(1.1);
}

.color-swatch.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px #000, 0 0 0 4px #fff;
  transform: scale(1.1);
}

/* Edit Row */
.edit-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.edit-btn {
  width: 50px;
  min-width: 50px;
  height: 50px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.15s;
  flex-shrink: 0;
}

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

.edit-btn svg {
  width: 28px;
  height: 28px;
}

.delete-btn {
  background: #dc3545;
  color: #fff;
}

.delete-btn:hover {
  background: #c82333;
}

.confirm-btn {
  background: #28a745;
  color: #fff;
}

.confirm-btn:hover {
  background: #218838;
}

.edit-name-input {
  flex: 1;
  min-width: 0;
  height: 50px;
  border: none;
  border-radius: 12px;
  padding: 0 12px;
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  background: #fff;
  color: #000;
  outline: none;
}

.edit-name-input:focus {
  box-shadow: 0 0 0 3px rgba(255,255,255,0.3);
}

/* Empty State - Big Onboarding Button */
.empty-state-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #2ECC40 0%, #01FF70 100%);
  border: none;
  cursor: pointer;
  color: #000;
  text-align: center;
  padding: 40px;
  transition: transform 0.15s, filter 0.15s;
}

.empty-state-btn:hover {
  filter: brightness(1.1);
}

.empty-state-btn:active {
  transform: scale(0.98);
  filter: brightness(0.95);
}

.empty-state-btn svg {
  width: 120px;
  height: 120px;
  margin-bottom: 24px;
  opacity: 0.9;
}

.empty-state-btn span {
  font-size: 1.5rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Add Player Button (below player list) */
.add-player-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 16px 20px;
  margin-top: 8px;
  background: #333;
  border: 2px dashed #555;
  border-radius: 12px;
  color: #aaa;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0; /* Prevent shrinking - enable scroll */
}

.add-player-btn:hover {
  background: #444;
  border-color: #666;
  color: #fff;
}

.add-player-btn:active {
  transform: scale(0.98);
}

.add-player-btn svg {
  width: 28px;
  height: 28px;
  opacity: 0.7;
}

/* Sound button state */
.toolbar-btn .sound-off {
  display: none;
}

.toolbar-btn.sound-off .sound-on {
  display: none;
}

.toolbar-btn.sound-off .sound-off {
  display: block;
}

/* Landscape mode */
@media (orientation: landscape) {
  .toolbar {
    padding: 4px 16px;
  }

  .toolbar-top {
    padding-top: max(4px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  .toolbar-bottom {
    padding-bottom: max(4px, env(safe-area-inset-bottom));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  .toolbar-btn {
    min-width: 44px;
    height: 40px;
  }

  .player-row {
    min-height: 50px;
    padding: 6px 16px;
  }

  .player-name {
    font-size: 1.2rem;
  }

  .player-score {
    font-size: 1.5rem;
  }

  .score-btn {
    width: 44px;
    height: 44px;
    font-size: 1.6rem;
  }

  .player-list {
    flex: 1;
    min-height: 0; /* Important for flex scroll */
    overflow-y: auto;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .add-player-btn {
    padding: 10px 16px;
    margin: 4px 0;
  }
}

/* Small height landscape */
@media (orientation: landscape) and (max-height: 400px) {
  .toolbar {
    padding: 2px 12px;
  }

  .toolbar-btn {
    height: 32px;
    min-width: 36px;
    padding: 0 8px;
    font-size: 12px;
  }

  .toolbar-btn svg {
    width: 20px;
    height: 20px;
  }

  .sort-label,
  .sound-label {
    display: none;
  }

  .player-row {
    min-height: 40px;
    padding: 4px 12px;
  }

  .player-name {
    font-size: 1rem;
  }

  .player-score {
    font-size: 1.2rem;
  }

  .score-btn {
    width: 36px;
    height: 36px;
    font-size: 1.3rem;
  }

  .add-player-btn {
    padding: 8px 12px;
    font-size: 0.9rem;
  }

  .add-player-btn svg {
    width: 20px;
    height: 20px;
  }
}

/* Tablet/larger screens */
@media (min-width: 768px) {
  .toolbar-btn {
    min-width: 60px;
    height: 50px;
    padding: 0 16px;
  }

  .player-row {
    min-height: 70px;
    padding: 12px 24px;
    gap: 12px;
  }

  .player-name {
    font-size: 1.8rem;
  }

  .player-score {
    font-size: 2.2rem;
  }

  .score-btn {
    width: 60px;
    height: 60px;
    font-size: 2.2rem;
  }
}

/* PWA Install Banner */
.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, #0074D9 0%, #7FDBFF 100%);
  color: #fff;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 150;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.2);
}

.install-banner span {
  flex: 1;
  font-weight: 600;
}

.install-btn {
  background: #fff;
  color: #0074D9;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s;
}

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

.install-dismiss {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  padding: 4px 8px;
  cursor: pointer;
  opacity: 0.7;
}

.install-dismiss:hover {
  opacity: 1;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  padding-bottom: env(safe-area-inset-bottom);
}

.toast {
  background: #333;
  color: #fff;
  padding: 12px 20px;
  border-radius: 25px;
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  pointer-events: auto;
  animation: toastIn 0.3s ease-out;
  max-width: calc(100vw - 32px);
}

.toast.hiding {
  animation: toastOut 0.2s ease-in forwards;
}

.toast-undo-btn {
  background: #0074D9;
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 15px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.toast-undo-btn:hover {
  background: #0063B8;
}

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

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

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* Gesture Hints Overlay */
.gesture-hints-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  gap: 28px;
  animation: fadeIn 0.3s ease-out;
}

.gesture-hints-overlay h2 {
  color: #fff;
  font-size: 1.3rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.gesture-hint {
  display: flex;
  align-items: center;
  gap: 16px;
  color: #fff;
  width: 100%;
  max-width: 320px;
}

.gesture-hint-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.4rem;
}

.gesture-hint-text {
  font-size: 0.95rem;
  line-height: 1.4;
}

.gesture-hint-text strong {
  display: block;
  font-size: 1rem;
  margin-bottom: 2px;
}

.gesture-hints-dismiss {
  margin-top: 12px;
  background: #fff;
  color: #000;
  border: none;
  padding: 14px 40px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s;
}

.gesture-hints-dismiss:active {
  transform: scale(0.95);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Increment Picker */
.increment-picker {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1a1a1a;
  border-top: 1px solid #333;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 120;
  animation: slideUp 0.2s ease-out;
}

.increment-picker-label {
  color: #888;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
  text-align: center;
}

.increment-options {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.increment-option {
  min-width: 52px;
  height: 44px;
  border: 2px solid #444;
  border-radius: 10px;
  background: #2a2a2a;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  padding: 0 12px;
}

.increment-option:active {
  transform: scale(0.95);
}

.increment-option.selected {
  border-color: #2ECC40;
  background: rgba(46, 204, 64, 0.15);
  color: #2ECC40;
}

.increment-custom-input {
  width: 64px;
  height: 44px;
  border: 2px solid #444;
  border-radius: 10px;
  background: #2a2a2a;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  outline: none;
}

.increment-custom-input:focus {
  border-color: #0074D9;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* Increment indicator on score buttons */
.score-btn .increment-label {
  font-size: 0.7rem;
  opacity: 0.7;
  position: absolute;
  bottom: 2px;
  right: 4px;
}

.score-btn {
  position: relative;
}

/* Game Dialog (Save/New Game) */
.game-dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.2s ease-out;
}

.game-dialog {
  background: #2a2a2a;
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.game-dialog h2 {
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.game-dialog-summary {
  color: #999;
  font-size: 0.85rem;
  margin-bottom: 16px;
  line-height: 1.4;
}

.game-dialog-input {
  width: 100%;
  height: 48px;
  border: 2px solid #444;
  border-radius: 10px;
  padding: 0 14px;
  font-size: 1rem;
  font-weight: 600;
  background: #1a1a1a;
  color: #fff;
  outline: none;
  margin-bottom: 16px;
  box-sizing: border-box;
}

.game-dialog-input:focus {
  border-color: #0074D9;
}

.game-dialog-input::placeholder {
  color: #666;
}

.game-dialog-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.game-dialog-btn {
  width: 100%;
  height: 48px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}

.game-dialog-btn:active {
  transform: scale(0.98);
}

.game-dialog-btn.save-btn {
  background: #2ECC40;
  color: #000;
}

.game-dialog-btn.discard-btn {
  background: #444;
  color: #fff;
}

.game-dialog-past-link {
  background: none;
  border: none;
  color: #0074D9;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 8px;
  text-align: center;
}

.game-dialog-past-link:hover {
  text-decoration: underline;
}

/* Past Games */
.past-games-dialog {
  max-height: 85vh;
}

.past-games-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.past-games-header h2 {
  margin-bottom: 0;
}

.past-games-close {
  background: none;
  border: none;
  color: #888;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.past-games-close:hover {
  color: #fff;
}

.past-games-list {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.past-games-empty {
  color: #666;
  text-align: center;
  padding: 32px 16px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.past-game-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid #3a3a3a;
  cursor: pointer;
  transition: background 0.15s;
  border-radius: 8px;
  padding-left: 8px;
  padding-right: 4px;
}

.past-game-item:hover {
  background: rgba(255,255,255,0.05);
}

.past-game-item:last-child {
  border-bottom: none;
}

.past-game-info {
  flex: 1;
  min-width: 0;
}

.past-game-name {
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.past-game-meta {
  color: #888;
  font-size: 0.8rem;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.past-game-menu-btn {
  background: none;
  border: none;
  color: #666;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 8px;
  letter-spacing: 2px;
  flex-shrink: 0;
}

.past-game-menu-btn:hover {
  color: #fff;
}

/* Popup Menu */
.past-game-popup-menu {
  background: #333;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  z-index: 200;
  overflow: hidden;
  min-width: 140px;
}

.popup-menu-item {
  display: block;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: none;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.popup-menu-item:hover {
  background: rgba(255,255,255,0.1);
}

.popup-menu-item.delete {
  color: #dc3545;
}
