:root {
  --bg-primary: #0a0a1a;
  --bg-secondary: #0f1a2e;
  --bg-card: #0f2a4a;
  --text-primary: #d0e8ff;
  --text-secondary: #6a8aaa;
  --accent: #00e5ff;
  --accent-hover: #5affff;
  --green: #00ff88;
  --yellow: #ffd600;
  --gray: #3a4a5a;
  --border: #1a2a4a;
  --shadow: rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  text-align: center;
  padding: 1.5rem 1rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 2px solid var(--border);
}
header h1 { font-size: 2rem; color: var(--accent); text-shadow: 0 0 10px rgba(0, 229, 255, 0.4); }
header .subtitle { color: var(--text-secondary); margin-top: 0.25rem; }
.user-info {
  display: flex; align-items: center; justify-content: center; gap: 1rem;
  margin-top: 0.5rem; font-size: 0.9rem;
}

/* Main */
main { flex: 1; padding: 1rem; max-width: 900px; margin: 0 auto; width: 100%; }

/* Auth */
.auth-container { max-width: 400px; margin: 2rem auto; border: 1px solid var(--accent); border-radius: 12px; padding: 1.5rem; box-shadow: 0 0 20px rgba(0, 229, 255, 0.1); }
.auth-tabs { display: flex; border-bottom: 2px solid var(--border); }
.auth-tabs button {
  flex: 1; padding: 0.75rem; background: none; border: none;
  color: var(--text-secondary); cursor: pointer; font-size: 1rem;
  border-bottom: 3px solid transparent; transition: all 0.2s;
}
.auth-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); text-shadow: 0 0 6px rgba(0, 229, 255, 0.4); }
.auth-form { padding: 1.5rem 0; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.3rem; color: var(--text-secondary); font-size: 0.9rem; }
.form-group input {
  width: 100%; padding: 0.75rem; background: var(--bg-secondary);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-primary); font-size: 1rem;
}
.form-group input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 8px rgba(0, 229, 255, 0.2); }

