/* Modern Design System Variables */
:root {
  --primary-color: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --secondary-color: #8b5cf6;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --dark-bg: #0f172a;
  --dark-card: #1e293b;
  --dark-card-hover: #334155;
  --light-bg: #f8fafc;
  --light-card: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-light: #94a3b8;
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
  --gradient-warning: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  --gradient-dark: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: linear-gradient(to bottom, #f8fafc 0%, #e2e8f0 100%);
  background-attachment: fixed;
  min-height: 100vh;
  color: var(--text-primary);
  line-height: 1.6;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.page-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
}

.main-content {
  flex: 1;
  padding-bottom: 2rem;
}

/* Modern Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.display-4 {
  font-size: 3.5rem;
  font-weight: 800;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 1rem;
}

.lead {
  font-size: 1.25rem;
  color: var(--text-secondary);
  font-weight: 400;
}

/* Modern Navbar */
.navbar {
  background: rgba(255, 255, 255, 0.95) !important;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow-md);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 0;
  position: relative;
  z-index: 1030;
}

header {
  position: relative;
  z-index: 1030;
}

.navbar-brand {
  font-size: 1.5rem;
  font-weight: 800;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  transition: transform 0.2s ease;
}

.navbar-brand:hover {
  transform: scale(1.05);
}

.nav-link {
  font-weight: 500;
  color: var(--text-primary) !important;
  padding: 0.5rem 1rem !important;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
  margin: 0 0.25rem;
}

.nav-link:hover {
  background: var(--primary-color);
  color: white !important;
  transform: translateY(-1px);
}

.nav-link.active {
  background: var(--gradient-primary);
  color: white !important;
}

.nav-item.dropdown {
  position: relative;
}

.dropdown-menu {
  border: none;
  box-shadow: var(--shadow-lg);
  border-radius: 0.75rem;
  padding: 0.5rem;
  margin-top: 0.5rem;
  z-index: 1050 !important;
  position: absolute;
}

.dropdown-item {
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  transition: all 0.2s ease;
  font-weight: 500;
}

.dropdown-item:hover {
  background: var(--primary-color);
  color: white;
  transform: translateX(4px);
}

/* Modern Cards */
.card {
  border: none;
  border-radius: 1rem;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transition: all 0.3s ease;
  background: white;
  margin-bottom: 2rem;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-xl);
}

.card-header {
  background: var(--gradient-primary);
  color: white;
  border: none;
  padding: 1.5rem;
  font-weight: 600;
}

.card-body {
  padding: 2rem;
}

/* Modern Buttons */
.btn {
  border-radius: 0.75rem;
  font-weight: 600;
  padding: 0.75rem 1.5rem;
  transition: all 0.2s ease;
  border: none;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.btn:hover::before {
  width: 300px;
  height: 300px;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--gradient-primary);
  color: white;
}

.btn-success {
  background: var(--gradient-success);
  color: white;
}

.btn-warning {
  background: var(--gradient-warning);
  color: white;
}

.btn-secondary {
  background: var(--text-secondary);
  color: white;
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

.btn-lg {
  padding: 1rem 2rem;
  font-size: 1.125rem;
}

/* Modern Alerts */
.alert {
  border: none;
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  border-left: 4px solid;
  position: relative;
  z-index: 1;
}

.alert-primary {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
  border-left-color: var(--primary-color);
  color: var(--text-primary);
}

.alert-success {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(5, 150, 105, 0.1) 100%);
  border-left-color: var(--success-color);
}

.alert-danger {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, rgba(220, 38, 38, 0.1) 100%);
  border-left-color: var(--danger-color);
}

.alert-info {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, rgba(37, 99, 235, 0.1) 100%);
  border-left-color: #3b82f6;
}

/* Modern Progress Bars */
.progress {
  height: 2rem;
  border-radius: 1rem;
  background: rgba(0, 0, 0, 0.05);
  overflow: visible;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
  position: relative;
}

.progress-bar {
  background: var(--gradient-primary);
  border-radius: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: width 0.6s ease;
  position: static;
  color: white;
  min-width: fit-content;
  overflow: visible;
}

