/* =========================================================
   File: /css/styles.css
   Program: Albatross Index
   Updated: November 12, 2025, 3:40 PM
   Purpose: Final unification — fixes iPhone grid flicker,
            Safari scrollbar compensation, and keeps modular
            header/footer + dark mode fully intact.
   ========================================================= */

/* =========================================================
   Safari Viewport Stabilizer — Added Nov 12 2025, 5:00 PM
   Locks initial viewport width and prevents iOS flicker.
   ========================================================= */
html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  -webkit-text-size-adjust: 100%; /* prevent Safari zoom recalculation */
}

body {
  width: 100%;
  margin: 0 auto;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0)
           env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
  position: relative;
  overflow-x: hidden;
}

/* --- Prevent Safari scrollbar compensation (WebKit-only) --- */
@supports (-webkit-touch-callout: none) {
  html {
    overflow-y: scroll;              /* keeps consistent scroll area */
    overscroll-behavior-y: none;     /* stops bounce recalculation */
  }
  body {
    margin: 0 auto;
    max-width: 100%;
    overflow-x: hidden;
    position: relative;
  }
}

/* =========================================================
   Core Variables
   ========================================================= */
:root {
  --bg:#fff;
  --fg:#000;
  --muted:#888;
  --divider:#eee;
  --chip:#666;
  --focus:#1a73e8;
  --col-gap:18px;
  --row-gap:10px;
  --maxw:1200px;
}

/* --- Prevent Safari grid snap on header injection --- */
html, body {
  width: 100vw;
  overflow-x: hidden;
}

* { box-sizing: border-box; }

html, body {
  margin:0; padding:0;
  background:var(--bg);
  color:var(--fg);
  font:16px/1.5 system-ui,-apple-system,Segoe UI,Roboto,sans-serif;
}
.sr-only { position:absolute; left:-9999px; width:1px; height:1px; overflow:hidden; }

/* =========================================================
   HEADER
   ========================================================= */
.site-header {
  position:sticky;
  top:0;
  z-index:10;
  background:#fff;
  border-bottom:none;
  display:flex;
  flex-direction:column;
  align-items:center;
  padding-top:14px;
  padding-bottom:6px;
}
.site-header .site-brand { text-align:center; margin-bottom:6px; }
#site-title { margin:0; font-size:28px; font-weight:700; }
#site-tagline { margin-top:2px; font-size:12px; color:var(--muted); }

.nav { margin-top:4px; }
#nav-links {
  list-style:none;
  display:flex;
  gap:20px;
  justify-content:center;
  margin:0;
  padding:0;
}
#nav-links a { color:inherit; text-decoration:none; }
#nav-links a:hover, #nav-links a:focus, #nav-links a.active {
  text-decoration:underline;
  outline:none;
}

.search-bar {
  display:flex;
  align-items:stretch;
  gap:8px;
  flex-wrap:wrap;
  max-width:var(--maxw);
  margin:10px auto 12px;
  padding:0 12px;
}
.search-bar #q {
  flex:1 1 auto;
  min-width:200px;
  padding:10px 12px;
  border:1px solid var(--divider);
  border-radius:6px;
  font-size:14px;
}
.search-actions {
  display:flex;
  gap:8px;
  align-items:center;
}
.btn-search, .btn-reset {
  padding:10px 14px;
  border:1px solid var(--divider);
  background:#fafafa;
  border-radius:6px;
  cursor:pointer;
  font:inherit;
}
.btn-search:hover, .btn-search:focus,
.btn-reset:hover, .btn-reset:focus {
  text-decoration:underline;
  outline:none;
}
@media (max-width:600px) {
  .search-actions { width:100%; justify-content:flex-start; }
}

/* =========================================================
   THEME TOGGLE
   ========================================================= */
.theme-toggle {
  width:36px; height:20px;
  border:1px solid var(--divider);
  border-radius:12px;
  align-self:center;
  margin-top:4px;
}

/* =========================================================
   HOME (Leaderboards Grid)
   ========================================================= */
.home { max-width:var(--maxw); margin:12px auto; padding:0 12px; }
.columns {
  display:grid;
  grid-template-columns:1fr;
  gap:var(--col-gap);
  width:100%;
  min-width:100vw; /* ensures no narrow render on load */
}
@media (min-width:1024px) {
  .columns {
    grid-template-columns:repeat(3,1fr);
    grid-auto-rows:1fr;
    grid-template-rows:repeat(2,auto);
  }
  .column { min-height:260px; }
}
.column { display:flex; flex-direction:column; gap:var(--row-gap); }

/* =========================================================
   HEADLINES
   ========================================================= */
.headline {
  display:block;
  padding:8px 0;
  color:inherit;
  text-decoration:none;
  font-weight:600;
  border:0 !important;
}
.headline + .headline {
  border-top:1px solid var(--divider) !important;
}
.headline:hover, .headline:focus {
  text-decoration:underline;
  outline:none;
}
.meta { color:var(--muted); font-size:12px; margin-left:6px; }
.chip { color:var(--chip); font-size:12px; margin-left:6px; }

/* =========================================================
   CONTRIBUTE PAGE
   ========================================================= */
.contribute { max-width:720px; margin:20px auto; padding:0 12px; }
.form-row { margin-bottom:14px; }
.form-row label { display:block; font-weight:600; margin-bottom:6px; }
.form-row input[type="text"],
.form-row input[type="url"],
.form-row textarea {
  width:100%;
  padding:10px 12px;
  border:1px solid var(--divider);
  border-radius:6px;
  font-size:14px;
}
.form-row.actions { display:flex; gap:10px; }
button {
  padding:10px 14px;
  border:1px solid var(--divider);
  background:#fafafa;
  cursor:pointer;
  border-radius:6px;
}
button:hover, button:focus {
  text-decoration:underline;
  outline:none;
}
.hp { display:none; }
.submit-result { margin-top:10px; min-height:20px; }

