/* n-ga.ge front page and 404 page.

   The look borrows from the hardware: game cards are drawn as memory cards
   with one clipped corner, screenshots sit in a 176x208 screen at whole-pixel
   scale, statuses are signal bars, and labels are set like the small print on
   a handset. From 480px up the page width snaps to whole columns of cards
   (see "Layout"), so a screenshot is shown at exactly its own size. */

:root {
  color-scheme: light dark;
  --page: #e4e2dc;
  --card: #f5f4ef;
  --edge: #b9b6ac;
  --ink: #1a1c20;
  --dim: #555a64;
  --accent: #b34700;        /* links and focus: readable on the page colour */
  --signal: #ff7a1a;        /* the orange itself, for fills */
  --field: #fbfaf7;
  --ok: #1c7a39;
  --warn: #8a6100;
  --info: #2059b3;
  --bad: #b3261e;
  --idle: #686c75;
  /* The masthead and the screens stay dark in both themes, as the handset's
     faceplate and its display are. */
  --plate: #1c1f25;
  --plate-ink: #f1efe8;
  --plate-dim: #a9aeb9;
  --lcd: #0c1114;
  --notch: 16px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #15171c;
    --card: #20242c;
    --edge: #3b414d;
    --ink: #ebe9e2;
    --dim: #a3a9b5;
    --accent: #ff9147;
    --field: #1a1d23;
    --ok: #5fd183;
    --warn: #e8b84a;
    --info: #86b4ff;
    --bad: #ff8078;
    --idle: #9399a5;
    --plate: #0e1013;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: 12px; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
  background: var(--page); color: var(--ink); font: 15px/1.5 var(--sans);
}
main { flex: 1; padding-block: 20px 40px; }
main:focus { outline: none; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
code { font: 0.92em var(--mono); }
p { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.defs { position: absolute; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 10; padding: 8px 12px; background: var(--signal); color: #15171c; font-weight: 700; }
.skip:focus { top: 8px; }

/* Layout: fluid with two columns of cards on a phone; from 480px up the
   content is exactly 2 to 6 cards wide (204px each, 16px apart) and centred.
   Each step leaves room for the page margin and a scrollbar. */
.wrap { width: 100%; margin-inline: auto; padding-inline: 12px; }
@media (min-width: 480px) { .wrap { width: 424px; padding-inline: 0; } }
@media (min-width: 712px) { .wrap { width: 644px; } }
@media (min-width: 932px) { .wrap { width: 864px; } }
@media (min-width: 1152px) { .wrap { width: 1084px; } }
@media (min-width: 1372px) { .wrap { width: 1304px; } }

/* Masthead */
.masthead {
  background-color: var(--plate); color: var(--plate-ink); border-bottom: 3px solid var(--signal);
  /* A dot matrix that fades in towards the right edge. */
  background-image: linear-gradient(90deg, var(--plate) 35%, transparent), radial-gradient(circle at 1px 1px, rgb(255 255 255 / .13) 1px, transparent 1.4px);
  background-size: auto, 6px 6px;
}
.masthead-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 24px; padding-block: 18px 0; }
.brand { margin: 0; font-size: 0; line-height: 0; }
.brand a { display: block; padding: 4px 0; }
.wordmark { display: block; width: 150px; height: 35px; }
.wm-ink { fill: var(--plate-ink); }
.wm-dot { fill: var(--signal); }
.topnav, .footnav { display: flex; flex-wrap: wrap; gap: 4px 20px; font: 600 12px/1.3 var(--mono); letter-spacing: .06em; text-transform: uppercase; }
.topnav a { color: var(--plate-ink); text-decoration: none; padding: 8px 0; border-bottom: 2px solid transparent; }
.topnav a:hover { border-bottom-color: var(--signal); }
.masthead :focus-visible { outline-color: var(--signal); }
.intro { padding-block: 22px 26px; }
.lede { font-size: clamp(22px, 2.2vw + 14px, 34px); line-height: 1.15; font-weight: 700; letter-spacing: -.01em; text-wrap: balance; }
.sub { margin-top: 8px; max-width: 60ch; color: var(--plate-dim); }

/* Search, order, status filter and multiplayer switch */
.controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px 12px; align-items: end; }
.field { display: grid; gap: 4px; min-width: 0; }
.field-label { padding: 0; font: 600 11px/1.3 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--dim); }
.controls input[type="search"], .controls select {
  width: 100%; min-height: 40px; padding: 6px 10px; border: 1px solid var(--edge); border-radius: 2px;
  background: var(--field); color: var(--ink); font: inherit; font-size: 16px; /* 16px keeps iOS from zooming in on focus */
}
.controls select { padding-right: 6px; }
.controls input[type="search"]::placeholder { color: var(--dim); opacity: 1; }
.controls input[type="search"]:focus-visible, .controls select:focus-visible { outline-offset: 0; border-color: var(--accent); }
.filter-row { grid-column: 1 / -1; min-width: 0; display: flex; flex-wrap: wrap; gap: 12px 20px; }
.filters { min-width: 0; margin: 0; padding: 0; border: 0; display: grid; gap: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; display: block; cursor: pointer; }
.chip input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.chip-face {
  display: flex; align-items: center; gap: 7px; min-height: 36px; padding: 4px 10px; border: 1px solid var(--edge); border-radius: 2px;
  background: var(--card); font-size: 14px; font-weight: 600; white-space: nowrap;
}
.chip-count { font: 600 12px var(--mono); color: var(--dim); }
.chip-none .chip-face { color: var(--dim); font-weight: 500; }
.chip:hover .chip-face { border-color: var(--ink); }
.chip input:checked + .chip-face { background: var(--ink); border-color: var(--ink); color: var(--page); }
.chip input:checked + .chip-face .chip-count, .chip input:checked + .chip-face .sig, .chip input:checked + .chip-face .mp-mark { color: inherit; }
.chip input:focus-visible + .chip-face { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (pointer: coarse) {
  .chip-face { min-height: 44px; }
  .controls input[type="search"], .controls select { min-height: 44px; }
}
/* On the narrowest phones the search box gets a row of its own. */
@media (max-width: 359px) { .controls .field { grid-column: 1 / -1; } }
/* The filters in two or three rows rather than four on most phones. */
@media (max-width: 479px) { .chip-face { gap: 6px; padding-inline: 8px; font-size: 13.5px; } }
.summary { margin: 14px 0 12px; font: 12px/1.4 var(--mono); letter-spacing: .04em; color: var(--dim); }

/* Status and CI labels: a shape and a word; colour only repeats them. */
.sig { flex: none; width: 14px; height: 12px; fill: currentColor; }
.status { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 700; }
.status-ingame .sig, .chip-ingame .sig { color: var(--ok); }
.status-menu .sig, .chip-menu .sig { color: var(--warn); }
.status-boots .sig, .chip-boots .sig { color: var(--info); }
.status-broken .sig, .chip-broken .sig { color: var(--bad); }
.status-untested .sig, .chip-untested .sig { color: var(--idle); }
.status-untested { font-weight: 500; color: var(--dim); }
.ci { display: inline-flex; align-items: center; gap: 5px; font: 11px/1.3 var(--mono); letter-spacing: .03em; color: var(--dim); white-space: nowrap; }
.ci-mark { flex: none; width: 10px; height: 10px; }
.ci-pass .ci-mark { color: var(--ok); }
.ci-fail .ci-mark { color: var(--bad); }
.ci-fail { color: var(--ink); }
/* Multiplayer: two players and the word. The colour says how far Bluetooth
   play gets here, which the detail view says in words. */
.mp { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; }
.mp-mark { flex: none; width: 14px; height: 12px; fill: currentColor; color: var(--idle); }
.mp-plays .mp-mark { color: var(--ok); }
.mp-connects .mp-mark { color: var(--info); }
.mp-broken .mp-mark { color: var(--bad); }

/* The grid of cards */
.grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 10px; }
@media (min-width: 480px) { .grid { grid-template-columns: repeat(auto-fill, 204px); gap: 20px 16px; } }