/* Progress bar text overlay - always readable with white background, positioned relative to progress container */
.progress-bar strong {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
  /* Dark text with solid white background for maximum contrast */
  color: #0f172a;
  background: #ffffff;
  padding: 3px 10px;
  border-radius: 5px;
  font-weight: 700;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  text-shadow: none;
  width: max-content;
  /* Position relative to progress container, not progress-bar */
  margin-left: 0;
}

/* For better contrast, we'll use a wrapper approach */
.progress-with-text {
  position: relative;
}

.progress-with-text .progress-text-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  color: var(--text-primary);
  text-shadow: 
    -1px -1px 0 rgba(255, 255, 255, 0.9),
    1px -1px 0 rgba(255, 255, 255, 0.9),
    -1px 1px 0 rgba(255, 255, 255, 0.9),
    1px 1px 0 rgba(255, 255, 255, 0.9),
    0 0 6px rgba(255, 255, 255, 1);
}

.progress-bar-striped {
  background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
  background-size: 1rem 1rem;
}

.progress-bar-animated {
  animation: progress-bar-stripes 1s linear infinite;
}

@keyframes progress-bar-stripes {
  0% {
    background-position: 1rem 0;
  }
  100% {
    background-position: 0 0;
  }
}

/* Modern Tables */
.table {
  border-radius: 0.75rem;
  overflow: hidden;
}

.table thead {
  background: var(--gradient-primary);
  color: white;
}

.table thead th {
  border: none;
  font-weight: 600;
  padding: 1rem;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

.table tbody tr {
  transition: all 0.2s ease;
}

.table tbody tr:hover {
  background: rgba(99, 102, 241, 0.05);
  transform: scale(1.01);
}

.table-striped tbody tr:nth-of-type(odd) {
  background: rgba(0, 0, 0, 0.02);
}

.table-info {
  background: rgba(59, 130, 246, 0.1) !important;
}

/* Modern Badges */
.badge {
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
}

/* Modern Form Controls */
.form-control {
  border-radius: 0.75rem;
  border: 2px solid var(--border-color);
  padding: 0.75rem 1rem;
  transition: all 0.2s ease;
}

.form-control:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
  outline: none;
}

.form-floating > label {
  color: var(--text-secondary);
}

/* Modern Container */
.container {
  max-width: 1200px;
}

/* Modern Footer */
.footer {
  background: var(--dark-bg);
  color: var(--text-light);
  padding: 2rem 0;
  border-top: 1px solid var(--border-color);
  width: 100%;
  flex-shrink: 0;
  margin-top: 2rem;
  position: static !important;
  bottom: auto !important;
  line-height: normal !important;
}

