/* ------------------------------------------------------------
   Studio shelf template — tokens
   ------------------------------------------------------------ */
:root {
  --paper: #f4f5f7;
  --paper-2: #e7eaee;
  --line: #cfd4db;
  --ink: #15181f;
  --ink-2: #4b515c;
  --ink-3: #5b6270;
  --accent: #d9294f;
  --accent-ink: #b01f40;
  --green: #5f8c6e;
  --green-ink: #3f6b4e;
  --white: #ffffff;
  --radius: 6px;
  --gutter: clamp(1rem, 3vw, 2.5rem);
  --measure: 66ch;
  --font: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", "Segoe UI", system-ui, sans-serif;
}

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

html { font-family: var(--font); color: var(--ink); background: var(--paper); -webkit-text-size-adjust: 100%; }
body { margin: 0; font-size: 1rem; line-height: 1.65; min-width: 0; }
[hidden] { display: none !important; }

img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent-ink); text-underline-offset: 0.15em; }
a:hover { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 700; }
h1 { font-size: 1.85rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
ul { list-style: none; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

:focus-visible { outline: 3px 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; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
  a, button { transition: color 0.15s, background-color 0.15s, border-color 0.15s; }
}

/* ------------------------------------------------------------
   Masthead + full-width nav row
   ------------------------------------------------------------ */
.masthead { background: var(--ink); display: flex; justify-content: center; padding: 0.9rem var(--gutter); }
.masthead-mark { display: inline-block; border-radius: var(--radius); }
.masthead-mark:focus-visible { outline-color: var(--paper); }
.masthead-logo { width: 202px; height: auto; aspect-ratio: 404 / 94; }

.navrow { background: var(--white); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.navrow-inner { display: flex; align-items: center; gap: 1rem; padding: 0 var(--gutter); min-height: 3rem; }
.navrow-name { font-weight: 700; font-size: 0.95rem; white-space: nowrap; }
.site-nav { flex: 1; min-width: 0; }
.site-nav-list { display: flex; flex-wrap: wrap; gap: 0 0.25rem; justify-content: flex-end; }
.site-nav-list a { display: block; padding: 0.75rem 0.8rem; color: var(--ink); text-decoration: none; font-weight: 600; border-bottom: 3px solid transparent; }
.site-nav-list a:hover { color: var(--accent-ink); }
.site-nav-list a[aria-current="page"] { border-bottom-color: var(--accent); color: var(--accent-ink); }

.menu-toggle { display: inline-flex; align-items: center; gap: 0.4rem; margin-left: auto; padding: 0.45rem 0.7rem; background: var(--white); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); font: inherit; font-weight: 600; cursor: pointer; }
.menu-toggle[aria-expanded="true"] { background: var(--ink); color: var(--white); border-color: var(--ink); }

@media (max-width: 768px) {
  .navrow-inner { flex-wrap: wrap; }
  .js .site-nav { flex-basis: 100%; }
  .js .site-nav:not(.is-open) { display: none; }
  .site-nav-list { flex-direction: column; gap: 0; padding-bottom: 0.5rem; }
  .site-nav-list a { padding: 0.6rem 0.25rem; border-bottom: 1px solid var(--paper-2); }
  .site-nav-list a[aria-current="page"] { border-left: 3px solid var(--accent); padding-left: 0.6rem; border-bottom-color: var(--paper-2); }
}
@media (min-width: 769px) {
  .menu-toggle { display: none !important; }
}

/* ------------------------------------------------------------
   Shared: covers, actions
   ------------------------------------------------------------ */
.cover { display: block; aspect-ratio: 4 / 3; background: var(--paper-2); border-radius: var(--radius); overflow: hidden; }
.cover img { width: 100%; height: 100%; object-fit: contain; object-position: center; }
.cover--thumb { width: 5rem; flex: none; }

.action { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.55rem 1rem; border: 1px solid var(--ink); border-radius: var(--radius); color: var(--ink); text-decoration: none; font-weight: 600; font-size: 0.95rem; background: var(--white); }
.action:hover { border-color: var(--accent); color: var(--accent-ink); }
.action--primary { background: var(--accent); border-color: var(--accent); color: var(--white); }
.action--primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: var(--white); }

/* ------------------------------------------------------------
   Index: category row + shelves
   ------------------------------------------------------------ */
.shelf-index { background: var(--paper-2); border-bottom: 1px solid var(--line); }
.shelf-index-list { display: flex; gap: 0.25rem; overflow-x: auto; padding: 0.4rem var(--gutter); scrollbar-width: thin; }
.shelf-index-list a { display: inline-flex; align-items: baseline; gap: 0.35rem; padding: 0.35rem 0.6rem; white-space: nowrap; color: var(--ink); text-decoration: none; font-size: 0.9rem; font-weight: 600; border-radius: var(--radius); }
.shelf-index-list a:hover { background: var(--white); color: var(--accent-ink); }
.shelf-index-count { font-size: 0.75rem; color: var(--ink-3); font-weight: 400; }

.studio { padding: 0 var(--gutter) 3rem; }
.studio-intro { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1rem 2rem; align-items: end; padding: 1.75rem 0 1.25rem; border-bottom: 1px solid var(--line); }
.studio-intro-text { max-width: var(--measure); }
.studio-intro-text p { margin-top: 0.5rem; color: var(--ink-2); }
.studio-facts { display: flex; gap: 1.75rem; margin: 0; }
.studio-facts div { display: flex; flex-direction: column-reverse; }
.studio-facts dt { font-size: 0.8rem; color: var(--ink-3); }
.studio-facts dd { margin: 0; font-size: 1.6rem; font-weight: 700; line-height: 1.1; color: var(--green-ink); }
.studio-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.6rem; }

