/* ============================================================
   TinyLabo Games — GamePix系スレートUI
   構造: トップ=カテゴリ別の横スクロール帯 / 正方形タイル
        ゲームページ=全画面ステージ+極小アイコンバー
   軽量(Webフォントなし・単一CSS)・RTL自動対応(論理プロパティ)
   ============================================================ */
:root {
  --bg: #232b31;
  --bg2: #2d373f;      /* GamePixテーマ色系 */
  --card: #3a454f;
  --text: #f2f5f7;
  --dim: #9fb0bc;
  --accent: #ffa726;   /* アンバー */
  --accent2: #4dd0a6;
  --radius: 14px;
  --bar-h: 48px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "BIZ UDGothic", "Yu Gothic UI",
    "Segoe UI", "Noto Naskh Arabic", system-ui, sans-serif;
  line-height: 1.6; font-size: 15px;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
.wrap { max-width: 1200px; margin-inline: auto; padding-inline: 16px; }

/* ---------- ヘッダー(トップ・カテゴリページ用) ---------- */
.site-head { background: var(--bg2); position: sticky; top: 0; z-index: 10;
  box-shadow: 0 1px 0 rgba(255,255,255,.06); }
.site-head .wrap { display: flex; align-items: center; gap: 12px;
  min-height: 54px; flex-wrap: wrap; padding-block: 6px; }
.logo { font-size: 1.15rem; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.logo .dot { width: 15px; height: 15px; border-radius: 5px;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); transform: rotate(8deg); }
.lang-switch { margin-inline-start: auto; display: flex; gap: 6px; }
.lang-switch a { padding: 4px 12px; border-radius: 999px; font-size: .8rem;
  font-weight: 700; background: var(--card); color: var(--dim); }
.lang-switch a[aria-current="true"] { background: var(--accent); color: #26200e; }

.chips { display: flex; gap: 8px; padding-block: 12px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; padding: 6px 16px; border-radius: 999px;
  background: var(--card); color: var(--dim); font-weight: 700; font-size: .9rem; }
.chip:hover, .chip:focus-visible { color: var(--text); }
.chip[aria-current="true"] { background: var(--accent); color: #26200e; }

/* ---------- カテゴリ帯(横スクロール) ---------- */
.shelf { margin-block: 20px 6px; }
.shelf-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.shelf-head h2 { font-size: 1.05rem; margin: 0; display: flex; align-items: center; gap: 8px; }
.shelf-head h2::before { content: ""; width: 8px; height: 18px; border-radius: 4px;
  background: var(--accent); }
.shelf-head .more { margin-inline-start: auto; font-size: .82rem; font-weight: 700;
  color: var(--accent); white-space: nowrap; }
.shelf-row { display: grid; grid-auto-flow: column;
  grid-auto-columns: clamp(116px, 24vw, 156px);
  gap: 12px; overflow-x: auto; padding-block: 2px 8px;
  scroll-snap-type: x proximity; scrollbar-width: none; }
.shelf-row::-webkit-scrollbar { display: none; }

/* ---------- 正方形タイル ---------- */
.sq { scroll-snap-align: start; display: block; }
.sq .pic { display: block; position: relative; aspect-ratio: 1 / 1; border-radius: var(--radius);
  overflow: hidden; background: var(--card); outline: 1px solid rgba(255,255,255,.06);
  transition: transform .15s, outline-color .15s; }
/* サムネ未設定・読み込み失敗時: タイトルの頭文字を表示 */
.sq .pic::before { content: attr(data-l); position: absolute; inset: 0;
  display: grid; place-items: center; font-size: 2.6rem; font-weight: 800;
  color: rgba(255,255,255,.18);
  background: linear-gradient(135deg, #3a454f, #2d373f); }
.sq:hover .pic, .sq:focus-visible .pic { transform: scale(1.05); outline: 2px solid var(--accent); }
.sq .pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.sq .badge { position: absolute; top: 7px; inset-inline-start: 7px; font-size: .64rem;
  font-weight: 800; padding: 2px 7px; border-radius: 6px;
  background: var(--accent2); color: #06251f; }
.sq .t { margin-top: 6px; font-size: .82rem; font-weight: 700; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* カテゴリページ用グリッド */
.grid { display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); padding-block: 8px; }
h1 { font-size: 1.25rem; margin: 16px 0 4px; }
h2.sec { font-size: 1.05rem; margin: 22px 0 10px; }

/* ---------- ゲームページ: 全画面ステージ+極小バー ---------- */
.gp-shell { height: 100dvh; display: flex; flex-direction: column; background: #000; }
.gp-bar { height: var(--bar-h); flex: none; display: flex; align-items: center; gap: 10px;
  padding-inline: 10px; background: var(--bg2);
  padding-top: env(safe-area-inset-top); box-sizing: content-box; }
.gp-icon { width: 36px; height: 36px; flex: none; display: grid; place-items: center;
  border-radius: 10px; background: var(--card); color: var(--text);
  font-size: 1.05rem; border: 0; cursor: pointer; }
.gp-icon:hover { background: var(--accent); color: #26200e; }
.gp-title { font-weight: 700; font-size: .92rem; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.gp-frame { flex: 1; min-height: 0; position: relative; }
.gp-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* フルスクリーン時: バーも消してゲームだけに(iPhoneは擬似FS) */
.gp-shell.fs { position: fixed; inset: 0; z-index: 100; }
.gp-shell.fs .gp-bar { display: none; }
.gp-shell.fs .gp-exit { display: grid; }
.gp-exit { display: none; position: absolute; top: max(8px, env(safe-area-inset-top));
  inset-inline-end: 8px; z-index: 101; width: 40px; height: 40px; place-items: center;
  border: 0; border-radius: 12px; background: rgba(30,38,44,.72); color: #fff;
  font-size: 1.1rem; cursor: pointer; backdrop-filter: blur(4px); }
html.fs-lock, html.fs-lock body { overflow: hidden; overscroll-behavior: none; }

/* ゲームページの下部(スクロールで出る情報エリア) */
.gp-below { padding-block: 18px 8px; }
.desc-box { color: var(--dim); max-width: 75ch; }

/* ---------- 広告枠 ---------- */
.ad-slot { min-height: 90px; display: grid; place-items: center; margin-block: 14px;
  border: 1px dashed #4a5763; border-radius: var(--radius); color: #677684;
  font-size: .75rem; background: var(--bg2); }

/* ---------- フッター ---------- */
.site-foot { margin-block-start: 36px; background: var(--bg2);
  padding-block: 20px; font-size: .85rem; color: var(--dim); }
.site-foot .wrap { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; }
.site-foot a:hover { color: var(--text); text-decoration: underline; }

/* ---------- 専用アプリモード(?app=1) ---------- */
html.is-app .lang-switch, html.is-app .site-foot { display: none; }
html.is-app .site-head { position: static; }

:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .sq:hover .pic { transform: none; }
}

/* ---------- レーティング ---------- */
.sq .rt { display: block; font-size: .74rem; color: var(--accent); font-weight: 700; }
.rate-box { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 4px 0 12px; }
.rate-label { font-size: .85rem; color: var(--dim); }
.stars { display: inline-flex; gap: 2px; }
.star { font-size: 1.5rem; line-height: 1; background: none; border: 0; cursor: pointer;
  color: #55636e; padding: 2px; transition: transform .1s, color .1s; }
.star:hover, .star:focus-visible { transform: scale(1.2); }
.star.on { color: var(--accent); }
.rate-info { font-size: .9rem; font-weight: 700; color: var(--accent); }

/* ---------- 年齢レーティングバッジ(PEGI風の色分け) ---------- */
.age { position: absolute; top: 7px; inset-inline-end: 7px;
  font-size: .68rem; font-weight: 800; padding: 2px 7px; border-radius: 6px;
  color: #fff; background: #58a75e; }
.age-6, .age-8 { background: #58a75e; }
.age-10 { background: #d1a41c; color: #2a2306; }
.age-16 { background: #e07b2a; }
.age-18 { background: #d84343; }
.age-big { position: static; font-size: .78rem; vertical-align: middle;
  margin-inline-start: 6px; padding: 3px 10px; }
.age-big.age-all { background: #58a75e; }

/* ---------- コメント ---------- */
.cm { margin-block: 18px; }
.cm-form { display: grid; gap: 8px; max-width: 560px; margin-bottom: 16px; }
.cm-form input, .cm-form textarea {
  background: var(--bg2); color: var(--text); border: 1px solid #4a5763;
  border-radius: 10px; padding: 9px 11px; font: inherit; font-size: .92rem; }
.cm-form textarea { min-height: 64px; resize: vertical; }
.cm-form button { justify-self: start; font: inherit; font-weight: 700; border: 0;
  border-radius: 10px; padding: 9px 22px; background: var(--accent); color: #26200e; cursor: pointer; }
.cm-msg { font-size: .85rem; color: var(--accent2); font-weight: 700; }
.cm-item { padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.07); }
.cm-head { display: flex; gap: 10px; align-items: baseline; font-size: .88rem; }
.cm-time { color: var(--dim); font-size: .75rem; }
.cm-item p { margin: 4px 0 0; color: var(--text); font-size: .92rem; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- ビルドバージョン表示 ---------- */
.site-foot .ver { margin-inline-start: auto; font-size: .7rem; color: #56646f;
  font-family: ui-monospace, monospace; }


/* ---------- スコアランキング ---------- */
.rank { margin-block: 18px; }
.rank-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.rtab { font: inherit; font-weight: 700; font-size: .82rem; border: 0; cursor: pointer;
  padding: 5px 16px; border-radius: 999px; background: var(--card); color: var(--dim); }
.rtab.on { background: var(--accent); color: #26200e; }
.rank-list { list-style: none; margin: 0; padding: 0; max-width: 480px;
  counter-reset: rk; }
.rank-list li { display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-radius: 10px; counter-increment: rk; }
.rank-list li:nth-child(odd) { background: var(--bg2); }
.rank-list li::before { content: counter(rk); font-weight: 800; color: var(--dim);
  min-width: 1.6em; text-align: center; }
.rank-list li:nth-child(1)::before { content: "🥇"; }
.rank-list li:nth-child(2)::before { content: "🥈"; }
.rank-list li:nth-child(3)::before { content: "🥉"; }
.rank-list b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-score { font-family: ui-monospace, monospace; font-weight: 700; color: var(--accent); }
.rk-empty { color: var(--dim); font-size: .9rem; }
.rk-empty::before { content: "" !important; min-width: 0 !important; }
.score-bar { display: none; align-items: center; gap: 8px; margin-top: 12px;
  background: var(--bg2); border: 1px solid var(--accent); border-radius: 12px;
  padding: 10px 12px; max-width: 480px; flex-wrap: wrap; }
.score-bar.show { display: flex; }
.score-bar #scoreval { font-weight: 800; color: var(--accent); }
.score-bar input { flex: 1; min-width: 120px; background: var(--bg); color: var(--text);
  border: 1px solid #4a5763; border-radius: 8px; padding: 7px 10px; font: inherit; }
.score-bar button { font: inherit; font-weight: 700; border: 0; border-radius: 8px;
  padding: 8px 16px; background: var(--accent); color: #26200e; cursor: pointer; }


/* ---------- ランキング: 自分のスコア強調 ---------- */
.rank-list li.mine {
  outline: 2px solid var(--accent);
  background: rgba(255, 167, 38, .14) !important;
  animation: minePulse 1.4s ease-in-out 3;
}
.rank-list li.rk-my::before { content: "👤"; }
@keyframes minePulse {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: 0 0 16px rgba(255, 167, 38, .75); }
}
@media (prefers-reduced-motion: reduce) {
  .rank-list li.mine { animation: none; }
}
