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

html, body, .wrapper {
  margin: 0;
  padding: 0;
}

/* CSS Custom Properties for theming */
:root {
  --color-primary: #561C1D;
  --color-primary-dark: #3d1415;
  --color-accent: #C5A144;
  --color-accent-hover: #a68535;
  --color-success: #28a745;
  --color-error: #dc3545;
  --color-warning: #ffc107;
  --color-info: #17a2b8;
  
  --bg-primary: #f5f5f5;
  --bg-card: #ffffff;
  --bg-hover: #f8f9fa;
  --text-primary: #333;
  --text-secondary: #666;
  --text-tertiary: #999;
  --border-color: #ddd;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 2px 4px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-xl: 0 8px 24px rgba(0,0,0,0.2);
  
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 350ms ease;
}

/* Force light mode only */
:root {
  color-scheme: light;
}

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

/* Base Styles */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: #C5A144;
  text-decoration: none;
  transition: color 0.2s;
}

a:focus,
button:focus,
.btn:focus,
input:focus,
select:focus,
textarea:focus {
  outline: 3px solid #C5A144;
  outline-offset: 2px;
}

a:hover {
  color: #a68535;
  text-decoration: underline;
}

.wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header Styles */
header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #561C1D;
  z-index: 1000;
  padding: 12px 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  flex-wrap: wrap;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

/* Auto-hiding header */
header.header-hidden {
  transform: translateY(-100%);
  box-shadow: none;
}

/* Safe area support for notched devices */
@supports (padding: max(0px)) {
  header {
    padding-left: max(30px, env(safe-area-inset-left));
    padding-right: max(30px, env(safe-area-inset-right));
  }
}

.header-left {
  display: flex;
  align-items: center;
  gap: 15px;
}

