/* =========================================================
   NEKORONOMIKON — 実画像アーケード筐体 ＋ アトラクト→画面ズーム
   筐体画像(cabinet.webp 16:9)を contain 表示し、CRTの黒矩形に
   基準1024x768のゲームを等比フィット。スタートでカメラごとズーム。
   本番 style.css は無変更。これを後ろに重ねるだけ。
   ========================================================= */

:root {
  /* cabinet.webp 内の黒いモニター面の外接矩形（実測 740,333,440,318 / 1920x1080） */
  --scr-x: 38.542%;
  --scr-y: 30.833%;
  --scr-w: 22.917%;
  --scr-h: 29.444%;
}

html, body { height: 100%; overflow: hidden; }
body { background: #050608 radial-gradient(ellipse 120% 100% at 50% 40%, #0c0e16 0%, #050608 70%); }

/* CRT演出オーバーレイは筐体方式では使わない（画面rect内に自前で出す） */
.crt { display: none; }

/* カメラ（ズーム対象） */
.cam {
  position: fixed; inset: 0;
  transform-origin: 0 0;
  transition: transform 0.8s cubic-bezier(.62,.02,.2,1);
  will-change: transform;
}

/* 筐体画像をビューポート全面にcover表示（全画面）。背面=暗い室内(画像読込前/ズーム時の保険） */
.cab-wrap {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse 80% 75% at 50% 42%, #15151f 0%, #070709 100%);
}
/* ★前面フレーム：AI生成の正面筐体（スクリーン部分=透過穴）を最前面にcoverで重ね、
   コンテンツのはみ出しをベゼルでマスク（トップ画面のみ。ズーム時は非表示）。
   PC=16:9喫茶店シーン横長 / モバイル=縦型筐体(media query で差替) */
.cab-wrap::after {
  content: ''; position: absolute; inset: 0; z-index: 10; pointer-events: none;
  background: url('../assets/images/ui/cabinet-wide-frame.webp?v=202606141530') center / cover no-repeat;
  transition: opacity .4s;
}
body.is-play .cab-wrap::after { opacity: 0; }   /* クリック拡大時は外して通常ページに */

/* スクリーン枠 = 筐体画像の全面を覆うクリップ層（コンテンツの座標系＝cab-wrap） */
.cab-screen {
  position: absolute; inset: 0;
  overflow: hidden;
  background: transparent;
}

/* ゲーム本体スケーラ：基準1024x768 → JSが transform を設定
   トップ=matrix3d(台形に合わせる) / クリック拡大=translate+scale(正対)。切替はcam同様0.8sで補間（画面がこちらを向く演出） */
.game-scaler {
  position: absolute; top: 0; left: 0;
  width: 1024px; height: 768px;
  transform-origin: 0 0;
  transition: transform 0.8s cubic-bezier(.62,.02,.2,1);
  pointer-events: none;            /* アトラクト中はゲーム非操作（表示のみ） */
}
/* CRTの走査線＋ふち暗：コンテンツと一緒に台形変形させる */
.game-scaler::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 50;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.16) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse 100% 100% at 50% 50%, transparent 72%, rgba(0,0,0,.45) 100%);
  mix-blend-mode: multiply;
}
body.is-play .game-scaler { pointer-events: auto; }  /* ズーム後に操作可 */

/* v3ゲームの全画面前提を「スケーラ内」に閉じ込める */
.game-scaler .screen {
  position: absolute; inset: 0;
  min-height: 0; height: 100%;
  overflow-y: auto; overflow-x: hidden;
  /* 露骨なスクロールバーを隠す（スクロール機能は維持） */
  scrollbar-width: none;        /* Firefox */
  -ms-overflow-style: none;     /* 旧Edge/IE */
}
.game-scaler .screen::-webkit-scrollbar { width: 0 !important; height: 0 !important; display: none; } /* Chrome/Safari */
.game-scaler .hud { position: sticky; top: 0; z-index: 30; }
.game-scaler body[data-screen="boot"] .screen--boot::before,
body[data-screen="boot"] .game-scaler .screen--boot::before { position: absolute; inset: 0; }
.game-scaler .lightbox,
.game-scaler .mviewer,
.game-scaler .vmodal { position: absolute; inset: 0; }