.shelf { padding: 1.5rem 0 1rem; border-bottom: 1px solid var(--line); }
.shelf-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.4rem 0.9rem; margin-bottom: 0.9rem; }
.shelf-head h2 { font-size: 1.25rem; }
.shelf-count { font-size: 0.85rem; color: var(--ink-3); }
.shelf-more { margin-left: auto; display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.9rem; font-weight: 600; text-decoration: none; }
.shelf-more:hover { text-decoration: underline; }
.shelf-marker { font-size: 0.75rem; font-weight: 700; color: var(--white); background: var(--accent); padding: 0.15rem 0.5rem; border-radius: var(--radius); align-self: center; }

.shelf-row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(150px, 180px); gap: 1rem; overflow-x: auto; padding: 0.25rem 0 0.75rem; scrollbar-width: thin; scroll-snap-type: x proximity; }
.shelf--start .shelf-row { grid-auto-columns: minmax(190px, 230px); }
.shelf--featured .shelf-row { grid-auto-columns: minmax(170px, 200px); }
.shelf-item { scroll-snap-align: start; min-width: 0; }
.shelf-item a { display: block; color: var(--ink); text-decoration: none; border-radius: var(--radius); }
.shelf-item a:hover .shelf-item-name { color: var(--accent-ink); }
.shelf-item .cover { border: 1px solid var(--line); }
.shelf-item-name { display: block; margin-top: 0.5rem; font-weight: 600; font-size: 0.95rem; line-height: 1.35; }
.shelf-item-en { display: block; font-size: 0.78rem; color: var(--ink-3); line-height: 1.35; margin-top: 0.15rem; }
.shelf--start { background: linear-gradient(180deg, var(--white), var(--paper)); margin: 0 calc(-1 * var(--gutter)); padding-left: var(--gutter); padding-right: var(--gutter); }

.studio-outro { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; padding: 2rem 0 0; color: var(--ink-2); }

@media (max-width: 640px) {
  .studio-intro { grid-template-columns: 1fr; align-items: start; }
  .studio-facts { gap: 1.25rem; }
}

/* ------------------------------------------------------------
   Games: index tabs at the margin + editorial two-column shelf
   ------------------------------------------------------------ */
.library { display: grid; grid-template-columns: 3.25rem minmax(0, 1fr); gap: 0 var(--gutter); padding: 0 var(--gutter) 3rem 0; }
.library-body, .index-tabs { min-width: 0; }
.index-tabs { border-right: 1px solid var(--line); }
.index-tabs-list { position: sticky; top: 0; display: flex; flex-direction: column; gap: 0.5rem; padding: 1.5rem 0 1rem; max-height: 100vh; overflow-y: auto; scrollbar-width: none; }
.index-tabs-list a { writing-mode: vertical-rl; display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.75rem 0.55rem; margin-left: 0.5rem; color: var(--ink-2); text-decoration: none; font-size: 0.85rem; font-weight: 600; letter-spacing: 0.08em; border-left: 3px solid transparent; border-radius: 0 var(--radius) var(--radius) 0; background: var(--paper-2); }
.index-tabs-list a:hover { color: var(--accent-ink); background: var(--white); }
.index-tabs-list a[aria-current="true"] { border-left-color: var(--accent); background: var(--white); color: var(--ink); }
.index-tab-count { font-size: 0.7rem; color: var(--ink-3); font-weight: 400; letter-spacing: 0; }

