:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --sunk: #e1e6ed;
  --ink: #121a28;
  --muted: #586376;
  --line: #d2d9e3;
  --accent: #0a5fd1;
  --accent-hover: #084fb0;
  --accent-ink: #ffffff;
  --focus: #0a5fd1;
    --shadow: 0 1px 2px rgb(18 26 40 / 0.06), 0 12px 40px -12px rgb(18 26 40 / 0.28);

  --font: 'M PLUS 1', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, monospace;
  --radius: 10px;
  --gutter: clamp(16px, 4vw, 40px);
  --max: 1240px;
  --header: 64px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0c1422;
    --surface: #142036;
    --sunk: #1a2842;
    --ink: #e3e9f2;
    --muted: #8a97ab;
    --line: #233250;
    --accent: #5aa6ff;
    --accent-hover: #7db9ff;
    --accent-ink: #061020;
    --focus: #7db9ff;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 16px 48px -12px rgb(0 0 0 / 0.6);
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #0c1422;
  --surface: #142036;
  --sunk: #1a2842;
  --ink: #e3e9f2;
  --muted: #8a97ab;
  --line: #233250;
  --accent: #5aa6ff;
  --accent-hover: #7db9ff;
  --accent-ink: #061020;
  --focus: #7db9ff;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 16px 48px -12px rgb(0 0 0 / 0.6);
  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header) + 56px);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.55 var(--font);
  font-feature-settings: 'palt' 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

img { display: block; max-width: 100%; }

a { color: inherit; text-decoration: none; }
p a, .also a, .foot a { color: var(--accent); }
p a:hover, .also a:hover, .foot a:hover { text-decoration: underline; text-underline-offset: 3px; }

h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }

