/* ------------------------------------------------------------
   Reference index — white / graphite surfaces, crisp rules,
   green actions, restrained blue accent.
   ------------------------------------------------------------ */
:root {
  --rail-w: 168px;
  --aside-w: 248px;
  --max-w: 1360px;

  --bg: #ffffff;
  --bg-soft: #f3f4f6;
  --graphite: #262a2e;
  --graphite-2: #32373c;
  --ink: #1d2024;
  --ink-2: #4a5057;
  --ink-3: #6c737a;
  --rule: #d6dae0;
  --rule-soft: #e7eaee;

  --green: #177a36;
  --green-2: #125f2a;
  --green-soft: #e6f3ea;
  --blue: #1a56b0;
  --blue-soft: #e8eff9;
  --blue-light: #8db8ff;

  --radius: 4px;
  --font: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC",
          "Hiragino Sans GB", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; letter-spacing: 0 !important; }

html { font-family: var(--font); font-size: 16px; line-height: 1.6; color: var(--ink); background: var(--bg); -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; }

img { display: block; max-width: 100%; height: auto; }
svg { width: 1.1em; height: 1.1em; flex: none; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-family: var(--mono); font-size: 0.92em; background: var(--bg-soft); padding: 0.1em 0.35em; border-radius: 3px; }