.library-head { padding: 1.75rem 0 1rem; max-width: var(--measure); }
.library-head p { margin-top: 0.5rem; color: var(--ink-2); }

.finder { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto auto; gap: 0.6rem; align-items: end; padding: 1rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.finder-field { position: relative; display: grid; gap: 0.25rem; min-width: 0; }
.finder-field label { font-size: 0.8rem; color: var(--ink-3); font-weight: 600; }
.finder-field > svg { position: absolute; left: 0.7rem; bottom: 0.8rem; color: var(--ink-3); pointer-events: none; }
.finder-chevron { left: auto !important; right: 0.7rem; }
.finder-field input, .finder-field select { width: 100%; min-height: 2.75rem; padding: 0.5rem 0.75rem 0.5rem 2.4rem; font: inherit; color: var(--ink); background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); appearance: none; }
.finder-field select { padding-left: 0.75rem; padding-right: 2.2rem; }
.finder-field input:focus, .finder-field select:focus { border-color: var(--ink); }
.finder-status { font-size: 0.9rem; color: var(--ink-2); padding-bottom: 0.7rem; white-space: nowrap; }
.finder-status output { font-weight: 700; color: var(--green-ink); }
.finder-reset { display: inline-flex; align-items: center; gap: 0.35rem; min-height: 2.75rem; padding: 0.5rem 0.9rem; font: inherit; font-weight: 600; color: var(--ink); background: var(--white); border: 1px solid var(--ink); border-radius: var(--radius); cursor: pointer; }
.finder-reset:hover { color: var(--accent-ink); border-color: var(--accent); }

.library-empty { padding: 2rem 0; color: var(--ink-2); border-bottom: 1px solid var(--line); }

.editorial { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--gutter); }
.entry { display: grid; grid-template-rows: auto 1fr; gap: 0.9rem; padding: 1.75rem 0; border-bottom: 1px solid var(--line); min-width: 0; }
.entry .cover { border: 1px solid var(--line); }
/* second column sits a step lower than the first for an editorial stagger */
.entry:nth-child(5n+3), .entry:nth-child(5n+5) { padding-top: 3.25rem; }
.entry-text { display: flex; flex-direction: column; gap: 0.5rem; align-items: flex-start; min-width: 0; }
.entry-cat { font-size: 0.8rem; font-weight: 700; color: var(--green-ink); text-decoration: none; text-transform: uppercase; }
.entry-cat:hover { text-decoration: underline; }
.entry-name { font-size: 1.3rem; overflow-wrap: anywhere; }
.entry-en { font-size: 0.85rem; color: var(--ink-3); overflow-wrap: anywhere; }
.entry-tags { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.entry-tags li { font-size: 0.75rem; padding: 0.1rem 0.5rem; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink-2); background: var(--white); }
.entry-desc { color: var(--ink-2); max-width: var(--measure); overflow-wrap: anywhere; white-space: pre-line; }
.entry-download { margin-top: 0.4rem; }

/* Lead entry: spans both columns, cover beside text, extra air */
.entry--lead { grid-column: 1 / -1; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); grid-template-rows: none; gap: var(--gutter); padding: 2.5rem 0; }
.entry--lead .entry-name { font-size: 1.65rem; }
.entry--lead .entry-text { padding-top: 0.25rem; }
.entry:target { background: linear-gradient(90deg, rgba(217, 41, 79, 0.06), transparent 40%); }
.entry:target .entry-name::before { content: ""; display: inline-block; width: 0.55em; height: 0.55em; margin-right: 0.4rem; border-radius: 50%; background: var(--accent); vertical-align: middle; }

