/* ==========================================================================
   text.games — accessible text-game portal
   --------------------------------------------------------------------------
   Design rules for this stylesheet (do not break these):
   1. Nothing conveys meaning by colour alone. Every rating/tier has text.
   2. Focus is ALWAYS visible. Never `outline: none` without a replacement.
   3. Respect prefers-reduced-motion and prefers-color-scheme.
   4. Body text never below 1rem. Line length capped ~72ch.
   5. No layout depends on JS. JS is enhancement only.
   ========================================================================== */

:root {
  color-scheme: light dark;

  --bg:            #fbfaf7;
  --bg-raised:     #ffffff;
  --bg-sunken:     #f1efe9;
  --fg:            #1a1917;
  --fg-muted:      #4d4a44;
  --border:        #d9d5cb;
  --accent:        #7a3e00;
  --accent-fg:     #ffffff;
  --focus:         #0b57d0;
  --ok:            #1c5b2e;
  --warn:          #7a4a00;
  --bad:           #8a1c1c;

  --radius: 6px;
  --measure: 72ch;
  --gutter: clamp(1rem, 4vw, 2.5rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #14130f;
    --bg-raised:   #1e1d18;
    --bg-sunken:   #0d0c0a;
    --fg:          #ece8df;
    --fg-muted:    #b0aa9c;
    --border:      #3a382f;
    --accent:      #ffb066;
    --accent-fg:   #1a1200;
    --focus:       #8ab4f8;
    --ok:          #7fd196;
    --warn:        #e0b25e;
    --bad:         #f08a8a;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 1.0625rem/1.65 ui-serif, Georgia, "Iowan Old Style", "Palatino Linotype", serif;
}

/* --- Focus: the single most important accessibility rule here ------------ */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}
/* Fallback for browsers without :focus-visible */
:focus:not(:focus-visible) { outline: none; }

/* --- Skip link ----------------------------------------------------------- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.75rem 1.25rem;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 700;
  text-decoration: none;
}
.skip-link:focus {
  left: 0;
}

/* --- Layout -------------------------------------------------------------- */
.wrap {
  width: 100%;
  max-width: 68rem;
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.prose { max-width: var(--measure); }

/* --- Header / nav -------------------------------------------------------- */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}
.site-header .wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 2rem;
  align-items: baseline;
  padding-block: 1.25rem;
}
.brand {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--fg);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
.brand:hover { color: var(--accent); }
.brand .dot { color: var(--accent); }
.tagline {
  margin: 0;
  color: var(--fg-muted);
  font-size: 0.9375rem;
  flex: 1 1 20ch;
}

.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.site-nav a {
  color: var(--fg);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  padding: 0.25rem 0;
  display: inline-block;
}
.site-nav a:hover { color: var(--accent); }
.site-nav [aria-current="page"] {
  font-weight: 700;
  color: var(--accent);
}

