/* ========================================================================
   CSS Variables for Themes
   ======================================================================== */

:root {
  /* Light theme (default) */
  --bg-primary: #ffffff;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f5f5f5;
  --header-bg: #001538;
  --footer-bg: #001538;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-tertiary: #94a3b8;
  --accent-primary: #3b82f6;
  --accent-hover: #2563eb;
  --accent-light: #dbeafe;
  --success: #10b981;
  --success-light: #d1fae5;
  --error: #ef4444;
  --error-light: #fee2e2;
  --border: #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);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --header-text: #ffffff;
  --footer-text: #cbd5e1;
}

[data-theme="dark"] {
  --bg-primary: #000000;
  --bg-secondary: #0a0a0a;
  --bg-tertiary: #141414;
  --header-bg: #000000;
  --footer-bg: #000000;
  --text-primary: #ffffff;
  --text-secondary: #888888;
  --text-tertiary: #666666;
  --accent-primary: #3b82f6;
  --accent-hover: #2563eb;
  --accent-light: #1e3a8a;
  --success: #34d399;
  --success-light: #064e3b;
  --error: #f87171;
  --error-light: #7f1d1d;
  --border: #1a1a1a;
  --shadow-sm: none;
  --shadow-md: none;
  --shadow-lg: none;
  --header-text: #ffffff;
  --footer-text: #888888;
}

[data-theme="black"] {
  --bg-primary: #000000;
  --bg-secondary: #0a0a0a;
  --bg-tertiary: #1a1a1a;
  --header-bg: #000000;
  --footer-bg: #000000;
  --text-primary: #e5e5e5;
  --text-secondary: #a3a3a3;
  --text-tertiary: #737373;
  --accent-primary: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-light: #1e3a8a;
  --success: #34d399;
  --success-light: #064e3b;
  --error: #f87171;
  --error-light: #7f1d1d;
  --border: #1a1a1a;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5);
  --header-text: #ffffff;
  --footer-text: #737373;
}

/* ========================================================================
   Base Styles
   ======================================================================== */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: var(--transition);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* Touch-friendly sizes */
button,
.btn,
select,
input {
  min-height: 44px;
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

/* ========================================================================
   Custom Scrollbar
   ======================================================================== */

/* Webkit browsers (Chrome, Safari, Edge) */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

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

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg-secondary);
}

/* ========================================================================
   Loading Screen
   ======================================================================== */

.loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.loading-screen.hidden {
  display: none;
}

.loading-content {
  text-align: center;
}

.loading-icon {
  width: 4rem;
  height: 4rem;
  color: var(--accent-primary);
  animation: pulse 2s ease-in-out infinite;
}

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

.loading-content p {
  margin-top: 1rem;
  color: var(--text-secondary);
  font-size: 1.125rem;
}

/* ========================================================================
   Container
   ======================================================================== */

.container {
  max-width: 1600px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ========================================================================
   Header
   ======================================================================== */

.header {
  background-color: var(--header-bg);
  color: var(--header-text);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.header-left {
  flex: 1;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0;
  cursor: pointer;
  transition: opacity 0.2s;
}

.title:hover {
  opacity: 0.7;
}


.subtitle {
  display: none;
}

/* Theme Selector */
.theme-selector {
  position: relative;
  display: flex;
  align-items: center;
}

.theme-btn {
  width: 2.5rem;
  height: 2.5rem;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: var(--transition);
  color: #ffffff !important;
  padding: 0;
  margin: 0;
}

.theme-btn:hover {
  opacity: 0.7;
}

.theme-icon-sun,
.theme-icon-moon {
  display: none;
  width: 1rem;
  height: 1rem;
}

/* Show sun icon when in dark mode (clicking will switch to light) */
[data-theme="dark"] .theme-icon-sun {
  display: block;
  color: #ffffff !important;
}

/* Show moon icon when in light mode (clicking will switch to dark) */
[data-theme="light"] .theme-icon-moon {
  display: block;
  color: #ffffff !important;
}


/* Filter Controls */
.filter-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Filter Button */
.btn-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.1);
  color: var(--header-text);
  font-family: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: var(--transition);
}

.btn-filter:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn-filter i {
  width: 1rem;
  height: 1rem;
}

.btn-apply {
  background: rgba(255, 255, 255, 0.2);
  font-weight: 600;
}

.btn-apply:hover {
  background: rgba(255, 255, 255, 0.3);
}

.btn-apply.has-changes {
  background: rgba(255, 200, 0, 0.3);
  animation: pulse-subtle 2s ease-in-out infinite;
}

@keyframes pulse-subtle {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.8;
  }
}

/* Select */
.select {
  padding: 0.5rem 1rem;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.1);
  color: var(--header-text);
  font-family: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: var(--transition);
}

.select:hover {
  background: rgba(255, 255, 255, 0.2);
}

.select:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.4);
}

