:root {
  --primary-bg: #00205b;
  --secondary-clr: #43d0e6;
  --accent-clr: #217523;
  --text-light: white;

  /* Theme Variables */
  --bg-body: white;
  --text-main: #333;
  --nav-bg: var(--primary-bg);
  --nav-text: var(--text-light);
  --bg-alt: #f8f9fa;
  --bg-news: #eef2f5;
  --bg-card: white;
  --bg-card-alt: #f4f4f4;
  --heading-color: var(--primary-bg);
  --shadow-color: rgba(0, 0, 0, 0.1);
  --text-on-accent: white;
  --text-on-secondary: var(--primary-bg);
  --link-clr: #0056b3;
  --link-visited-clr: #6f42c1;
  --link-hover-clr: #003580;
}

body.dark-mode {
  --bg-body: #121212;
  --text-main: #e0e0e0;
  --nav-bg: #203448;
  --nav-text: #e0e0e0;
  --bg-alt: #1e1e1e;
  --bg-news: #181818;
  --bg-card: #2d2d2d;
  --bg-card-alt: #333;
  --heading-color: #90caf9;
  --primary-bg: #90caf9;
  --secondary-clr: #66bb6a;
  --shadow-color: rgba(0, 0, 0, 0.5);
  --text-on-accent: #121212;
  --text-on-secondary: #121212;
  --link-clr: #8ab4f8;
  --link-visited-clr: #c58af9;
  --link-hover-clr: #d2e3fc;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--secondary-clr) var(--bg-body);
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: var(--bg-body);
  color: var(--text-main);
  transition: background-color 0.3s, color 0.3s;
}

/* Custom Scrollbar for Webkit */
::-webkit-scrollbar {
  width: 12px;
}

::-webkit-scrollbar-track {
  background: var(--bg-body);
}

::-webkit-scrollbar-thumb {
  background-color: var(--secondary-clr);
  border-radius: 6px;
  border: 3px solid var(--bg-body);
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--primary-bg);
}

a {
  color: var(--link-clr);
}

a:visited {
  color: var(--link-visited-clr);
}

a:hover {
  color: var(--link-hover-clr);
  text-decoration: underline;
}

.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--secondary-clr);
  color: var(--text-on-secondary);
  padding: 1rem;
  z-index: 10001;
  text-decoration: none;
  font-weight: bold;
  transition: top 0.3s;
}

.skip-link:focus {
  top: 0;
}

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--nav-bg);
  color: var(--nav-text);
  padding: 0 1rem;
  position: sticky;
  top: 0;
  z-index: 1000;
  transition: background-color 0.3s;
}

#alert-banner {
  background-color: #fff3cd;
  color: #856404;
  padding: 0.75rem 1.25rem;
  text-align: center;
  cursor: pointer;
  border-bottom: 1px solid #ffeeba;
  font-weight: bold;
  transition: background-color 0.3s;
  z-index: 999;
  position: relative;
  padding-right: 3rem;
}

#alert-banner:hover {
  background-color: #ffeeba;
}

body.dark-mode #alert-banner {
  background-color: #3b321b;
  color: #ffeeba;
  border-bottom-color: #5a4d2b;
}

body.dark-mode #alert-banner:hover {
  background-color: #5a4d2b;
}

#close-alert {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.5rem;
  font-weight: bold;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  padding: 0.25rem 0.5rem;
  line-height: 1;
}

#close-alert:hover {
  opacity: 1;
}

.logo {
  padding: 0.6rem 0;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.logo img {
  height: 40px;
  width: auto;
  display: block;
}

.hamburger {
  display: none;
  flex-direction: column;
  cursor: pointer;
  gap: 5px;
}

.hamburger span {
  width: 25px;
  height: 3px;
  background-color: var(--nav-text);
  transition: 0.3s;
}

.hamburger.active span:nth-child(1) {
  transform: translateY(8px) rotate(45deg);
}

.hamburger.active span:nth-child(2) {
  opacity: 0;
}

.hamburger.active span:nth-child(3) {
  transform: translateY(-8px) rotate(-45deg);
}

.nav-links {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 1.5rem;
  align-items: center;
}

.nav-links a {
  color: var(--nav-text);
  text-decoration: none;
  display: block;
  padding: 0.6rem 1rem;
  border-radius: 12px;
}

.nav-links a:hover {
  background-color: var(--secondary-clr);
  color: var(--text-on-secondary);
}

.btn {
  display: inline-block;
  background-color: var(--secondary-clr);
  color: var(--text-on-secondary);
  padding: 0.75rem 1.5rem;
  text-decoration: none;
  border-radius: 5px;
  font-weight: bold;
  border: none;
  cursor: pointer;
  font-size: 1rem;
}

.quick-links {
  padding: 4rem 2rem;
  background-color: var(--bg-alt);
}

.quick-links h2 {
  text-align: center;
  font-size: 2.5rem;
  margin-bottom: 3rem;
  color: var(--heading-color);
}

#linkSearch,
#faqSearch {
  width: 100%;
  max-width: 400px;
  padding: 12px;
  margin: 0 auto 2rem auto;
  display: block;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  box-sizing: border-box;
}

.search-wrapper {
  position: relative;
  max-width: 400px;
  margin: 0 auto 2rem auto;
}

.search-wrapper #faqSearch {
  margin: 0;
  padding-right: 40px;
}

.clear-btn {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-main);
  opacity: 0.5;
  display: none;
  padding: 0 10px;
}

.clear-btn:hover {
  opacity: 1;
}

.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

.link-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: 16px;
  text-decoration: none;
  color: var(--heading-color);
  box-shadow: 0 4px 6px var(--shadow-color);
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  animation: fadeInUp 0.6s ease backwards;
  animation-delay: calc(var(--i) * 0.05s);
}

.link-item:visited {
  color: var(--heading-color);
}

.link-item span {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  transition: transform 0.3s ease;
}

.link-item:hover {
  transform: translateY(-5px) scale(1.05);
  box-shadow: 0 12px 20px rgba(0,0,0,0.1);
  background-color: var(--primary-bg);
  color: var(--text-on-accent);
  text-decoration: none;
}

.link-item:hover span {
  transform: scale(1.2);
}
.black-to-white:hover {
  color: var(--text-on-accent);
}

/* Invert dark icons to white on hover or in dark mode */
.link-item.black-to-white:hover img,
body.dark-mode .link-item.black-to-white img {
  filter: brightness(0) invert(1);
}

/* Revert to original color on hover in dark mode */
body.dark-mode .link-item.black-to-white:hover img {
  filter: none;
}

/* Adaptive icon: White on hover (light mode), Black on hover (dark mode), Normal otherwise */
.link-item.adaptive-icon:hover img {
  filter: brightness(0) invert(1);
}

body.dark-mode .link-item.adaptive-icon img {
  filter: none;
}

body.dark-mode .link-item.adaptive-icon:hover img {
  filter: brightness(0);
}

.link-item svg,
.link-item img {
  width: 1em;
  height: 1em;
}

.news {
  padding: 4rem 2rem;
  background-color: var(--bg-news);
}

.news h2 {
  text-align: center;
  font-size: 2.5rem;
  margin-bottom: 3rem;
  color: var(--heading-color);
}

.news-carousel {
  display: flex;
  position: relative;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  gap: 2rem;
  padding-bottom: 1rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  will-change: filter, scroll-position;
}

.news-carousel::-webkit-scrollbar {
  display: none;
}

.news-item {
  flex: 0 0 calc((100% - 4rem) / 3);
  scroll-snap-align: start;
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 4px var(--shadow-color);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-sizing: border-box;
}