/* Buttons */
.btn-primary {
  width: 100%; padding: 0.75rem; background: var(--accent);
  border: none; border-radius: 8px; color: #0a0a1a;
  font-size: 1rem; cursor: pointer; transition: background 0.2s, box-shadow 0.2s;
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.3);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); box-shadow: 0 0 15px rgba(0, 229, 255, 0.5); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  padding: 0.5rem 1rem; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-primary); cursor: pointer;
}
.btn-secondary:hover { background: var(--bg-secondary); }
.btn-small {
  padding: 0.3rem 0.6rem; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 4px;
  color: var(--text-primary); cursor: pointer; font-size: 0.8rem;
}
.btn-small:hover { background: var(--bg-secondary); }
.btn-danger { background: #c0392b; border-color: #c0392b; }
.btn-danger:hover { background: #e74c3c; }

/* Messages */
.auth-message, .guess-message { margin-top: 1rem; text-align: center; font-size: 0.9rem; }
.auth-message.success, .guess-message.success { color: var(--green); }
.auth-message.error, .guess-message.error { color: var(--accent); text-shadow: 0 0 6px rgba(0, 229, 255, 0.4); }

/* Game */
.game-container { text-align: center; }
.game-header { margin-bottom: 1rem; }
.guess-counter { font-size: 1.2rem; color: var(--text-secondary); }
.game-result { margin-top: 0.5rem; font-size: 1.1rem; padding: 0.5rem; border-radius: 8px; border: 1px solid var(--accent); box-shadow: 0 0 10px rgba(0, 229, 255, 0.2); }
.game-result.win { background: rgba(83, 194, 59, 0.2); color: var(--green); }
.game-result.loss { background: rgba(0, 229, 255, 0.15); color: var(--accent); }

/* Feedback Table — full width, scroll only when screen is too narrow */
.feedback-container { margin: 1rem 0; }
.feedback-table { width: 100%; border-collapse: collapse; border: 1px solid var(--border); }
.feedback-table th, .feedback-table td {
  padding: 0.5rem; text-align: center; border: 1px solid var(--border);
}
.feedback-table th { background: var(--bg-secondary); font-size: 0.9rem; }
.feedback-table td:first-child { text-align: center; }
.guess-code { font-weight: bold; font-size: 1rem; color: var(--accent); letter-spacing: 1px; text-transform: uppercase; text-shadow: 0 0 6px rgba(0, 229, 255, 0.5); }
.station-name { font-size: 0.8rem; color: var(--text-secondary); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.feedback-cell {
  padding: 0.4rem 0.15rem; border-radius: 4px; font-size: 0.75rem;
  min-width: 50px; display: inline-block;
}
.feedback-cell.green { background: rgba(0, 255, 136, 0.15); color: var(--green); }
.feedback-cell.yellow { background: rgba(255, 214, 0, 0.15); color: var(--yellow); }
.feedback-cell.gray { background: rgba(58, 74, 90, 0.2); color: var(--text-secondary); }

/* Secret answer row (shown on loss) */
.secret-row td { background: rgba(0, 229, 255, 0.05); }
.secret-row .guess-code { color: var(--accent); opacity: 0.7; font-style: italic; }
.secret-row .station-name { color: var(--accent); opacity: 0.7; }

/* Guess Input */
.daily-leaderboard { margin: 1rem 0; }
.daily-leaderboard h3 { font-size: 1rem; color: var(--accent); text-align: center; margin-bottom: 0.5rem; }

.guess-input-container { margin: 1rem 0; }
.guess-form { display: flex; gap: 0.5rem; max-width: 400px; margin: 0 auto; }
.guess-input {
  flex: 1; padding: 0.75rem; background: var(--bg-secondary);
  border: 2px solid var(--border); border-radius: 8px;
  color: var(--text-primary); font-size: 1.1rem;
  text-transform: uppercase; text-align: center; letter-spacing: 2px;
}
.guess-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 8px rgba(0, 229, 255, 0.2); }
.guess-input::placeholder { text-transform: none; letter-spacing: normal; font-size: 0.9rem; }

/* Legend */
.legend { margin: 1.5rem 0; }
.legend h3 { font-size: 1rem; margin-bottom: 0.5rem; color: var(--text-secondary); }
.legend-items { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; }
.color-box { width: 16px; height: 16px; border-radius: 3px; display: inline-block; }
.color-box.green { background: var(--green); }
.color-box.yellow { background: var(--yellow); }
.color-box.gray { background: var(--gray); }

/* Nav buttons */
.nav-buttons { display: flex; gap: 0.5rem; justify-content: center; margin-top: 1.5rem; flex-wrap: wrap; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 1rem;
}
.modal {
  background: var(--bg-secondary); border-radius: 12px;
  max-width: 600px; width: 100%; max-height: 80vh;
  overflow-y: auto; border: 1px solid var(--accent); box-shadow: 0 0 20px rgba(0, 229, 255, 0.15);
}
.modal-large { max-width: 800px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.5rem; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.2rem; }
.modal-close {
  background: none; border: none; color: var(--text-primary);
  font-size: 1.5rem; cursor: pointer;
}
.modal-body { padding: 1.5rem; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { text-align: center; padding: 1rem; background: var(--bg-card); border-radius: 8px; border: 1px solid var(--border); }
.stat-value { font-size: 1.8rem; font-weight: bold; color: var(--accent); text-shadow: 0 0 8px rgba(0, 229, 255, 0.3); }
.stat-label { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.25rem; }

.guess-dist h3 { font-size: 1rem; margin-bottom: 0.75rem; }
.dist-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.3rem; }
.dist-row span:first-child { width: 60px; text-align: right; font-size: 0.85rem; }
.dist-bar-container { flex: 1; height: 20px; background: var(--bg-primary); border-radius: 4px; overflow: hidden; }
.dist-bar { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.3s; box-shadow: 0 0 8px rgba(0, 229, 255, 0.3); }
.dist-row span:last-child { width: 30px; font-size: 0.85rem; }

/* Leaderboard */
.leaderboard-table { width: 100%; border-collapse: collapse; }
.leaderboard-table th, .leaderboard-table td { padding: 0.5rem; text-align: center; border-bottom: 1px solid var(--border); }
.leaderboard-table th { color: var(--text-secondary); font-size: 0.85rem; }
.highlight { background: rgba(0, 229, 255, 0.08); }
.badge { padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.8rem; }
.badge.win { background: rgba(83, 194, 59, 0.2); color: var(--green); }
.badge.loss { background: rgba(0, 229, 255, 0.15); color: var(--accent); }

/* Admin table */
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { padding: 0.5rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.admin-table th { color: var(--text-secondary); }

.no-data { text-align: center; color: var(--text-secondary); padding: 2rem; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 0.5rem; margin-top: 1rem; }
.pagination button:disabled { opacity: 0.3; cursor: not-allowed; }

/* Footer */
footer { text-align: center; padding: 1rem; color: var(--text-secondary); font-size: 0.8rem; border-top: 1px solid var(--border); }

/* Responsive — Mobile-first tweaks */
@media (max-width: 600px) {
  /* Header */
  header { padding: 1rem 0.75rem 0.75rem; }
  header h1 { font-size: 1.4rem; }
  header .subtitle { font-size: 0.85rem; }
  .user-info { font-size: 0.8rem; gap: 0.5rem; }

  /* Main container */
  main { padding: 0.75rem; }

  /* Auth */
  .auth-container { margin: 1rem auto; padding: 1rem; max-width: 100%; }
  .auth-tabs button { padding: 0.6rem 0.5rem; font-size: 0.9rem; }
  .auth-form { padding: 1rem 0; }

  /* Game container */
  .game-container { padding: 0.75rem; }
  .game-header { flex-direction: column; gap: 0.5rem; align-items: stretch; text-align: center; }
  .guess-counter { font-size: 1.1rem; }
  .game-result { font-size: 0.9rem; padding: 0.5rem; }

  /* Feedback table — horizontal scroll */
  .feedback-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .feedback-table { font-size: 0.75rem; }
  .feedback-table thead th { font-size: 0.7rem; padding: 0.3rem 0.2rem; white-space: nowrap; }
  .feedback-table tbody td { padding: 0.3rem 0.2rem; }
  .guess-code { font-size: 0.75rem; }
  .station-name { font-size: 0.75rem; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .feedback-cell { font-size: 0.7rem; padding: 0.2rem 0.15rem; }

  /* Legend */
  .legend h3 { font-size: 0.9rem; }
  .legend-items { flex-wrap: wrap; gap: 0.4rem; }
  .legend-item { font-size: 0.75rem; }
  .color-box { width: 12px; height: 12px; }

  /* Nav buttons — stack on mobile */
  .nav-buttons { flex-direction: column; gap: 0.4rem; }
  .nav-buttons button { width: 100%; }

  /* Leaderboard tables — horizontal scroll */
  .leaderboard-table { font-size: 0.8rem; }
  .leaderboard-table th, .leaderboard-table td { padding: 0.4rem 0.3rem; font-size: 0.75rem; }

  /* Stats */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
  .stat-value { font-size: 1.4rem; }
  .stat-label { font-size: 0.7rem; }
  .guess-dist { padding: 0.75rem; }
  .dist-row span:first-child { width: 50px; }

  /* Modals */
  .modal { margin: 0.5rem; max-height: 90vh; }
  .modal-header { padding: 0.75rem 1rem; }
  .modal-header h2 { font-size: 1rem; }
  .modal-body { padding: 1rem; }
  .modal-large { max-width: 100%; }

  /* Admin table */
  .admin-table { font-size: 0.75rem; }
  .admin-table th, .admin-table td { padding: 0.4rem 0.3rem; }
}

/* Extra small screens (e.g. iPhone SE) */
@media (max-width: 380px) {
  header h1 { font-size: 1.2rem; }
  .guess-code { font-size: 0.65rem; }
  .station-name { max-width: 60px; }
  .feedback-cell { font-size: 0.65rem; }
  .stat-value { font-size: 1.2rem; }
}