/* --- Hero ---------------------------------------------------------------- */
.hero {
  padding-block: clamp(2rem, 6vw, 3.5rem) 1.5rem;
}
.hero h1 {
  font-size: clamp(1.9rem, 5vw, 2.9rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 0.75rem;
  max-width: 22ch;
}
.hero p { margin: 0 0 1rem; max-width: var(--measure); }
.lede { font-size: 1.15rem; color: var(--fg-muted); }

/* --- Promo / banner ad slot ---------------------------------------------
   Rules for anything placed in .promo:
   - Must be real text, not an image of text. Screen readers get everything.
   - Must sit inside <aside class="promo" aria-label="Sponsor"> so it is
     announced as a complementary landmark and can be skipped.
   - No animation that a reduced-motion user cannot opt out of.
   - No autoplay, no interstitial, no layout shift after paint.
   ------------------------------------------------------------------------ */
.promo {
  margin-block: 2rem;
}
.promo-inner {
  position: relative;
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, #2a0d0d 0%, #40120c 45%, #100a14 100%);
  color: #f6ece0;
  text-decoration: none;
  padding: clamp(1.25rem, 3vw, 2rem);
  overflow: hidden;
  isolation: isolate;
}
.promo-inner::after {
  /* decorative ember glow — purely presentational */
  content: "";
  position: absolute;
  inset: -40% -10% auto auto;
  width: 26rem; height: 26rem;
  background: radial-gradient(circle, rgba(255,140,40,0.28), transparent 65%);
  z-index: -1;
  pointer-events: none;
}
.promo-label {
  display: inline-block;
  font: 700 0.6875rem/1 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #ffcf9e;
  border: 1px solid rgba(255, 207, 158, 0.5);
  border-radius: 999px;
  padding: 0.35rem 0.6rem;
  margin-bottom: 0.9rem;
}
.promo-title {
  margin: 0 0 0.4rem;
  font-size: clamp(1.35rem, 3.5vw, 1.9rem);
  line-height: 1.2;
  color: #fff3e4;
}
.promo-copy {
  margin: 0 0 1rem;
  max-width: 52ch;
  color: #e4d3c2;
}
.promo-cta {
  display: inline-block;
  font-weight: 700;
  border-bottom: 2px solid #ffb066;
  padding-bottom: 2px;
  color: #ffcf9e;
}
.promo-inner:hover .promo-cta { border-bottom-color: #fff3e4; color: #fff3e4; }
.promo-inner:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

/* --- Section scaffolding ------------------------------------------------- */
.section { padding-block: 2.25rem; border-top: 1px solid var(--border); }
.section > .wrap > h2 {
  font-size: clamp(1.4rem, 3.5vw, 1.85rem);
  letter-spacing: -0.01em;
  margin: 0 0 0.35rem;
}
.section-note {
  margin: 0 0 1.75rem;
  color: var(--fg-muted);
  max-width: var(--measure);
}

/* --- Game cards ---------------------------------------------------------- */
.games {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1.25rem;
}
@media (min-width: 60rem) {
  .games.two-up { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.game {
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: var(--bg-raised);
  padding: 1.25rem 1.4rem 1.4rem;
}
.game > header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
}
.game h3 { margin: 0; font-size: 1.25rem; letter-spacing: -0.01em; }
.game h3 a { color: var(--fg); text-underline-offset: 3px; }
.game h3 a:hover { color: var(--accent); }

.rank {
  font: 700 0.875rem/1 ui-monospace, Menlo, Consolas, monospace;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.6rem;
  color: var(--fg-muted);
}
.game p { margin: 0 0 0.75rem; }
.game p:last-child { margin-bottom: 0; }

/* Badges. Colour is decorative — the text carries the meaning. */
.badges { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 0.85rem; padding: 0; list-style: none; }
.badge {
  font: 600 0.8125rem/1.3 ui-sans-serif, system-ui, sans-serif;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem 0.5rem;
  background: var(--bg-sunken);
  color: var(--fg-muted);
}
.badge.is-free   { color: var(--ok);   border-color: currentColor; }
.badge.is-paid   { color: var(--warn); border-color: currentColor; }
.badge.is-caution{ color: var(--bad);  border-color: currentColor; }

/* Accessibility rating — text first, stars are aria-hidden decoration. */
.a11y {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  align-items: baseline;
  margin: 0 0 0.85rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg-sunken);
  border-radius: var(--radius);
  font-size: 0.9375rem;
}
.a11y dt { font-weight: 700; margin: 0; }
.a11y dd { margin: 0; color: var(--fg-muted); }
.stars { letter-spacing: 0.1em; color: var(--accent); }

.connect {
  font: 0.875rem/1.5 ui-monospace, Menlo, Consolas, monospace;
  background: var(--bg-sunken);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.7rem;
  margin: 0.85rem 0 0;
  overflow-x: auto;
  white-space: pre;
}

/* --- Tables (clients guide) ---------------------------------------------- */
.table-scroll { overflow-x: auto; margin-block: 1.5rem; }
table { border-collapse: collapse; width: 100%; min-width: 40rem; font-size: 0.9375rem; }
caption { text-align: left; color: var(--fg-muted); padding-bottom: 0.6rem; }
th, td { text-align: left; vertical-align: top; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
thead th { background: var(--bg-sunken); border-bottom: 2px solid var(--border); }

/* --- Callout ------------------------------------------------------------- */
.callout {
  border: 1px solid var(--border);
  border-left: 4px solid var(--warn);
  border-radius: var(--radius);
  background: var(--bg-raised);
  padding: 1rem 1.25rem;
  margin-block: 1.5rem;
  max-width: var(--measure);
}
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout h2, .callout h3 { font-size: 1.0625rem; }

/* --- Links --------------------------------------------------------------- */
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

/* --- Footer -------------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
  margin-top: 3rem;
  padding-block: 2rem 2.5rem;
  color: var(--fg-muted);
  font-size: 0.9375rem;
}
.site-footer h2 { font-size: 1rem; margin: 0 0 0.5rem; color: var(--fg); }
.footer-cols {
  display: grid;
  gap: 1.5rem 2.5rem;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
}
.site-footer ul { list-style: none; margin: 0; padding: 0; }
.site-footer li { margin-bottom: 0.35rem; }

/* Noizu Labs credit — a brand lockup: decorative logomark (aria-hidden) +
   wordmark. All pieces share one text baseline (no inline-flex middle trick,
   which always lands a few px off); the mark is nudged below the baseline to
   optically center it on the lowercase wordmark. "Labs" is set in a gold that
   keeps 4.5:1 on the light footer and brightens to the true brand gold in
   dark mode. Colours are brand marks, not status signalling. */
.brought-by { margin: 1.5rem 0 0; }
.brand-link {
  --brand-gold: #8a6a00;
  font-family: ui-sans-serif, system-ui, sans-serif;
  color: var(--fg);
  white-space: nowrap;
}
.brand-link:hover { text-decoration-thickness: 2px; }
.brand-mark {
  width: 1.02em;
  height: 1.02em;
  vertical-align: -0.17em;
  margin-right: 0.13em;
}
.brand-name { font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { font-weight: 400; color: var(--brand-gold); }
@media (prefers-color-scheme: dark) {
  .brand-link { --brand-gold: #ffca02; }
}

/* --- Visually hidden (still announced) ----------------------------------- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --- Motion / contrast preferences --------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-contrast: more) {
  :root { --border: currentColor; --fg-muted: var(--fg); }
  .promo-inner::after { display: none; }
}

/* --- Print --------------------------------------------------------------- */
@media print {
  .promo, .site-nav, .skip-link { display: none; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .game { break-inside: avoid; border-left-width: 1px; }
  a::after { content: " (" attr(href) ")"; font-size: 9pt; word-break: break-all; }
}

/* ==========================================================================
   Community layer — votes, reviews, auth forms, flash
   --------------------------------------------------------------------------
   Same rules as the rest of this file. Of particular note here:
   - Vote buttons are real <button type="submit"> in real <form> elements.
     There is no JS. aria-pressed carries state; .is-active is only a visual
     echo of it, never the sole signal.
   - Flash regions use role="status"/role="alert" so the outcome of a POST is
     announced. Without this, a no-JS form submission is silent to a screen
     reader user, who has to go hunting for what changed.
   - Touch targets are >= 44px tall (WCAG 2.5.5).
   ========================================================================== */

.wrap.narrow { max-width: 40rem; }
.breadcrumb { margin: 0 0 1rem; font-size: 0.9375rem; }

/* --- Flash ---------------------------------------------------------------- */
.flash-region { max-width: 68rem; margin: 1rem auto 0; padding-inline: var(--gutter); }
.flash {
  margin: 0 0 0.75rem;
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius);
  background: var(--bg-raised);
}
.flash-info  { border-left-color: var(--ok); }
.flash-error { border-left-color: var(--bad); }

/* --- Buttons -------------------------------------------------------------- */
.button {
  display: inline-block;
  min-height: 44px;
  padding: 0.65rem 1.4rem;
  font: 600 1rem/1.4 ui-sans-serif, system-ui, sans-serif;
  color: var(--accent-fg);
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
}
.button:hover { filter: brightness(1.1); }

/* A button that must read as a link. Still a button to assistive tech, because
   it performs an action (sign out, delete) rather than navigating. */
.linkish {
  min-height: 44px;
  padding: 0;
  font: inherit;
  color: var(--accent);
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.linkish:hover { text-decoration-thickness: 2px; }
.inline-form { display: inline; }

/* --- Votes ---------------------------------------------------------------- */
.votes {
  margin: 1.1rem 0 0;
  padding: 0.9rem 1rem;
  background: var(--bg-sunken);
  border-radius: var(--radius);
}
.votes-heading {
  margin: 0 0 0.5rem;
  font: 700 0.8125rem/1 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.vote-tally {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.25rem;
  margin: 0 0 0.75rem;
  font-size: 0.9375rem;
}
.vote-count { white-space: nowrap; }
.vote-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.vote-form { margin: 0; }

.vote-button {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.5rem 0.9rem;
  font: 600 0.9375rem/1.3 ui-sans-serif, system-ui, sans-serif;
  color: var(--fg);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
.vote-button:hover { border-color: var(--accent); color: var(--accent); }

/* The active state is doubled up: a border AND a filled background AND the
   accessible name says "currently your vote". Never colour alone. */
.vote-button.is-active {
  border-color: var(--accent);
  border-width: 2px;
  background: var(--accent);
  color: var(--accent-fg);
}
.vote-note { margin: 0.6rem 0 0; font-size: 0.875rem; color: var(--fg-muted); }
.review-link { margin: 0.85rem 0 0; font-size: 0.9375rem; }

/* --- Reviews -------------------------------------------------------------- */
.reviews { list-style: none; margin: 0 0 2rem; padding: 0; display: grid; gap: 1rem; }
.review {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  padding: 1rem 1.2rem;
}
.review-head { margin-bottom: 0.5rem; }
.review-byline { margin: 0; font-size: 1.0625rem; }
.review-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin: 0.2rem 0 0;
  font-size: 0.875rem;
  color: var(--fg-muted);
}
.review-sr { font-weight: 600; }
.review-body { margin: 0 0 0.6rem; white-space: pre-wrap; }

/* --- Forms ---------------------------------------------------------------- */
.write-review {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.stack-form { display: grid; gap: 1.4rem; max-width: 42rem; margin-block: 1.25rem; }
.field { display: grid; gap: 0.4rem; }
.field-inline {
  grid-auto-flow: column;
  justify-content: start;
  align-items: center;
  gap: 0.6rem;
}
.field label { font-weight: 700; }
.field-hint { margin: 0; font-size: 0.875rem; color: var(--fg-muted); font-weight: 400; }

.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field select,
.field textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.6rem 0.75rem;
  font: inherit;
  color: var(--fg);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.field textarea { min-height: 10rem; resize: vertical; line-height: 1.6; }
.field input[type="checkbox"] { width: 1.35rem; height: 1.35rem; }

/* Invalid fields get a thicker border AND an adjacent error message wired up
   with aria-describedby. The border alone would be colour-only signalling. */
.field [aria-invalid="true"] { border-color: var(--bad); border-width: 2px; }

.field-error {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--bad);
}

@media (prefers-contrast: more) {
  .vote-button, .button, .field input, .field select, .field textarea {
    border-width: 2px;
  }
}

/* ==========================================================================
   Chat
   --------------------------------------------------------------------------
   The transcript is a role="log" live region. Two rules that matter more than
   they look:
   - No max-height + overflow scroll with auto-scroll-to-bottom. Yanking the
     viewport is the visual equivalent of stealing focus, and it makes the room
     unusable at high magnification. The log grows; the user scrolls.
   - No animation on message arrival. New content appearing under a screen
     magnifier is disorienting enough without movement.
   ========================================================================== */

.chat-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  margin-bottom: 1.25rem;
}
.chat-unread { margin: 0; font-size: 0.9375rem; color: var(--fg-muted); }

.chat-log {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}
.chat-message {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 0.25rem 0.75rem;
  align-items: baseline;
  padding: 0.6rem 0.8rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
@media (max-width: 40rem) {
  .chat-message { grid-template-columns: 1fr; }
}
.chat-author { font-weight: 700; }
.chat-time {
  font: 0.8125rem/1.4 ui-monospace, Menlo, Consolas, monospace;
  color: var(--fg-muted);
}
.chat-body { white-space: pre-wrap; overflow-wrap: anywhere; }

.chat-composer {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 0.5rem;
  max-width: 42rem;
}
.chat-composer label { font-weight: 700; }
.chat-composer textarea {
  width: 100%;
  min-height: 5.5rem;
  padding: 0.6rem 0.75rem;
  font: inherit;
  line-height: 1.6;
  color: var(--fg);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
}
.chat-composer .button { justify-self: start; }
