/* ==================================================================
   Digi Bites app: styles.
   Mobile-first: the base rules are for phones; the @media (min-width)
   blocks at the bottom add more space on bigger screens.
   Colours are the same as digibites.me (copied from the games).
   ================================================================== */

/* ---------- 1. Colours: dark by default, light when the system says so ---------- */
:root {
  --bg: #0c1020;
  --bg-raised: rgba(255, 255, 255, 0.035);
  --fg: #f0ece4;
  --fg-soft: #c4b9a8;
  --dim: #8a7d68;
  --hairline: rgba(240, 236, 228, 0.16);
  --accent: #ff6b35;   /* Digi Bites orange: the brand's one accent colour */
  --logo-stroke: #f0ece4;  /* the D mark's lines: paper on dark */
  --cyan: #00d4ff;
  --green: #00bfa5;

  --mono: 'Space Mono', ui-monospace, Menlo, monospace;
  --sans: 'Outfit', system-ui, -apple-system, sans-serif;
  --radius: 14px;

  /* iPhone notch / home-bar space (0 everywhere else). */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf6ee;
    --bg-raised: rgba(34, 28, 16, 0.035);
    --fg: #221c10;
    --fg-soft: #4e4536;
    --dim: #7a7059;
    --hairline: rgba(34, 28, 16, 0.16);
    --accent: #a04d00;
    --logo-stroke: #0c1020;  /* ink on light */
    --cyan: #006e8a;
    --green: #1e7a52;
    color-scheme: light;
  }
}

/* ---------- 2. Basics ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  /* Stop iOS from enlarging text when the phone is rotated. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  /* Keep everything clear of the notch and the rounded corners. */
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- 3. Header and tabs ---------- */
.masthead {
  position: sticky; top: 0; z-index: 10;
  padding: calc(14px + var(--safe-top)) 18px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--hairline);
}

.brand {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none;
}
/* The D mark (inline SVG): its lines are currentColor, its dot is orange. */
.brand-logo { width: 40px; height: 40px; display: block; flex: none; color: var(--logo-stroke); }
/* Wordmark per the brand: "digi" light in the soft text colour, "bites" bold
   in the main text colour. Outfit, because Space Mono has no weight 300. */
.wordmark { font-family: var(--sans); font-size: 22px; letter-spacing: -0.3px; }
.wm-d { font-weight: 300; color: var(--fg-soft); }
.wm-b { font-weight: 700; color: var(--fg); }

.tagline {
  margin-top: 2px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--dim);
}

.tabs { display: flex; gap: 4px; margin-top: 12px; }
.tab {
  flex: 1; text-align: center;
  padding: 10px 0 12px;
  font-family: var(--mono); font-size: 14px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--dim); text-decoration: none;
  border-bottom: 3px solid transparent;
}
.tab[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }

/* ---------- 4. Panels ---------- */
main { padding: 16px 18px 32px; max-width: 980px; margin: 0 auto; }
.panel[hidden] { display: none; }

.intro, .count { color: var(--fg-soft); font-size: 15px; }
.count { font-family: var(--mono); font-size: 12px; color: var(--dim); margin: 10px 0; }

/* ---------- 5. Papers: search + chips ---------- */
.toolbar { display: grid; gap: 12px; }

.search input {
  width: 100%;
  /* 16px or more: below that, iPhone Safari zooms in when you tap the box. */
  font-size: 16px;
  font-family: var(--sans);
  padding: 12px 14px;
  color: var(--fg);
  background: var(--bg-raised);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  -webkit-appearance: none;
  appearance: none;
}
.search input::placeholder { color: var(--dim); }
.search input:focus { outline: none; border-color: var(--accent); }

/* Chips scroll sideways on a phone instead of wrapping into many rows. */
.chips {
  display: flex; gap: 8px;
  overflow-x: auto; padding-bottom: 4px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  font: 12px/1 var(--mono); letter-spacing: 0.5px;
  padding: 9px 13px;
  color: var(--fg-soft);
  background: var(--bg-raised);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  cursor: pointer;
}
.chip[aria-pressed="true"] { color: var(--bg); background: var(--accent); border-color: var(--accent); }

/* "Save all for offline" and its progress line. */
.save-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.save-all {
  min-height: 36px;
  font: 12px/1 var(--mono); letter-spacing: 0.5px;
  padding: 9px 14px;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  cursor: pointer;
}
.save-all:hover, .save-all:focus-visible { border-color: var(--accent); }
.save-all[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.save-all:disabled { opacity: 0.6; cursor: default; }
.save-status { font: 12px/1.5 var(--mono); color: var(--fg-soft); }
.save-all[hidden], .save-status[hidden] { display: none; }

/* ---------- 6. Papers: notice + cards ---------- */
.notice {
  margin-top: 12px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--fg);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: var(--radius);
}
.notice[hidden], .empty[hidden] { display: none; }

