/* ==========================================
   1. DESIGN SYSTEM & ROOT VARIABLES
   ========================================== */
:root {
  /* Theme Defaults (Dark Theme) */
  --bg-primary: #0E0E10;
  --bg-surface: #18181B;
  --bg-surface-hover: #27272A;
  --accent-color: #E8FF57;
  --accent-color-rgb: 232, 255, 87;
  --text-primary: #FFFFFF;
  --text-secondary: #A1A1AA;
  --text-muted: #71717A;
  --error-color: #FF4F4F;
  --error-bg: rgba(255, 79, 79, 0.15);
  
  /* Caret & Highlights */
  --caret-color: var(--accent-color);
  --caret-style: inline; /* line, block, underline */
  --word-highlight-style: none; /* none, underline, box */
  --caret-transition: left 0.1s cubic-bezier(0.25, 0.46, 0.45, 0.94), top 0.1s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  
  /* Typography defaults */
  --font-display: 'Syne', 'Outfit', sans-serif;
  --font-typing: 'JetBrains Mono', 'Fira Code', monospace;
  --font-size-typing: 18px;
  --line-height-typing: 1.6; /* Increased default line height */
  
  /* Layout specific sizing */
  --border-radius: 12px;
  --border-radius-sm: 8px;
  --transition-base: all 0.25s ease;
  --container-width: 1200px;
  --nav-height: 70px;
}

/* CSS Theme Implementations */
[data-theme="light"] {
  --bg-primary: #F4F4F5;
  --bg-surface: #FFFFFF;
  --bg-surface-hover: #E4E4E7;
  --accent-color: #0F172A;
  --accent-color-rgb: 15, 23, 42;
  --text-primary: #0F172A;
  --text-secondary: #4B5563;
  --text-muted: #9CA3AF;
  --error-color: #DC2626;
  --error-bg: rgba(220, 38, 38, 0.1);
}

[data-theme="sepia"] {
  --bg-primary: #F4EFE6;
  --bg-surface: #EFE9DC;
  --bg-surface-hover: #E5DDC9;
  --accent-color: #78350F;
  --accent-color-rgb: 120, 53, 15;
  --text-primary: #451A03;
  --text-secondary: #78350F;
  --text-muted: #A16207;
  --error-color: #B91C1C;
  --error-bg: rgba(185, 28, 28, 0.1);
}

[data-theme="dracula"] {
  --bg-primary: #282A36;
  --bg-surface: #44475A;
  --bg-surface-hover: #6272A4;
  --accent-color: #FF79C6;
  --accent-color-rgb: 255, 121, 198;
  --text-primary: #F8F8F2;
  --text-secondary: #8BE9FD;
  --text-muted: #6272A4;
  --error-color: #FF5555;
  --error-bg: rgba(255, 85, 85, 0.2);
}

[data-theme="nord"] {
  --bg-primary: #2E3440;
  --bg-surface: #3B4252;
  --bg-surface-hover: #434C5E;
  --accent-color: #88C0D0;
  --accent-color-rgb: 136, 192, 208;
  --text-primary: #ECEFF4;
  --text-secondary: #D8DEE9;
  --text-muted: #4C566A;
  --error-color: #BF616A;
  --error-bg: rgba(191, 97, 106, 0.2);
}

[data-theme="monokai"] {
  --bg-primary: #272822;
  --bg-surface: #3E3D32;
  --bg-surface-hover: #49483E;
  --accent-color: #FD971F;
  --accent-color-rgb: 253, 151, 31;
  --text-primary: #F8F8F2;
  --text-secondary: #A6E22E;
  --text-muted: #75715E;
  --error-color: #F92672;
  --error-bg: rgba(249, 38, 114, 0.2);
}

[data-theme="rose_pine"] {
  --bg-primary: #191724;
  --bg-surface: #1F1D2E;
  --bg-surface-hover: #26233A;
  --accent-color: #EBBCBA;
  --accent-color-rgb: 235, 188, 186;
  --text-primary: #E0DEF4;
  --text-secondary: #908CAA;
  --text-muted: #6E6A86;
  --error-color: #EB6F92;
  --error-bg: rgba(235, 111, 146, 0.2);
}