.card { position: relative; isolation: isolate; display: flex; flex-direction: column; gap: 5px; min-width: 0; padding: 10px; }
@media (min-width: 480px) { .card { padding: 14px; } }
/* The card's outline and face are two clipped layers behind the content, so
   the clipped corner does not cut off the focus ring. */
.card::before, .card::after { content: ""; position: absolute; z-index: -1; }
.card::before { inset: 0; background: var(--edge); clip-path: polygon(0 0, calc(100% - var(--notch)) 0, 100% var(--notch), 100% 100%, 0 100%); }
.card::after { inset: 1px; background: var(--card); clip-path: polygon(0 0, calc(100% - var(--notch) + .6px) 0, 100% calc(var(--notch) - .6px), 100% 100%, 0 100%); }
.card:hover::before, .card:has(.card-link:focus-visible)::before { background: var(--accent); }
@media (prefers-reduced-motion: no-preference) {
  .card { transition: transform .12s ease-out; }
  .card:hover { transform: translateY(-2px); }
}
.card-shot { position: relative; margin-bottom: 5px; }
.card-title { margin: 0; font-size: 15px; line-height: 1.25; font-weight: 700; overflow-wrap: anywhere; }
.card-link { color: inherit; text-decoration: none; }
/* The title's link covers the whole card; the Details button sits above it. */
.card-link::after { content: ""; position: absolute; inset: 0; z-index: 1; }
.card-link:focus-visible { outline: none; }
.card-link:focus-visible::after { outline: 2px solid var(--accent); outline-offset: 2px; }
.card:hover .card-link { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; }
.card-variant, .card-by { font-size: 12.5px; line-height: 1.35; color: var(--dim); overflow-wrap: anywhere; }
.card-variant { font-style: italic; }
.card .status { margin-top: auto; padding-top: 5px; }
.card-net { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 3px 8px; }
/* How many rooms are open for the game: the one lit thing on a card. */
.card-rooms { margin-left: auto; padding: 1px 6px; border-radius: 2px; background: var(--signal); color: #15171c; font: 700 11px/1.5 var(--mono); letter-spacing: .04em; white-space: nowrap; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 30px; }
.more {
  position: relative; z-index: 2; flex: none; min-height: 30px; margin-right: -4px; padding: 3px 8px; border: 1px solid transparent; border-radius: 2px;
  background: none; color: var(--accent); font: 600 12.5px var(--sans); text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.more:hover { border-color: var(--accent); text-decoration: none; }
@media (pointer: coarse) { .more { min-height: 40px; padding-inline: 10px; } }
/* On the narrowest phones the CI label and the button do not fit side by side. */
@media (max-width: 359px) {
  .card-foot { flex-wrap: wrap; }
  .more { margin-left: -10px; }
}

/* Open rooms: on the page above the games, and in a game's detail view. A row
   on the page is as wide as one and a half or two cards. */
.rooms { display: grid; gap: 6px; margin-bottom: 24px; padding-bottom: 20px; border-bottom: 1px solid var(--edge); }
.rooms-title { display: flex; align-items: baseline; gap: 8px; margin: 0; font-size: 18px; line-height: 1.25; }
.rooms-sub { color: var(--dim); font-size: 14px; }
.rooms .room-list { margin-top: 6px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 314px), 1fr)); gap: 8px 16px; }
.rooms-more { justify-self: start; margin: 0 0 0 -8px; }
.room-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.room { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 8px 10px 8px 12px; border: 1px solid var(--edge); border-left: 3px solid var(--signal); background: var(--card); }
.room-text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.room-game { font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.room-game a { color: inherit; text-decoration: none; }
.room-game a:hover { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; }
.room-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 12px; font-size: 13px; line-height: 1.45; color: var(--dim); overflow-wrap: anywhere; }
.room-meta code { letter-spacing: .08em; }
.room-join { flex: none; min-height: 36px; padding-inline: 14px; }
@media (pointer: coarse) { .room-join { min-height: 44px; } }
.rooms-heading { font-weight: 700; }
.detail-rooms .room { background: var(--field); }