code { font-family: var(--mono); font-size: 0.88em; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

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

.skip {
  position: absolute; left: 12px; top: -48px; z-index: 50;
  background: var(--accent); color: var(--accent-ink);
  padding: 8px 12px; border-radius: 6px; font-weight: 600;
}
.skip:focus { top: 12px; }

.wrap {
  width: 100%;
  max-width: var(--max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* ---------------------------------------------------------------- header */

.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}

.top-inner {
  max-width: var(--max);
  margin-inline: auto;
  padding-inline: var(--gutter);
  height: var(--header);
  display: flex; align-items: center; gap: clamp(12px, 3vw, 32px);
}

.mark {
  font-weight: 800;
  font-size: 24px;
  letter-spacing: -0.04em;
  line-height: 1;
  padding-bottom: 3px;
}

.search { position: relative; flex: 1; max-width: 560px; }

.search input {
  width: 100%;
  height: 40px;
  padding: 0 40px 0 14px;
  font: inherit; font-size: 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  appearance: none;
}
.search input::placeholder { color: var(--muted); opacity: 1; }
.search input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.search input::-webkit-search-cancel-button { display: none; }

.search kbd {
  position: absolute; right: 10px; top: 50%; translate: 0 -50%;
  font: 500 12px/1 var(--mono);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 6px;
  pointer-events: none;
}
.search input:focus ~ kbd, .search input:not(:placeholder-shown) ~ kbd { display: none; }

.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  margin: 0; padding: 6px; list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: min(70vh, 480px); overflow-y: auto;
}
.suggest a {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 8px; border-radius: 6px;
}
.suggest img { width: 40px; height: 40px; border-radius: 6px; background: var(--sunk); flex: none; }
.suggest .s-name { font-weight: 600; font-size: 15px; line-height: 1.25; }
.suggest .s-sub { color: var(--muted); font-size: 13px; }
.suggest [aria-selected='true'] a, .suggest a:hover { background: var(--sunk); }
.suggest .s-all a { color: var(--accent); font-size: 14px; padding: 10px 8px; }
.suggest .s-empty { color: var(--muted); font-size: 14px; padding: 10px 8px; }

.theme {
  margin-left: auto;
  display: grid; place-items: center;
  width: 40px; height: 40px;
  color: var(--muted);
  background: none; border: 0; border-radius: 8px;
  cursor: pointer;
}
.theme:hover { color: var(--ink); background: var(--sunk); }

/* ---------------------------------------------------------------- home */

.section-head {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px;
  margin-bottom: 16px;
}
.section-head h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.section-head p { margin: 0; color: var(--muted); font-size: 14px; }

.recent { margin-top: clamp(28px, 4vw, 44px); }

.shelf {
  list-style: none; margin: 0; padding: 0 0 8px;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(132px, 1fr);
  gap: 16px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.shelf > li { scroll-snap-align: start; min-width: 132px; }

.all { margin-top: 48px; padding-bottom: 24px; }

.letters {
  position: sticky; top: var(--header); z-index: 10;
  display: flex; gap: 2px;
  margin: 0 calc(var(--gutter) * -1) 8px;
  padding: 8px var(--gutter);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  overflow-x: auto;
  scrollbar-width: none;
}
.letters::-webkit-scrollbar { display: none; }
.letters a {
  flex: none;
  min-width: 30px; height: 30px;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 600;
  color: var(--muted);
  border-radius: 6px;
}
.letters a:hover { color: var(--ink); background: var(--sunk); }

.letter-group { padding-top: 20px; }
.letter {
  font-size: 32px; font-weight: 800; letter-spacing: -0.03em;
  color: var(--muted);
  margin-bottom: 14px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 24px 16px;
}

/* A game is shown as its first four avatars, the way they'd sit in the XMB picker. */
.tile { display: block; }
.mosaic {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--sunk);
}
.mosaic.single { grid-template-columns: 1fr; }
.mosaic img { width: 100%; height: 100%; object-fit: cover; background: var(--sunk); }
.tile-name {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
  overflow: hidden;
  margin-top: 10px;
  font-size: 15px; font-weight: 600; line-height: 1.3;
}
.tile-count { display: block; margin-top: 2px; font-size: 13px; color: var(--muted); }
.tile:hover .tile-name { color: var(--accent); }
.tile:hover .mosaic { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile:focus-visible { outline: none; }
.tile:focus-visible .mosaic { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------------------------------------------------------------- game */

.game, .avatar-page, .results { padding-top: 28px; padding-bottom: 48px; }

.back {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; color: var(--muted);
}
.back::before { content: ''; width: 7px; height: 7px; border-left: 1.75px solid; border-bottom: 1.75px solid; rotate: 45deg; margin-top: 1px; }
.back:hover { color: var(--ink); }

.game-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 20px 32px;
  margin: 16px 0 28px;
}
.game-head h1, .results h1 {
  font-size: clamp(28px, 4.4vw, 44px);
  font-weight: 800;
  letter-spacing: -0.03em;
  max-width: 22ch;
}
.meta { margin: 8px 0 0; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 20px; }

.button {
  display: inline-flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 16px;
  font: inherit; font-size: 15px; font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.button:hover { border-color: var(--muted); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button .dim { font-weight: 400; opacity: 0.75; font-size: 13px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: -8px 0 20px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px;
  font-size: 14px; font-weight: 600;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}
.chip span { font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip:hover { border-color: var(--muted); }
.chip[aria-current] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip[aria-current] span { color: inherit; opacity: 0.7; }

.avatars {
  list-style: none; margin: 0; padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 14px;
}
.av {
  display: block;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--sunk);
  aspect-ratio: 1;
}
.av img { width: 100%; height: 100%; object-fit: cover; }
.av:hover { outline: 2px solid var(--accent); outline-offset: 2px; }
.av.current { outline: 2px solid var(--ink); outline-offset: 2px; }
.av-caption { display: block; margin-top: 6px; font-size: 13px; color: var(--muted); line-height: 1.3; }

.hint { color: var(--muted); font-size: 14px; margin: 28px 0 0; }

/* ---------------------------------------------------------------- avatar page */

.detail {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 28px;
  align-items: start;
}
.big {
  width: 240px; height: 240px;
  border-radius: 14px;
  background: var(--sunk);
}
.detail-body { min-width: 0; padding-top: 4px; }
.detail-body h1, .detail-body h2 { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.also { color: var(--muted); margin: 6px 0 0; font-size: 14px; }

.id-row { display: flex; align-items: center; gap: 8px; margin: 14px 0 18px; flex-wrap: wrap; }
.id {
  font-size: 13px;
  color: var(--muted);
  background: var(--sunk);
  padding: 4px 8px;
  border-radius: 6px;
  word-break: break-all;
  user-select: all;
}
.copy {
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--accent);
  background: none; border: 0; padding: 4px 6px; border-radius: 6px;
  cursor: pointer;
}
.copy:hover { background: var(--sunk); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; }

.avatar-page .detail { margin: 20px 0 48px; }

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 20px;
  margin: 24px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.facts > div { display: contents; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; min-width: 0; }
.facts dd a { color: var(--accent); }
.facts dd a:hover { text-decoration: underline; text-underline-offset: 3px; }
.facts code { font-size: 13px; word-break: break-all; }
.more { font-size: 20px; font-weight: 700; margin-bottom: 16px; }

.media { width: 240px; }
.stepper {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 12px;
}
.stepper a, .stepper > span[aria-hidden] {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 8px;
  background: var(--sunk);
}
.stepper a:hover { background: var(--line); }
.stepper > span[aria-hidden] { opacity: 0.35; }
.stepper .count { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.detail-body h1 a:hover { color: var(--accent); }

/* ---------------------------------------------------------------- search + misc */

.results h1 { margin-bottom: 24px; }
.empty { color: var(--muted); max-width: 60ch; }
.empty code { background: var(--sunk); padding: 2px 6px; border-radius: 4px; }

.foot {
  width: calc(100% - 2 * var(--gutter));
  max-width: calc(var(--max) - 2 * var(--gutter));
  margin: 48px auto 0;
  padding: 24px 0 40px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 32px;
}
.foot p { margin: 0; max-width: 72ch; }

@media (max-width: 640px) {
  :root { --header: 60px; }
  .search kbd { display: none; }
  .search input { padding-right: 14px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 20px 12px; }
  .avatars { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
  .tile-name { font-size: 14px; }
  .detail { grid-template-columns: 1fr; gap: 20px; }
  .media { width: min(240px, 100%); }
  .big { width: 100%; height: auto; aspect-ratio: 1; }
  .game-head .button { width: 100%; justify-content: center; }
  .actions .button { flex: 1 1 auto; justify-content: center; padding: 0 12px; }
  .letter { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
