/* GCSE Revision Hub - Component Styles */
/* Buttons, badges, cards, navigation elements */

/* ==============================================
   Touch Target Compliance
   All interactive elements must be at least 44px
   ============================================== */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  min-height: var(--touch-target-min, 44px);
  font-size: var(--font-sm);
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

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

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

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

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

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

.btn svg {
  width: 16px;
  height: 16px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-sm);
  font-size: var(--font-xs);
  font-weight: 500;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  color: var(--text-secondary);
}

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

.badge-success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.badge-warning {
  background: rgba(234, 179, 8, 0.15);
  color: var(--warning);
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: all var(--transition-fast);
}

.card:hover {
  border-color: var(--border-light);
  background: var(--bg-hover);
}

.card-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.card-link:hover {
  color: inherit;
}

/* Subject cards for homepage */
.subject-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-lg);
}

.subject-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  text-align: center;
  transition: all var(--transition-fast);
}

.subject-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.subject-card-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-md);
  color: var(--accent);
}

.subject-card h2 {
  font-size: var(--font-lg);
  margin-bottom: var(--space-xs);
}

.subject-card p {
  font-size: var(--font-sm);
  color: var(--text-muted);
  margin: 0;
}

/* Icon styling */
.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon svg {
  width: 100%;
  height: 100%;
}

.icon-sm { width: 14px; height: 14px; }
.icon-md { width: 18px; height: 18px; }
.icon-lg { width: 24px; height: 24px; }

/* Chevron icon for expandables */
.chevron {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  transition: transform var(--transition-fast);
  flex-shrink: 0;
}

details[open] > summary .chevron {
  transform: rotate(90deg);
}

/* Marks indicator */
.marks {
  font-size: var(--font-xs);
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

/* Progress indicator */
.progress-ring {
  width: 32px;
  height: 32px;
}

.progress-ring circle {
  fill: none;
  stroke-width: 3;
}

.progress-ring .bg {
  stroke: var(--border);
}

.progress-ring .progress {
  stroke: var(--accent);
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: center;
}

/* Info boxes */
.info-box {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  font-size: var(--font-sm);
}

.info-box-note {
  background: rgba(59, 130, 246, 0.1);
  border-left: 3px solid var(--accent);
}

.info-box-tip {
  background: rgba(34, 197, 94, 0.1);
  border-left: 3px solid var(--success);
}

.info-box-warning {
  background: rgba(234, 179, 8, 0.1);
  border-left: 3px solid var(--warning);
}

.info-box-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

/* Divider */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-lg) 0;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-2xl);
  color: var(--text-muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-md);
  opacity: 0.5;
}

/* Loading skeleton */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-hover) 0%,
    var(--bg-card) 50%,
    var(--bg-hover) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--radius-sm);
}

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

/* Tooltip */
.tooltip {
  position: relative;
}

.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-xs) var(--space-sm);
  background: var(--text-primary);
  color: var(--bg-primary);
  font-size: var(--font-xs);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
  z-index: 100;
}

.tooltip:hover::after {
  opacity: 1;
  visibility: visible;
}

/* ==============================================
   Footer Buttons (Premium, Mode Toggle)
   ============================================== */

.btn-footer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  min-height: var(--touch-target-min);
  padding: 0 var(--space-md);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: var(--font-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn-footer:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-footer.premium {
  background: var(--gradient-primary);
  border: none;
  color: white;
}

.btn-footer.premium:hover {
  opacity: 0.9;
}

.btn-footer.mode-toggle:hover {
  border-color: var(--warning);
  color: var(--warning);
}

/* Sign Out button - inherits from btn-footer, adds red styling */
.btn-footer.btn-sign-out {
  border-color: var(--error);
  color: var(--error);
}

.btn-footer.btn-sign-out:hover {
  background: var(--error);
  color: white;
  border-color: var(--error);
}

.btn-footer.btn-sign-out svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ==============================================
   Unified Header Styles (all pages)
   ============================================== */

.site-header {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 300;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: center;
}

.site-header-inner {
  width: 100%;
  max-width: 800px;
  padding: var(--space-sm) var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

/* Left section: menu + home */
.site-header .header-left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

/* Center section: search bar */
.site-header .header-center {
  flex: 1;
  max-width: 500px;
  margin: 0 auto;
}

/* Right section: profile + theme toggle */
.site-header .header-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

/* Header Sign Out Button */
.header-sign-out {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.header-sign-out:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: #ef4444;
  color: #ef4444;
}

.header-sign-out.hidden {
  display: none;
}

.site-header .back-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--font-sm);
  white-space: nowrap;
}

