/* Canonical site stylesheet (served at /styles/main.css)
 * Note: Dev server maps /styles/* -> site/styles/* and build copies site/styles -> dist/styles
 */

/* 1) Global box sizing */
*, *::before, *::after { box-sizing: border-box; }

/* 2) Theme variables (light defaults; dark via [data-theme="dark"]) */
:root {
  --background-color: #ffffff;
  --text-color: #000000;
  --border-color: #000000;
  --link-hover-background: #f4f4f4;
  /* Populated at runtime (scripts/core/main.js) */
  --safe-top: 0px;
  --safe-bottom: 0px;
  /* Layout rhythm */
  --edge-vert-pad: 0.7em;        /* shared header/footer vertical padding */
  --body-gap: clamp(0px, 2dvh, 16px);
  /* Nav sizing (tuned by header.js) */
  --nav-gap: 0.6em;
  --nav-gap-min: 0.1em;
  --nav-pad-inline: 0.75em;
  --nav-pad-inline-min: 0.25em;
  /* Highlights */
  --tap-highlight: rgba(0,0,0,0.25);
  --selection-bg: #000;
  --selection-fg: #fff;
  /* Dynamic feed gap scaling */
  --feed-gap-min: 0.85rem;   /* original min gap */
  --feed-gap-vw: 2vw;        /* viewport responsive component */
  --feed-gap-max: 1.25rem;   /* original max gap */
  --feed-gap-scale: 1.75;    /* increase gap ~75% (between 50% and 100% as requested) */
}

/* Fallback to prefers-color-scheme: dark while JS loads */
@media (prefers-color-scheme: dark) {
  :root {
    --background-color: #121212;
    --text-color: #ffffff;
    --border-color: #ffffff;
    --link-hover-background: #333333;
    --tap-highlight: rgba(255,255,255,0.25);
    --selection-bg: #fff;
    --selection-fg: #000;
  }
}

[data-theme="dark"] {
  --background-color: #121212;
  --text-color: #ffffff;
  --border-color: #ffffff;
  --link-hover-background: #333333;
  --tap-highlight: rgba(255,255,255,0.25);
  --selection-bg: #fff;
  --selection-fg: #000;
}

/* 3) Root elements */
html, body {
  height: 100dvh;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-tap-highlight-color: var(--tap-highlight);
}
html { overflow-y: hidden; background-color: var(--background-color); }

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--background-color);
  color: var(--text-color);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--body-gap);
  min-height: 0;
}

/* Selection */
::selection { background: var(--selection-bg); color: var(--selection-fg); }
::-moz-selection { background: var(--selection-bg); color: var(--selection-fg); }

/* 4) Generic container used by pages */
.container {
  max-width: 90vw;
  width: 100%;
  box-sizing: border-box;
  margin: 0 auto;
  padding: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* 5) Typography */
h1.massive {
  font-size: clamp(3rem, 10vw + 1rem, 12rem);
  line-height: 1;
  margin: 0;
  position: absolute;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
}

h1 { font-size: clamp(1.5rem, 5vw, 2.5rem); margin: 1.2em 0 0.5em; }
h2 { font-size: clamp(1.1rem, 4vw, 1.6rem); margin: 1.2em 0 0.5em; }

p, li { font-size: clamp(1rem, 3.5vw, 1.15rem); line-height: 1.7; }

/* 6) Footer (site footer component) */
footer {
  width: 100%;
  padding: var(--edge-vert-pad) 0;
  margin-top: auto;
  flex-shrink: 0;
  background: none;
  border: none;
  box-shadow: none;
  display: block;
  text-align: center;
  min-height: 70px;
}
footer p { margin: 0; font-size: 0.95em; }
footer a { color: var(--text-color); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* 7) Buttons */
a.button {
  display: inline-block;
  color: var(--text-color);
  padding: 10px 20px;
  margin-top: 25px;
  text-decoration: none;
  border: 2px solid var(--border-color);
  border-radius: 5px;
  font-weight: bold;
  transition: background-color 0.3s, color 0.3s;
  max-width: 100%;
  width: auto;
  box-sizing: border-box;
}
a.button:hover { background-color: var(--link-hover-background); }