[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.rail :focus-visible { outline-color: var(--blue-light); }

.skip { position: absolute; left: 8px; top: -60px; z-index: 50; background: var(--green); color: #fff; padding: 8px 12px; border-radius: var(--radius); }
.skip:focus { top: 8px; }

/* ---------- Left rail (desktop) / masthead (mobile) ---------- */
.rail { position: fixed; top: 0; left: 0; bottom: 0; width: var(--rail-w); background: var(--graphite); color: #d9dde2; display: flex; flex-direction: column; overflow-y: auto; z-index: 20; }
.rail__brand { padding: 18px 16px 14px; border-bottom: 1px solid var(--graphite-2); }
.rail__logo { display: block; }
.rail__logo img { width: 136px; height: auto; aspect-ratio: 404 / 94; }
.rail__toggle { display: none; align-items: center; gap: 6px; background: transparent; color: #fff; border: 1px solid #4b5158; border-radius: var(--radius); padding: 6px 10px; min-height: 40px; }
.rail__toggle svg { width: 20px; height: 20px; }
.rail__toggle[aria-expanded="true"] .rail__ico-menu { display: none; }
.rail__toggle[aria-expanded="false"] .rail__ico-x { display: none; }
.no-js .rail__toggle { display: none; }

.rail__nav { display: flex; flex-direction: column; flex: 1; padding: 10px 0 16px; }
.rail__list li a { display: block; padding: 9px 16px 9px 13px; border-left: 3px solid transparent; color: #d9dde2; font-weight: 500; }
.rail__list li a:hover { color: #fff; background: var(--graphite-2); text-decoration: none; }
.rail__list li a[aria-current="page"] { color: #fff; border-left-color: var(--blue-light); background: var(--graphite-2); }
.rail__meta { margin-top: auto; padding: 16px 16px 0; font-size: 0.8rem; line-height: 1.5; color: #a4abb3; border-top: 1px solid var(--graphite-2); }
.rail__meta span { display: block; }
.rail__dl { display: inline-flex; align-items: center; gap: 6px; margin: 12px 16px 0; padding: 8px 12px; background: var(--green); color: #fff; border-radius: var(--radius); font-weight: 600; font-size: 0.9rem; }
.rail__dl:hover { background: var(--green-2); text-decoration: none; }

/* ---------- Main frame ---------- */
.main, .foot { margin-left: var(--rail-w); }
.main { container-type: inline-size; }
.wrap { max-width: var(--max-w); padding: 28px 32px 40px; display: grid; grid-template-columns: var(--aside-w) minmax(0, 1fr); column-gap: 36px; row-gap: 8px; align-items: start; }
.page-head { grid-column: 1 / -1; padding-bottom: 16px; margin-bottom: 12px; border-bottom: 2px solid var(--ink); }
.page-head__title { font-size: 1.85rem; line-height: 1.25; font-weight: 700; }
.page-head__lede { margin-top: 6px; color: var(--ink-2); max-width: 70ch; }

.side { min-width: 0; }
.side--sticky { position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow-y: auto; padding: 3px; margin: -3px; }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.content { min-width: 0; }

/* ---------- Side panels ---------- */
.panel { padding: 14px 0 16px; border-top: 1px solid var(--rule); }
.panel:first-child { border-top: 0; padding-top: 4px; }
.panel__label { display: block; font-size: 0.78rem; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }
.panel__label--gap { margin-top: 14px; }
.panel__more { display: inline-flex; align-items: center; gap: 4px; margin-top: 8px; font-size: 0.9rem; font-weight: 500; }

.field { display: flex; border: 1px solid var(--rule); border-radius: var(--radius); background: #fff; }
.field:focus-within { border-color: var(--blue); }
.field__in { flex: 1; min-width: 0; border: 0; background: transparent; padding: 8px 10px; min-height: 40px; }
.field__in:focus { outline: none; }
.field__btn { border: 0; border-left: 1px solid var(--rule); background: var(--bg-soft); color: var(--ink-2); padding: 0 10px; display: flex; align-items: center; }
.field__btn:hover { color: var(--green); }

.select { position: relative; }
.select__in { width: 100%; appearance: none; -webkit-appearance: none; border: 1px solid var(--rule); border-radius: var(--radius); background: #fff; padding: 8px 34px 8px 10px; min-height: 40px; }
.select__in:focus { border-color: var(--blue); outline: none; }
.select__ico { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--ink-3); }

.tally { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; }
.tally__text { font-size: 0.9rem; color: var(--ink-2); }
.tally__text strong { color: var(--ink); }

.catlist li a, .toc li a { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 5px 0; color: var(--ink); border-bottom: 1px dotted var(--rule-soft); }
.catlist li a:hover, .toc li a:hover { color: var(--blue); text-decoration: none; }
.catlist li a[aria-current="true"] { color: var(--blue); font-weight: 600; }
.catlist__t { min-width: 0; overflow-wrap: anywhere; }
.catlist__n { font-size: 0.8rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.toc__l3 a { padding-left: 14px; font-size: 0.92rem; }

.quick li a, .quick__ext { display: inline-flex; align-items: center; gap: 4px; padding: 4px 0; color: var(--ink); font-weight: 500; }
.quick li a:hover, .quick__ext:hover { color: var(--blue); }

/* ---------- Section heads ---------- */
.sec-head { display: flex; align-items: baseline; gap: 12px; padding-bottom: 8px; margin-bottom: 12px; border-bottom: 1px solid var(--ink); }
.sec-head__t { font-size: 1.25rem; font-weight: 700; }
.sec-head__n { font-size: 0.85rem; color: var(--ink-3); }
.sec-head__link { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; font-size: 0.9rem; font-weight: 500; }

/* ---------- Featured strip ---------- */
.pick { margin-bottom: 28px; }
.pick__list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px 14px; }
.pick__item { display: flex; flex-direction: column; min-width: 0; }
.pick__cover { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: var(--bg-soft); border: 1px solid var(--rule-soft); border-radius: var(--radius); }
.pick__name { margin-top: 8px; font-weight: 700; color: var(--ink); line-height: 1.35; }
.pick__name:hover { color: var(--blue); }
.pick__en { font-size: 0.8rem; color: var(--ink-3); overflow-wrap: anywhere; }
.pick__cat { margin-top: 4px; font-size: 0.78rem; color: var(--blue); }

/* ---------- Compact index ---------- */
.jump { margin-bottom: 18px; }
.jump ul { display: flex; flex-wrap: wrap; gap: 6px; }
.jump li a { display: inline-flex; align-items: baseline; gap: 4px; padding: 4px 10px; border: 1px solid var(--rule); border-radius: var(--radius); color: var(--ink); font-size: 0.88rem; }
.jump li a small { color: var(--ink-3); font-size: 0.78rem; }
.jump li a:hover { border-color: var(--blue); color: var(--blue); text-decoration: none; }

.ix__group { margin-bottom: 24px; scroll-margin-top: 20px; }
.ix__ghead { display: flex; align-items: baseline; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--rule); }
.ix__gtitle { font-size: 1.05rem; font-weight: 700; padding-left: 10px; border-left: 3px solid var(--blue); line-height: 1.3; }
.ix__gcount { font-size: 0.82rem; color: var(--ink-3); }
.ix__glink { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; font-size: 0.85rem; white-space: nowrap; }

.ix__list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); column-gap: 24px; }
.ix__item { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px dotted var(--rule); min-width: 0; }
.ix__thumb { width: 64px; height: 48px; flex: none; object-fit: contain; background: var(--bg-soft); border: 1px solid var(--rule-soft); border-radius: 3px; }
.ix__text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.35; }
.ix__name { font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }
.ix__name:hover { color: var(--blue); }
.ix__en { font-size: 0.78rem; color: var(--ink-3); overflow-wrap: anywhere; }
.ix__dl { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 1px solid var(--rule); border-radius: var(--radius); color: var(--green); }
.ix__dl:hover { background: var(--green); border-color: var(--green); color: #fff; }

/* ---------- Directory rows (games page) ---------- */
.dir__grid { display: grid; grid-template-columns: 132px minmax(0, 1fr) 176px 124px; column-gap: 18px; }
.dir__head { padding: 0 0 8px; border-bottom: 2px solid var(--ink); font-size: 0.78rem; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em; }
.row { padding: 16px 0; border-bottom: 1px solid var(--rule); align-items: start; scroll-margin-top: 20px; }
.row:target { background: var(--blue-soft); box-shadow: -12px 0 0 var(--blue-soft), 12px 0 0 var(--blue-soft); }
.row__cover img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: var(--bg-soft); border: 1px solid var(--rule-soft); border-radius: var(--radius); }
.row__body { min-width: 0; }
.row__title { font-size: 1.1rem; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.row__en { font-size: 0.82rem; color: var(--ink-3); margin-top: 2px; overflow-wrap: anywhere; }
.row__desc { margin-top: 8px; color: var(--ink-2); font-size: 0.94rem; overflow-wrap: anywhere; }
.row__class { min-width: 0; font-size: 0.88rem; }
.row__cat { display: inline-block; font-weight: 600; padding: 2px 8px; background: var(--blue-soft); border-radius: 3px; }
.row__cat:hover { text-decoration: none; background: var(--blue); color: #fff; }
.tags { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 8px; }
.tags li { color: var(--ink-3); font-size: 0.8rem; }
.tags li::before { content: "#"; color: var(--rule); }
.row__action { display: flex; flex-direction: column; gap: 6px; }
.dir__empty { padding: 32px 0; text-align: center; color: var(--ink-2); border-bottom: 1px solid var(--rule); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 6px 14px; border-radius: var(--radius); border: 1px solid transparent; font-weight: 600; font-size: 0.92rem; white-space: nowrap; }
.btn:hover { text-decoration: none; }
.btn--green { background: var(--green); color: #fff; }
.btn--green:hover { background: var(--green-2); }
.btn--ghost { background: #fff; color: var(--ink-2); border-color: var(--rule); min-height: 36px; padding: 4px 10px; font-size: 0.85rem; }
.btn--ghost:hover { border-color: var(--ink-2); color: var(--ink); }

/* ---------- Reference manual (support pages) ---------- */
.manual { max-width: 76ch; }
.manual h2 { font-size: 1.35rem; font-weight: 700; line-height: 1.3; margin-top: 30px; padding: 6px 0 6px 12px; border-left: 3px solid var(--blue); scroll-margin-top: 20px; }
.manual h3 { font-size: 1.1rem; font-weight: 700; line-height: 1.35; margin-top: 22px; scroll-margin-top: 20px; }
.manual > :first-child { margin-top: 0; }
.manual p { margin-top: 12px; color: var(--ink-2); }
.manual ul, .manual ol { margin-top: 10px; padding-left: 1.5em; color: var(--ink-2); }
.manual ul { list-style: disc; }
.manual ol { list-style: decimal; }
.manual li { margin-top: 4px; }
.manual li::marker { color: var(--blue); }
.manual a { text-decoration: underline; text-underline-offset: 2px; }
.manual strong { color: var(--ink); }
.manual p, .manual li { overflow-wrap: anywhere; }

/* ---------- Footer ---------- */
.foot { border-top: 1px solid var(--rule); background: var(--bg-soft); }
.foot__in { max-width: var(--max-w); padding: 20px 32px 28px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; font-size: 0.88rem; color: var(--ink-2); }
.foot__name { font-weight: 700; color: var(--ink); }
.foot__nav { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.foot__nav a { color: var(--ink-2); }
.foot__nav a:hover { color: var(--blue); }
.foot__meta { flex-basis: 100%; }

/* ---------- Download gate: index sheet ----------
   A single graphite-tabbed sheet in the same rule-and-column language as
   the directory rows: dark tab bar with the blue index rule, a slim
   status line (blue while loading, green once done), then the framed
   gate and a plain foot rule. Only the frame flexes with the viewport. */
.ixgate { width: min(560px, calc(100vw - 24px)); max-width: none; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); margin: auto; padding: 0; border: 1px solid var(--graphite); border-radius: var(--radius); background: #fff; color: var(--ink); box-shadow: 0 10px 28px rgba(29, 32, 36, 0.28); overflow: hidden; }
.ixgate::backdrop { background: rgba(38, 42, 46, 0.62); }
.ixgate__sheet { display: flex; flex-direction: column; max-height: calc(100vh - 26px); max-height: calc(100dvh - 26px); }
.ixgate__bar, .ixgate__status, .ixgate__foot { flex: none; }
.ixgate__bar { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px; background: var(--graphite); color: #fff; border-left: 4px solid var(--blue-light); }
.ixgate__title { flex: 1; min-width: 0; font-weight: 700; font-size: 0.98rem; line-height: 1.35; overflow-wrap: anywhere; }
.ixgate__close { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; padding: 0; background: transparent; color: #fff; border: 1px solid #4b5158; border-radius: var(--radius); font-size: 1.3rem; line-height: 1; }
.ixgate__close:hover { background: var(--graphite-2); }
.ixgate__close:focus-visible { outline-color: var(--blue-light); }
.ixgate__glyph { width: 20px; height: 20px; }
.ixgate__status { padding: 7px 14px; font-size: 0.86rem; line-height: 1.45; color: var(--ink-2); background: var(--blue-soft); border-bottom: 1px solid var(--rule); }
.ixgate__status:empty { display: none; }
.ixgate[data-state="done"] .ixgate__status { background: var(--green-soft); color: var(--green-2); font-weight: 600; }
.ixgate__frame { display: block; width: 100%; height: 360px; min-height: 160px; flex: 0 1 auto; border: 0; background: #fff; }
.ixgate__foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 7px 14px; font-size: 0.85rem; background: var(--bg-soft); border-top: 1px solid var(--rule); }
.ixgate__direct { display: inline-flex; align-items: center; min-height: 32px; padding: 0 4px; color: var(--green-2); font-weight: 600; }
.ixgate__direct:hover { color: var(--green); }

/* ---------- Tablet ---------- */
@media (max-width: 1100px) {
  :root { --aside-w: 216px; }
  .wrap { padding: 24px 24px 36px; column-gap: 24px; }
  .dir__grid { grid-template-columns: 112px minmax(0, 1fr) 150px; }
  .dir__head span:last-child { display: none; }
  .row__class { grid-column: 3; }
  .row__action { grid-column: 3; margin-top: 10px; }
}

/* ---------- Masthead ---------- */
@media (max-width: 900px) {
  .rail { position: sticky; bottom: auto; width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; overflow: visible; }
  .rail__brand { flex: 1 1 100%; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 0; }
  .rail__logo img { width: 120px; }
  .rail__toggle { display: inline-flex; }
  .js .rail__nav:not(.is-open) { display: none; }
  .rail__nav { flex: 1 1 100%; padding: 4px 0 14px; border-top: 1px solid var(--graphite-2); }
  .rail__list { display: flex; flex-wrap: wrap; }
  .rail__list li a { padding: 10px 16px; border-left: 0; border-bottom: 3px solid transparent; }
  .rail__list li a[aria-current="page"] { border-bottom-color: var(--blue-light); }
  .rail__meta { margin-top: 8px; border-top: 0; padding-top: 6px; display: flex; gap: 14px; }
  .rail__dl { margin-top: 8px; }

  .main, .foot { margin-left: 0; }
  .side--sticky { position: static; max-height: none; overflow: visible; }
}

/* ---------- Mobile ---------- */
@media (max-width: 767px) {
  .wrap { grid-template-columns: minmax(0, 1fr); padding: 20px 16px 32px; }
  .page-head__title { font-size: 1.5rem; }
  .side { margin-bottom: 16px; }
  .site--index .content { order: 1; }
  .site--index .side { order: 2; }
  .js .site--games .side nav.panel { display: none; }
  .catlist, .toc { display: flex; flex-wrap: wrap; gap: 6px; }
  .catlist li a, .toc li a { gap: 5px; padding: 4px 10px; border: 1px solid var(--rule); border-radius: var(--radius); font-size: 0.88rem; }
  .toc__l3 a { padding-left: 10px; }
  .catlist li a[aria-current="true"] { border-color: var(--blue); }
  .quick { display: flex; flex-wrap: wrap; gap: 4px 18px; }

  .ix__list { grid-template-columns: minmax(0, 1fr); }
  .pick__list { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }

  .dir__head { display: none; }
  .dir__grid { grid-template-columns: 96px minmax(0, 1fr); column-gap: 14px; }
  .row { grid-template-areas: "cover body" "cover class" "action action"; row-gap: 8px; }
  .row__cover { grid-area: cover; }
  .row__body { grid-area: body; }
  .row__class { grid-area: class; }
  .row__action { grid-area: action; flex-direction: row; margin-top: 4px; padding-top: 10px; border-top: 1px dotted var(--rule); }
  .row__action .btn { flex: 1; }
  .row:target { box-shadow: -8px 0 0 var(--blue-soft), 8px 0 0 var(--blue-soft); }

  .foot__in { padding: 18px 16px 24px; }
}

/* Reflow against available content width, including browser/CSS zoom. */
@container (max-width: 700px) {
  .wrap { grid-template-columns: minmax(0, 1fr); padding: 20px 16px 32px; }
  .side--sticky { position: static; max-height: none; overflow: visible; }
  .dir__head { display: none; }
  .dir__grid { grid-template-columns: 80px minmax(0, 1fr); column-gap: 14px; }
  .row { grid-template-areas: "cover body" "cover class" "action action"; row-gap: 8px; }
  .row__cover { grid-area: cover; }
  .row__body { grid-area: body; }
  .row__class { grid-area: class; }
  .row__action { grid-area: action; margin-top: 4px; }
  .ix__list { grid-template-columns: minmax(0, 1fr); }
  .sec-head, .ix__ghead { flex-wrap: wrap; }
}

@media (max-width: 420px) {
  .rail__brand { padding: 8px 12px; }
  .rail__toggle span { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .rail__toggle { position: relative; padding: 6px; min-width: 40px; justify-content: center; }
  .dir__grid { grid-template-columns: 80px minmax(0, 1fr); }
  .ixgate { width: calc(100vw - 16px); max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); }
  .ixgate__sheet { max-height: calc(100vh - 18px); max-height: calc(100dvh - 18px); }
  .ixgate__bar { padding-left: 10px; }
  .ixgate__status, .ixgate__foot { padding-left: 10px; padding-right: 10px; }
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
  .btn, .ix__dl, .rail__list li a, .ixgate__close, .ixgate__direct { transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease; }
  .ixgate[open] { animation: ixgate-in 160ms ease-out; }
  @keyframes ixgate-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
  }
}