/* アトラクト時のスタート誘導（画面の上にうっすら） */
.attract-cta {
  position: fixed; left: 50%; bottom: 6vh; transform: translateX(-50%);
  z-index: 200; text-align: center; pointer-events: none;
  font-family: 'Press Start 2P', monospace; color: #00E8D8;
  text-shadow: 0 0 12px #00E8D8, 0 2px 0 #000;
  font-size: clamp(10px, 1.4vw, 16px); letter-spacing: .12em;
  animation: blink 1.1s steps(2, start) infinite;
}
.attract-cta small { display:block; margin-top:.7em; color:#F8D878; font-size:.7em; text-shadow:0 0 8px #F8D878,0 2px 0 #000; }
/* ズーム後は blink アニメが opacity:0 を上書きして点滅し続ける→アニメも停止 */
body.is-play .attract-cta { opacity: 0; animation: none; transition: opacity .3s; }
@keyframes blink { 50% { opacity: .25; } }

/* 戻る（プレイ時のみ） */
.exit-cab {
  position: fixed; top: 14px; left: 14px; z-index: 300;
  display: none; align-items: center; gap: 8px;
  font-family: 'Press Start 2P', monospace; font-size: 10px;
  color: #FCFCFC; background: rgba(8,10,16,.8); border: 1px solid #00E8D8;
  padding: 10px 14px; cursor: pointer; letter-spacing: .1em;
  text-shadow: 0 0 6px #00E8D8;
}
.exit-cab:hover { background:#00E8D8; color:#000; }
/* EXIT は「ライブラリ画面」のときだけ表示（ステージはゲームの◀LIBRARYで戻る＝重なり回避） */
body.is-play[data-screen="library"] .exit-cab { display: inline-flex; }

/* ===== モバイル/狭幅 ===== */
@media (max-width: 820px) {
  /* --- アトラクト: 筐体を画面いっぱい(cover)に表示・タップで中身へ --- */
  body:not(.is-play) .cam { position: fixed; inset: 0; display: block; transform: none !important; }
  body:not(.is-play) .cab-wrap {
    position: absolute; inset: 0; width: auto; height: auto; aspect-ratio: auto;
    background: radial-gradient(ellipse 80% 75% at 50% 42%, #15151f 0%, #070709 100%);
    filter: none;
  }
  body:not(.is-play) .cab-wrap::after {
    display: block !important;
    background: url('../assets/images/ui/cabinet-front-frame.webp?v=202606141500') center / cover no-repeat;
  }
  body:not(.is-play) .cab-screen { position: absolute; inset: 0; overflow: hidden; }
  body:not(.is-play) .game-scaler { position: absolute; top: 0; left: 0; width: 1024px; height: 768px; }

  /* --- タップ後: 中身を全画面 --- */
  /* html height:100% を解除し「文書そのもの」を自然にスクロールさせる。
     旧 overflow:auto は html(height:100%)を固定高スクロール箱にしてしまい、
     縦に長いステージの下部がクリップされ到達不能だった → height:auto + overflow:visible */
  html:has(body.is-play), body.is-play { height: auto !important; overflow: visible !important; overflow-x: hidden; }
  body.is-play .cam { position: static; display: block; transform: none !important; }
  /* min-height:100dvh は .screen 側が担保。ここで重ねると上方向の余白積み増しの一因になるため外す */
  body.is-play .cab-wrap { position: static; width: 100%; aspect-ratio: auto; min-height: 0; background: none; filter: none; }
  body.is-play .cab-wrap::after { display: none !important; }
  body.is-play .cab-screen { position: static; width: 100%; height: auto; }
  body.is-play .game-scaler::after { display: none; }
  body.is-play .game-scaler { position: static; width: 100%; height: auto; transform: none !important; }
  /* 画面は必ず上詰め。LIBRARY等の justify-content:center は縦長端末で
     コンテンツを画面中央へ押し下げ「下までスクロールしないと見えない」原因になる */
  body.is-play .game-scaler .screen { position: relative; min-height: 100dvh; height: auto; justify-content: flex-start; }
  body.is-play .game-scaler .hud { position: sticky; }
  body.is-play .crt { display: block; } /* タップ後は従来CRT演出 */

  .attract-cta, .exit-cab { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .cam { transition: none; }
  .attract-cta { animation: none; }
}

/* =========================================================
   棚カセット = リッチなジャケ写カバー（cabinet版のみ／本番style.css無変更）
   ========================================================= */
.game-scaler .cart__icon { display: none; }
.game-scaler .cart__label {
  position: relative;
  padding: 0;
  gap: 0;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background-size: cover;
  background-position: center;
  border-color: rgba(0, 0, 0, 0.45);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.12);
}
.game-scaler .cart[data-key="movie"]     .cart__label { background-image: url('../assets/images/carts/cart-movie.webp?v=202606131640'); }
.game-scaler .cart[data-key="illust"]    .cart__label { background-image: url('../assets/images/carts/cart-illust.webp?v=202606131640'); }
.game-scaler .cart[data-key="game"]      .cart__label { background-image: url('../assets/images/carts/cart-game.webp?v=202606131640'); }
.game-scaler .cart[data-key="education"] .cart__label { background-image: url('../assets/images/carts/cart-study.webp?v=202606131640'); }
.game-scaler .cart[data-key="manga"]     .cart__label { background-image: url('../assets/images/carts/cart-manga.webp?v=202606131640'); }
.game-scaler .cart[data-key="web"]       .cart__label { background-image: url('../assets/images/carts/cart-web.webp?v=202606131640'); }
.game-scaler .cart[data-key="connect"]   .cart__label { background-image: url('../assets/images/carts/cart-connect.webp?v=2026062103'); }
.game-scaler .cart[data-key="profile"]   .cart__label { background-image: url('../assets/images/profile.jpg?v=202606131546'); background-position: center top; }
/* 下部グラデ＋名前/枚数オーバーレイ */
.game-scaler .cart__label::after {
  content: ''; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: linear-gradient(transparent 52%, rgba(0,0,0,.88) 100%);
}
.game-scaler .cart__name {
  position: absolute; left: 6px; right: 6px; bottom: 22px; z-index: 2;
  text-shadow: 0 1px 4px #000, 0 0 8px rgba(0,0,0,.8);
}
.game-scaler .cart__count {
  position: absolute; left: 6px; right: 6px; bottom: 7px; z-index: 2;
  filter: brightness(1.9);
  text-shadow: 0 1px 4px #000;
}

/* =========================================================
   1024×768基準内に全オブジェクトを収める（vw由来のはみ出し対策）
   ========================================================= */
/* ライブラリを768px基準に収める。元凶2つ:
   ①.screen--library の padding:70px/70px(上下140px占有) → 圧縮
   ②.library__deck が position:fixed;bottom:0 でdialog(メッセージ欄)を上から覆って潰していた → in-flow化 */
.game-scaler .screen--library { padding: 8px 16px 8px; gap: 6px; }
.game-scaler .library__sub { margin-top: 3px; }
.game-scaler .library__deck { position: static; padding: 6px 14px; }
/* 棚：vw幅をやめ、基準内に収める */
.game-scaler .shelf {
  width: 94%;
  max-width: 980px;
  padding: 14px;
}
.game-scaler .shelf__row { gap: 14px; }
/* カセットを少し小さく＝8枚が画面内に収まる */
.game-scaler .cart { padding: 7px 7px 0; gap: 5px; }
.game-scaler .cart__label { aspect-ratio: 5 / 6; }
.game-scaler .cart::after { height: 8px; margin-top: 3px; }
.game-scaler .cart__name { bottom: 18px; }
.game-scaler .cart__count { bottom: 5px; }
/* マーキー/ダイアログをコンパクトに（メッセージ欄が潰れない・縦に収める） */
.game-scaler .library__marquee { padding-top: 2px; padding-bottom: 2px; }
.game-scaler .dialog { margin-top: 0; min-height: 0; padding: 6px 12px; gap: 10px; }
.game-scaler .dialog__face { font-size: 1.2rem; line-height: 1.2; }
.game-scaler .dialog__text { line-height: 1.45; }

/* ステージ/プロフィール/マニュアル本文：min(1060px,94vw)のvw基準が
   1024pxスクリーンをはみ出し右端が切れる → 基準内(%)に収める */
.game-scaler .stage__body,
.game-scaler .profile__body,
.game-scaler .manual__body {
  width: 94%;
  max-width: 980px;
}
/* グリッドのgap/カードもvw由来の膨張を抑え、基準内で破綻させない */
.game-scaler .stage__grid { gap: 16px; }
.game-scaler .stage__extra { gap: 14px; }

/* ステージ見出しのリッチエンブレム（カセット絵） */
.game-scaler .stage__icon.rich-emblem {
  width: 84px; height: 112px;
  object-fit: cover;
  image-rendering: auto;
  border-radius: 7px;
  border: 2px solid rgba(255,255,255,.25);
  box-shadow: 0 0 22px rgba(0,0,0,.7), 0 4px 14px rgba(0,0,0,.6);
}

/* タイトルロゴ（NEKORONOMIKON）— ピクセル化を解除して鮮明に */
.game-scaler .title__logo { image-rendering: auto; width: clamp(220px, 42%, 420px); height: auto; }
/* プロフィールのリッチ黒猫ヒーロー */
.game-scaler .profile__photo.rich-hero {
  width: 132px; height: 176px;
  object-fit: cover;
  image-rendering: auto;
  border-radius: 8px;
  border: 2px solid rgba(0,232,216,.5);
  box-shadow: 0 0 26px rgba(0,232,216,.35), 0 6px 16px rgba(0,0,0,.6);
}

/* タイトル画面の背景にリッチなKVを敷く */
.game-scaler .screen--title {
  background-image:
    linear-gradient(rgba(5,6,14,.55), rgba(5,6,14,.78)),
    url('../assets/images/ui/title-kv.webp?v=202606131710');
  background-size: cover; background-position: center;
}

/* =========================================================
   漫画ビューワーを筐体スケーラ(1024×768基準)に正しく収める
   ・page の max-height が 100vh 依存で溢れる → コンテナ基準(%)へ
   ・背後(タイトル/ステージ)の透けを断つ＝背景を完全不透明に
   ========================================================= */
.game-scaler .mviewer { background: #000; }
.game-scaler .mviewer__bar { padding: 8px 14px; }            /* バーを薄く＝ページ領域を広げる */
.game-scaler .mviewer__stage { min-height: 0; padding: 6px 10px; }
.game-scaler .mviewer__page {
  max-height: 100%;
  max-width: 96%;
  height: auto;
  width: auto;
}
.game-scaler .mviewer__hint { padding: 3px 12px 5px; font-size: .72rem; }

/* ビューワー等モーダルが開いている間は、.cam(transform)より前面に描画される
   アトラクトCTA(PRESS START/INSERT COIN)を確実に隠す（透け対策） */
body:has(.game-scaler .mviewer.is-open) .attract-cta,
body:has(.game-scaler .lightbox.is-open) .attract-cta,
body:has(.game-scaler .vmodal.is-open) .attract-cta { display: none !important; }

/* =========================================================
   注目サイト＝アーケード「ENTER SITE」ギミックカード
   （WEBステージ EXTERNAL LINKS の feat 指定リンク）
   光る筐体＋点滅ENTER＋ホバー電源ON演出で、ライブサイトへ誘導
   ＝「その先のページも見たくなる」仕掛け
   ========================================================= */
.game-scaler .work--feat {
  border-color: #00E8D8 !important;
  box-shadow: 0 0 0 2px rgba(0,232,216,.55), 0 0 22px rgba(0,232,216,.42);
  animation: featPulse 1.7s ease-in-out infinite;
}
@keyframes featPulse { 50% { box-shadow: 0 0 0 2px rgba(0,232,216,.95), 0 0 36px rgba(0,232,216,.78); } }
.game-scaler .work--feat .work__img { transition: filter .25s, transform .25s; }
/* 画像領域に重なる ENTER プレート：既定は下端、ホバーで中央＋拡大＝起動感 */
.game-scaler .work--feat .work__enter {
  position: absolute; top: 0; left: 0; right: 0;
  aspect-ratio: 16 / 9;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 10px; z-index: 3; pointer-events: none;
  transition: background .25s;
}
.game-scaler .work--feat .work__enter b {
  font-family: 'Press Start 2P', monospace; font-weight: normal;
  font-size: 10px; letter-spacing: .06em; color: #FCFCFC;
  background: rgba(4,8,10,.64); border: 1px solid rgba(0,232,216,.55);
  border-radius: 4px; padding: 7px 9px;
  text-shadow: 0 0 8px #00E8D8, 0 1px 0 #000;
  animation: blink 1.15s steps(2,start) infinite;
  transition: font-size .2s;
}
.game-scaler .work--feat:hover { transform: translateY(-6px) scale(1.015); }
.game-scaler .work--feat:hover .work__img { filter: brightness(.58); }
.game-scaler .work--feat:hover .work__enter { align-items: center; background: rgba(2,6,8,.32); }
.game-scaler .work--feat:hover .work__enter b { font-size: 12px; }
/* NEW バッジを点滅シアンで強調 */
.game-scaler .work--feat .work__badge { background: #00E8D8; color: #002320; animation: blink 1.5s steps(2,start) infinite; }
@media (prefers-reduced-motion: reduce) {
  .game-scaler .work--feat,
  .game-scaler .work--feat .work__enter b,
  .game-scaler .work--feat .work__badge { animation: none; }
}
