:root {
  --bg: #0b0d14;
  --panel: #151926;
  --panel-2: #1d2233;
  --line: rgba(255, 255, 255, .1);
  --text: #eef0f6;
  --muted: #9aa1b5;
  --accent: #a78bfa;
  --gutter: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(167, 139, 250, .14), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(34, 211, 238, .10), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: "M PLUS 1p", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;            /* 一覧は1画面に収める。詳細はシートの中でスクロールする */
}
a { color: inherit; }
button { font: inherit; color: inherit; }

/* ───────── 一覧：100dvh に収める ───────── */
.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right))
           max(8px, env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
  max-width: 1440px;
  margin: 0 auto;
}

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-icon { width: 40px; height: 40px; image-rendering: pixelated; flex: none;
  background: var(--panel-2); border-radius: 10px; border: 1px solid var(--line); }
h1 { margin: 0; font-size: 19px; font-weight: 900; letter-spacing: .01em; line-height: 1.1; }
.tagline { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); }
.tagline b { color: var(--text); }
.gh { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted); flex: none; }
.gh:hover { color: var(--text); }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: 8px;
  min-height: 0;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
  text-align: left;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.card:hover, .card:focus-visible {
  transform: translateY(-2px);
  border-color: var(--c);
  box-shadow: 0 6px 24px -8px var(--c);
  outline: none;
}
.card .thumb { position: relative; flex: 1 1 auto; min-height: 0; background: #000; }
.card .thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: left center; display: block; }
.card .meta { flex: none; display: flex; align-items: center; gap: 6px; padding: 5px 7px 6px; }
.card .no { flex: none; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 6px;
  font-family: "DotGothic16"; font-size: 12px; color: #0b0d14; background: var(--c); }
.card .names { min-width: 0; }
.card .name { display: block; font-size: 12px; font-weight: 900; line-height: 1.2; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .genre { display: block; font-size: 10px; color: var(--muted); line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .badge { position: absolute; top: 6px; right: 6px; z-index: 1; font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px; background: rgba(11, 13, 20, .82); color: var(--c); border: 1px solid var(--c); }
.card.asset { border-style: dashed; border-color: rgba(34, 211, 238, .45); }

.foot { font-size: 9.5px; line-height: 1.45; color: var(--muted); text-align: center; }

/* 横長の画面（PC・横向きのスマホ）はサムネイルの比率（1200:630）を崩さずに並べる。
   カードの幅は「列で割った幅」と「行で割った高さから逆算した幅」の小さいほう。
   一覧の箱の大きさは container query（cqw / cqh）で読む */
@media (min-aspect-ratio: 1/1) {
  .grid {
    --cols: 5; --rows: 2; --gap: 12px; --meta: 44px;
    display: flex; flex-wrap: wrap; justify-content: center; align-content: center;
    gap: var(--gap);
    container-type: size;
  }
  .card {
    flex: none;
    width: min(calc((100cqw - (var(--cols) - 1) * var(--gap)) / var(--cols)),
               calc(((100cqh - (var(--rows) - 1) * var(--gap)) / var(--rows) - var(--meta)) * 1.9));
  }
  .card .thumb { flex: none; aspect-ratio: 1200 / 630; }
  .card .meta { height: var(--meta); padding: 0 10px; }
  .card .name { font-size: 14px; letter-spacing: 0; }
  .card .genre { font-size: 11px; }
}
@media (min-aspect-ratio: 1/1) and (max-width: 899px) {
  .grid { --gap: 8px; --meta: 36px; }
  .card .meta { padding: 0 7px; gap: 5px; }
  .card .name { font-size: 12px; letter-spacing: -.02em; }
  .card .genre { font-size: 10px; }
}
/* PC くらいの高さがあれば 4 列 × 3 行にして、1枚を大きく見せる（最後の行は中央寄せ） */
@media (min-aspect-ratio: 1/1) and (min-height: 700px) and (min-width: 1000px) {
  .grid { --cols: 4; --rows: 3; --gap: 16px; --meta: 50px; }
  .card .name { font-size: 15px; }
  .card .genre { font-size: 12px; }
}
@media (min-aspect-ratio: 1/1) and (min-width: 900px) {
  .app { gap: 16px; padding-top: 20px; padding-bottom: 14px; }
  h1 { font-size: 24px; }
  .tagline { font-size: 13px; }
  .brand-icon { width: 48px; height: 48px; }
  .foot { font-size: 11px; }
}
/* 縦がとても短い横画面では、説明行を畳んで一覧に高さを渡す */
@media (max-height: 420px) {
  .tagline, .foot { display: none; }
  .brand-icon { width: 30px; height: 30px; }
  h1 { font-size: 16px; }
  .card .genre { display: none; }
}

/* ───────── 詳細シート ───────── */
.sheet {
  --accent: #a78bfa;
  padding: 0;
  border: 0;
  width: 100%;
  max-width: 760px;
  max-height: 92dvh;
  margin: auto auto 0;
  border-radius: 20px 20px 0 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 -10px 60px rgba(0, 0, 0, .6);
  overflow: hidden;
}
.sheet[open] { animation: up .22s ease-out; }
.sheet::backdrop { background: rgba(4, 5, 10, .66); backdrop-filter: blur(3px); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 800px) and (min-height: 600px) {
  .sheet { margin: auto; border-radius: 20px; max-height: 90dvh; }
}
@media (prefers-reduced-motion: reduce) { .sheet[open] { animation: none; } .card { transition: none; } }

.sheet-inner { max-height: inherit; overflow-y: auto; overscroll-behavior: contain;
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); }

.sh-bar { position: sticky; top: -10px; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  margin: -10px -18px 6px; padding: 10px 12px 8px; background: linear-gradient(var(--panel) 75%, transparent); }
.sh-bar .grab { position: absolute; left: 50%; top: 5px; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: rgba(255, 255, 255, .22); }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; font-size: 17px; line-height: 1; }
.icon-btn:hover { border-color: var(--accent); }
.sh-nav { display: flex; gap: 6px; }

.app-row { display: flex; gap: 14px; align-items: center; }
.app-icon { flex: none; width: 76px; height: 76px; border-radius: 18px; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--accent) 45%, #1d2233), #10131c 75%);
  box-shadow: 0 0 0 1px var(--line), 0 8px 24px -10px var(--accent); }