.news-item p {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.news-item h3 {
  color: var(--heading-color);
  margin-top: 0;
}

.news-item a {
  color: var(--primary-bg);
  text-decoration: none;
  font-weight: bold;
  display: inline-block;
  margin-top: 1rem;
}

.news-item.current-alert {
  border-left: 5px solid #d32f2f;
}

.news-item.current-alert h3 {
  color: #d32f2f;
  display: flex;
  align-items: center;
  gap: 8px;
}

.news-item.current-alert h3::before {
  content: "⚠️";
}

#news-reader-content.alert-content h2 {
  color: #d32f2f;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 2px solid #d32f2f;
  padding-bottom: 10px;
}

#news-reader-content.alert-content h2::before {
  content: "⚠️";
}

.carousel-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  margin-bottom: 1rem;
}

.carousel-dots {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: var(--text-main);
  opacity: 0.3;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: all 0.3s ease;
}

.dot.active {
  background-color: var(--secondary-clr);
  opacity: 1;
  transform: scale(1.2);
}

.carousel-btn {
  background-color: var(--bg-card-alt);
  border: 1px solid #ddd;
  color: var(--text-main);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 1.5rem;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.carousel-btn:hover {
  background-color: var(--secondary-clr);
  color: var(--text-on-secondary);
  border-color: var(--secondary-clr);
}

.news-reader {
  background: var(--bg-card);
  padding: 2rem;
  margin-top: 2rem;
  border-radius: 8px;
  box-shadow: 0 4px 6px var(--shadow-color);
  position: relative;
  animation: fadeInUp 0.3s ease;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

.news-reader .close-btn {
  position: sticky;
  top: 60px;
  float: right;
  margin-top: -1.5rem;
  margin-right: -1rem;
  z-index: 10;
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: var(--heading-color);
}

.news-reader img {
  max-width: 100%;
  height: auto;
}

.reader-footer {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 2rem;
}

.back-to-news-btn {
  margin: 0; /* Reset margin since it's now in a flex container */
}

.copy-link-btn {
  background-color: var(--heading-color);
  color: var(--text-on-accent);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: transform 0.2s ease, background-color 0.3s ease;
}

.copy-link-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.copy-link-btn span {
  transition: opacity 0.3s ease;
}

.help-faq {
  padding: 4rem 2rem;
  background-color: var(--bg-body);
}

.help-faq h2 {
  text-align: center;
  font-size: 2.5rem;
  margin-bottom: 3rem;
  color: var(--heading-color);
}

.faq-container {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.faq-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

.faq-controls button {
  background: none;
  border: none;
  color: var(--link-clr);
  cursor: pointer;
  padding: 5px;
  font-family: inherit;
  font-size: inherit;
  font-weight: bold;
}

.faq-controls button:hover {
  color: var(--link-hover-clr);
  text-decoration: underline;
}

.faq-controls .separator {
  color: var(--text-main);
  opacity: 0.5;
}

details {
  background-color: var(--bg-card-alt);
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 1rem;
  box-sizing: border-box;
  transition: all 0.3s ease;
  overflow: hidden; /* Contain summary's negative margin */
}

details:hover {
  background-color: var(--bg-card);
  box-shadow: 0 2px 5px var(--shadow-color);
}

summary {
  font-weight: bold;
  color: var(--heading-color);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.1rem;
  padding: 1rem;
  margin: -1rem;
  cursor: pointer;
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  content: '';
  width: 0.5em;
  height: 0.5em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.3s ease;
  margin-left: 0.5em;
}

.faq-copy-btn {
  float: right;
  margin: 0 0 0.5rem 1rem;
  background-color: transparent;
  color: var(--link-clr);
  border: 1px solid var(--link-clr);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s ease;
}

.faq-copy-btn:hover {
  background-color: var(--link-clr);
  color: white;
}

details[open] summary::after {
  transform: rotate(225deg);
}

details[open].closing summary::after {
  transform: rotate(45deg);
}

details p {
  margin-top: 1rem;
  line-height: 1.6;
  color: var(--text-main);
  border-top: 1px solid #eee;
  padding-top: 1rem;
}

@media (max-width: 900px) {
  .news-item {
    flex: 0 0 calc((100% - 2rem) / 2);
  }
}

@media (max-width: 600px) {
  .navbar {
    flex-direction: row;
  }

  .hamburger {
    display: flex;
  }

  .nav-links {
    display: flex;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background-color: var(--nav-bg);
    background-color: color-mix(in srgb, var(--nav-bg) 90%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    flex-direction: column;
    align-items: center;
    padding: 0;
    margin: 0;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.4s ease-in-out, opacity 0.4s ease-in-out, padding 0.4s ease;
  }

  .nav-links.active {
    max-height: 500px;
    opacity: 1;
    padding: 1rem 0;
  }

  .links-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .news-item {
    flex: 0 0 100%;
  }
}

footer {
  background-color: var(--nav-bg);
  color: var(--nav-text);
  text-align: center;
  padding: 0.25rem;
  margin-top: auto;
  font-size: 0.8rem;
}

footer p {
  margin: 0;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#backToTop {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 30px;
  z-index: 99;
  font-size: 1.5rem;
  border: none;
  outline: none;
  background-color: var(--secondary-clr);
  color: var(--text-on-secondary);
  cursor: pointer;
  width: 50px;
  height: 50px;
  padding: 0;
  text-align: center;
  line-height: 50px;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
  opacity: 0.8;
  transition: all 0.3s ease;
}

#backToTop:hover {
  background-color: var(--primary-bg);
  color: var(--secondary-clr);
  height: 59px;
  line-height: 59px;
  opacity: 1;
}

#themeToggle,
#motionToggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0.5rem;
  border-radius: 50%;
  transition: background-color 0.3s;
}
#themeToggle:hover,
#motionToggle:hover {
  background-color: rgba(255,255,255,0.2);
}

#loader-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-body);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.5s ease;
}