.select option {
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

/* ELO Display Header */
.elo-display-header {
  display: flex;
  align-items: center;
}

.elo-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  min-height: 44px;
  border: none;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.1);
  color: var(--header-text);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.elo-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.elo-btn i {
  width: 1rem;
  height: 1rem;
}

/* ========================================================================
   Main Content
   ======================================================================== */

.main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: 2rem;
}

.hidden {
  display: none !important;
}

/* ========================================================================
   Welcome Screen
   ======================================================================== */

.welcome-screen {
  width: 100%;
  max-width: 800px;
  text-align: center;
}

.welcome-content {
  padding: 2rem;
}


.welcome-content h2 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.welcome-content > p {
  font-size: 1.125rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

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

.stat-card {
  display: flex;
  align-items: center;
  padding: 1.5rem;
  background-color: var(--bg-secondary);
  border-radius: 0.5rem;
}

[data-theme="light"] .stat-card {
  background-color: #f5f5f5;
}

[data-theme="dark"] .stat-card {
  background-color: var(--bg-secondary);
}


.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ========================================================================
   Buttons
   ======================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 0.5rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  background-color: var(--accent-primary);
  color: white;
}

.btn:active {
  transform: scale(0.98);
}

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

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

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

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ========================================================================
   Quiz Screen
   ======================================================================== */

.quiz-screen {
  width: 100%;
  max-width: 1400px;
}

.quiz-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Stats Bar */
.quiz-stats-bar {
  display: flex;
  gap: 2rem;
  padding: 1rem;
  background-color: var(--bg-secondary);
  border-radius: 0.5rem;
  flex-wrap: wrap;
}

[data-theme="light"] .quiz-stats-bar {
  background-color: #f5f5f5;
}

[data-theme="dark"] .quiz-stats-bar {
  background-color: var(--bg-secondary);
}

.stat-item {
  display: flex;
  align-items: center;
  font-size: 0.875rem;
  color: var(--text-secondary);
}


.stat-item strong {
  color: var(--text-primary);
  font-weight: 700;
}

/* Side-by-side layout */
.quiz-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

.quiz-left {
  display: flex;
  flex-direction: column;
}