.header-left a {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.logo {
  height: 45px;
  width: auto;
}

header h1 {
  font-size: 24px;
  color: #fff;
  font-weight: 600;
}

header h1 a {
  color: #fff;
  text-decoration: none;
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  flex-direction: column;
  gap: 5px;
  min-width: 44px;
  min-height: 44px;
  justify-content: center;
  align-items: center;
}

.hamburger-line {
  width: 25px;
  height: 3px;
  background: #fff;
  border-radius: 2px;
  transition: all 0.3s;
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-line:nth-child(1) {
  transform: rotate(45deg) translate(7px, 7px);
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-line:nth-child(2) {
  opacity: 0;
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-line:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -7px);
}

.nav {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 15px;
}

.nav a {
  color: #fff;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.nav a:hover {
  background-color: rgba(255,255,255,0.1);
  text-decoration: none;
}

.nav .user-info {
  color: #C5A144;
  font-weight: 500;
}

.nav .logout-link {
  color: #ffcccc;
}

/* Content Area */
.content {
  flex: 1;
  margin-top: 80px;
  margin-bottom: 60px;
  padding: 30px;
  max-width: 1400px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

/* Footer */
footer {
  background-color: #561C1D;
  padding: 15px 30px;
  text-align: center;
  margin-top: auto;
}

.footer-blurb {
  font-size: 14px;
  color: #fff;
}

.footer-blurb a {
  color: #C5A144;
}

/* Flash Messages */
#flash-messages {
  margin-bottom: 20px;
}

.alert {
  padding: 12px 20px;
  margin-bottom: 15px;
  border-radius: 6px;
  font-size: 15px;
  border-left: 4px solid;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: slideIn 0.3s ease-out;
  box-shadow: var(--shadow-md);
}

/* Alert entrance animation */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Alert exit animation */
@keyframes slideOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

.alert.dismissing {
  animation: slideOut 0.3s ease-out forwards;
}

/* Dismiss button */
.alert-dismiss {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: inherit;
  opacity: 0.5;
  cursor: pointer;
  padding: 0;
  margin-left: 15px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: opacity var(--transition-fast), background-color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.alert-dismiss:hover {
  opacity: 1;
  background-color: rgba(0, 0, 0, 0.1);
}

.alert-success {
  background-color: #d4edda;
  border-color: var(--color-success);
  color: #155724;
}

.alert-error, .alert-danger {
  background-color: #f8d7da;
  border-color: var(--color-error);
  color: #721c24;
}

.alert-info {
  background-color: #d1ecf1;
  border-color: var(--color-info);
  color: #0c5460;
}

.alert-warning {
  background-color: #fff3cd;
  border-color: var(--color-warning);
  color: #856404;
}

/* Cards */
.card {
  background: white;
  border-radius: 8px;
  padding: 25px;
  margin-bottom: 25px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}

.card h3 {
  margin-bottom: 20px;
  color: #561C1D;
  font-size: 20px;
  font-weight: 600;
}

.card-header-with-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.card-header-with-link h3 {
  margin-bottom: 0;
}

.view-all-link {
  font-size: 14px;
  white-space: nowrap;
}

.card h4 {
  margin-top: 20px;
  margin-bottom: 12px;
  color: #666;
  font-size: 16px;
  font-weight: 600;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: 6px;
  border: none;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition-fast);
  text-align: center;
  min-height: 44px;
  line-height: 1.5;
  touch-action: manipulation;
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  vertical-align: middle;
}

/* Enhanced touch feedback */
.btn:active {
  transform: scale(0.97);
  transition-duration: 50ms;
}

/* Ripple effect */
.btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.btn:active::after {
  width: 300px;
  height: 300px;
}

.btn-primary {
  background-color: #561C1D;
  color: white;
}

.btn-primary:hover {
  background-color: #3d1415;
  text-decoration: none;
}

.btn-secondary {
  background-color: #6c757d;
  color: white;
}

.btn-secondary:hover {
  background-color: #5a6268;
  text-decoration: none;
}

.btn-warning {
  background-color: #ffc107;
  color: #333;
}

.btn-warning:hover {
  background-color: #e0a800;
}

.btn-danger {
  background-color: #dc3545;
  color: white;
}

.btn-danger:hover {
  background-color: #c82333;
}

.btn-success {
  background-color: #28a745;
  color: white;
}

.btn-success:hover {
  background-color: #218838;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

/* Forms */
.form-group {
  margin-bottom: 20px;
  position: relative;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="email"],
.form-group input[type="search"],
.form-group input[type="tel"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  font-size: 15px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  background-color: var(--bg-card);
  color: var(--text-primary);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(86, 28, 29, 0.1);
}

/* Valid input state */
.form-group input:valid:not(:placeholder-shown):not([type="search"]) {
  border-color: var(--color-success);
}

/* Invalid input state */
.form-group input:invalid:not(:placeholder-shown):not(:focus):not([type="search"]) {
  border-color: var(--color-error);
}

/* Search inputs don't need validation colors */
.form-group input[type="search"]:focus {
  border-color: var(--color-primary);
}

/* Input with error animation */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.form-group.has-error input {
  animation: shake 0.5s;
  border-color: var(--color-error);
}

.form-group input:disabled {
  background-color: #f0f0f0;
  color: #999;
}

.form-group small {
  display: block;
  margin-top: 5px;
  font-size: 13px;
  color: #666;
}

/* Login/Auth Pages */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 200px);
}

.login-box {
  background: white;
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  width: 100%;
  max-width: 400px;
}

.login-box h2 {
  color: #561C1D;
  margin-bottom: 10px;
  text-align: center;
}

.login-box .subtitle {
  text-align: center;
  color: #666;
  margin-bottom: 30px;
  font-size: 14px;
}

.admin-link, .user-link {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
}

/* Dashboard */
.dashboard-header h2 {
  color: #561C1D;
  margin-bottom: 25px;
  font-size: 28px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 25px;
  margin-bottom: 25px;
}

.stats-card .stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 15px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
}

.stat-label {
  font-size: 13px;
  color: #666;
  margin-bottom: 5px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: #561C1D;
}

.quick-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Games List */
.games-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.game-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--bg-card);
  border-radius: 8px;
  border-left: 4px solid var(--color-primary);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}

.game-item:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.game-players {
  flex: 1;
  font-size: 15px;
  line-height: 1.5;
}

.game-players .winner {
  font-weight: 600;
  color: var(--color-success);
  position: relative;
  padding-left: 18px;
}