.loader {
  border: 5px solid var(--bg-card-alt);
  border-top: 5px solid var(--secondary-clr);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

mark {
  background-color: var(--secondary-clr);
  color: var(--text-on-secondary);
  border-radius: 2px;
  padding: 0 2px;
}

/* Manual Reduced Motion Class */
body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Utility classes to replace inline styles */
.full-content { display: none; }
.hidden { display: none; }
#news-reader { display: none; }
#faqNoResults { display: none; text-align: center; font-style: italic; color: var(--text-main); }
.myq-logo { max-width: 200px; }
.small-text { font-size: smaller; }
.bold { font-weight: bold; }
.halfimg { max-width: 50%; height: auto; }
.text-accent { color: var(--accent-clr); font-weight: bold; }

/* Highlight class */
.highlight {
  background-color: var(--bg-card-alt);
  border-left: 4px solid var(--secondary-clr);
  padding: 1rem;
  margin: 1rem 0;
}

/* Code block for network settings */
.code-block {
  background-color: #f4f4f4;
  padding: 1rem;
  border-radius: 4px;
  font-family: monospace;
  margin: 1rem 0;
  color: #333;
  line-height: 1.5;
}

/* Animation delays for link items */
.link-item:nth-child(1) { --i: 1; }
.link-item:nth-child(2) { --i: 2; }
.link-item:nth-child(3) { --i: 3; }
.link-item:nth-child(4) { --i: 4; }
.link-item:nth-child(5) { --i: 5; }
.link-item:nth-child(6) { --i: 6; }
.link-item:nth-child(7) { --i: 7; }
.link-item:nth-child(8) { --i: 8; }
.link-item:nth-child(9) { --i: 9; }
.link-item:nth-child(10) { --i: 10; }
.link-item:nth-child(11) { --i: 11; }
.link-item:nth-child(12) { --i: 12; }
.link-item:nth-child(13) { --i: 13; }
.link-item:nth-child(14) { --i: 14; }
.link-item:nth-child(15) { --i: 15; }
.link-item:nth-child(16) { --i: 16; }
.link-item:nth-child(17) { --i: 17; }
.link-item:nth-child(18) { --i: 18; }