.footer a {
  color: var(--primary-light);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer a:hover {
  color: var(--primary-color);
}

/* Mode Cards */
.mode-card {
  background: white;
  border-radius: 1rem;
  padding: 2rem;
  box-shadow: var(--shadow-md);
  transition: all 0.3s ease;
  height: 100%;
  border: 2px solid transparent;
}

.mode-card:hover {
  transform: translateY(-8px);
  box-shadow: var(--shadow-xl);
  border-color: var(--primary-color);
}

.mode-card h5 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.mode-card p {
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.mode-card .btn {
  margin-top: 1rem;
  width: 100%;
}

/* Global Level Card */
.global-level-card {
  background: var(--gradient-primary);
  color: white;
  border-radius: 1rem;
  padding: 2rem;
  box-shadow: var(--shadow-xl);
  margin-bottom: 2rem;
}

.global-level-card h3 {
  color: white;
  margin-bottom: 0.5rem;
}

.global-level-card p {
  color: rgba(255, 255, 255, 0.9);
}

/* Leaderboard Styles */
.leaderboard-card {
  background: white;
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.leaderboard-header {
  background: var(--gradient-primary);
  color: white;
  padding: 1.5rem;
}

.leaderboard-header h4 {
  margin: 0;
  color: white;
}

/* Tab Navigation */
.nav-tabs {
  border-bottom: 2px solid var(--border-color);
}

.nav-tabs .nav-link {
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-secondary);
  padding: 1rem 1.5rem;
  margin-bottom: -2px;
  border-radius: 0;
}

.nav-tabs .nav-link:hover {
  background: transparent !important;
  border-bottom-color: var(--primary-light);
  color: var(--primary-color);
}

.nav-tabs .nav-link.active {
  background: transparent !important;
  border-bottom-color: var(--primary-color);
  color: var(--primary-color) !important;
  font-weight: 600;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 0.5s ease-out;
}

/* Responsive Improvements */
@media (max-width: 768px) {
  html {
    font-size: 14px;
  }
  
  .display-4 {
    font-size: 2rem;
  }
  
  .lead {
    font-size: 1.1rem;
  }
  
  .card-body {
    padding: 1rem;
  }
  
  .card-header {
    padding: 1rem;
    font-size: 0.95rem;
  }
  
  .mode-card {
    margin-bottom: 1.5rem;
    padding: 1.5rem;
  }
  
  .mode-card h5 {
    font-size: 1.25rem;
  }
  
  .global-level-card {
    padding: 1.5rem;
  }
  
  .global-level-card h3 {
    font-size: 1.5rem;
  }
  
  .navbar {
    padding: 0.75rem 0;
  }
  
  .navbar-brand {
    font-size: 1.25rem;
  }
  
  .nav-link {
    padding: 0.5rem 0.75rem !important;
    font-size: 0.9rem;
  }
  
  .btn {
    padding: 0.625rem 1.25rem;
    font-size: 0.9rem;
  }
  
  .btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
  }
  
  .container {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  
  .main-content {
    padding-bottom: 1rem;
  }
  
  .footer {
    padding: 1.5rem 0;
    font-size: 0.875rem;
  }
  
  .table {
    font-size: 0.875rem;
  }
  
  .table thead th {
    padding: 0.75rem 0.5rem;
    font-size: 0.7rem;
  }
  
  .table tbody td {
    padding: 0.75rem 0.5rem;
  }
  
  /* Better table responsiveness on tablets */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
  }
  
  .alert {
    padding: 1rem;
    font-size: 0.9rem;
  }
  
  .progress {
    height: 1.75rem;
  }
  
  .progress-bar {
    font-size: 0.8rem;
  }
  
  .form-control {
    padding: 0.625rem 0.875rem;
    font-size: 0.9rem;
  }
  
  .badge {
    padding: 0.375rem 0.625rem;
    font-size: 0.8rem;
  }
  
  .dropdown-menu {
    font-size: 0.9rem;
    padding: 0.5rem;
  }
  
  .dropdown-item {
    padding: 0.625rem 0.875rem;
  }
  
  /* Hero section mobile */
  .hero-section {
    padding: 2.5rem 0;
    margin-bottom: 2rem;
  }
  
  .feature-icon {
    font-size: 3rem;
  }
  
  /* Tab navigation mobile */
  .nav-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  
  .nav-tabs::-webkit-scrollbar {
    display: none;
  }
  
  .nav-tabs .nav-link {
    padding: 0.75rem 1rem;
    white-space: nowrap;
    font-size: 0.85rem;
  }
  
  /* Leaderboard mobile */
  .leaderboard-header {
    padding: 1rem;
  }
  
  .leaderboard-header h4 {
    font-size: 1.25rem;
  }
  
  /* Avatar mobile */
  .avatar {
    width: 28px !important;
    height: 28px !important;
  }
  
  /* Mode card buttons full width on mobile */
  .mode-card .btn {
    width: 100%;
    margin-top: 1rem;
  }
  
  /* Board comparison mobile */
  .board-comparison > .col-md-6 {
    margin-bottom: 1.5rem;
  }
  
  /* Global level card mobile layout */
  .global-level-card .row {
    flex-direction: column;
  }
  
  .global-level-card .col-md-4 {
    text-align: center !important;
    margin-top: 1rem;
  }
  
  .global-level-card .col-md-8 {
    margin-bottom: 0;
  }
  
  /* Login partial mobile */
  .navbar-nav .btn {
    margin-left: 0 !important;
    margin-top: 0.5rem;
    width: 100%;
  }
  
  /* Profile dropdown mobile */
  .navbar-nav .dropdown-menu {
    width: 100%;
    margin-top: 0.5rem;
  }
}

/* Extra small devices (phones, less than 576px) */
@media (max-width: 575.98px) {
  html {
    font-size: 13px;
  }
  
  .display-4 {
    font-size: 1.75rem;
  }
  
  .container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
  
  .card-body {
    padding: 0.875rem;
  }
  
  .mode-card {
    padding: 1.25rem;
  }
  
  .global-level-card {
    padding: 1.25rem;
  }
  
  .btn {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
  }
  
  .btn-lg {
    padding: 0.625rem 1.25rem;
    font-size: 0.95rem;
  }
  
  .hero-section {
    padding: 2rem 0;
  }
  
  .feature-icon {
    font-size: 2.5rem;
  }
  
  /* Better table handling on very small screens - keep horizontal scroll but improve appearance */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    border-radius: 0.5rem;
  }
  
  .table {
    min-width: 600px; /* Ensure table doesn't get too compressed */
  }
  
  /* Make table cells more compact */
  .table thead th {
    padding: 0.5rem 0.25rem;
    font-size: 0.65rem;
  }
  
  .table tbody td {
    padding: 0.5rem 0.25rem;
    font-size: 0.8rem;
  }
  
  /* Smaller badges in tables on mobile */
  .table .badge {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
  }
  
  /* Smaller images in tables */
  .table img {
    width: 32px !important;
    height: 32px !important;
  }
  
  .table .rounded-circle {
    width: 32px !important;
    height: 32px !important;
  }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
  .btn {
    min-height: 44px;
    min-width: 44px;
  }
  
  .nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  
  .dropdown-item {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  
  .form-control {
    min-height: 44px;
  }
  
  /* Remove hover effects on touch devices */
  .card:hover {
    transform: none;
  }
  
  .mode-card:hover {
    transform: none;
  }
  
  .btn:hover {
    transform: none;
  }
}

/* Landscape mobile orientation */
@media (max-width: 768px) and (orientation: landscape) {
  .hero-section {
    padding: 1.5rem 0;
  }
  
  .navbar {
    padding: 0.5rem 0;
  }
}

/* Focus States */
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
  outline: none;
}