/* 8) Top navigation */
.topnav {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: visible;
  justify-content: center;
  gap: var(--nav-gap);
  padding: var(--edge-vert-pad) 0;
  background: none;
  border-bottom: none;
  font-size: 1.15rem;
  position: relative;
  z-index: 10;
  box-sizing: border-box;
  min-width: 0;
  width: 100%;
}
.topnav a {
  color: var(--text-color);
  text-decoration: none;
  padding: 0.4em var(--nav-pad-inline);
  border-radius: 4px;
  transition: background 0.2s;
  white-space: nowrap;
  margin: 0;
  min-width: 0;
  flex-shrink: 1;
}
.topnav a.active {
  text-decoration: underline;
  text-underline-offset: 0.25em;
  text-decoration-thickness: 2px;
  background: none;
}
.topnav a:hover { background: var(--link-hover-background); text-decoration: none; }

/* 9) Legal pages layout helpers */
.legal-container {
  max-width: clamp(95vw, 90ch, 700px);
  flex: 1 1 auto;
  min-height: 0;
  margin-inline: auto;
  padding-block-end: var(--safe-bottom);
  background: none;
  border-radius: 10px;
  box-sizing: border-box;
  text-align: left;
  display: flex;
  flex-direction: column;
  overflow: visible;
  max-height: none;
}
.legal-container h1 {
  font-size: clamp(1.75rem, 6vw, 2.5rem);
  margin-bottom: clamp(1.5rem, 8vw, 3.5rem);
  font-weight: 700;
  letter-spacing: -1px;
  margin-top: 0;
}
.legal-edition { font-size: 0.6em; color: #888; font-weight: 400; margin-left: 0.5em; }
.legal-container section { margin-bottom: clamp(1.2em, 5vw, 2.2em); }
.legal-container h2 { font-size: clamp(1rem, 4.5vw, 1.4rem); margin: 0 0 clamp(0.25em, 1vw, 0.3em); font-weight: 600; color: var(--text-color); }
.legal-container p { margin: 0 0 clamp(0.3em, 1vw, 0.5em); color: var(--text-color); line-height: clamp(1.45, 1.45 + 2 * (100dvh - 400px) / 1000, 1.7); }

/* 10) Contact email sizes */
.email-large { font-size: 2em; margin: 30px 0; }
.email-large a { color: var(--text-color); text-decoration: none; font-weight: bold; transition: opacity 0.3s; }
.email-large a:hover { opacity: 0.8; }
.massive-email { font-size: clamp(1.2rem, 8vw, 3rem); font-weight: bold; margin: 5svh 0 2svh; max-width: 100%; width: 100%; text-align: center; display: flex; align-items: center; justify-content: center; }
.massive-email a { color: var(--text-color); text-decoration: none; font-weight: bold; width: 100%; display: block; overflow-wrap: break-word; }

/* ----------------------------------------------------------- */
/* Home page feed styles                                       */
/* ----------------------------------------------------------- */
.home-page .container {
  /* Ensure the home content is centered and uses full viewport width */
  max-width: 100vw;
  align-items: center; /* center children horizontally */
  justify-content: flex-start; /* start at the top */
}

.feed {
  max-width: 900px;       /* cap the feed width */
  width: 100%;            /* fill available space inside container */
  margin: 0 auto;         /* center horizontally */
  display: flex;
  flex-direction: column;
  /* Dynamic gap: original values scaled by --feed-gap-scale (≈75% bigger). Adjust scale var to tune globally. */
  gap: clamp(
    calc(var(--feed-gap-min) * var(--feed-gap-scale)),
    calc(var(--feed-gap-vw) * var(--feed-gap-scale)),
    calc(var(--feed-gap-max) * var(--feed-gap-scale))
  );
  padding: clamp(0.25rem, 1vh, 0.75rem) clamp(12px, 4vw, 20px) var(--safe-bottom);
}

.feed-card {
  position: relative;
  background: var(--background-color);
  border: 1px solid rgba(127,127,127,0.25);
  border-radius: 14px;
  --feed-card-pad: clamp(0.8rem, 1.5vw, 1.1rem);
  padding: var(--feed-card-pad);
  text-align: left;
  transition: transform 120ms ease, box-shadow 120ms ease, background 200ms ease;
  overflow: clip;
  text-decoration: none; /* anchor reset */
  color: inherit;        /* anchor reset */
  display: block;        /* make full card clickable */
}

/* Embed container and iframe styling */
.embed { width: 100%; display: block; }
.embed-frame {
  display: block;
  width: 100%;
  height: auto;
  border: 0;          /* no iframe border */
  outline: none;
  border-radius: 4px 4px 4px 4px; /* subtle rounding at the top only */
  background: transparent;
}

/* Hidden state for filtered-out cards; preserves DOM nodes to avoid iframe reloads */
.feed .is-filtered-out { display: none !important; }

/* Header layout: left meta+title, right actions */
.feed-card .head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
}