.quiz-right {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Question Section */
.question-section {
  flex: 1;
}

.question-text {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
}

.options-container {
  display: grid;
  gap: 1rem;
}

.option-btn {
  width: 100%;
  padding: 1rem 1.5rem;
  background-color: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
}

[data-theme="light"] .option-btn {
  background-color: #ffffff;
  border-color: #e5e5e5;
}

[data-theme="light"] .option-btn:hover:not(:disabled) {
  background-color: #f5f5f5;
  border-color: #d0d0d0;
}

[data-theme="dark"] .option-btn {
  background-color: var(--bg-primary);
  border-color: var(--border);
}

[data-theme="dark"] .option-btn:hover:not(:disabled) {
  background-color: var(--bg-secondary);
  border-color: var(--border);
}

.option-btn:active {
  transform: scale(0.98);
}

.option-btn.correct {
  background-color: var(--success-light);
  color: var(--success);
}

.option-btn.incorrect {
  background-color: var(--error-light);
  color: var(--error);
}

.option-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* Company Card */
.company-card {
  background-color: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 2rem;
}

[data-theme="light"] .company-card {
  background-color: #ffffff;
  border-color: #e5e5e5;
}

[data-theme="dark"] .company-card {
  background-color: var(--bg-primary);
  border-color: var(--border);
}

.company-header {
  display: flex;
  align-items: center;
  margin-bottom: 1.5rem;
}


.company-name {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

.company-details {
  display: grid;
  gap: 1rem;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.detail-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.detail-label i {
  width: 1rem;
  height: 1rem;
}

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

/* Feedback */
.feedback {
  display: none;
}

.feedback.success {
  background-color: var(--success-light);
  color: var(--success);
}

.feedback.error {
  background-color: var(--error-light);
  color: var(--error);
}

/* ========================================================================
   Modal
   ======================================================================== */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background-color: var(--bg-primary);
  border-radius: 1rem;
  box-shadow: var(--shadow-xl);
  max-width: 900px;
  width: 90%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 0.5rem;
  transition: var(--transition);
}

.modal-close:hover {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

.modal-body {
  padding: 2rem;
  overflow-y: auto;
}

.modal-description {
  margin-bottom: 1.5rem;
  color: var(--text-secondary);
}

#elo-chart {
  max-height: 400px;
}

/* Year Filter */
.year-checkboxes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 2rem;
  max-height: 400px;
  overflow-y: auto;
  contain: layout style;
  will-change: contents;
}

.year-checkbox-item {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
  background-color: var(--bg-secondary);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background-color 0.1s ease;
  contain: layout style;
}

.year-checkbox-item:hover {
  background-color: var(--bg-tertiary);
}

.year-checkbox-item input[type="checkbox"] {
  display: none;
}

.year-checkbox-item label {
  cursor: pointer;
  user-select: none;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.year-checkbox-item:has(input:checked) {
  background-color: var(--accent-primary);
}

.year-checkbox-item:has(input:checked) label {
  color: white;
}

.modal-actions {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.modal-footer-actions {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  padding-top: 1rem;
  margin-top: 1rem;
  border-top: 1px solid var(--border);
}

/* Custom Quiz Modal */
.custom-filter-section {
  margin-bottom: 2rem;
}

.filter-section-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.filter-checkboxes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  max-height: 300px;
  overflow-y: auto;
}

.filter-checkbox-item {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
  background-color: var(--bg-secondary);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: var(--transition);
}

.filter-checkbox-item:hover {
  background-color: var(--bg-tertiary);
}

.filter-checkbox-item input[type="checkbox"] {
  display: none;
}

.filter-checkbox-item label {
  cursor: pointer;
  user-select: none;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.filter-checkbox-item:has(input:checked) {
  background-color: var(--accent-primary);
}

.filter-checkbox-item:has(input:checked) label {
  color: white;
}

/* ========================================================================
   Footer
   ======================================================================== */

.footer {
  background-color: var(--footer-bg);
  color: var(--footer-text);
  padding: 1.5rem 2rem;
  margin-top: auto;
  border-top: 1px solid var(--border);
}

.footer-content {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 2rem;
  align-items: flex-start;
}

.footer-column {
  display: flex;
  flex-direction: column;
}

.footer-tagline {
  font-weight: 500;
  font-size: 0.8125rem;
  margin-bottom: 0.75rem;
  color: var(--footer-text);
}

.footer-description {
  font-size: 0.6875rem;
  line-height: 1.4;
}

.footer-disclaimer {
  font-size: 0.625rem;
  opacity: 0.6;
  line-height: 1.4;
}

.footer-links-vertical {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.footer-column a {
  color: var(--footer-text);
  text-decoration: none;
  font-size: 0.8125rem;
  transition: var(--transition);
}

.footer-column a:hover {
  opacity: 0.7;
}

/* ========================================================================
   Responsive Design
   ======================================================================== */

@media (max-width: 1024px) {
  .quiz-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  html {
    font-size: 15px;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
  }

  .header-right {
    width: 100%;
    flex-wrap: wrap;
  }

  .filter-controls {
    width: 100%;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .title {
    font-size: 1.5rem;
  }

  .subtitle {
    font-size: 0.875rem;
  }

  .welcome-content h2 {
    font-size: 2rem;
  }

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

  .main {
    padding: 1rem;
  }

  .company-card {
    padding: 1.5rem;
  }

  .company-name {
    font-size: 1.375rem;
  }

  .options-grid {
    gap: 0.875rem;
  }

  .option-btn {
    padding: 0.875rem 1.25rem;
  }

  .modal-content {
    width: 95%;
  }

  .year-checkboxes,
  .filter-checkboxes {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  .footer-content {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 14px;
  }

  .container {
    padding: 0;
  }

  .header {
    padding: 0.75rem;
  }

  .title {
    font-size: 1.25rem;
  }

  .subtitle {
    font-size: 0.75rem;
  }

  .main {
    padding: 0.75rem;
  }

  .welcome-content h2 {
    font-size: 1.75rem;
  }

  .btn {
    padding: 0.75rem 1.5rem;
    font-size: 0.875rem;
  }

  .company-card {
    padding: 1.5rem;
  }

  .company-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .company-name {
    font-size: 1.25rem;
  }

  .company-details {
    gap: 0.5rem;
  }

  .detail-item {
    font-size: 0.875rem;
    padding: 0.5rem;
  }

  .detail-item i {
    width: 1rem;
    height: 1rem;
  }

  .options-grid {
    gap: 0.75rem;
  }

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

  .quiz-stats-bar {
    gap: 0.75rem;
    padding: 0.75rem;
  }

  .stat-item {
    font-size: 0.75rem;
  }

  .quiz-layout {
    gap: 1rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .stat-card {
    padding: 1rem;
  }

  .stat-value {
    font-size: 1.5rem;
  }

  .stat-label {
    font-size: 0.75rem;
  }

  .modal-content {
    width: 95%;
    max-height: 90vh;
  }

  .modal-header {
    padding: 1rem;
  }

  .modal-header h2 {
    font-size: 1.25rem;
  }

  .modal-body {
    padding: 1rem;
    max-height: calc(90vh - 100px);
  }

  .year-checkboxes,
  .filter-checkboxes {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.5rem;
  }

  .btn-filter {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
  }

  .select {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
  }

  .footer {
    padding: 1rem;
  }

  .footer-content {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .filter-controls {
    width: 100%;
  }

  .btn-apply {
    width: 100%;
    justify-content: center;
  }

  .theme-selector {
    width: 100%;
  }

  #themeToggle {
    width: 100%;
    justify-content: center;
  }
}