/* Chess Board Comparison Styles */
/* Add border between comparison boards in result screen */
.board-comparison > .col-md-6:first-child {
  border-right: 2px solid var(--border-color);
  padding-right: 2rem;
}

.board-comparison > .col-md-6:last-child {
  padding-left: 2rem;
}

@media (max-width: 768px) {
  .board-comparison > .col-md-6:first-child {
    border-right: none;
    border-bottom: 2px solid var(--border-color);
    padding-right: 0;
    padding-bottom: 2rem;
    margin-bottom: 2rem;
  }
  
  .board-comparison > .col-md-6:last-child {
    padding-left: 0;
    padding-top: 2rem;
  }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 10px;
}

::-webkit-scrollbar-track {
  background: var(--light-bg);
}

::-webkit-scrollbar-thumb {
  background: var(--primary-color);
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-dark);
}

/* User Profile Avatar */
.avatar {
  border-radius: 50%;
  border: 3px solid white;
  box-shadow: var(--shadow-md);
  transition: all 0.2s ease;
}

.avatar:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-lg);
}

/* Loading States */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

/* Modern Spacing */
.mt-6 {
  margin-top: 4rem;
}

.mb-6 {
  margin-bottom: 4rem;
}

.py-6 {
  padding-top: 4rem;
  padding-bottom: 4rem;
}

/* Responsive Chess Boards */
.chessboard-responsive {
  max-width: 100%;
  margin: 0 auto;
}

.chessboard-responsive canvas {
  max-width: 100% !important;
  height: auto !important;
}

@media (max-width: 768px) {
  .chessboard-responsive {
    max-width: 100%;
    padding: 0 10px;
  }
  
  /* Ensure chessboard container is responsive */
  #board, #board2, #boardUserAnswer, #boardCorrect,
  #boardDistorted, #boardOriginal, #boardMirror,
  #boardMemory, #boardTarget, #boardBefore, #boardAfter,
  #boardInput {
    max-width: 100% !important;
  }
}