@media (max-width: 900px) {
  .library { grid-template-columns: minmax(0, 1fr); padding-left: var(--gutter); }
  .index-tabs { border-right: 0; border-bottom: 1px solid var(--line); margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter); }
  .index-tabs-list { position: static; flex-direction: row; gap: 0.35rem; overflow-x: auto; overflow-y: hidden; padding: 0.6rem 0; max-height: none; scrollbar-width: thin; }
  .index-tabs-list a { writing-mode: horizontal-tb; margin-left: 0; padding: 0.4rem 0.7rem; border-left: 0; border-bottom: 3px solid transparent; border-radius: var(--radius) var(--radius) 0 0; white-space: nowrap; letter-spacing: 0; }
  .index-tabs-list a[aria-current="true"] { border-bottom-color: var(--accent); }
  .finder { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .finder-status { grid-column: 1; }
  .finder-reset { grid-column: 2; justify-self: end; }
  .entry--lead { grid-template-columns: 1fr; padding: 2rem 0; }
}
@media (max-width: 640px) {
  .editorial { grid-template-columns: 1fr; }
  .entry, .entry:nth-child(5n+3), .entry:nth-child(5n+5) { padding: 1.5rem 0; }
  .finder { grid-template-columns: 1fr; }
  .finder-status, .finder-reset { grid-column: 1; justify-self: start; }
}

/* ------------------------------------------------------------
   Category page: group heading column + game list
   ------------------------------------------------------------ */
.catalog { padding: 0 var(--gutter) 3rem; }
.catalog-head { padding: 1.75rem 0 1.25rem; border-bottom: 1px solid var(--line); max-width: var(--measure); }
.catalog-head p { margin-top: 0.5rem; color: var(--ink-2); }
.catalog-sum { font-weight: 600; color: var(--green-ink); }