.feed-card .head-left {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0; /* allow truncation if needed */
}

.feed-card .head-right.actions {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  flex-shrink: 0;
}

/* Actions */
.action {
  font-size: 0.85rem;
  line-height: 1;
  padding: 0.35rem 0.6rem;
  border: 1px solid rgba(127,127,127,0.35);
  border-radius: 6px;
  background: transparent;
  color: inherit;
}

.action:hover { background: var(--link-hover-background); }
.action:focus { outline: 2px solid rgba(127,127,127,0.5); outline-offset: 2px; }
.action-open { text-decoration: none; }

/* Only make hand cursor for cards that navigate on click */
.feed-card.clickable:hover { cursor: pointer; }

.feed-card:hover {
  /* No transform to avoid click jitter */
  box-shadow: 0 6px 22px rgba(0,0,0,0.09);
  background: color-mix(in srgb, var(--link-hover-background) 25%, var(--background-color));
}

/* Tweak meta spacing when in header */
.feed-card .head .meta { margin-bottom: 0.1rem; }

.feed-card .meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  color: #777;
  margin-bottom: 0.4rem;
}

.feed-card .pin {
  font-size: 0.75rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px dashed rgba(127,127,127,0.5);
}

/* NEW: generic badge + prerelease styling */
.feed-card .badge {
  /* inline with the title */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: baseline;
  /* a bit after the title */
  margin-left: 0.6rem;
  /* slightly larger chip to better match title height */
  font-size: 0.9em; /* relative to h3 size */
  font-weight: 600;
  line-height: 1.1;
  padding: 0.2em 0.7em;
  border-radius: 999px;
  border: none;
  position: relative;
  top: -0.05em; /* Slight upward nudge to align with title text */
}