.paper-list { list-style: none; display: grid; gap: 12px; }

.paper-card {
  display: block;
  padding: 16px;
  text-decoration: none;
  background: var(--bg-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  transition: border-color 0.2s;
}
.paper-card:hover, .paper-card:focus-visible { border-color: var(--accent); }

/* Top line of a card: the category, then the "Saved" badge on the right. */
.paper-top { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.paper-category {
  font: 11px/1.4 var(--mono); letter-spacing: 1px; text-transform: uppercase;
  color: var(--cyan);
}
/* Small "Saved" badge: this paper can be read offline. */
.paper-saved {
  margin-left: auto;
  padding: 2px 8px;
  font: 10px/1.4 var(--mono); letter-spacing: 1px; text-transform: uppercase;
  color: var(--green);
  border: 1px solid color-mix(in srgb, var(--green) 55%, transparent);
  border-radius: 999px;
}
.paper-saved::before { content: "✓ "; }
.paper-saved[hidden] { display: none; }
.paper-title { font-size: 18px; font-weight: 600; line-height: 1.35; }
.paper-dates {
  display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px;
  font: 12px/1.5 var(--mono); color: var(--dim);
}
.paper-summary { margin-top: 8px; color: var(--fg-soft); font-size: 15px; }
.paper-open { margin-top: 10px; font: 12px var(--mono); color: var(--accent); }

.empty { margin-top: 24px; text-align: center; color: var(--fg-soft); }

/* ---------- 7. Paper reader (#paper/<slug>) ---------- */
/* One readable column: about 65 characters per line. */
.reader { max-width: 65ch; margin: 0 auto; }
.reader [hidden] { display: none !important; }

.reader-back {
  display: inline-flex; align-items: center;
  min-height: 44px; padding: 0 16px;
  font: 14px var(--mono); letter-spacing: 0.5px;
  color: var(--fg); background: transparent;
  border: 1px solid var(--hairline); border-radius: 999px;
  cursor: pointer;
}
.reader-back:hover, .reader-back:focus-visible { border-color: var(--accent); color: var(--accent); }

.reader-status { margin-top: 28px; text-align: center; font: 13px var(--mono); color: var(--dim); }

.reader-head { margin: 22px 0 26px; padding-bottom: 18px; border-bottom: 1px solid var(--hairline); }
.reader-head h1 { font-size: 26px; font-weight: 800; line-height: 1.25; letter-spacing: -0.3px; }
.reader-head h1:focus { outline: none; }
.reader-meta {
  margin-top: 10px;
  font: 11px/1.6 var(--mono); letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--dim);
}

/* The article. Its HTML comes from the server already cleaned up
   (functions/api/paper.js), so these few rules style all of it. */
.reader-body { font-size: 17px; line-height: 1.75; color: var(--fg-soft); overflow-wrap: break-word; }
.reader-body > :first-child { margin-top: 0; }
.reader-body p, .reader-body ul, .reader-body ol, .reader-body pre,
.reader-body table, .reader-body figure, .reader-body blockquote { margin: 0 0 1.1em; }
.reader-body p:empty { display: none; } /* stray empty paragraphs from untidy pages */

.reader-body h1, .reader-body h2, .reader-body h3, .reader-body h4 { color: var(--fg); line-height: 1.3; }
.reader-body h1 { font-size: 24px; margin: 1.6em 0 0.6em; }
.reader-body h2 {
  font-size: 21px; font-weight: 700; letter-spacing: -0.2px;
  margin: 1.8em 0 0.6em; padding-top: 0.2em;
}
.reader-body h3 {
  font: 700 14px/1.4 var(--mono); letter-spacing: 1px; text-transform: uppercase;
  color: var(--green);
  margin: 1.6em 0 0.5em;
}
.reader-body h4 { font-size: 17px; margin: 1.4em 0 0.4em; }

.reader-body ul, .reader-body ol { padding-left: 1.4em; }
.reader-body ul { list-style: disc; }
.reader-body li { margin-bottom: 0.45em; padding-left: 0.2em; }
.reader-body li::marker { color: var(--accent); }

.reader-body strong, .reader-body b { color: var(--fg); font-weight: 600; }
.reader-body a {
  color: var(--cyan); text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--cyan) 40%, transparent);
  text-underline-offset: 3px;
}
.reader-body a:hover { text-decoration-color: var(--cyan); }

.reader-body blockquote {
  padding: 14px 18px;
  border-left: 3px solid var(--accent);
  background: var(--bg-raised);
  border-radius: 0 10px 10px 0;
  font-style: italic;
}
.reader-body blockquote > :last-child { margin-bottom: 0; }