.app-icon img { width: 64px; height: 64px; image-rendering: pixelated; object-fit: contain; }
.app-title { margin: 0; font-size: 22px; font-weight: 900; line-height: 1.15; }
.app-genre { margin: 3px 0 0; font-size: 13px; font-weight: 700; color: var(--accent); }

.stats { display: flex; margin: 14px 0 12px; padding: 8px 0; border-block: 1px solid var(--line); }
.stats div { flex: 1; text-align: center; font-size: 11px; color: var(--muted); line-height: 1.35; padding: 0 4px; }
.stats div + div { border-left: 1px solid var(--line); }
.stats b { display: block; font-size: 14px; color: var(--text); font-weight: 900; white-space: nowrap; }
.stats .st-wip b { color: #fbbf24; }

.actions { display: flex; gap: 8px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 44px; padding: 0 18px;
  border-radius: 12px; font-weight: 900; font-size: 15px; text-decoration: none; border: 1px solid var(--line); }
.btn.play { flex: 1; background: var(--accent); color: #0b0d14; border-color: transparent; }
.btn.play:hover { filter: brightness(1.08); }
.btn.sub { background: var(--panel-2); }

.shots { display: flex; gap: 8px; margin: 16px -18px 4px; padding: 0 18px 6px; overflow-x: auto;
  scroll-snap-type: x mandatory; scroll-padding: 0 18px; scrollbar-width: thin; }
.shots button { flex: none; padding: 0; border: 0; background: none; cursor: zoom-in; scroll-snap-align: start; }
.shots img { display: block; height: min(40dvh, 380px); border-radius: 12px; border: 1px solid var(--line); background: #000; }
.shots .wide img { aspect-ratio: 1200 / 630; }
.shots .tall img { aspect-ratio: 9 / 16; object-fit: cover; object-position: top; }

.about h3 { margin: 14px 0 6px; font-size: 15px; font-weight: 900; }
.about .lead { margin: 0 0 6px; font-weight: 900; font-size: 15px; }
.about p { margin: 0; font-size: 13.5px; line-height: 1.75; color: #cfd3df; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.tags span { font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); }

/* ───────── 拡大表示 ───────── */
.lightbox { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, .9); cursor: zoom-out; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }
