:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #3b82f6;
  --accent-light: #60a5fa;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --danger-light: #f87171;
  --danger-hover: #dc2626;
  --ok: #10b981;
  --ok-light: #34d399;
  --ok-hover: #059669;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

* { 
  box-sizing: border-box; 
}

html, body { 
  height: 100%; 
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Prevent pull-to-refresh on mobile */
  overscroll-behavior-y: contain;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px 20px;
}

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

.title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.title h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
  letter-spacing: -0.5px;
}

.title .sub {
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
}

.nav a {
  color: var(--text);
  text-decoration: none;
  border: 1.5px solid var(--border);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--card);
  font-weight: 500;
  font-size: 14px;
  transition: all 0.2s ease;
  box-shadow: var(--shadow);
  -webkit-tap-highlight-color: rgba(59, 130, 246, 0.2);
  touch-action: manipulation;
  display: inline-block;
  min-height: 44px; /* iOS minimum touch target */
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav a:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.player {
  border: 2px solid var(--border-light);
  border-radius: 16px;
  padding: 24px;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  transition: all 0.2s ease;
}

.player:hover {
  border-color: var(--border);
  box-shadow: var(--shadow);
}

.player h2 {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

.big {
  font-size: 72px;
  font-weight: 800;
  line-height: 1;
  margin: 12px 0 20px;
  color: var(--text);
  letter-spacing: -2px;
}

.btnrow {
  display: flex;
  gap: 12px;
}

button {
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid transparent;
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
  transition: all 0.2s ease;
  box-shadow: var(--shadow);
  font-family: inherit;
  -webkit-tap-highlight-color: rgba(59, 130, 246, 0.2);
  touch-action: manipulation; /* Improves touch responsiveness */
  user-select: none; /* Prevents text selection on tap */
}

button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

button.primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
  color: white;
  border-color: var(--accent);
  box-shadow: 0 4px 14px 0 rgba(59, 130, 246, 0.3);
}

button.primary:hover {
  background: linear-gradient(135deg, var(--accent-hover) 0%, var(--accent) 100%);
  box-shadow: 0 6px 20px 0 rgba(59, 130, 246, 0.4);
}

button.danger {
  background: linear-gradient(135deg, var(--danger) 0%, var(--danger-light) 100%);
  color: white;
  border-color: var(--danger);
  box-shadow: 0 4px 14px 0 rgba(239, 68, 68, 0.3);
}

button.danger:hover {
  background: linear-gradient(135deg, var(--danger-hover) 0%, var(--danger) 100%);
  box-shadow: 0 6px 20px 0 rgba(239, 68, 68, 0.4);
}

button.ok {
  background: linear-gradient(135deg, var(--ok) 0%, var(--ok-light) 100%);
  color: white;
  border-color: var(--ok);
  box-shadow: 0 4px 14px 0 rgba(16, 185, 129, 0.3);
}

button.ok:hover {
  background: linear-gradient(135deg, var(--ok-hover) 0%, var(--ok) 100%);
  box-shadow: 0 6px 20px 0 rgba(16, 185, 129, 0.4);
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.kv {
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.input {
  flex: 1;
  min-width: 220px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s ease;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.input::placeholder {
  color: var(--muted);
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
}

.table th, .table td {
  text-align: left;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  font-size: 14px;
}

.table th {
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.05em;
  background: var(--bg);
}

.table tr {
  transition: background 0.2s ease;
}

.table tr:hover {
  background: var(--bg);
}

.table tr:last-child td {
  border-bottom: none;
}

.badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  background: var(--card);
}

.badge.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.1);
}

.small {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

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

.modal-content {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  max-width: 420px;
  width: 90%;
  box-shadow: var(--shadow-xl);
  animation: slideUp 0.3s ease;
}

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

.modal-content h2 {
  margin: 0 0 12px;
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.modal-content p {
  margin: 0 0 20px;
  color: var(--muted);
}

/* Mobile-first responsive design */
@media (max-width: 768px) {
  .container {
    padding: 16px 12px;
  }

  .header {
    margin-bottom: 20px;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .title h1 {
    font-size: 24px;
  }

  .title .sub {
    font-size: 13px;
  }

  .nav a {
    width: 100%;
    text-align: center;
    padding: 12px 16px;
  }

  .grid {
    gap: 16px;
  }

  .card {
    padding: 20px 16px;
    border-radius: 16px;
  }

  .scoreboard {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .player {
    padding: 20px;
  }

  .big {
    font-size: 64px;
    margin: 16px 0 24px;
  }

  button {
    padding: 16px 20px;
    font-size: 18px;
    min-height: 56px; /* Minimum touch target size */
    border-radius: 14px;
  }

  .btnrow {
    gap: 12px;
  }

  .row {
    flex-direction: column;
    gap: 12px;
  }

  .row button {
    width: 100%;
  }

  .input {
    width: 100%;
    min-width: unset;
    padding: 14px 16px;
    font-size: 16px; /* Prevents zoom on iOS */
    min-height: 48px;
  }

  .table {
    font-size: 13px;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table th, .table td {
    padding: 12px 10px;
    white-space: nowrap;
  }

  .table th {
    font-size: 11px;
  }

  .badge {
    padding: 8px 12px;
    font-size: 11px;
  }

  .kv {
    font-size: 13px;
  }

  .small {
    font-size: 12px;
  }

  .modal-content {
    padding: 24px 20px;
    margin: 20px;
    width: calc(100% - 40px);
    max-width: none;
  }

  .modal-content h2 {
    font-size: 22px;
  }
}

/* Extra small devices */
@media (max-width: 480px) {
  .container {
    padding: 12px 10px;
  }

  .title h1 {
    font-size: 22px;
  }

  .big {
    font-size: 56px;
  }

  .card {
    padding: 16px 12px;
  }

  .player {
    padding: 16px;
  }

  button {
    padding: 14px 18px;
    font-size: 16px;
    min-height: 52px;
  }

  .table th, .table td {
    padding: 10px 8px;
    font-size: 12px;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  button {
    min-height: 48px;
    padding: 14px 20px;
  }

  .nav a {
    min-height: 44px;
    padding: 12px 16px;
  }

  /* Remove hover effects on touch devices */
  button:hover {
    transform: none;
  }

  .card:hover {
    box-shadow: var(--shadow-md);
  }

  .player:hover {
    border-color: var(--border-light);
    box-shadow: none;
  }
}

/* Prevent text size adjustment on iOS */
@media screen and (max-width: 768px) {
  input, select, textarea {
    font-size: 16px !important;
  }
}