/* .highlight-box ("Key Takeaways") becomes a callout. */
.reader-body .highlight-box {
  margin: 1.6em 0;
  padding: 16px 18px 6px;
  background: color-mix(in srgb, var(--green) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--green) 30%, transparent);
  border-left: 4px solid var(--green);
  border-radius: 10px;
}
.reader-body .highlight-box > :first-child { margin-top: 0; }
.reader-body .article-tag, .reader-body .article-meta {
  font: 11px/1.6 var(--mono); letter-spacing: 1px; text-transform: uppercase; color: var(--dim);
}

.reader-body code {
  font: 0.88em var(--mono);
  padding: 1px 5px;
  background: var(--bg-raised);
  border: 1px solid var(--hairline);
  border-radius: 5px;
}
/* Wide things scroll sideways instead of widening the page. */
.reader-body pre {
  overflow-x: auto; padding: 12px 14px;
  background: var(--bg-raised); border: 1px solid var(--hairline); border-radius: 10px;
}
.reader-body pre code { padding: 0; border: 0; background: none; }
.reader-body table { display: block; overflow-x: auto; border-collapse: collapse; font-size: 15px; }
.reader-body th, .reader-body td { padding: 6px 10px; border: 1px solid var(--hairline); text-align: left; vertical-align: top; }
.reader-body th { color: var(--fg); }
.reader-body img { max-width: 100%; height: auto; border-radius: 8px; }
.reader-body figcaption { font-size: 14px; color: var(--dim); margin-top: 6px; }
.reader-body hr { border: 0; border-top: 1px solid var(--hairline); margin: 2em 0; }
.reader-body sup, .reader-body sub { line-height: 0; }

/* Footer links and the buttons in the "can't show it" box. */
.reader-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.reader-foot { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--hairline); }
.pill {
  display: inline-flex; align-items: center;
  min-height: 44px; padding: 0 16px;
  font: 13px var(--mono); letter-spacing: 0.3px;
  color: var(--fg); background: transparent; text-decoration: none;
  border: 1px solid var(--hairline); border-radius: 999px;
  cursor: pointer;
}
.pill:hover, .pill:focus-visible { border-color: var(--accent); color: var(--accent); }

/* "Not saved for offline yet" and friends. */
.reader-problem {
  margin-top: 22px; padding: 20px 18px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: var(--radius);
}
.reader-problem h2 { font-size: 20px; line-height: 1.3; }
.reader-problem p { margin: 8px 0 16px; color: var(--fg-soft); }

/* ---------- 8. "New version" toast ---------- */
.toast {
  position: fixed; z-index: 50;
  left: calc(12px + var(--safe-left)); right: calc(12px + var(--safe-right));
  bottom: calc(12px + var(--safe-bottom));
  max-width: 520px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 8px 16px;
  font-size: 15px; line-height: 1.35;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.toast[hidden] { display: none; }
.toast-text { flex: 1; }
.toast-refresh, .toast-close {
  min-height: 44px; min-width: 44px;
  font: 700 13px var(--mono);
  border-radius: 10px; cursor: pointer;
}
.toast-refresh { padding: 0 14px; color: var(--bg); background: var(--accent); border: 0; }
.toast-close { font-size: 20px; color: var(--fg-soft); background: transparent; border: 0; }

/* ---------- 9. Games grid ---------- */
.game-grid {
  list-style: none;
  display: grid; gap: 12px; margin-top: 14px;
  grid-template-columns: 1fr;               /* phones: one column */
}

.game-card {
  display: flex; gap: 14px; align-items: center;
  height: 100%;
  padding: 14px 16px;
  text-decoration: none;
  background: var(--bg-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  transition: border-color 0.2s, transform 0.2s;
}
.game-card:hover, .game-card:focus-visible { border-color: var(--accent); }
.game-card:active { transform: scale(0.98); }

.game-icon {
  flex: none;
  display: grid; place-items: center;
  width: 52px; height: 52px;
  font-size: 28px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-radius: 12px;
}
.game-text { display: grid; }   /* stacks kind / name / blurb */
.game-name { font-weight: 600; font-size: 17px; line-height: 1.3; }
.game-kind { font: 11px var(--mono); letter-spacing: 1px; text-transform: uppercase; color: var(--dim); }
.game-blurb { color: var(--fg-soft); font-size: 14px; line-height: 1.45; margin-top: 2px; }

/* ---------- 10. Footer ---------- */
.site-foot {
  padding: 18px 18px 24px; text-align: center;
  font: 12px var(--mono); color: var(--dim);
}
.site-foot a { color: var(--fg-soft); }

/* ---------- 11. Bigger screens ---------- */
@media (min-width: 640px) {
  .masthead { padding-left: 28px; padding-right: 28px; }
  .tabs { max-width: 360px; }
  main { padding: 24px 28px 40px; }
  .game-grid { grid-template-columns: repeat(2, 1fr); }
  .paper-card { padding: 20px; }
  .reader-head h1 { font-size: 30px; }
}
@media (min-width: 940px) {
  .game-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Respect "reduce motion". */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