[data-theme="mono"] {
  --bg-primary: #000000;
  --bg-surface: #121212;
  --bg-surface-hover: #222222;
  --accent-color: #FFFFFF;
  --accent-color-rgb: 255, 255, 255;
  --text-primary: #FFFFFF;
  --text-secondary: #CCCCCC;
  --text-muted: #777777;
  --error-color: #FF5A5A;
  --error-bg: rgba(255, 90, 90, 0.15);
}

/* ==========================================
   2. GLOBAL RESET & BASE STYLES
   ========================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-surface-hover) var(--bg-primary);
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Outfit', sans-serif;
  overflow-x: hidden;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
}

a {
  color: var(--accent-color);
  text-decoration: none;
  transition: var(--transition-base);
}

button {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
}

input, select, textarea {
  font-family: inherit;
  background: var(--bg-surface);
  border: 1px solid var(--text-muted);
  color: var(--text-primary);
  border-radius: var(--border-radius-sm);
  padding: 8px 12px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent-color);
}

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

.container {
  max-width: var(--container-width);
  width: 100%;
  margin: 0 auto;
  padding: 0 24px;
}

.hidden {
  display: none !important;
}

/* ==========================================
   3. NAVIGATION & HEADER
   ========================================== */
header {
  background-color: var(--bg-surface);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  transition: var(--transition-base);
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: 24px;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.logo {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--accent-color);
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo::before {
  content: '⚡';
  font-size: 20px;
}

.xp-badge-strip {
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(0, 0, 0, 0.2);
  padding: 6px 12px;
  border-radius: 50px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.superfan-keycap-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 242, 0, 0.14);
  border: 1px solid rgba(255, 242, 0, 0.32);
  color: #FFF9B8;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.superfan-keycap-badge.hidden {
  display: none !important;
}

.user-level {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent-color);
  white-space: nowrap;
}

.xp-bar-container {
  width: 120px;
  height: 8px;
  background: rgba(128, 128, 128, 0.2); /* Semi-transparent gray visible in both light/dark themes */
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.xp-bar-fill {
  height: 100%;
  background: var(--accent-color);
  width: 0%;
  border-radius: 4px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

#goal-progress-fill {
  background: #FFF200 !important; /* Always brand yellow */
  box-shadow: 0 0 10px rgba(255, 242, 0, 0.35);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s ease;
}

.streak-container {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 800; /* Extra bold weight */
  font-size: 14px;
  cursor: pointer;
  color: #FF9F43; /* Warm flame orange color */
  text-shadow: 0 0 6px rgba(255, 159, 67, 0.4); /* Slight flame glow */
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), text-shadow 0.2s ease;
}

.streak-container:hover {
  transform: scale(1.08); /* Hover pop animation */
  text-shadow: 0 0 10px rgba(255, 159, 67, 0.7);
}

.streak-freeze-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #38BDF8;
  display: inline-block;
  box-shadow: 0 0 8px #38BDF8;
}

nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav-link {
  padding: 8px 16px;
  border-radius: var(--border-radius-sm);
  font-weight: 500;
  font-size: 15px;
  color: var(--text-secondary);
  transition: var(--transition-base);
}

.nav-link:hover, .nav-link.active {
  color: var(--text-primary);
  background-color: var(--bg-surface-hover);
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 32px 0 40px;
  position: relative;
}

.layout-switcher-dock {
  position: fixed;
  top: calc(var(--nav-height) + 18px);
  right: 24px;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 999px;
  background: rgba(17, 17, 22, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(10px);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.2);
  z-index: 140;
}

.layout-switcher-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-base);
}

.layout-switcher-btn:hover {
  color: var(--text-primary);
  border-color: rgba(var(--accent-color-rgb), 0.35);
  background: rgba(var(--accent-color-rgb), 0.08);
}

.layout-switcher-btn.active {
  color: var(--bg-primary);
  background: var(--accent-color);
  border-color: var(--accent-color);
}

body[data-layout="minimal"] .layout-switcher-dock,
body[data-layout="focus"] .layout-switcher-dock {
  display: flex;
}

body[data-layout="minimal"] .header-container {
  gap: 12px;
}

body[data-layout="minimal"] .logo {
  font-size: 22px;
}

body[data-layout="minimal"] .logo::before {
  font-size: 18px;
}

body[data-layout="minimal"] nav,
body[data-layout="minimal"] .xp-badge-strip {
  display: none;
}

body[data-layout="minimal"] header {
  height: 56px;
}

body[data-layout="minimal"] .header-wrapper {
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
}

body[data-layout="focus"] .layout-switcher-dock {
  top: 18px;
}

