/* ═══════════════════════════════════════════
   Design Tokens
   ═══════════════════════════════════════════ */
:root {
  /* Colors — dark palette with warm accents */
  --bg-primary: #0f1117;
  --bg-secondary: #181b25;
  --bg-card: #1e2230;
  --bg-card-hover: #252a3a;
  --bg-input: #14171f;

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-input: rgba(255, 255, 255, 0.1);
  --border-focus: #6c7bf7;

  --text-primary: #f0f1f5;
  --text-secondary: #9299b0;
  --text-muted: #5c6380;

  --accent: #6c7bf7;
  --accent-hover: #8490ff;
  --accent-glow: rgba(108, 123, 247, 0.25);

  --success: #34d399;
  --success-hover: #4eeab2;
  --success-bg: rgba(52, 211, 153, 0.12);

  --warning: #fbbf24;
  --warning-hover: #fcd34d;
  --warning-bg: rgba(251, 191, 36, 0.12);

  --danger: #f87171;
  --danger-hover: #fca5a5;
  --danger-bg: rgba(248, 113, 113, 0.12);
  --danger-intense: #ef4444;

  --lost-bg: rgba(239, 68, 68, 0.10);
  --lost-border: rgba(239, 68, 68, 0.35);

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

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

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration: 200ms;
}

/* ═══════════════════════════════════════════
   Reset & Base
   ═══════════════════════════════════════════ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

ul {
  list-style: none;
}

button {
  cursor: pointer;
  font-family: inherit;
  border: none;
  background: none;
}

input {
  font-family: inherit;
  border: none;
  background: none;
  outline: none;
}

/* ═══════════════════════════════════════════
   App Container
   ═══════════════════════════════════════════ */
#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 var(--space-md) var(--space-2xl);
}

/* ═══════════════════════════════════════════
   Header
   ═══════════════════════════════════════════ */
#header {
  padding: var(--space-xl) 0 var(--space-lg);
  text-align: center;
}

.header-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
}

.header-icon {
  font-size: 2.5rem;
  line-height: 1;
  filter: drop-shadow(0 0 12px var(--accent-glow));
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

#header h1 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

/* ═══════════════════════════════════════════
   Sections
   ═══════════════════════════════════════════ */
.section {
  margin-top: var(--space-lg);
  animation: fadeUp 0.4s var(--ease) both;
}

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

.section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.section-icon {
  font-size: 1rem;
}

.hidden {
  display: none !important;
}

/* ═══════════════════════════════════════════
   Add Player Form
   ═══════════════════════════════════════════ */
.add-player-form {
  display: flex;
  gap: var(--space-sm);
}

.add-player-form input {
  flex: 1;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: border-color var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease);
}

.add-player-form input::placeholder {
  color: var(--text-muted);
}

.add-player-form input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ═══════════════════════════════════════════
   Buttons
   ═══════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: 0.65rem 1.1rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: all var(--duration) var(--ease);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
}

.btn:active::after {
  opacity: 0.08;
}

.btn-icon {
  font-size: 1.1em;
  font-weight: 700;
}

/* Primary */
.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 16px var(--accent-glow);
}

/* Accent */
.btn-accent {
  background: var(--accent);
  color: white;
}
.btn-accent:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 16px var(--accent-glow);
}

/* Success */
.btn-success {
  background: var(--success);
  color: #0f1117;
}
.btn-success:hover {
  background: var(--success-hover);
  box-shadow: 0 4px 16px rgba(52, 211, 153, 0.25);
}

/* Warning */
.btn-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid rgba(251, 191, 36, 0.2);
}
.btn-warning:hover:not(:disabled) {
  background: rgba(251, 191, 36, 0.18);
}
.btn-warning:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Danger */
.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.2);
}
.btn-danger:hover {
  background: rgba(248, 113, 113, 0.18);
}

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}
.btn-ghost:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* ═══════════════════════════════════════════
   Player List
   ═══════════════════════════════════════════ */
.player-list {
  margin-top: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.player-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  animation: fadeUp 0.3s var(--ease) both;
}