/* The screen */
.screen { position: relative; width: 100%; max-width: 176px; aspect-ratio: 176 / 208; margin-inline: auto; overflow: hidden; background: var(--lcd); box-shadow: 0 0 0 1px #000; }
.screen img { display: block; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; }
/* A phone's two fluid columns shrink the picture by an odd factor, where
   smoothing reads better than dropped rows of pixels. */
@media (max-width: 479px) { .card .screen img { image-rendering: auto; } }
.screen-empty {
  background-image: linear-gradient(rgb(255 255 255 / .04) 1px, transparent 1px), linear-gradient(90deg, rgb(255 255 255 / .04) 1px, transparent 1px);
  background-size: 4px 4px;
}
.sprite { position: absolute; left: 30%; top: 24%; width: 40%; height: auto; }
.sprite-body { fill: hsl(var(--hue) 28% 44%); }
.sprite-eyes { fill: hsl(var(--hue) 55% 78%); }
.noshot { position: absolute; left: 0; right: 0; bottom: 9%; text-align: center; font: 9px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: rgb(255 255 255 / .5); }
/* Not working: still a link, but the screen is greyed and carries a hazard strip. */
.card-broken .screen img, .card-broken .sprite { filter: grayscale(1) brightness(.6); }
.card-broken .noshot { display: none; }
.stamp {
  position: absolute; left: 50%; bottom: 0; width: 100%; max-width: 176px; transform: translateX(-50%); padding: 4px 2px 3px; text-align: center;
  background: #ffcf33; color: #15171c; font: 700 10px/1.2 var(--mono); letter-spacing: .1em; text-transform: uppercase;
  border-top: 5px solid; border-image: repeating-linear-gradient(135deg, #15171c 0 6px, #ffcf33 6px 12px) 5;
}

/* Notices: no JavaScript, loading, failed to load, nothing matches */
.notice { max-width: 644px; margin: 12px 0; padding: 14px 16px; border: 1px solid var(--edge); border-left: 4px solid var(--signal); background: var(--card); display: grid; gap: 8px; }
.notice-error { border-left-color: var(--bad); }
.notice-title { font-weight: 700; font-size: 16px; }
.notice-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 6px 16px; border: 1px solid var(--edge); border-radius: 2px;
  background: var(--field); color: var(--ink); font: 600 14px var(--sans); text-decoration: none; cursor: pointer;
}
.button:hover { border-color: var(--ink); }
.button.primary { background: var(--signal); border-color: var(--signal); color: #15171c; }
.button.primary:hover { border-color: var(--ink); }

/* Detail view */
.detail {
  width: min(760px, calc(100vw - 20px)); max-width: none; max-height: calc(100vh - 20px); max-height: calc(100dvh - 20px); padding: 0;
  border: 1px solid var(--edge); border-top: 3px solid var(--signal); background: var(--card); color: var(--ink); overflow: hidden;
}
.detail[open] { display: flex; }
.detail::backdrop { background: rgb(8 10 13 / .66); }
.detail-body { flex: 1; min-width: 0; overflow: auto; overscroll-behavior: contain; display: grid; gap: 16px; padding: 18px 16px; }
.detail-shot .screen { max-width: 176px; }
.detail-text { display: grid; gap: 12px; align-content: start; min-width: 0; }
.detail-title { margin: 0; font-size: 22px; line-height: 1.2; overflow-wrap: anywhere; }
.detail-title:focus { outline: none; }
.detail-by { margin-top: -8px; color: var(--dim); }
.detail-block { display: grid; gap: 4px; padding-top: 12px; border-top: 1px solid var(--edge); }
.detail-block .status { font-size: 15px; }
.detail-block .ci { font-size: 12px; }
.note { padding-left: 10px; border-left: 2px solid var(--edge); }
.ci-error { overflow-wrap: anywhere; color: var(--bad); }
.facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 16px; margin: 0; padding-top: 12px; border-top: 1px solid var(--edge); font-size: 14px; }
.facts dt { font: 600 11px/1.9 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--dim); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.plain { list-style: none; margin: 0; padding: 0; }
.mp-fact { display: grid; gap: 4px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; }
.detail-actions .primary { min-width: 120px; }
@media (min-width: 700px) {
  .detail-body { grid-template-columns: 352px minmax(0, 1fr); gap: 22px; padding: 22px; }
  .detail-shot .screen { max-width: 352px; }
  .detail-shot .noshot { font-size: 12px; }
}

/* Footer */
.colophon { border-top: 1px solid var(--edge); padding-block: 20px 28px; font-size: 13px; color: var(--dim); }
.colophon .wrap { display: grid; gap: 6px; }
.colophon p { max-width: 80ch; }
.build:empty { display: none; }
.footnav { margin-top: 10px; }
.footnav a { padding: 6px 0; }

/* 404 */
.lost { flex: 1; display: grid; place-content: center; justify-items: center; gap: 14px; padding: 40px 16px; text-align: center; }
.lost .screen { width: 176px; display: grid; place-content: center; gap: 10px; color: rgb(255 255 255 / .8); }
.lost-code { font: 700 44px/1 var(--mono); letter-spacing: .06em; color: var(--signal); }
.lost-line { font: 10px/1.4 var(--mono); letter-spacing: .14em; text-transform: uppercase; }
.lost h1 { margin: 6px 0 0; font-size: 22px; }
.lost p { max-width: 46ch; color: var(--dim); }
.lost .notice-actions { justify-content: center; }

/* Forced colours drop backgrounds, and with them the card's two layers. */
@media (forced-colors: active) {
  .card { border: 1px solid CanvasText; }
  .card::before, .card::after { display: none; }
  .chip input:checked + .chip-face { outline: 2px solid Highlight; }
  .stamp { border: 1px solid CanvasText; }
  .card-rooms { border: 1px solid CanvasText; }
  .masthead { background-image: none; border-bottom-color: CanvasText; }
  .wm-ink { fill: CanvasText; }
  .wm-dot { fill: Highlight; }
}