@media (max-width: 1180px) {
  .header-wrapper {
    height: auto;
    padding: 10px 0;
  }

  .header-container {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .logo-section {
    width: 100%;
    justify-content: space-between;
  }

  nav {
    width: 100%;
    justify-content: flex-start;
  }

  .xp-badge-strip {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 10px;
    width: 100%;
  }

  .user-level {
    white-space: normal;
  }
}

@media (max-width: 900px) {
  .container {
    padding: 0 18px;
  }

  .logo {
    font-size: 22px;
  }

  .nav-link {
    padding: 7px 12px;
    font-size: 14px;
  }

  .layout-switcher-dock {
    right: 14px;
    gap: 6px;
    padding: 6px;
  }
}

@media (max-width: 720px) {
  main {
    padding: 24px 0 36px;
  }

  .logo-section {
    gap: 10px;
  }

  .xp-badge-strip {
    padding: 6px 10px;
  }

  .xp-bar-container {
    width: 88px;
  }

  nav {
    gap: 6px;
  }

  .nav-link {
    padding: 7px 10px;
    font-size: 13px;
  }

  .layout-switcher-dock {
    right: 12px;
    gap: 5px;
    padding: 6px;
  }

  .layout-switcher-btn {
    width: 30px;
    height: 30px;
    font-size: 10px;
  }
}

/* ==========================================
   12. FOOTER
   ========================================== */
footer {
  background-color: var(--bg-surface);
  padding: 20px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: auto;
}

/* Custom Alert Modal styles */
.custom-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: var(--transition-base);
}

/* Premium Toast Notification */
#toast-notification {
  position: fixed;
  top: 85px; /* Directly below the 70px navigation header */
  right: 24px;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--accent-color);
  padding: 14px 40px 14px 20px; /* Leave padding on the right for the close button */
  border-radius: var(--border-radius-sm);
  z-index: 9999;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4), 0 0 15px rgba(var(--accent-color-rgb), 0.1);
  opacity: 0;
  transform: translateY(-10px) scale(0.95);
  pointer-events: auto; /* Allow clicks on close button */
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 350px;
}

#toast-notification.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast-text {
  flex: 1;
  line-height: 1.4;
}

.toast-close-btn {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
  line-height: 1;
  transition: color 0.2s ease;
}

.toast-close-btn:hover {
  color: var(--text-primary);
}

/* Mobile responsive adjustments */
@media (max-width: 480px) {
  #toast-notification {
    top: auto;
    bottom: 24px; /* Move toast to bottom on mobile for better accessibility */
    left: 16px;
    right: 16px;
    max-width: none;
    padding: 12px 36px 12px 16px;
    font-size: 13px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  }

  .logo-section {
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
  }

  .xp-badge-strip {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px 10px;
  }

  .xp-bar-container {
    width: 70px;
  }

  nav {
    justify-content: center;
    flex-wrap: wrap;
    gap: 4px;
  }

  .nav-link {
    padding: 6px 8px;
    font-size: 11px;
  }

  .header-container {
    justify-content: center;
    align-items: center;
    gap: 12px;
  }
}

.custom-modal-card {
  background: var(--bg-surface);
  border-radius: var(--border-radius);
  border: 1px solid rgba(var(--accent-color-rgb), 0.2);
  padding: 36px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  animation: zoom-in-bounce 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.custom-modal-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(var(--accent-color-rgb), 0.1);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 28px;
  color: var(--accent-color);
  border: 2px solid var(--accent-color);
  box-shadow: 0 0 15px rgba(var(--accent-color-rgb), 0.15);
}

.custom-modal-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
}

.custom-modal-message {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.custom-modal-actions {
  display: flex;
  gap: 16px;
  width: 100%;
  justify-content: center;
}

.custom-modal-actions .action-btn {
  min-width: 120px;
  justify-content: center;
}

/* Animation for Badge Unlock */
.badge-unlock-animation {
  animation: badge-pulse 1.5s infinite ease-in-out;
}

.badge-icon-custom {
  font-size: 32px;
  filter: drop-shadow(0 0 8px rgba(var(--accent-color-rgb), 0.5));
}

@keyframes badge-pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 15px rgba(var(--accent-color-rgb), 0.2);
  }
  50% {
    transform: scale(1.1);
    box-shadow: 0 0 25px rgba(var(--accent-color-rgb), 0.5);
  }
}

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