.player-list-item .player-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.player-list-item .remove-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-size: 1.1rem;
  transition: all var(--duration) var(--ease);
}

.player-list-item .remove-btn:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ═══════════════════════════════════════════
   Scoreboard
   ═══════════════════════════════════════════ */
.scoreboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: var(--space-md);
}

.score-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg) var(--space-md);
  text-align: center;
  transition: all 0.3s var(--ease);
  position: relative;
  overflow: hidden;
}

.score-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--success));
  opacity: 0.6;
}

.score-card:hover {
  transform: translateY(-2px);
  border-color: rgba(108, 123, 247, 0.2);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.score-card .card-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.score-card .card-points {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  transition: color 0.3s var(--ease);
}

/* Lost state */
.score-card.lost {
  background: var(--lost-bg);
  border-color: var(--lost-border);
}

.score-card.lost::before {
  background: var(--danger-intense);
  opacity: 0.9;
}

.score-card.lost .card-points {
  color: var(--danger);
}

.score-card .lost-badge {
  display: none;
  margin-top: var(--space-sm);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--danger-intense);
  background: rgba(239, 68, 68, 0.15);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-full);
  animation: pulse 2s ease-in-out infinite;
}

.score-card.lost .lost-badge {
  display: inline-block;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ═══════════════════════════════════════════
   Round Inputs
   ═══════════════════════════════════════════ */
.round-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.round-header .section-title {
  margin-bottom: 0;
}

.round-inputs {
  margin-top: var(--space-md);
  animation: fadeUp 0.3s var(--ease) both;
}

.round-fields {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.round-field {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 0.6rem 1rem;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.round-field .field-label {
  flex: 1;
  font-weight: 600;
  font-size: 0.9rem;
}

.round-field input {
  width: 80px;
  text-align: center;
  padding: 0.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1.1rem;
  font-weight: 700;
  transition: border-color var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease);
}

.round-field input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Remove spinner arrows */
.round-field input[type="number"]::-webkit-inner-spin-button,
.round-field input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.round-field input[type="number"] {
  -moz-appearance: textfield;
}

.round-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

.round-actions .btn {
  flex: 1;
}

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

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: var(--space-lg);
  font-size: 0.9rem;
}

.history-item {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  animation: fadeUp 0.3s var(--ease) both;
}

.history-item-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-xs);
}

.history-item-scores {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-md);
}

.history-score {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.85rem;
}

.history-score .h-name {
  color: var(--text-secondary);
  font-weight: 500;
}

.history-score .h-points {
  font-weight: 700;
  color: var(--accent);
}

.history-score .h-points.positive {
  color: var(--danger);
}

/* ═══════════════════════════════════════════
   Controls
   ═══════════════════════════════════════════ */
.controls-row {
  display: flex;
  gap: var(--space-sm);
}

.controls-row .btn {
  flex: 1;
  padding: 0.75rem;
  font-size: 0.8rem;
}

/* ═══════════════════════════════════════════
   Toast Notifications
   ═══════════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: var(--space-lg);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}

.toast {
  padding: 0.7rem 1.2rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  color: white;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.35s var(--ease);
  white-space: nowrap;
}

.toast.info {
  background: rgba(108, 123, 247, 0.9);
}

.toast.success {
  background: rgba(52, 211, 153, 0.9);
  color: #0f1117;
}

.toast.error {
  background: rgba(248, 113, 113, 0.9);
}

.toast.exit {
  animation: toastOut 0.3s var(--ease) forwards;
}

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

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(16px) scale(0.95);
  }
}

/* ═══════════════════════════════════════════
   Confirmation Modal
   ═══════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: var(--space-md);
  animation: fadeIn 0.2s var(--ease);
}

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

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  max-width: 340px;
  width: 100%;
  text-align: center;
  animation: modalIn 0.3s var(--ease);
}

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

.modal-message {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: var(--space-lg);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: var(--space-sm);
}

.modal-actions .btn {
  flex: 1;
  padding: 0.75rem;
}