.game-players .winner::before {
  content: '🏆';
  position: absolute;
  left: 0;
  font-size: 14px;
}

.game-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 14px;
  color: #666;
}

.delete-form-inline {
  display: inline-block;
  margin: 0;
  margin-left: 8px;
}

.btn-delete-small {
  background-color: #dc3545;
  color: white;
  border: none;
  padding: 2px 6px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.85em;
  transition: background-color 0.2s;
  line-height: 1;
  min-height: 28px;
}

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

.elo-change {
  font-weight: 600;
  color: #C5A144;
}

.game-time {
  font-size: 13px;
}

/* Tables */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
  max-width: 100%;
}

table {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
  background: white;
}

.leaderboard-table {
  min-width: 500px;
}

table thead {
  background: #f8f9fa;
  position: sticky;
  top: 0;
  z-index: 1;
}

table th {
  padding: 12px;
  text-align: left;
  font-weight: 600;
  color: #555;
  border-bottom: 2px solid #dee2e6;
  white-space: nowrap;
}

table td {
  padding: 12px;
  border-bottom: 1px solid #dee2e6;
}

table tr:hover {
  background: #f8f9fa;
}

table tr.highlight {
  background: #fff3cd;
}

.leaderboard-table .rank-cell {
  font-weight: 700;
  color: var(--color-primary);
  font-size: 16px;
}

/* Medal badges for top 3 ranks */
.leaderboard-table tbody tr:nth-child(1) .rank-cell {
  position: relative;
  color: #FFD700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.leaderboard-table tbody tr:nth-child(1) .rank-cell::before {
  content: '🥇';
  margin-right: 4px;
}

.leaderboard-table tbody tr:nth-child(2) .rank-cell {
  position: relative;
  color: #C0C0C0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.leaderboard-table tbody tr:nth-child(2) .rank-cell::before {
  content: '🥈';
  margin-right: 4px;
}

.leaderboard-table tbody tr:nth-child(3) .rank-cell {
  position: relative;
  color: #CD7F32;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.leaderboard-table tbody tr:nth-child(3) .rank-cell::before {
  content: '🥉';
  margin-right: 4px;
}

/* Highlight top 3 rows */
.leaderboard-table tbody tr:nth-child(-n+3) {
  background: linear-gradient(to right, rgba(197, 161, 68, 0.05), transparent);
  font-weight: 500;
}

.leaderboard-table .elo-cell {
  font-weight: 600;
  color: var(--color-accent);
  font-size: 15px;
}

.winner-cell {
  font-weight: 600;
  color: #28a745;
}

/* Tournament Lists */
.tournament-list {
  list-style: none;
}