.feed-card .badge-prerelease { background: #000 !important; color: #fff !important; }

/* Dark-mode inversion for prerelease badge: white bg, black text */
@media (prefers-color-scheme: dark) {
  .feed-card .badge-prerelease { background: #fff !important; color: #000 !important; }
}

[data-theme="dark"] .feed-card .badge-prerelease {
  background: #fff !important;
  color: #000 !important;
}

.feed-card h3 { margin: 0 0 0.6rem 0; font-size: clamp(1.05rem, 3.5vw, 1.25rem); }

/* Palette preview */
.preview-palette {
  display: flex;
  height: clamp(90px, 18vw, 140px);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(127,127,127,0.25);
}

.preview-palette .swatch {
  flex: 1 1 0;
  display: flex;
  align-items: end;
  justify-content: center;
  position: relative;
}

.preview-palette .label {
  font-size: 0.8rem;
  margin: 0.35rem;
  padding: 0.15rem 0.4rem;
  border-radius: 0.35rem;
  background: rgba(0,0,0,0.45);
  color: #fff;
}

/* ----------------------------------------------------------- */
/* Map page image styles                                       */
/* ----------------------------------------------------------- */
.map-img-container {
  /* Let the flex column + gap handle layout — removing the extra margins avoids the 32 px overshoot */
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  /* Reserve space for the 16 px shadow so it never forces overflow */
  padding-block: 16px;
  max-width: 100dvw;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  margin: 0;
  height: auto;
}

.map-img {
  max-width: 100dvw;
  max-height: 100%;
  width: auto;
  height: auto;
  margin: 0 auto;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
  object-fit: contain;
  /* No border-radius */
}

/* Remove horizontal padding from image on mobile */
@media (max-width: 600px) {
  .map-img { padding-left: 0 !important; padding-right: 0 !important; }
}

/* ----------------------------------------------------------- */
/* Home page search bar                                        */
/* ----------------------------------------------------------- */
.home-page .feed-search {
  max-width: 900px; /* match .feed */
  width: 100%;
  margin: 0 auto;   /* center */
  padding: clamp(0.25rem, 1vh, 0.75rem) clamp(12px, 4vw, 20px) 0; /* match .feed side padding */
  box-sizing: border-box;
  /* add spacing below search before the feed */
  margin-bottom: clamp(0.4rem, 1.8vw, 1rem);
}

.home-page .feed-search input[type="search"] {
  display: block;
  width: 100%;
  font-size: clamp(0.95rem, 3.5vw, 1.05rem);
  color: var(--text-color);
  background: transparent;
  border: 1px solid rgba(127,127,127,0.35);
  border-radius: 999px; /* pill */
  padding: 0.6rem 0.9rem;
  outline: none;
  appearance: none;
}

/* The native clear button is blue on some platforms. Replace it with a masked X colored by var(--text-color). */
.home-page .feed-search input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  height: 1.05em;
  width: 1.05em;
  background-color: var(--text-color);
  /* X icon mask */
  -webkit-mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M6 6 L18 18 M18 6 L6 18" stroke="black" stroke-width="3" stroke-linecap="round"/></svg>');
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
  -webkit-mask-size: 100% 100%;
  cursor: pointer;
  opacity: 0.7;
}
.home-page .feed-search input[type="search"]:hover::-webkit-search-cancel-button,
.home-page .feed-search input[type="search"]:focus::-webkit-search-cancel-button { opacity: 1; }

.home-page .feed-search input[type="search"]::placeholder {
  color: var(--text-color);
  opacity: 0.55; /* subtle */
}

.home-page .feed-search input[type="search"]:focus {
  border-color: rgba(127,127,127,0.6);
  outline: 2px solid rgba(127,127,127,0.4);
  outline-offset: 1px;
}

@media (prefers-color-scheme: dark) {
  .home-page .feed-search input[type="search"] { border-color: rgba(255,255,255,0.28); }
  .home-page .feed-search input[type="search"]:focus {
    border-color: rgba(255,255,255,0.55);
    outline-color: rgba(255,255,255,0.35);
  }
}

/* 11) Responsive tweaks */
@media (max-width: 600px) {
  .legal-container return-home { margin-top: 1.5em; }
  .legal-container return-home .button { width: auto !important; min-width: 120px; font-size: 1em; }
  h1.massive { position: static; top: auto; left: auto; transform: none; margin-top: 2em; margin-bottom: 2em; }
  .legal-container { padding: 0.5em 0.2em; margin: 0.5em 0.1em; }
  .legal-container section { margin-bottom: 1.2em; }
  .legal-container h1 { font-size: clamp(1.2em, 5vw, 1.4em); margin-bottom: 20px; }
  .legal-container h2 { font-size: clamp(0.9em, 4vw, 1em); margin-bottom: 0.2em; }
  .legal-container p { font-size: clamp(0.8em, 3.5vw, 0.85em); margin-bottom: 0.1em; line-height: 1.4; }
  .topnav { gap: 0.5em; padding: 0.5em 0; font-size: 1em; overflow-x: visible; }
  .topnav a { padding: 0.5em 1em; }
  h1, h2 { text-align: left; }
  footer p { font-size: 0.9em; }
  a.button { width: 100%; box-sizing: border-box; font-size: 1em; }
  footer { padding: calc(var(--edge-vert-pad) * 0.86) 0 !important; min-height: 36px !important; font-size: 0.85em !important; }
  /* Mobile: move badge below title (new line) while keeping header alignment; ensure chip only wraps its text */
  .feed-card h3 .badge {
    display: block;
    margin-left: 0;
    margin-top: 0.45rem;
    width: fit-content; /* shrink to text content */
    max-width: max-content; /* fallback for some engines */
    flex: 0 0 auto; /* prevent growth */
  }
}

/* Pre-release badge line break control */
.feed-card h3 .badge-break { display: none; }
@media (max-width: 600px) { .feed-card h3 .badge-break { display: block; } }