.site-header .back-link:hover {
  color: var(--accent-hover);
}

.site-header .back-link .icon {
  width: 18px;
  height: 18px;
}

/* Search in header */
.site-header .header-search {
  position: relative;
  width: 100%;
}

.site-header .header-search-input {
  width: 100%;
  padding: var(--space-sm) var(--space-sm) var(--space-sm) 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--font-sm);
  transition: all var(--transition-fast);
}

.site-header .header-search-input::placeholder {
  color: var(--text-muted);
}

.site-header .header-search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.site-header .header-search-icon {
  position: absolute;
  left: var(--space-sm);
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.site-header .header-search-shortcut {
  position: absolute;
  right: var(--space-sm);
  top: 50%;
  transform: translateY(-50%);
  padding: 2px 6px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  pointer-events: none;
}

/* Legacy footer support (will be removed) */
.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 300;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  height: 48px;
  display: flex;
  justify-content: center;
}

.site-footer-inner {
  width: 100%;
  max-width: 800px;
  padding: var(--space-sm) var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.site-footer .footer-text {
  color: var(--text-muted);
  font-size: var(--font-sm);
}

.site-footer .controls-bar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.site-footer .back-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--font-sm);
}

.site-footer .back-link:hover {
  color: var(--accent-hover);
}

.site-footer .back-link .icon {
  width: 18px;
  height: 18px;
}

/* Footer links (simple text links with background) */
.footer-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: var(--font-sm);
  font-weight: 500;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  background: var(--bg-hover);
  transition: all var(--transition-fast);
  min-height: var(--touch-target-min);
  display: inline-flex;
  align-items: center;
}

.footer-link:hover {
  color: var(--accent);
  background: var(--bg-card);
}

/* Separator between footer links */
.footer-link + .footer-link {
  margin-left: 4px;
}

.footer-link + .footer-link::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 50%;
  transform: translateY(-50%);
  width: 1px;
  height: 16px;
  background: var(--border);
}

.controls-bar .footer-link {
  position: relative;
}

/* Theme toggle in footer */
.theme-toggle-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}

.theme-toggle-label:hover {
  background: var(--bg-hover);
}

.theme-toggle-label .icon {
  width: 20px;
  height: 20px;
}

/* Show/hide theme icons based on theme state */
.light-icon { display: none; }
.dark-icon { display: block; }

#theme-toggle:checked ~ .page-wrapper .light-icon,
#theme-toggle:checked ~ * .light-icon,
:root[data-theme="light"] .light-icon { display: block; }

#theme-toggle:checked ~ .page-wrapper .dark-icon,
#theme-toggle:checked ~ * .dark-icon,
:root[data-theme="light"] .dark-icon { display: none; }

/* Menu button in footer (subject pages) */
.menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}

.menu-btn:hover {
  background: var(--bg-hover);
}

.menu-btn .icon {
  width: 20px;
  height: 20px;
}

/* ==============================================
   Modal Base Component
   ============================================== */

.modal {
  border: none;
  border-radius: var(--radius-xl);
  padding: 0;
  background: var(--bg-secondary);
  color: var(--text-primary);
  max-width: 360px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.8);
}

.modal-content {
  padding: var(--space-xl);
}

.modal-title {
  margin: 0 0 var(--space-sm);
  font-size: var(--font-lg);
  font-weight: 600;
  text-align: center;
}

.modal-subtitle {
  margin: 0 0 var(--space-md);
  color: var(--text-muted);
  font-size: var(--font-sm);
  text-align: center;
}

.modal-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

.modal-actions .btn {
  flex: 1;
}