/* =========================================================
   FAQ PAGE
   ========================================================= */
.faq { max-width:760px; margin:20px auto; padding:0 12px; }
.faq a { color:inherit; text-decoration:none; }
.faq a:hover, .faq a:focus { text-decoration:underline; }
.policy {
  border-top:1px solid var(--divider);
  margin-top:16px;
  padding-top:12px;
  color:#111;
}

/* =========================================================
   DEVELOPER FAQ
   ========================================================= */
.devfaq { max-width:900px; margin:20px auto; padding:0 12px 30px; }
.devfaq .doc ol { padding-left:20px; }
.devfaq .doc li { margin-bottom:10px; }

/* =========================================================
   MODAL
   ========================================================= */
.modal { position:fixed; inset:0; display:none; }
.modal.open { display:block; }
.modal-backdrop { position:absolute; inset:0; background:rgba(0,0,0,.35); }
.modal-content {
  position:absolute; inset:6% 50% auto 50%; transform:translate(-50%,0);
  width:min(820px,92vw);
  background:#fff;
  border:1px solid var(--divider);
  border-radius:10px;
  padding:14px 14px 18px;
  max-height:88vh;
  overflow:auto;
}
.modal-title { margin:4px 0 10px; font-size:20px; }
.modal-body { font-size:15px; color:#111; }
.modal-close {
  position:absolute; top:6px; right:10px;
  background:transparent; border:none;
  font-size:24px; line-height:1;
  cursor:pointer;
}
.context { margin-top:14px; border-top:1px solid var(--divider); padding-top:10px; }
.context-list { display:flex; flex-direction:column; gap:8px; }
.context-item {
  border-bottom:1px solid var(--divider);
  padding:6px 0;
  font-size:14px;
}
.context-item a { color:inherit; text-decoration:none; }
.context-item a:hover, .context-item a:focus { text-decoration:underline; }
.context-form textarea { font-size:14px; }

/* =========================================================
   ACCESSIBILITY
   ========================================================= */
:focus-visible { outline:2px solid var(--focus); outline-offset:2px; }

/* =========================================================
   REDUCED MOTION
   ========================================================= */
@media (prefers-reduced-motion:reduce){ .modal-content{transition:none;} }

/* =========================================================
   STABILIZATION FOR ASYNC LOAD
   ========================================================= */
.columns, .leaderboards {
  min-width: 100%;
  contain: layout paint style;
  content-visibility: auto;
}
.board-card {
  min-height: 260px;
  transition: none !important;
}
.board-list {
  min-height: 40px;
}

/* =========================================================
   DARK MODE
   ========================================================= */
body.dark {
  background-color: #000 !important;
  color: #fff !important;
}
body.dark .board, body.dark .board-card, body.dark .columns, body.dark .column {
  background-color: #111 !important;
  border-color: #333 !important;
  color: #fff !important;
}
body.dark input, body.dark textarea {
  background-color: #111 !important;
  color: #fff !important;
  border-color: #333 !important;
}
body.dark button {
  background-color: #222 !important;
  color: #fff !important;
  border-color: #444 !important;
}
body.dark .site-header, body.dark .site-footer {
  background-color: #000 !important;
  color: #fff !important;
  border: none !important;
}
/* =========================================================
   DARK MODE — Enhanced Readability (Added November 12, 2025, 6:00 PM)
   Purpose: Increases contrast and ensures legibility of text,
            links, and board cards in dark theme.
   ========================================================= */

body.dark {
  background-color: #0a0a0a !important;
  color: #f5f5f5 !important;
}

/* Main containers */
body.dark .site-header,
body.dark .site-footer,
body.dark .board-card,
body.dark .column,
body.dark .columns,
body.dark .leaderboards,
body.dark main {
  background-color: #121212 !important;
  color: #f5f5f5 !important;
  border-color: #2c2c2c !important;
  box-shadow: none !important;
}

/* Headings and titles */
body.dark h1, body.dark h2, body.dark h3, body.dark h4, body.dark h5, body.dark h6 {
  color: #ffffff !important;
}

/* Text and links */
body.dark p, body.dark span, body.dark small, body.dark label {
  color: #e0e0e0 !important;
}
body.dark a {
  color: #9ec9ff !important;
}
body.dark a:hover,
body.dark a:focus {
  color: #c6e1ff !important;
  text-decoration: underline;
}

/* Inputs and buttons */
body.dark input,
body.dark textarea,
body.dark select {
  background-color: #1a1a1a !important;
  color: #f5f5f5 !important;
  border: 1px solid #333 !important;
}
body.dark button,
body.dark .btn-search,
body.dark .btn-reset {
  background-color: #1f1f1f !important;
  color: #fff !important;
  border: 1px solid #3a3a3a !important;
}
body.dark button:hover,
body.dark .btn-search:hover,
body.dark .btn-reset:hover {
  background-color: #2a2a2a !important;
}

/* Divider lines */
body.dark hr,
body.dark .headline + .headline,
body.dark .board-title {
  border-color: #333 !important;
}

/* Leaderboard headings */
body.dark .board-title {
  color: #ffffff !important;
  border-bottom: 1px solid #333 !important;
}

/* Cards & context boxes */
body.dark .modal-content,
body.dark .context-item,
body.dark .ad-slot {
  background-color: #1a1a1a !important;
  border-color: #333 !important;
  color: #f0f0f0 !important;
}

/* Muted / meta text */
body.dark .meta,
body.dark .chip {
  color: #aaa !important;
}