.group { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 1rem var(--gutter); padding: 1.75rem 0; border-bottom: 1px solid var(--line); }
.group-head { position: sticky; top: 1rem; align-self: start; display: flex; flex-direction: column; align-items: flex-start; gap: 0.35rem; }
.group-head h2 { font-size: 1.5rem; }
.group-count { color: var(--ink-3); font-size: 0.9rem; }
.group-more { display: inline-flex; align-items: center; gap: 0.3rem; font-weight: 600; text-decoration: none; font-size: 0.9rem; margin-top: 0.4rem; }
.group-more:hover { text-decoration: underline; }
.group-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.5rem 1.5rem; }
.group-item a { display: flex; gap: 0.8rem; align-items: center; padding: 0.5rem 0; color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--paper-2); }
.group-item a:hover .group-item-name { color: var(--accent-ink); }
.group-item .cover { border: 1px solid var(--line); }
.group-item-text { min-width: 0; }
.group-item-name { display: block; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.group-item-en { display: block; font-size: 0.8rem; color: var(--ink-3); overflow-wrap: anywhere; }

@media (max-width: 768px) {
  .group { grid-template-columns: 1fr; }
  .group-head { position: static; }
}

/* ------------------------------------------------------------
   Reader (tutorial / about / contact / privacy): chapter column + text column
   ------------------------------------------------------------ */
.reader { padding: 0 var(--gutter) 3rem; counter-reset: chapter; }
.reader-head { padding: 1.75rem 0 1.25rem; border-bottom: 1px solid var(--line); max-width: var(--measure); }
.reader-head p { margin-top: 0.5rem; color: var(--ink-2); }

.chapter { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 0.75rem var(--gutter); padding: 2rem 0; border-bottom: 1px solid var(--line); }
.chapter-head { align-self: start; position: sticky; top: 1rem; }
.chapter-head h2 { font-size: 1.6rem; max-width: 20ch; }
.chapter-head h2::before { counter-increment: chapter; content: counter(chapter, decimal-leading-zero); display: block; font-size: 0.85rem; font-weight: 700; color: var(--accent); margin-bottom: 0.35rem; }
.chapter--lead { padding-top: 1.5rem; }
.chapter-text { max-width: var(--measure); display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.chapter-text p { color: var(--ink-2); overflow-wrap: anywhere; }
.chapter-text .chapter-sub { margin-top: 0.5rem; color: var(--ink); }
.chapter-list { padding-left: 1.4rem; color: var(--ink-2); display: grid; gap: 0.35rem; }
.chapter-list li { padding-left: 0.2rem; }
ul.chapter-list { list-style: disc; }
ul.chapter-list li::marker { color: var(--green); }
ol.chapter-list li::marker { color: var(--accent-ink); font-weight: 700; }
.chapter-text code { font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: 0.9em; background: var(--paper-2); padding: 0.1em 0.35em; border-radius: 4px; }

.reader-next { display: flex; flex-wrap: wrap; gap: 0.6rem; padding-top: 2rem; }

@media (max-width: 768px) {
  .chapter { grid-template-columns: 1fr; gap: 0.75rem; padding: 1.5rem 0; }
  .chapter-head { position: static; }
  .chapter-head h2 { font-size: 1.4rem; }
  .chapter--lead .chapter-head { display: none; }
}

/* ------------------------------------------------------------
   Footer
   ------------------------------------------------------------ */
.colophon { background: var(--ink); color: var(--paper-2); }
.colophon-inner { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem 2rem; padding: 1.5rem var(--gutter); }
.colophon-brand img { width: 121px; height: auto; aspect-ratio: 404 / 94; }
.colophon-stats { margin-top: 0.5rem; font-size: 0.85rem; color: #b6bcc6; }
.colophon-links { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; }
.colophon-links a { color: var(--paper); text-decoration: none; font-size: 0.9rem; }
.colophon-links a:hover { color: var(--white); text-decoration: underline; }
.colophon a:focus-visible { outline-color: var(--paper); }

/* ------------------------------------------------------------
   Download verification dialog: centred sheet over the shelves
   ------------------------------------------------------------ */
.gate { width: min(38rem, calc(100vw - 2rem)); max-width: 100%; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); color: var(--ink); }
.gate::backdrop { background: rgba(21, 24, 31, 0.6); }
.gate-inner { display: flex; flex-direction: column; gap: 0.9rem; padding: 1.25rem var(--gutter) 1.25rem; }

.gate-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 0 0.75rem; }
.gate-eyebrow { grid-column: 1; font-size: 0.8rem; font-weight: 700; color: var(--accent); }
.gate-title { grid-column: 1; font-size: 1.3rem; }
.gate-close { grid-column: 2; grid-row: 1 / span 2; display: inline-flex; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem; padding: 0; background: var(--white); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.gate-close:hover { background: var(--ink); color: var(--white); border-color: var(--ink); }
.gate-note { color: var(--ink-2); font-size: 0.9rem; max-width: var(--measure); }

.gate-stage { display: flex; flex-direction: column-reverse; gap: 0.75rem; }
.gate-frame { position: relative; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); overflow: hidden; min-height: 12rem; }
.gate-iframe { display: block; width: 100%; height: clamp(12rem, 42vh, 20rem); border: 0; }
.gate-frame::after { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--paper-2); }
.gate-stage[data-state="loading"] .gate-frame::after { background: linear-gradient(90deg, var(--paper-2) 0 40%, var(--accent) 40% 60%, var(--paper-2) 60% 100%); background-size: 250% 100%; background-position: 100% 0; }
.gate-stage[data-state="ready"] .gate-frame::after { background: var(--accent); }
.gate-stage[data-state="complete"] .gate-frame::after { background: var(--green); }
.gate-stage[data-state="error"] .gate-frame::after { background: var(--accent-ink); }

.gate-status { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; font-weight: 600; color: var(--ink-2); }
.gate-status::before { content: ""; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--ink-3); flex: none; }
.gate-stage[data-state="ready"] .gate-status { color: var(--accent-ink); }
.gate-stage[data-state="ready"] .gate-status::before { background: var(--accent); }
.gate-stage[data-state="complete"] .gate-status { color: var(--green-ink); }
.gate-stage[data-state="complete"] .gate-status::before { background: var(--green); }
.gate-stage[data-state="error"] .gate-status { color: var(--accent-ink); }
.gate-stage[data-state="error"] .gate-status::before { background: var(--accent-ink); }

.gate-foot { border-top: 1px solid var(--line); padding-top: 0.75rem; }
.gate-fallback { font-size: 0.9rem; font-weight: 600; }

@media (prefers-reduced-motion: no-preference) {
  .gate[open] { animation: gate-in 0.18s ease-out; }
  .gate-stage[data-state="loading"] .gate-frame::after { animation: gate-scan 1.1s linear infinite; }
}
@keyframes gate-in { from { opacity: 0; transform: translateY(0.5rem); } }
@keyframes gate-scan { to { background-position: 0 0; } }

@media (max-width: 480px) {
  .gate { width: calc(100vw - 1rem); }
  .gate-inner { padding: 1rem; }
  .gate-title { font-size: 1.15rem; }
}