.tournament-list li {
  padding: 12px;
  margin-bottom: 8px;
  background: #f8f9fa;
  border-radius: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.tournament-list a {
  font-weight: 500;
  flex: 1;
}

.tournament-status {
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-open {
  background: #d4edda;
  color: #155724;
}

.status-active {
  background: #d1ecf1;
  color: #0c5460;
}

.status-completed {
  background: #d6d8db;
  color: #383d41;
}

.tournament-format,
.tournament-participants {
  font-size: 14px;
  color: #666;
}

/* Page Container */
.page-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
}

/* Tournament Pages */
.page-container h2 {
  color: #561C1D;
  margin-bottom: 25px;
  font-size: 28px;
}

.tournament-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.tournament-card {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
  border-left: 4px solid #561C1D;
}

.tournament-card.active {
  border-left-color: #17a2b8;
}

.tournament-card h4 {
  margin-bottom: 12px;
  color: #561C1D;
}

.tournament-info {
  display: flex;
  gap: 15px;
  margin-bottom: 15px;
  font-size: 14px;
  color: #666;
}

.tournament-header {
  margin-bottom: 25px;
}

.tournament-meta {
  display: flex;
  gap: 15px;
  margin-top: 10px;
}

.signup-box {
  background: #e7f3ff;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 25px;
}

.signup-box h3 {
  color: #561C1D;
  margin-bottom: 15px;
}

.rating-input {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.rating-label {
  cursor: pointer;
}

.rating-label input {
  display: none;
}

.rating-label span {
  display: inline-block;
  padding: 8px 14px;
  background: white;
  border: 2px solid #ddd;
  border-radius: 6px;
  font-weight: 600;
  transition: all 0.2s;
}

.rating-label input:checked + span {
  background: #561C1D;
  color: white;
  border-color: #561C1D;
}

.rating-label:hover span {
  border-color: #561C1D;
}

/* Bracket Visualization */
.bracket-container {
  margin-bottom: 40px;
}

.bracket-container h4 {
  color: #561C1D;
  margin-bottom: 20px;
  font-size: 20px;
}

.bracket-round {
  margin-bottom: 30px;
}

.bracket-round h5 {
  color: #666;
  margin-bottom: 15px;
  font-size: 16px;
}

.matches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 15px;
}

.match-card {
  background: white;
  border: 2px solid #ddd;
  border-radius: 8px;
  padding: 15px;
}

.match-card.completed {
  border-color: #28a745;
}

.match-header {
  font-size: 12px;
  color: #666;
  margin-bottom: 10px;
  text-align: center;
  font-weight: 600;
}

.match-player {
  padding: 8px 12px;
  background: #f8f9fa;
  border-radius: 4px;
  margin-bottom: 6px;
  font-size: 14px;
}

.match-player.winner {
  background: #d4edda;
  font-weight: 600;
  color: #155724;
}

.match-vs {
  text-align: center;
  font-size: 12px;
  color: #999;
  margin: 6px 0;
}

.match-result {
  margin-top: 12px;
  padding: 8px;
  background: #d4edda;
  border-radius: 4px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #155724;
}

.match-report-form {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

.match-report-form select {
  flex: 1;
  padding: 6px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
}

/* Search Input Wrapper */
.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrapper input {
  flex: 1;
  padding-right: 40px;
}

.search-loading {
  position: absolute;
  right: 12px;
  font-size: 20px;
  animation: pulse 1s ease-in-out infinite;
  pointer-events: none;
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}

/* Search Results */
.search-results {
  position: absolute;
  background: var(--bg-card);
  border: 2px solid var(--color-primary);
  border-radius: 8px;
  max-height: 320px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  left: 0;
  z-index: 100;
  box-shadow: var(--shadow-xl);
  display: none;
  margin-top: 4px;
}

.search-results::-webkit-scrollbar {
  width: 8px;
}

.search-results::-webkit-scrollbar-track {
  background: transparent;
}

.search-results::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.search-result-item {
  padding: 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background-color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.search-result-item .player-name {
  font-weight: 600;
  flex: 1;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover,
.search-result-item:focus {
  background: var(--bg-hover);
}

.search-result-item:active {
  background: var(--border-color);
}

.search-result-item.no-results {
  cursor: default;
  color: var(--text-tertiary);
  font-style: italic;
}

.search-result-item.no-results:hover {
  background: transparent;
}

.selected-opponent {
  margin-top: 10px;
  display: none;
  animation: fadeIn 0.3s ease;
}

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

.selected-opponent-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: linear-gradient(135deg, #e7f3ff 0%, #d0e9ff 100%);
  border-radius: 8px;
  border: 2px solid #b8d7f5;
  box-shadow: var(--shadow-sm);
}

.selected-opponent-card strong {
  flex: 1;
  color: var(--text-primary);
  font-size: 15px;
}

.elo-badge {
  padding: 4px 10px;
  background: #C5A144;
  color: white;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
}

.clear-btn {
  margin-left: auto;
  background: #dc3545;
  color: white;
  border: none;
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.clear-btn:hover {
  background: #c82333;
  transform: scale(1.1);
}

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

.clear-btn:focus {
  outline: 2px solid var(--color-error);
  outline-offset: 2px;
}

/* Radio Groups */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 14px 16px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  transition: all var(--transition-fast);
  min-height: 48px;
  position: relative;
  background: var(--bg-card);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.radio-label:hover {
  border-color: var(--color-primary);
  background: var(--bg-hover);
  box-shadow: var(--shadow-sm);
}

.radio-label:active {
  transform: scale(0.98);
  box-shadow: inset var(--shadow-sm);
}

.radio-label:has(input:checked) {
  border-color: var(--color-primary);
  background: rgba(86, 28, 29, 0.05);
  box-shadow: 0 0 0 1px var(--color-primary);
}

.radio-label input[type="radio"] {
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  cursor: pointer;
  accent-color: var(--color-primary);
}

.radio-label span {
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.4;
}

/* Admin Styles */
.admin-container {
  max-width: 1200px;
  margin: 0 auto;
}

.admin-container h2 {
  color: #561C1D;
  margin-bottom: 30px;
  font-size: 32px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
}

.stat-card {
  background: white;
  padding: 25px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
  text-align: center;
  border-top: 4px solid #561C1D;
}

.admin-section {
  background: white;
  padding: 25px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
  margin-bottom: 30px;
}

.admin-section h3 {
  color: #561C1D;
  margin-bottom: 20px;
  font-size: 22px;
}

.admin-form.inline-form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.admin-form.inline-form .form-group {
  flex: 1;
  min-width: 150px;
  margin-bottom: 0;
}

.admin-table {
  width: 100%;
}

.actions-cell {
  white-space: nowrap;
}

.actions-cell form {
  display: inline;
  margin-right: 5px;
}

.archived-row {
  opacity: 0.6;
}

.incomplete-profile {
  background-color: #fff3cd;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 10px;
  margin-left: 8px;
}

.badge-warning {
  background-color: #ffc107;
  color: #333;
}

.badge-inactive {
  background-color: #6c757d;
  color: #fff;
}

.help-text {
  color: #666;
  font-size: 14px;
  margin-bottom: 15px;
}

.incomplete-name {
  color: #999;
  font-style: italic;
}

.admin-actions {
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
  margin-top: 30px;
}

.admin-action-form {
  margin: 20px 0;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.modal-content {
  background: white;
  padding: 30px;
  border-radius: 12px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.modal-content h3 {
  color: #561C1D;
  margin-bottom: 20px;
}

.format-descriptions {
  margin-top: 15px;
}

.format-desc {
  display: none;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 6px;
  font-size: 14px;
  margin-top: 10px;
}

.format-desc strong {
  color: #561C1D;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 25px;
  align-items: stretch;
}

.form-actions .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Error Pages */
.error-container {
  text-align: center;
  padding: 60px 20px;
}

.error-container h1 {
  font-size: 120px;
  color: #561C1D;
  margin-bottom: 20px;
}

.error-container h2 {
  font-size: 32px;
  color: #666;
  margin-bottom: 15px;
}

.error-container p {
  font-size: 18px;
  color: #999;
  margin-bottom: 30px;
}

/* Skip to content link for accessibility */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-primary);
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  z-index: 10000;
  border-radius: 0 0 4px 0;
}

.skip-link:focus {
  top: 0;
}

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

/* Responsive Design */
@media (max-width: 768px) {
  /* Header adjustments */
  header {
    padding: 8px 15px;
    gap: 10px;
  }
  
  @supports (padding: max(0px)) {
    header {
      padding-left: max(15px, env(safe-area-inset-left));
      padding-right: max(15px, env(safe-area-inset-right));
    }
  }

  .mobile-menu-toggle {
    display: flex;
    order: 2;
  }

  .header-left {
    order: 1;
    flex: 1;
  }

  .nav {
    order: 3;
    flex-basis: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
  }

  .nav.mobile-menu-open {
    max-height: 500px;
    padding-top: 15px;
    padding-bottom: 10px;
  }
  
  .nav a,
  .nav .user-info {
    padding: 12px 16px;
    min-height: 44px;
    display: flex;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .nav a {
    background: rgba(255, 255, 255, 0.05);
  }

  .nav a:active {
    background: rgba(255, 255, 255, 0.15);
  }

  .content {
    padding: 15px;
    margin-top: 80px;
  }
  
  @supports (padding: max(0px)) {
    .content {
      padding-left: max(15px, env(safe-area-inset-left));
      padding-right: max(15px, env(safe-area-inset-right));
      padding-bottom: max(15px, env(safe-area-inset-bottom));
    }
  }
  
  /* Flash messages at bottom on mobile for easier dismissal */
  #flash-messages {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1001;
    margin: 0;
    padding: 10px;
  }
  
  @supports (padding: max(0px)) {
    #flash-messages {
      padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
  }
  
  .alert {
    margin-bottom: 8px;
    box-shadow: var(--shadow-xl);
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }
  
  .card {
    margin-bottom: 15px;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .tournament-grid {
    grid-template-columns: 1fr;
  }

  .matches {
    grid-template-columns: 1fr;
  }

  .admin-form.inline-form {
    flex-direction: column;
  }

  .admin-form.inline-form .form-group {
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .page-container {
    padding: 15px;
  }
  
  .page-container h2 {
    font-size: 24px;
    margin-bottom: 20px;
  }

  table {
    font-size: 14px;
  }

  table th,
  table td {
    padding: 8px 6px;
  }
  
  .leaderboard-table {
    min-width: 100%;
    table-layout: fixed;
    width: 100%;
  }
  
  .leaderboard-table.full {
    min-width: 100%;
    table-layout: fixed;
  }
  
  .leaderboard-table th,
  .leaderboard-table td {
    word-wrap: break-word;
    overflow-wrap: break-word;
  }
  
  /* Make rank and ELO columns narrower */
  .leaderboard-table .rank-cell {
    width: 15%;
    max-width: 50px;
  }
  
  .leaderboard-table .elo-cell {
    width: 25%;
    max-width: 70px;
  }
  
  .leaderboard-table td:nth-child(2) {
    width: 60%;
  }
  
  .btn {
    padding: 12px 20px;
    font-size: 16px;
    width: 100%;
  }
  
  .btn-sm {
    width: auto;
    padding: 8px 14px;
  }
  
  .quick-actions .btn {
    width: 100%;
  }
  
  .game-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .game-meta {
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 480px) {
  header h1 {
    font-size: 18px;
  }

  .logo {
    height: 35px;
  }

  .nav {
    font-size: 14px;
  }
  
  .nav a {
    font-size: 14px;
    padding: 10px 16px;
  }

  .login-box {
    padding: 25px;
  }

  .error-container h1 {
    font-size: 80px;
  }
  
  .content {
    margin-top: 70px;
  }
  
  .stat-value {
    font-size: 24px;
  }
  
  .card {
    padding: 15px;
    margin-bottom: 12px;
  }
  
  .card .table-container {
    margin-left: 0;
    margin-right: 0;
    border-radius: 0;
  }
  
  .dashboard-grid {
    gap: 12px;
  }
  
  table {
    font-size: 13px;
  }
  
  .leaderboard-table {
    min-width: 100%;
    table-layout: fixed;
    width: 100%;
  }
  
  .leaderboard-table.full {
    min-width: 100%;
    table-layout: fixed;
  }
  
  .leaderboard-table th,
  .leaderboard-table td {
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 12px;
  }
  
  /* Make rank and ELO columns narrower on small screens */
  .leaderboard-table .rank-cell {
    width: 15%;
    max-width: 40px;
    padding: 8px 4px;
  }
  
  .leaderboard-table .elo-cell {
    width: 20%;
    max-width: 60px;
    padding: 8px 4px;
  }
  
  .leaderboard-table td:nth-child(2) {
    width: 65%;
  }
  
  /* Hide white-space: nowrap on mobile for table headers */
  table th {
    white-space: normal;
    font-size: 12px;
  }
  
  /* Make games table more compact on mobile */
  .games-table {
    min-width: 100%;
    table-layout: auto;
  }
  
  .games-table th,
  .games-table td {
    padding: 8px 4px;
    font-size: 12px;
  }
  
  .games-table .btn-delete {
    padding: 4px 8px;
    font-size: 11px;
    min-height: 32px;
  }
  
  /* Tournament tables */
  .tournament-table {
    min-width: 100%;
  }
  
  .participants-table {
    min-width: 100%;
  }
  
  /* Ensure page containers don't overflow */
  .page-container {
    max-width: 100%;
    overflow-x: hidden;
  }
  
  /* Reduce table container padding on mobile */
  .table-container {
    margin-left: 0;
    margin-right: 0;
    border-radius: 8px;
    box-shadow: none;
  }
  
  .card .table-container {
    margin-left: 0;
    margin-right: 0;
    border-radius: 0;
  }
  
  /* Improved form controls for mobile */
  .form-group input[type="text"],
  .form-group input[type="password"],
  .form-group input[type="number"],
  .form-group input[type="email"],
  .form-group input[type="search"],
  .form-group input[type="tel"],
  .form-group select,
  .form-group textarea {
    font-size: 16px;
    padding: 14px 12px;
    min-height: 48px;
  }
  
  /* Larger touch targets for radio buttons */
  .radio-label {
    padding: 14px 12px;
    min-height: 52px;
  }
  
  .radio-label input[type="radio"] {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
  }
  
  .search-results {
    width: 100%;
    max-height: 50vh;
    border-width: 2px;
  }
  
  /* Make search results more prominent on mobile */
  .search-result-item {
    padding: 16px 14px;
    min-height: 56px;
    font-size: 16px;
  }
  
  .search-result-item strong {
    font-size: 16px;
  }
  
  .elo-badge {
    font-size: 14px;
    padding: 5px 12px;
  }
  
  /* Form improvements on mobile */
  .game-report-form {
    max-width: 100%;
  }
  
  .game-report-form .btn {
    width: 100%;
    margin-bottom: 8px;
  }
  
  .game-report-form .btn-primary {
    margin-right: 0;
  }
  
  .form-group label {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 8px;
  }
  
  .game-type-form h3 {
    font-size: 17px;
    margin-top: 24px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
  }
  
  .selected-opponent-card {
    padding: 14px;
  }
  
  .clear-btn {
    font-size: 22px;
    min-width: 44px;
    min-height: 44px;
  }
  
  .page-container {
    padding: 12px;
  }
  
  .page-container h2 {
    font-size: 22px;
    margin-bottom: 18px;
  }
  
  .rating-label span {
    padding: 12px 16px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* Expandable rows for mobile */
@media (max-width: 768px) {
  .leaderboard-table tbody tr:not(.player-details-row) {
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
  }
}

/* Desktop view - no expandable rows */
@media (min-width: 769px) {
  .leaderboard-table tbody tr {
    cursor: default;
  }
}

.player-details {
  display: none;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 16px;
  background: var(--bg-hover);
  border-top: 2px solid var(--border-color);
  animation: slideDown 0.3s ease;
  width: 100%;
  box-sizing: border-box;
}

.player-details.show {
  display: grid;
}

.player-details-row {
  background: transparent !important;
}

.player-details-row td {
  padding: 0 !important;
}

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

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

.detail-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  font-weight: 600;
}

.detail-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.detail-value.positive {
  color: var(--color-success);
}

.detail-value.negative {
  color: var(--color-error);
}

@media (max-width: 768px) {
  /* Hide Wins, Losses, Win Rate columns on mobile - only show on expand */
  .leaderboard-table thead th:nth-child(4),
  .leaderboard-table thead th:nth-child(5),
  .leaderboard-table thead th:nth-child(6),
  .leaderboard-table tbody tr:not(.player-details-row) td:nth-child(4),
  .leaderboard-table tbody tr:not(.player-details-row) td:nth-child(5),
  .leaderboard-table tbody tr:not(.player-details-row) td:nth-child(6) {
    display: none;
  }
  
  /* Make table full width on mobile */
  .leaderboard-table {
    min-width: 100%;
    width: 100%;
  }
  
  /* Remove any extra margins */
  .table-container {
    overflow-x: visible;
  }
}

@media (max-width: 600px) {
  /* Keep table compact on mobile */
  .leaderboard-table {
    font-size: 13px;
  }
  
  .leaderboard-table th,
  .leaderboard-table td {
    padding: 12px 10px;
  }
  
  .leaderboard-table tbody tr:not(.player-details-row) {
    border-left: 4px solid transparent;
    min-height: 56px;
  }
  
  .leaderboard-table tbody tr:not(.player-details-row):active {
    background: var(--bg-hover);
    border-left-color: var(--color-primary);
  }
  
  .leaderboard-table tbody tr.expanded {
    border-left-color: var(--color-primary);
    background: var(--bg-card);
  }
  
  /* Make rank and name more prominent on mobile */
  .leaderboard-table .rank-cell {
    font-size: 16px;
    font-weight: 700;
  }
  
  .leaderboard-table .elo-cell {
    font-size: 15px;
    font-weight: 600;
  }
  
  /* Adjust detail panels on smaller screens */
  .player-details {
    padding: 12px;
    gap: 10px;
  }
  
  .detail-label {
    font-size: 10px;
  }
  
  .detail-value {
    font-size: 15px;
  }
  
  /* Ensure table container is full width */
  .table-container {
    margin-left: 0;
    margin-right: 0;
    width: 100%;
    border-radius: 8px;
    overflow: visible;
  }
  
  .page-container {
    padding: 12px;
  }
}
  
  /* Pagination improvements on mobile */
  .pagination {
    flex-wrap: wrap;
    justify-content: center !important;
    gap: 12px !important;
  }
  
  .pagination .btn {
    min-width: 100px;
    min-height: 48px;
  }
  
  .pagination span:not(.btn) {
    width: 100%;
    text-align: center;
    font-weight: 600;
  }
}

/* Game Type Badges */
.game-type-badge-small {
  display: inline-block;
  width: 24px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  margin-right: 8px;
  flex-shrink: 0;
}

.game-type-badge-small.singles {
  background-color: #3498db;
  color: white;
}

.game-type-badge-small.doubles {
  background-color: #e67e22;
  color: white;
}

/* Game Type Badges - Full Size (for game history) */
.game-type-badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.85em;
  font-weight: 600;
}

.game-type-badge.singles {
  background-color: #3498db;
  color: white;
}

.game-type-badge.doubles {
  background-color: #e67e22;
  color: white;
}

/* Doubles Game Display */
.doubles-teams {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.team-label {
  font-size: 14px;
}

.team-label.winner {
  font-weight: 600;
  color: #28a745;
}

.vs-text {
  color: #999;
  margin: 0 4px;
  font-size: 13px;
}

/* Game History Specific Styles */
.doubles-match {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.singles-match {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.team {
  padding: 4px 8px;
  border-radius: 4px;
  background-color: #f8f9fa;
  font-size: 14px;
}

.winning-team {
  background-color: #d4edda;
  font-weight: 600;
}

.winner-name {
  font-weight: 600;
  color: #28a745;
}

.vs-separator {
  color: #6c757d;
  font-size: 0.9em;
  font-style: italic;
}

.delete-form {
  display: inline-block;
  margin: 0;
}

.btn-delete {
  background-color: #dc3545;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85em;
  transition: background-color 0.2s;
  min-height: 36px;
}

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

.cannot-delete {
  color: #6c757d;
  font-size: 0.9em;
}

.casual-game {
  color: #999;
  font-style: italic;
}

/* Game Type Form Sections */
.game-type-form {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 2px solid var(--border-color);
  animation: fadeIn 0.3s ease;
}

.game-type-form h3 {
  color: var(--color-primary);
  font-size: 18px;
  margin-bottom: 16px;
  margin-top: 20px;
}

.game-type-form h3:first-child {
  margin-top: 0;
}

/* Game Report Form */
.game-report-form {
  max-width: 600px;
  margin: 0 auto;
}

.game-report-form .btn {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}

.game-report-form .btn-primary {
  margin-right: 12px;
}

/* Loading States */
.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Loading button state */
.btn.loading {
  pointer-events: none;
  position: relative;
  color: transparent !important;
}

.btn.loading::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

button:disabled, .btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* Form Loading State */
form.loading button[type="submit"],
form.loading input[type="submit"] {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* Skeleton loading screens */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-hover) 25%,
    var(--border-color) 50%,
    var(--bg-hover) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 16px;
  margin-bottom: 8px;
}

.skeleton-title {
  height: 24px;
  width: 60%;
  margin-bottom: 12px;
}

.skeleton-card {
  height: 100px;
  margin-bottom: 12px;
}

/* Smooth Transitions */
.btn, a, button, input, select, textarea {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

/* Performance: Use GPU acceleration for animations */
.alert, .game-item, .card {
  will-change: auto;
  backface-visibility: hidden;
  transform: translateZ(0);
}
