/* Color theme variables and automatic light/dark support */
:root {
  --bg-color: #ffffff;
  --text-color: #000000;
  --link-color: #0563c1;
  --hr-color: #e0e0e0;
  --highlight-bg: #dcefff; /* light blue for light mode */
  --cta-yellow: #ffc107; /* Warm yellow for CTA */
}

.dark-mode {
  --bg-color: #0d1117;
  --text-color: #c9d1d9;
  --link-color: #58a6ff;
  --hr-color: #30363d;
  --highlight-bg: rgba(134, 112, 11, 0.25); /* soft yellow for dark mode */
}

html {
  /* color-scheme: light dark; -- This will be controlled by JS */
}

body {
  font-family: monospace;
  font-size: 12pt;
  line-height: 2;
  background-color: var(--bg-color);
  color: var(--text-color);
  max-width: 800px; /* Center content and set max-width for readability on large screens */
  margin: 0 auto;
  padding: 1rem 1rem;
}

img {
  vertical-align: middle;
  max-width: 100%;
  -webkit-filter: drop-shadow(0px 0px 1px rgba(128, 128, 128, 1.0));
  filter: drop-shadow(0px 0px 1px rgba(128, 128, 128, 1.0));
}

/* Icon size utility classes */
.icon-24 {
  width: 24px;
}

.icon-48 {
  height: 48px;
}

/* Twitter/X icon color: black in light, white in dark */
img[src$="twitter.svg"] {
  filter: none;
}

.dark-mode img[src$="twitter.svg"] {
  filter: invert(1);
}

a {
  color: var(--link-color);
}

hr {
  border: 1px solid var(--hr-color);
}

/* Top navigation bar */
.top-nav {
  display: flex;
  align-items: center; /* Vertically align items */
  gap: 1rem;
  line-height: 0.75;
  margin-bottom: 0.5rem;
  font-family: inherit;
  width: 100%;
  justify-content: space-between;
}

.main-header {
  margin-top: 0.5rem; /* Adjusted for proper spacing */
  margin-bottom: 0.5rem;
}

.header-row-1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-subtitle {
  font-size: 0.9rem;
  line-height: 1.4;
  margin-top: 0.2rem;
}

.top-nav a {
  text-decoration: none;
  font-family: inherit;
}

.top-nav a.active-nav {
  font-weight: bold;
  text-decoration: underline;
  background-color: var(--highlight-bg);
  border-radius: 12px;
  padding: 0.2rem 0.4rem; /* Add padding around the active link */
}

.top-nav b {
  font-family: inherit;
}

@media (max-width: 600px) {
  font[style*="monospace"] {
    font-size: clamp(0.7rem, 3.5vw, 1rem);
    word-break: break-all;
    overflow-wrap: anywhere;
  }

  .highlight {
    /* Fluidly shrink font size on small screens to prevent overflow */
    font-size: clamp(0.6rem, 3.5vw, 0.9rem);
  }

  .breakable-link {
    /* Fluidly shrink font size on small screens to prevent overflow */
    font-size: clamp(0.6rem, 4.5vw, 0.9rem);
    word-break: break-all; /* Ensure it wraps if it's still too long */
  }

  .top-nav {
    flex-wrap: wrap; /* Allow nav items to wrap to a new line */
    gap: 0.0rem; /* Reduce gap between nav items */
  }
}

/* General rule so it also applies above 600px for wrapping */
font[style*="monospace"] {
  word-break: break-all;
  overflow-wrap: anywhere;
}

/* Copy button styles */
.copy-btn {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.15rem 0.6rem;
  margin-left: 0.5rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background-color: var(--link-color);
  color: var(--bg-color);
}

.copy-btn:active {
  opacity: 0.8;
}

/* Theme toggle button */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.3rem;
  margin: 0;
  color: var(--text-color);
}

/* Language switcher toggle */
.lang-switcher-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.3rem;
}

/* By default (English), show the Ukrainian flag */
.lang-switcher-toggle .lang-icon-en {
  display: none;
}

/* When Ukrainian is active, show the English flag */
html.lang-uk .lang-switcher-toggle .lang-icon-en {
  display: inline;
}
html.lang-uk .lang-switcher-toggle .lang-icon-uk {
  display: none;
}

/* Call to action button on Join page */
.cta-button {
  display: inline-block;
  font-family: inherit;
  font-size: 1.5rem;
  font-weight: bold;
  padding: 0.8rem 1.5rem;
  margin-top: 2rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background-color: var(--cta-yellow);
  color: #000000; /* Black text for better contrast on yellow */
  text-decoration: none;
  text-align: center;
}

.cta-button:hover {
  opacity: 0.9;
}

.join-content {
  text-align: center;
  font-size: 1.2rem;
  padding: 1rem 0; /* Reduced vertical padding */
}