/* Light mode modal adjustments */
body:has(#theme-toggle:checked) .modal {
  background: #ffffff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

/* ==============================================
   Utility Classes
   ============================================== */

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus states for accessibility */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus-visible,
.btn:focus-visible,
a:focus-visible {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

/* ==============================================
   Header Mobile Responsive
   ============================================== */

@media (max-width: 600px) {
  .site-header-inner {
    padding: var(--space-xs) var(--space-sm);
    gap: var(--space-sm);
  }

  .site-header .header-center {
    max-width: none;
  }

  .site-header .header-search-shortcut {
    display: none;
  }

  .site-header .back-link span {
    display: none;
  }
}

/* ==============================================
   Freemium System Styles
   ============================================== */

/* Premium crown icon */
.premium-icon {
  display: inline-block;
  font-size: 1em;
  margin-right: var(--space-xs);
}

/* Premium badge */
.premium-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 2px var(--space-sm);
  font-size: var(--font-xs);
  font-weight: 600;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: white;
}

/* Freemium modals */
.freemium-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10001;
  padding: 0;
  border: none;
  border-radius: var(--radius-xl);
  background: transparent;
  max-width: 480px;
  width: calc(100% - var(--space-lg) * 2);
}

.freemium-modal::backdrop {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.freemium-modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl);
  text-align: center;
}

.freemium-icon {
  font-size: 4em;
  margin-bottom: var(--space-lg);
}

.freemium-title {
  font-size: var(--font-xl);
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 var(--space-md) 0;
}

.freemium-text {
  font-size: var(--font-base);
  color: var(--text-secondary);
  margin: 0 0 var(--space-lg) 0;
  line-height: 1.6;
}

.freemium-features {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-bottom: var(--space-xl);
  text-align: left;
}

.freemium-feature {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  font-size: var(--font-sm);
  color: var(--text-secondary);
  padding: var(--space-sm);
  background: var(--bg-card);
  border-radius: var(--radius-md);
}

.freemium-feature::before {
  content: '✓';
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
  border-radius: 50%;
  font-weight: 700;
  font-size: var(--font-xs);
}

.freemium-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.freemium-btn-primary {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border: none;
  color: white;
  font-weight: 600;
  padding: var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.freemium-btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.4);
}

.freemium-btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

/* Mobile responsive */
@media (max-width: 600px) {
  .freemium-modal {
    width: calc(100% - var(--space-md) * 2);
  }

  .freemium-modal-content {
    padding: var(--space-xl);
  }

  .freemium-icon {
    font-size: 3em;
  }

  .freemium-title {
    font-size: var(--font-lg);
  }
}

/* ==================== SESSION CARD IN GUEST MODE ==================== */

/* Guest unlock banner */
.guest-unlock-banner {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
  border: 2px solid rgba(99, 102, 241, 0.3);
}

.guest-unlock-content {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.guest-unlock-icon {
  font-size: 2.5em;
  flex-shrink: 0;
  animation: pulse 2s ease-in-out infinite;
}

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

.guest-unlock-text {
  flex: 1;
  color: white;
}

.guest-unlock-text strong {
  display: block;
  font-size: var(--font-lg);
  font-weight: 700;
  margin-bottom: var(--space-xs);
}

.guest-unlock-text p {
  font-size: var(--font-sm);
  margin: 0;
  opacity: 0.9;
}

.guest-unlock-btn {
  flex-shrink: 0;
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--font-base);
  font-weight: 600;
  background: white;
  color: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  white-space: nowrap;
}

.guest-unlock-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

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

/* Greyed out tasks in guest mode */
.guest-mode .session-task,
.guest-mode .bonus-task {
  opacity: 0.5;
  pointer-events: none;
  position: relative;
  filter: grayscale(50%);
}

.guest-mode .session-task::after,
.guest-mode .bonus-task::after {
  content: '🔒';
  position: absolute;
  right: var(--space-lg);
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2em;
  opacity: 0.7;
}

/* Hide XP in guest mode */
.guest-mode .task-xp,
.guest-mode .bonus-task-xp,
.guest-mode #session-total-xp {
  display: none;
}

/* Hide bonus tasks section header in guest mode (they'll see greyed tasks) */
.guest-mode #bonus-tasks {
  opacity: 0.5;
  pointer-events: none;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .guest-unlock-content {
    flex-direction: column;
    text-align: center;
    gap: var(--space-sm);
  }

  .guest-unlock-icon {
    font-size: 2em;
  }

  .guest-unlock-text strong {
    font-size: var(--font-base);
  }

  .guest-unlock-btn {
    width: 100%;
    padding: var(--space-md);
  }

  .guest-mode .session-task::after,
  .guest-mode .bonus-task::after {
    font-size: 1em;
  }
}