.video-links {
  margin-top: 3rem;
  margin-bottom: 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* Responsive adjustments for short screens (e.g., landscape phones) */
@media (max-height: 500px) {
  .join-content {
    padding: 0.0rem 0;
  }
  .video-links {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
  }
  .cta-button {
    margin-top: 1rem;
  }
}

.error-content {
  text-align: center;
  padding: 4rem 1rem;
}

.video-links a {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
}

/* Initially hide all translatable text to prevent flash of untranslated content */
[data-i18n] {
  visibility: hidden;
}
body.i18n-loaded [data-i18n] {
  visibility: visible;
}

/* Hide one of the icons based on theme */
/* Default to light-mode appearance (show moon icon) */
.theme-toggle .light-icon {
  display: none;
}

/* In dark mode, flip the icons (show sun icon) */
.dark-mode .theme-toggle .light-icon {
  display: inline;
}
.dark-mode .theme-toggle .dark-icon {
  display: none;
}

/* Highlight for important plain text values */
.highlight {
  background-color: var(--highlight-bg);
  padding: 0 2px;
  border-radius: 3px;
}

.fundraiser-link {
    background-color: var(--cta-yellow);
    padding: 0.2rem 0.4rem;
    border-radius: 5px;
    color: #000000; /* Black text for better contrast on yellow */
    text-decoration: none;
}

/* QR Page */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem 0;
}

.qr-item {
  text-align: center;
  max-width: 100%;
}

.qr-item img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Hide scrollbar for the QR container for a cleaner look */
.qr-container::-webkit-scrollbar {
  display: none;
}

.qr-container {
  -ms-overflow-style: none;
  /* IE and Edge */
  scrollbar-width: none;
  /* Firefox */
}

/* Media query for landscape phones and small tablets - VERTICAL SCROLL SNAP */
@media (max-height: 500px) and (min-width: 600px) {
  /* Tell header elements not to shrink */
  body > .top-nav,
  body > .main-header,
  body > hr {
    flex-shrink: 0;
  }

  .qr-container {
    /* Let this container grow to fill all remaining vertical space */
    flex-grow: 1;
    min-height: 0;
    /* This is crucial for flex-grow to work correctly with scrollable content */
    height: 100%;
    width: 100%;
    scroll-snap-type: y mandatory;
    /* Snap on the Y-axis */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: 0;
    gap: 0;
  }

  .qr-item {
    height: 100%;
    width: 100%;
    scroll-snap-align: center;
    /* Reverting to a simpler Flexbox layout */
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    padding: 0 1rem;
    box-sizing: border-box;
    gap: 1.5rem;
  }

  .qr-label {
    text-align: right;
  }

  .qr-image {
    display: flex;
    align-items: center;
    height: 100%;
    /* This is the key change to make the image smaller */
    max-width: 45vw;
  }

  .qr-item img {
    max-height: 90%;
    width: auto;
    height: auto;
    max-width: 100%;
    object-fit: contain;
  }

  .qr-item h3 {
    font-size: 1.1rem;
  }
}

/* FINAL SOLUTION for landscape QR page */
@media (max-height: 500px) and (min-width: 600px) {
  body.qr-page-body {
    /* Create a robust layout container for the whole page */
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }

  /* Target the main element for scrolling, leaving the header alone */
  body.qr-page-body > main {
    flex-grow: 1;
    min-height: 0;
  }

  /* Tell header elements not to shrink */
  body.qr-page-body > header {
    flex-shrink: 0;
  }

  .qr-container {
    height: 100%;
    overflow-y: auto;
    scroll-snap-type: y mandatory;
  }

  .qr-item {
    /* Each item is a full-height snap point */
    width: 100%;
    height: 100%;
    scroll-snap-align: center;
    flex-shrink: 0;
    /* Use a stable two-column grid for alignment */
    display: grid;
    /* Define a smaller, fixed column for the image, and a column for the label (sized to its content) */
    grid-template-columns: 25vw max-content;
    /* Align the entire two-column block to the left */
    justify-content: start;
    align-items: center;
    gap: 1.5rem;
    padding: 0 2rem;
    box-sizing: border-box;
  }

  .qr-label {
    /* Align the label to the left of its column */
    justify-self: start;
    text-align: left;
  }

  .qr-image {
    /* Align the image to the right of its column */
    justify-self: end;
    /* Ensure the container itself doesn't overflow its column */
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
  }

  .qr-item img {
    /* Ensure the image scales within its container */
    max-width: 100%;
    /* THIS IS THE FIX: Constrain the image height based on the viewport height */
    max-height: 40vh;
    object-fit: contain;
  }
}

/* Desktop & portrait large-screen layout for QR page */
@media (min-width: 768px) and (orientation: portrait), (min-width: 1024px) {
  body.qr-page-body .qr-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 2rem;
    justify-items: center;
    padding: 2rem 0;
  }

  body.qr-page-body .qr-item {
    max-width: none; /* allow grid cell to dictate width */
  }
}

/* QR spoiler blur */
.qr-code {
  cursor: pointer;
  transition: filter 0.3s ease;
}

.qr-code:not(.revealed) {
  filter: blur(8px);
}

.qr-image {
  position: relative; /* allow overlay positioning */
}

.qr-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: bold;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 8px;
  pointer-events: none; /* clicks fall through to image */
  transition: opacity 0.3s ease;
}

.qr-code.revealed + .qr-overlay {
  opacity: 0;
  visibility: hidden;
}
