/* ============================================================
   論文怪獣 | RONBUN KAIJU — R・K LAB 収容データベース
   ポケポケ風ダークUI / ポケカ比率(63:88)カード / CSS 3Dパック開封
   ============================================================ */

:root {
  --bg: #0a0b10;
  --panel: #14161f;
  --panel2: #1b1e2a;
  --line: #272b3a;
  --text: #e9eaf0;
  --dim: #9aa0b2;
  --accent: #fe0000;                 /* R・K公式の赤 (支給ロゴから採色) */
  --accent-soft: rgba(254, 0, 0, 0.14);
  /* 末尾の Helvetica/Arial は記号(> < 等)が絵文字フォントに落ちるのを防ぐ保険 */
  --jp: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", Helvetica, Arial, sans-serif;
  --eu: "Michroma", "Zen Kaku Gothic New", Helvetica, Arial, sans-serif;
  --tabbar-h: 62px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--jp);
  background:
    radial-gradient(1200px 500px at 50% -100px, #171a28 0%, var(--bg) 60%) fixed,
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }
.rk-hole { fill: var(--hole, var(--bg)); }

/* ---------------- スプラッシュ ---------------- */
.splash {
  position: fixed; inset: 0; z-index: 100;
  background: #06070b;
  display: grid; place-items: center;
  transition: opacity 0.7s;
}
.splash.hide { opacity: 0; pointer-events: none; }
.splash-inner { text-align: center; animation: splash-in 1s ease both; }
.splash-logo { width: 76px; height: auto; animation: pulse 2s infinite; }
.splash-lab { font-family: var(--eu); font-size: 10px; letter-spacing: 0.35em; color: var(--dim); margin: 18px 0 8px; }
.splash-mark { font-size: 46px; font-weight: 900; letter-spacing: 0.12em; }
.splash-sub { font-family: var(--eu); font-size: 13px; letter-spacing: 0.5em; color: var(--accent); margin-top: 6px; }
.splash-note { font-size: 11px; color: var(--dim); margin-top: 26px; letter-spacing: 0.08em; }
@keyframes splash-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* ---------------- ヘッダー ---------------- */
.site-header { padding: calc(14px + env(safe-area-inset-top)) 18px 10px; }
.brand { display: flex; align-items: center; gap: 12px; max-width: 1100px; margin: 0 auto; }
.brand-logo { width: 31px; height: auto; flex: none; }
.logo { font-size: 22px; font-weight: 900; letter-spacing: 0.1em; line-height: 1.1; }
.tagline { font-family: var(--eu); font-size: 9px; letter-spacing: 0.18em; color: var(--dim); margin-top: 3px; }
.nw { white-space: nowrap; }  /* 狭い画面で語の途中 (「収容データベ / ース」「回 / 転」) で折り返さない */
.pwa-btn {
  margin-left: auto; background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-size: 12px;
}

main { max-width: 1100px; margin: 0 auto; padding: 0 14px; }
.view-title { font-size: 20px; font-weight: 900; letter-spacing: 0.06em; }
.view-sub { font-size: 12px; color: var(--dim); margin-top: 4px; }

/* ---------------- 検索・チップ ---------------- */
.controls { padding: 6px 2px 14px; }
#search {
  /* 16px未満だとiOS Safariがフォーカス時にページ全体をズームしてしまう */
  width: 100%; padding: 11px 16px; font-size: 16px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; outline: none;
}
#search:focus { border-color: var(--accent); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.chip {
  background: var(--panel); color: var(--dim); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 13px; font-size: 12px;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.count { font-family: var(--eu); font-size: 10px; letter-spacing: 0.15em; color: var(--dim); margin-top: 10px; }
.empty { text-align: center; color: var(--dim); padding: 40px 0; }

/* ---------------- 図鑑グリッド ---------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 14px;
}
.card-slot {
  container-type: inline-size;
  min-width: 0;
  cursor: pointer;
  transition: transform 0.18s;
  /* チルト/フリップの遠近感: perspectiveは直下の子(.kcard)にしか効かないため
     祖先(.detail-card等)ではなくカードの直親に置く */
  perspective: 1000px;
}
.grid .card-slot:hover { transform: translateY(-4px); }
.card-slot.big { cursor: default; }

/* ============================================================
   カード (表面はフロー資料1-1版の9部位構成 / 比率はポケカ63:88)
   ============================================================ */
.kcard {
  position: relative;
  width: 100%;
  aspect-ratio: 63 / 88;
  transform-style: preserve-3d;
  transform: rotateX(var(--rx, 0deg)) rotateY(calc(var(--ry, 0deg) + var(--flip, 0deg)));
  transition: transform 0.55s cubic-bezier(0.2, 0.75, 0.3, 1.05);
}
.kcard.tilting { transition: transform 0.08s linear; }
.kcard.flipped { --flip: 180deg; }
.k-face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 4.5cqw;
  overflow: hidden;
  box-shadow: 0 6cqw 14cqw rgba(0, 0, 0, 0.55);
}
.k-back { transform: rotateY(180deg); }
/* 保険: Safari は 3D 内の一部要素 (独立レイヤー化したもの) に backface-visibility が
   効かず、表面の要素が裏面に鏡文字で透けることがある。回転が 90° を越える瞬間
   (0.55s の easing で約 0.08s) に見えない側の面を visibility でも消す */
.k-face { transition: visibility 0s linear 0.08s; }
.kcard.flipped .k-front { visibility: hidden; }
.kcard:not(.flipped) .k-back { visibility: hidden; }

/* --- 表面 (IGEI支給カード枠デザイン準拠) --- */
.k-outer {
  position: absolute; inset: 0;
  background: #fff;                    /* 白い外枠 */
  display: flex; flex-direction: column; gap: 1.5cqw;
  padding: 2.2cqw;
}
.k-top {                                /* 黒フレーム(ネームバー+アート+テキスト) */
  flex: 1; min-height: 0;
  background: #0b0b0d;
  border-radius: 3.2cqw;
  padding: 1.8cqw 2cqw;
  display: flex; flex-direction: column;
  position: relative; overflow: hidden;
}
.k-namebar {                            /* 1.モンスター名 + 2.マーク (白バー) */
  flex: none;
  background: #fff;
  border-radius: 1.5cqw;
  min-height: 7.6cqw;
  display: flex; align-items: center;
  padding: 0.7cqw 0.9cqw 0.7cqw 2.6cqw;
  gap: 1.5cqw;
}
.k-name {
  color: #0b0b0d; font-weight: 900; letter-spacing: 0.1em;
  font-size: calc(4.1cqw * var(--fit, 1));  /* 長い名前は切らずに縮める */
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.k-name rt { font-size: 42%; font-weight: 700; letter-spacing: 0.04em; }  /* 読み仮名 */
.k-mark {                               /* 黒丸に白紋章 */
  flex: none; width: 6.2cqw; height: 6.2cqw;
  background: #0b0b0d; border-radius: 50%;
  display: grid; place-items: center;
}
.k-mark img { width: 4.4cqw; height: auto; display: block; }
.k-art {                                /* 3.モンスター画像 (正方形・白縁、素材比≒73%) */
  flex: none;
  width: 70cqw; aspect-ratio: 1 / 1;    /* 要約と図鑑文の行数を増やすため微縮小 */
  align-self: center;
  margin-top: 1.4cqw;
  position: relative; z-index: 0;       /* 収容名ピル(z-index:1)を常にアートより上に */
  background-color: #16161a;
  /* 画像は枠いっぱいに中央で切り抜く (cover)。正方形でない旧カード (768x1024 等) は
     上下が切れるが、余白は出さない (オーナー指定)。新パイプラインの 768x768 はそのまま収まる。
     画像URLは app.js が style の background-image で渡す (JPEG書き出しの html2canvas も同じ切り抜き) */
  background-size: cover; background-position: center; background-repeat: no-repeat;
  border: 0.55cqw solid #fff; border-radius: 1cqw;
}
.k-text {                               /* 4.論文要約 + 罫線 + 5.図鑑引用 */
  position: relative;
  flex: 1; min-height: 0; overflow: hidden;
  padding: 1.2cqw 0.7cqw 0.3cqw;
  display: flex; flex-direction: column;
}
.k-watermark {
  position: absolute; right: -4cqw; bottom: -6cqw;
  width: 30cqw; height: auto;
  opacity: 0.08;
}
/* 文字は切らずに、長い時だけ縮める (--fit はJSが文字数から算出して各要素に付ける) */
.k-summary {
  flex: 1; min-height: 0; overflow: hidden;
  color: #f2f2f4; line-height: 1.62;
  font-size: calc(2.62cqw * var(--fit, 1));
}
/* 罫線の下に余白を取り、図鑑文が2〜3行に跨っても収まるようにする。
   高さもcqwにしてあるのは、カード内が全て幅比で組まれていること(=一度測った
   縮小率がどの表示サイズでも通用すること)を崩さないため */
.k-sep { height: 0.2cqw; background: rgba(255, 255, 255, 0.85); margin: 0.6cqw 0.4cqw 2.2cqw; flex: none; }
/* 収容名ピル (IGEI支給カードモック 2026-08-27準拠: 淡黄ピル+右斜めエッジ)。
   .k-text (overflow:hidden) の中に置くと、アートに掛かる上端 (負の margin-top ぶん) が
   切れて字の頭が欠けるので、.k-top 直下 (アートと .k-text の間) に置く。
   位置は従来どおり: アート下端から 1.2cqw 上に掛かり、左右は .k-text の内側 0.7cqw */
.k-typebar {
  align-self: flex-start; flex: none; position: relative; z-index: 1;
  margin: -1.2cqw 0.7cqw 0.7cqw; padding: 0.4cqw 2.4cqw 0.5cqw 1.3cqw;
  color: #0b0b0d;
  font-size: 2.9cqw; font-weight: 800; line-height: 1.35; letter-spacing: 0.04em;
  border-radius: 0.5cqw;
  /* 右端の斜めエッジは clip-path ではなく背景グラデーションで描く。clip-path だと
     Safari が 3D (preserve-3d) 内で独立レイヤーにし、裏返しても鏡文字で透け、
     アート枠との重なり順も狂う (上端が隠れる)。JPEG書き出しでは html2canvas がこれを描けないので
     app.js の slantPillForExport が同じ形の画像に差し替える (色・帯幅 1.7cqw を変えたらそちらも) */
  background:
    linear-gradient(to bottom right, #e9e3a6 calc(50% - 0.4px), transparent calc(50% + 0.4px)) right top / 1.7cqw 100% no-repeat,
    linear-gradient(#e9e3a6, #e9e3a6) left top / calc(100% - 1.7cqw + 0.5px) 100% no-repeat;
}
/* ピルの下余白(0.7cqw)が要約との間隔になる (従来の .k-text 上パディング込みの位置と同じ) */
.k-typebar + .k-text { padding-top: 0; }
.k-dex {
  /* 図鑑文は2行ぶんを常に確保 (長い時は--fitで縮めて2行に収める)。
     高さを固定することで、上の要約に配分される高さもカード間で一定になる */
  flex: none; height: 6.9cqw; overflow: hidden;
  color: #e6e6ea; line-height: 1.5;
  font-size: calc(2.25cqw * var(--fit, 1));
  text-align: right;
}
.k-cite {                               /* 6.論文引用情報 + 7.QRコード (白帯) */
  flex: none;
  display: flex; align-items: center; gap: 1.8cqw;
  min-height: 9.6cqw; padding: 0 0.8cqw;
}
.k-doc { width: 5.8cqw; height: auto; flex: none; }
.k-cite-text {
  font-family: var(--eu); font-size: 2.15cqw; line-height: 1.55;
  color: #0b0b0d; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* 人が書いたカードのクレジット (絵/命名/要約): 論文情報の空きスペースを使う */
.k-credit {
  font-family: var(--jp); font-size: 1.95cqw; color: #3a3a42;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.k-qr {
  width: 9.4cqw; height: 9.4cqw; margin-left: auto; flex: none;
  image-rendering: pixelated;
}
.k-foot {                               /* 8.GENピル + 9.©表記 (黒フッター) */
  flex: none; min-height: 10.4cqw;
  background: #0b0b0d; border-radius: 3.2cqw;
  display: flex; align-items: center; justify-content: space-between; gap: 1.6cqw;
  padding: 1.5cqw 2cqw;
}
.k-gen {
  flex: none;
  border: 0.35cqw solid #fff; border-radius: 999px;
  padding: 0.8cqw 1.7cqw;
  font-family: var(--eu); font-size: 2cqw; letter-spacing: 0.04em; color: #fff;
  white-space: nowrap;
}
.k-company {
  font-family: Georgia, "Times New Roman", serif; font-weight: 700;
  font-size: 1.7cqw; line-height: 1.55; color: #fff; text-align: right;
}

/* --- 裏面 (カードキー兼データベース) --- */
.kb-inner {
  position: absolute; inset: 0;
  background:
    radial-gradient(120% 90% at 50% 20%, #16161c 0%, #0b0b0d 65%);
  border: 2cqw solid #0b0b0d;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1.6cqw; text-align: center;
}
.kb-hazard {
  position: absolute; top: 0; left: 0; right: 0; height: 3.4cqw;
  background: repeating-linear-gradient(-45deg, var(--accent) 0 4cqw, #0b0b0d 4cqw 8cqw);
  opacity: 0.85;
}
.kb-logo { width: 26cqw; height: auto; }
.kb-title { font-size: 8.4cqw; font-weight: 900; letter-spacing: 0.16em; color: #f0f0f4; margin-top: 1cqw; }
.kb-en { font-family: var(--eu); font-size: 3cqw; letter-spacing: 0.5em; color: var(--accent); }
.kb-held { font-family: var(--eu); font-size: 2cqw; letter-spacing: 0.22em; color: #7e8290; margin-top: 4cqw; }
.kb-access {
  position: absolute; bottom: 4cqw; left: 6cqw; right: 6cqw;
  display: flex; align-items: center; justify-content: space-between;
}
.kb-access > span:first-child { font-family: var(--eu); font-size: 2.6cqw; letter-spacing: 0.2em; color: #d8d9e0; }
.kb-barcode {
  width: 34cqw; height: 5cqw;
  background: repeating-linear-gradient(90deg,
    #d8d9e0 0 0.7cqw, transparent 0.7cqw 1.6cqw, #d8d9e0 1.6cqw 2cqw, transparent 2cqw 3.4cqw);
}

/* --- ホロ(キラ)演出: 全カード共通の装飾。レアリティ概念はなし --- */
/* 光沢: 指の位置に沿って走る柔らかいハイライト+ごく淡い虹。
   color-dodgeは白飛びして不自然だったため overlay + 低不透明度に変更。 */
.foil {
  position: absolute; inset: 0; z-index: 3;
  border-radius: 4.5cqw;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(60% 45% at var(--fx, 50%) var(--fy, 50%),
      rgba(255, 255, 255, 0.34) 0%, rgba(255, 255, 255, 0.10) 40%, rgba(255, 255, 255, 0) 72%),
    linear-gradient(105deg,
      rgba(255, 150, 190, 0.10) calc(var(--fx, 50%) - 30%),
      rgba(150, 210, 255, 0.12) var(--fx, 50%),
      rgba(180, 255, 215, 0.09) calc(var(--fx, 50%) + 22%));
  mix-blend-mode: overlay;
  transition: opacity 0.35s ease;
}
.kcard.tilting .foil { opacity: 1; }
.kcard.revealed .foil { animation: holo-sweep 1.2s ease-out; }
@keyframes holo-sweep {
  0% { opacity: 0; }
  40% { opacity: 0.85; }
  100% { opacity: 0; }
}

/* ---------------- 詳細モーダル ---------------- */
.detail-modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(5, 6, 10, 0.82);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex;                      /* margin:autoで中央寄せ: 縦長でも先頭が切れずスクロールできる */
  /* ホーム画面アプリ (viewport-fit=cover) ではステータスバー/ホームバーの下に潜らない */
  padding: max(18px, env(safe-area-inset-top, 0px)) max(18px, env(safe-area-inset-right, 0px)) max(18px, env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px));
  overflow-y: auto;
  animation: fade-in 0.2s;
}
.detail-box { margin: auto; }
@keyframes fade-in { from { opacity: 0; } }
.detail-box {
  position: relative;
  display: flex; gap: 26px; align-items: flex-start;
  max-width: 860px; width: 100%;
  background: var(--panel);
  border: 1px solid var(--line); border-radius: 20px;
  padding: 26px;
}
/* 閉じる「×」: 指で押せる 44px 角 */
.detail-x, .modal-close {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  width: 44px; height: 44px; display: grid; place-items: center; padding: 0;
  background: none; border: none; border-radius: 999px;
  color: var(--dim); font: inherit; font-size: 26px; line-height: 1;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.detail-x:focus-visible, .modal-close:focus-visible { outline: 2px solid #fff; outline-offset: -4px; }
@media (hover: hover) { .detail-x:hover, .modal-close:hover { color: var(--text); background: rgba(255, 255, 255, 0.08); } }
/* スマホ (縦積み): カードが「×」の下から始まるよう上の余白を広げる (×がカードの角に被らない) */
@media (max-width: 640px) { .detail-box { padding-top: 52px; } }
/* 横並び: 長い怪獣名が右上の「×」の下に潜らないように */
@media (min-width: 641px) { .detail-info h2 { padding-right: 26px; } }
.detail-card { flex: none; width: min(330px, 42vw); perspective: 1000px; }
.detail-card .card-slot { width: 100%; }
.flip-btn { margin-top: 14px; }   /* 見た目は .btn .btn-secondary */
.detail-info { flex: 1; min-width: 0; }
.d-label { font-family: var(--eu); font-size: 9px; letter-spacing: 0.3em; color: var(--accent); margin: 14px 0 6px; }
.d-label:first-child { margin-top: 0; }
.detail-info h2 { font-size: 24px; font-weight: 900; letter-spacing: 0.04em; }
.detail-en { font-family: var(--eu); font-size: 11px; letter-spacing: 0.12em; color: var(--dim); margin-top: 4px; }
.detail-dex { font-size: 13px; color: var(--dim); line-height: 1.7; margin-top: 10px; }
.detail-paper { font-size: 12px; color: var(--dim); line-height: 1.55; }
.detail-doi { font-size: 11px; color: var(--dim); margin-top: 5px; word-break: break-all; }
.detail-doi a { color: var(--accent); text-decoration: none; }
.detail-doi a:hover { text-decoration: underline; }
.detail-credit { font-size: 11px; color: var(--dim); margin-top: 6px; }
.detail-headline { font-size: 15px; font-weight: 900; margin-top: 10px; }
.detail-variant {
  display: inline-block; margin-top: 8px; padding: 3px 10px;
  font-size: 11px; letter-spacing: 0.06em; color: var(--dim);
  border: 1px solid var(--line); border-radius: 999px;
}
/* 個体特性 (personality_balance) の6軸バー */
.detail-stats { display: grid; gap: 5px; margin: 6px 0 4px; }
.stat-row { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--dim); }
.stat-name { width: 64px; flex: none; }
.stat-bar { flex: 1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.stat-fill { display: block; height: 100%; background: var(--text); border-radius: 3px; }
.stat-val { width: 26px; flex: none; text-align: right; font-variant-numeric: tabular-nums; }
/* マスターラフ画 (docs/ref/ — 新世代カードのみ) */
.detail-ref {
  width: 100%; margin-top: 4px;
  border: 1px solid var(--line); border-radius: 8px;
}
.detail-summary { font-size: 13px; line-height: 1.8; margin-top: 6px; }
.detail-meta { font-size: 11px; color: var(--dim); margin-top: 12px; }
.detail-actions { margin-top: 22px; }   /* .btn-stack: 補助操作が上、主操作(論文を開く)が下 */

.mc-btn {
  display: inline-block;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 9px 18px; font-size: 13px; text-decoration: none;
  white-space: nowrap;
}
.mc-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.mc-btn.danger { color: #ff7d7d; border-color: #59333a; }
.mc-btn:hover { filter: brightness(1.12); }

/* デッキ選択 (シート内の選択肢リスト) */
.picker-list { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.picker-item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  width: 100%; min-height: 56px; padding: 10px 18px;
  background: rgba(255, 255, 255, 0.05); color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.10); border-radius: 16px;
  font: inherit; font-size: 15px; font-weight: 700; text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, background-color 0.15s ease;
}
.picker-item:active { transform: scale(0.98); }
.picker-item:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
@media (hover: hover) { .picker-item:hover { background: rgba(255, 255, 255, 0.09); } }
.pi-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pi-n { flex: none; color: var(--dim); font-size: 13px; font-weight: 500; }

/* ---------------- タブバー ---------------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: flex; justify-content: center; gap: 4px;
  background: rgba(13, 14, 20, 0.92);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; max-width: 130px;
  background: none; border: none; color: var(--dim);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 0; border-radius: 12px; font-size: 11px;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent); font-weight: 700; }

/* ---------------- デッキ ---------------- */
.deck-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 2px 16px;
}
.deck-list { display: flex; flex-direction: column; gap: 12px; }
.deck-item {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px 16px;
}
.deck-fan { position: relative; width: 96px; height: 84px; flex: none; }
.fan-card, .fan-empty {
  position: absolute; top: 4px; width: 52px; aspect-ratio: 63 / 88;
  background-color: var(--panel2);
  background-size: cover; background-position: center;
  border: 2px solid #101013; border-radius: 5px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}
.fan-card.f0 { left: 0; transform: rotate(-10deg); }
.fan-card.f1 { left: 20px; transform: rotate(2deg); z-index: 1; }
.fan-card.f2 { left: 40px; transform: rotate(13deg); z-index: 2; }
.deck-info { min-width: 120px; }
.deck-name { font-size: 15px; font-weight: 700; }
.deck-count { font-size: 12px; color: var(--dim); margin-top: 3px; }
.deck-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }

.builder-head { padding: 8px 0 6px; }
#bd-name {
  display: block; width: 100%; height: 52px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px; padding: 0 16px;
  font: inherit; font-size: 16px; /* iOSのフォーカス時ズーム防止 */
  outline: none;
}
#bd-name:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(254, 0, 0, 0.22); }
/* 戻る/保存: スクロールしても常に押せるよう、タブバーの上に浮かせる */
.builder-bar {
  position: sticky; z-index: 6;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 10px);
  max-width: 480px; margin: 18px auto 0;
  padding: 10px;
  background: #10121a;
  border: 1px solid var(--line); border-radius: 38px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.6);
}
.select-grid { margin-top: 14px; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
.selectable { position: relative; }
.sel-badge {
  position: absolute; top: -7px; right: -7px; z-index: 5;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: none; place-items: center;
  font-size: 15px; font-weight: 900;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
/* チェックマーク: 絵文字化しないようCSSの罫線で描く */
.sel-badge::before {
  content: "";
  width: 9px; height: 5px;
  border-left: 2.4px solid #fff; border-bottom: 2.4px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px);
}
.selectable.selected .sel-badge { display: grid; }
.selectable.selected .kcard { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4.5cqw; }

/* ---------------- パック開封 ---------------- */
/* 保険: 袋のはみ出し描画でページに横スクロールを出さない
   (clipはhiddenと違いスクロールコンテナを作らないので縦の挙動は変わらない) */
#view-pack { overflow-x: clip; overflow-y: visible; }
.pack-select { text-align: center; padding: 10px 0 30px; }
.pack-shelf {
  display: flex; justify-content: center; gap: 26px; flex-wrap: wrap;
  margin-top: 26px; perspective: 900px;
}
.pack-choice {
  background: none; border: none; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  transition: transform 0.2s;
}
.pack-choice:hover { transform: translateY(-6px); }
/* 3D描画のcanvasは袋より一回り大きい(回転・開封のはみ出しぶん)ので、
   狭い画面では袋自体を縮めて2つ並べても横スクロールが出ないようにする */
.pack-choice .pouch3d { --pw: min(168px, 38vw); pointer-events: none; }
.pack-choice .pouch { animation: shelf-sway 5s ease-in-out infinite; }
.pack-choice:nth-child(2) .pouch { animation-delay: -2.5s; }
@keyframes shelf-sway {
  0%, 100% { transform: rotateY(-9deg) rotateX(2deg); }
  50% { transform: rotateY(9deg) rotateX(-2deg); }
}
.pack-label { font-size: 14px; font-weight: 700; display: block; }
.pack-label small { display: block; font-size: 11px; color: var(--dim); font-weight: 400; margin-top: 3px; }
.pack-note { font-size: 11px; color: var(--dim); margin-top: 26px; }

/* --- 梱包袋 (pouch): IGEI支給画像(IMG_5917)の実測比を再現 --- */
.pouch3d { perspective: 900px; --red: #e8321e; }
.pouch {
  position: relative;
  width: var(--pw, 240px);
  aspect-ratio: 1 / 1.986;            /* 実測 849:1686 */
  transform-style: preserve-3d;
  transform: rotateY(var(--spin, 0deg));
  --u: calc(var(--pw, 240px) / 100);  /* 幅1%を1単位として全要素をスケール */
  --pd: calc(var(--u) * 7);           /* 袋の厚み */
}
.pouch-face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: calc(var(--u) * 2.2);
  overflow: hidden;
  color: var(--red);
  /* 素材の光沢フィルム: 縦方向のグラデ+左右のフィルム皺 */
  background:
    linear-gradient(90deg,
      rgba(120, 126, 140, 0.30) 0%, rgba(255, 255, 255, 0.95) 3%,
      rgba(206, 211, 220, 0.55) 6.5%, rgba(255, 255, 255, 0.9) 10%,
      rgba(232, 235, 240, 0.35) 14%, rgba(255, 255, 255, 0) 20%),
    linear-gradient(270deg,
      rgba(120, 126, 140, 0.26) 0%, rgba(255, 255, 255, 0.9) 3%,
      rgba(210, 215, 224, 0.5) 7%, rgba(255, 255, 255, 0.85) 11%,
      rgba(235, 238, 243, 0.3) 15%, rgba(255, 255, 255, 0) 21%),
    linear-gradient(180deg, #fdfdfe 0%, #ffffff 30%, #ffffff 70%, #f7f8fa 88%, #eef0f3 100%);
  box-shadow: 0 calc(var(--u) * 7) calc(var(--u) * 20) calc(var(--u) * -2) rgba(0, 0, 0, 0.6),
              inset 0 0 calc(var(--u) * 3) rgba(150, 158, 175, 0.18);
}
.pouch-front { transform: translateZ(calc(var(--pd) / 2)); }
.pouch-edge {                        /* 側面: 面の端とツライチで繋がる滑らかな箔面 */
  position: absolute; top: 0; height: 100%;
  width: var(--pd);
  border-radius: calc(var(--u) * 1) / calc(var(--u) * 2.2);
  background:
    /* 縦: 面の端と同じ回り込みトーン */
    linear-gradient(180deg, #cfd2da 0%, #e9ebef 12%, #dfe2e8 50%, #e6e8ed 88%, #c9ccd4 100%),
    #dfe2e8;
  background-blend-mode: normal;
  box-shadow: inset calc(var(--u) * 0.6) 0 calc(var(--u) * 1.2) rgba(255, 255, 255, 0.55),
              inset calc(var(--u) * -0.6) 0 calc(var(--u) * 1.2) rgba(96, 104, 122, 0.35);
}
.pouch-edge.left { left: calc(var(--pd) / -2); transform: rotateY(90deg); }
.pouch-edge.right { right: calc(var(--pd) / -2); transform: rotateY(90deg); }
.pouch-back {
  transform: rotateY(180deg) translateZ(calc(var(--pd) / 2));
  display: grid; place-items: center;
  /* 裏面はシルバー箔 (デザイナー指定) */
  background:
    linear-gradient(100deg,
      rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, 0.5) 44%,
      rgba(255, 255, 255, 0) 58%),
    repeating-linear-gradient(115deg,
      rgba(255, 255, 255, 0.12) 0 2px, rgba(120, 126, 140, 0.10) 2px 4px),
    linear-gradient(180deg,
      #cfd2da 0%, #eceef2 16%, #b8bcc7 38%, #e6e8ed 58%,
      #c3c7d0 78%, #dde0e6 100%);
}
.pouch-back .pouch-logo.dim {
  position: static; width: 42%; height: auto; margin: 0; opacity: 0.55;
  transform: none;                   /* 表面用のtranslateX(-50%)を打ち消して中央揃え */
  mix-blend-mode: multiply;
}
.pouch-back-held {
  position: absolute; bottom: 12%; left: 0; right: 0;
  font-family: var(--eu); font-weight: 700;
  font-size: calc(var(--u) * 2.6); letter-spacing: 0.14em;
  text-align: center; line-height: 2;
  color: #6d7280;
}

/* --- 実3Dパック (pack3d.js / models/pack.stl) ---
   GL時はCSSの3D変形・揺れを止め、--spin/--tear/--gx/--gyの値をGL側が毎フレーム読む */
.pouch.gl { transform: none; }
.pack-choice .pouch.gl { animation: none; }   /* 棚の揺れはGL側(autoSway)で回す */
.pouch-gl {
  position: absolute; left: -16%; top: -4%;
  width: 132%; height: 108%;
  display: block;
  filter: drop-shadow(0 calc(var(--u) * 6) calc(var(--u) * 8) rgba(0, 0, 0, 0.5));
}
.pouch.gl.open { animation: pouch-drop 0.7s ease-in 0.12s forwards; }

/* 静的な帯状シーン(素材のフィルム反射) — 傾けなくても常時ギラつく */
.pouch-sheen {
  position: absolute; inset: 0; z-index: 4; pointer-events: none;
  background: linear-gradient(100deg,
    rgba(255, 255, 255, 0) 38%, rgba(255, 255, 255, 0.4) 46%,
    rgba(222, 228, 238, 0.22) 50%, rgba(255, 255, 255, 0.45) 56%,
    rgba(255, 255, 255, 0) 64%);
  mix-blend-mode: screen; opacity: 0.5;
}

.pouch-crimp {                       /* 上下の圧着ギザ帯 (実測: 上0-3.6% / 下94-100%) */
  position: absolute; left: 0; right: 0; z-index: 3;
  background:
    repeating-linear-gradient(58deg, rgba(120, 128, 145, 0.30) 0 0.8px, rgba(255, 255, 255, 0) 0.8px 2.4px),
    repeating-linear-gradient(-58deg, rgba(120, 128, 145, 0.26) 0 0.8px, rgba(255, 255, 255, 0) 0.8px 2.4px),
    linear-gradient(180deg, #f2f3f6, #fbfbfd);
}
.pouch-crimp.top { top: 0; height: 3.6%; border-bottom: 1px solid rgba(180, 185, 196, 0.35); }
.pouch-crimp.bottom { bottom: 0; height: 4%; border-top: 1px solid rgba(180, 185, 196, 0.35); }

.pouch-hole {                        /* 吊り穴 (実測 cy 7.2%, 径 幅の10.4%) */
  position: absolute; top: 7.2%; left: 50%;
  transform: translate(-50%, -50%);
  width: 10.4%; aspect-ratio: 1; border-radius: 50%;
  background: #07080c; z-index: 8;   /* 膨らみ/シーン層より前面 (穴が灰色に見えないように) */
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.45),
              0 1px 1px rgba(255, 255, 255, 0.6);
  pointer-events: none;              /* 封(z6)の中央のタップを吸わない */
}

.pouch-seal {                        /* 開封スライダー(上部の広い当たり判定) */
  position: absolute; top: 0; left: 0; right: 0; height: 13%;
  z-index: 6;
  transform: translateX(calc(var(--tear, 0) * 108%)) rotate(calc(var(--tear, 0) * 6deg));
  transition: transform 0.25s ease-out;
  cursor: grab; touch-action: none;
  display: grid; place-items: end center;
}
.pouch.tearing .pouch-seal { transition: none; }
.seal-txt {
  font-family: var(--eu); font-weight: 700;
  font-size: calc(var(--u) * 2.6); letter-spacing: 0.14em;
  padding-bottom: 6%; opacity: 0.85;
}

.pouch-bar {                         /* TRADING CARD 赤帯 (y 16.3-20.2%, x 22.6-77.5%) */
  position: absolute; top: 16.3%; left: 22.6%; right: 22.5%; height: 3.9%;
  background: var(--red); color: #fff;
  font-family: "Zen Kaku Gothic New", Helvetica, Arial, sans-serif; font-weight: 900;
  font-size: calc(var(--u) * 5.6); letter-spacing: 0.005em;
  display: grid; place-items: center; white-space: nowrap;
  z-index: 2;
}
.pouch-care {                        /* 取扱注意 + REF + ◇! (y 23-26.5%) */
  position: absolute; top: 23%; left: 0; right: 0; height: 3.5%;
  display: flex; align-items: center; justify-content: center;
  gap: calc(var(--u) * 2.4);
  font-weight: 900; font-size: calc(var(--u) * 6.2); letter-spacing: 0.06em;
  z-index: 2;
}
.pc-ref {
  font-family: var(--eu); font-weight: 700;
  font-size: calc(var(--u) * 2.6); letter-spacing: 0.02em;
  border: calc(var(--u) * 0.45) solid var(--red); border-radius: 999px;
  padding: 0 calc(var(--u) * 1.4);
}
.pc-warn {                           /* 菱形の ! */
  position: relative;
  width: calc(var(--u) * 4.2); height: calc(var(--u) * 4.2);
  border: calc(var(--u) * 0.45) solid var(--red);
  transform: rotate(45deg);
}
.pc-warn::before, .pc-warn::after {
  content: ""; position: absolute; left: 50%; transform: translateX(-50%) ;
  background: var(--red); width: calc(var(--u) * 0.55);
}
.pc-warn::before { top: 18%; height: 42%; }
.pc-warn::after { bottom: 16%; height: calc(var(--u) * 0.55); border-radius: 50%; }

.pouch-logo {                        /* R・Kロゴ (実測 y29.4-64%, x17.4-76.6%) */
  position: absolute; top: 29.4%; height: 34.6%; width: auto;
  left: 47%; transform: translateX(-50%);
  z-index: 2;
}
.pouch-side {                        /* 左端の縦組み: ⊕ / MAX EXTD / INFRA */
  position: absolute; left: 2.2%; top: 37%;
  display: flex; flex-direction: column; align-items: center;
  gap: calc(var(--u) * 1.6); z-index: 2;
}
.pouch-globe {
  width: calc(var(--u) * 4); aspect-ratio: 1;
  border: calc(var(--u) * 0.4) solid var(--red); border-radius: 50%;
  background:
    linear-gradient(var(--red), var(--red)) center / 100% calc(var(--u) * 0.4) no-repeat,
    linear-gradient(var(--red), var(--red)) center / calc(var(--u) * 0.4) 100% no-repeat;
}
.pouch-stamp {
  display: flex; flex-direction: column; align-items: center;
  border: calc(var(--u) * 0.4) solid var(--red); border-radius: 999px;
  padding: calc(var(--u) * 1.2) calc(var(--u) * 0.5);
  font-family: var(--eu); line-height: 1.1;
}
.pouch-stamp i { font-style: normal; font-size: calc(var(--u) * 1.7); }
.pouch-stamp b {
  font-size: calc(var(--u) * 3.4); font-weight: 700;
  writing-mode: vertical-rl; letter-spacing: 0.06em;
}
.pouch-infra {
  writing-mode: vertical-rl; letter-spacing: 0.55em;
  font-family: var(--eu); font-size: calc(var(--u) * 2.4);
}

/* RONBUN KAIJU / 論文怪獣 / HELD IN は1つの縦積み (通常フロー) にする。以前はそれぞれ
   top 固定の絶対配置で、字形の上下位置がフォント (Webフォント未読込時の代替など) で変わり、
   KAIJU と 論文怪獣 が重なった。行高を明示したフローなので、どのフォントでも重ならない */
.pouch-names {                       /* 先頭 = RONBUN の行 (y 65.6%, x 25.4%) */
  position: absolute; top: 65.6%; left: 25.4%; right: 4%;
  display: flex; flex-direction: column; align-items: flex-start;
  z-index: 2;
}
.pouch-title {                       /* RONBUN KAIJU (y 67.2-74%) */
  font-family: "Zen Kaku Gothic New", Helvetica, Arial, sans-serif; font-weight: 900;
  font-size: calc(var(--u) * 10.6); line-height: 0.98; letter-spacing: -0.02em;
  transform: scaleX(0.94); transform-origin: left center;
}
.pouch-kanji {                       /* 論文怪獣 (y 75.6-79.6%): KAIJU との字の隙間 ≒ 3u (実測 Webフォント 2.9u / 代替フォント 3.4u) */
  margin: calc(var(--u) * 1.6) 0 0 calc(var(--u) * -0.2);
  font-size: calc(var(--u) * 10); font-weight: 900; letter-spacing: 0.02em; line-height: 1.1;
}
.pouch-held {                        /* HELD IN CONTAINMENT BY R・K LAB (y 81.6%) */
  margin-top: calc(var(--u) * 1.8);
  font-family: "Zen Kaku Gothic New", Helvetica, Arial, sans-serif; font-weight: 900;
  font-size: calc(var(--u) * 2.8); letter-spacing: 0.01em; line-height: 1.3;
}
.pouch-meta {                        /* 下部メタ列 (y 89.3-91.6%, x 16.3-68.6%) */
  position: absolute; top: 88.4%; left: 14%; right: 12%;
  display: flex; align-items: center; justify-content: space-between;
  gap: calc(var(--u) * 2);
  font-family: var(--eu); font-size: calc(var(--u) * 1.7); line-height: 1.55;
  z-index: 2;
}
.pm-reg {                            /* トンボ(+ + ○ + +) */
  display: grid; grid-template-columns: repeat(2, auto);
  gap: calc(var(--u) * 0.6) calc(var(--u) * 1.4);
  position: relative; padding: calc(var(--u) * 0.4);
}
.pm-reg i { font-style: normal; font-size: calc(var(--u) * 2); line-height: 1; }
.pm-ring {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: calc(var(--u) * 1.9); aspect-ratio: 1;
  border: calc(var(--u) * 0.35) solid var(--red); border-radius: 50%;
}
.pm-cert { display: flex; align-items: center; gap: calc(var(--u) * 1.2); }
.pm-e {
  display: inline-grid; place-items: center; flex: none;
  width: calc(var(--u) * 3.4); aspect-ratio: 1;
  border: calc(var(--u) * 0.35) solid var(--red); border-radius: 50%;
  font-weight: 700; font-size: calc(var(--u) * 2); line-height: 1;
}
.pm-pill {
  display: grid; place-items: center;
  width: calc(var(--u) * 6); height: calc(var(--u) * 2.6);
  border: calc(var(--u) * 0.35) solid var(--red); border-radius: 999px;
  font-size: calc(var(--u) * 2);
}
.pm-const { text-align: left; }

/* 開封アニメーション */
.pouch.open .pouch-seal {
  transition: transform 0.55s ease-in, opacity 0.55s;
  transform: translateX(150%) translateY(-70px) rotate(22deg);
  opacity: 0;
}
.pouch.open .pouch-face { animation: pouch-drop 0.7s ease-in 0.12s forwards; }
@keyframes pouch-drop {
  30% { transform: translateY(6px); }
  100% { transform: translateY(72vh) rotate(4deg); opacity: 0; }
}

/* 膨らみ: 中央の張り出しハイライト+縁の回り込み陰影+圧着際のくびれ+中のカード束の浮き */
.pouch-bulge {
  position: absolute; inset: 0; z-index: 4; pointer-events: none;
  background:
    /* 膨らみの頂点を走る広い縦シーン (実物のフィルム反射) */
    linear-gradient(90deg,
      rgba(255, 255, 255, 0) 26%, rgba(255, 255, 255, 0.34) 42%,
      rgba(255, 255, 255, 0.58) 50%, rgba(255, 255, 255, 0.34) 58%,
      rgba(255, 255, 255, 0) 74%),
    /* 中身のカード束が押し上げる浮き */
    radial-gradient(58% 40% at 50% 46%,
      rgba(255, 255, 255, 0.26), rgba(255, 255, 255, 0.08) 62%, rgba(255, 255, 255, 0) 78%),
    /* 胴全体の張り */
    radial-gradient(95% 62% at 50% 44%,
      rgba(255, 255, 255, 0.30), rgba(255, 255, 255, 0) 72%);
  mix-blend-mode: screen;
}
.pouch-bulge::after {
  content: ""; position: absolute; inset: 0;
  background:
    /* 圧着際のしわ筋 (上下から胴へ伸びる縦スジ) */
    repeating-linear-gradient(90deg,
      rgba(108, 116, 134, 0.16) 0 2px, rgba(255, 255, 255, 0) 2px 11px,
      rgba(108, 116, 134, 0.10) 11px 12px, rgba(255, 255, 255, 0) 12px 21px)
      top / 100% 11% no-repeat,
    repeating-linear-gradient(90deg,
      rgba(108, 116, 134, 0.14) 0 2px, rgba(255, 255, 255, 0) 2px 13px,
      rgba(108, 116, 134, 0.09) 13px 14px, rgba(255, 255, 255, 0) 14px 24px)
      bottom / 100% 10% no-repeat,
    /* 左右縁: 面が奥へ強く回り込む影 */
    linear-gradient(90deg,
      rgba(72, 80, 98, 0.46) 0%, rgba(110, 118, 136, 0.20) 6%,
      rgba(255, 255, 255, 0) 17% 83%,
      rgba(110, 118, 136, 0.20) 94%, rgba(72, 80, 98, 0.46) 100%),
    /* 上下: 圧着でつままれるくびれ影 */
    linear-gradient(180deg,
      rgba(90, 98, 116, 0.36) 0%, rgba(140, 148, 165, 0.14) 5%,
      rgba(255, 255, 255, 0) 12% 87%,
      rgba(140, 148, 165, 0.16) 93%, rgba(90, 98, 116, 0.38) 100%),
    /* 中身のカード束の稜線 */
    radial-gradient(64% 46% at 50% 46%,
      rgba(255, 255, 255, 0) 84%, rgba(105, 113, 132, 0.18) 92%, rgba(255, 255, 255, 0) 100%);
  mix-blend-mode: multiply;
}

/* --- ホロ反射+スパークル (指でなぞるとキラキラ) --- */
.pouch-glare {
  position: absolute; inset: 0; z-index: 5; pointer-events: none;
  opacity: 0; transition: opacity 0.3s;
  background:
    radial-gradient(46% 30% at var(--gx, 50%) var(--gy, 35%),
      rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0.18) 45%, rgba(255, 255, 255, 0) 75%),
    linear-gradient(105deg,
      rgba(255, 120, 170, 0.16) calc(var(--gx, 50%) - 30%),
      rgba(120, 200, 255, 0.18) var(--gx, 50%),
      rgba(170, 255, 205, 0.14) calc(var(--gx, 50%) + 20%));
  mix-blend-mode: screen;
}
.pouch.shine .pouch-glare { opacity: 1; }
.pouch-sparkle {
  position: absolute; inset: 0; z-index: 6; pointer-events: none;
  opacity: 0; transition: opacity 0.25s;
  background-image:
    radial-gradient(1.6px 1.6px at 12% 22%, #fff 55%, transparent 60%),
    radial-gradient(1.2px 1.2px at 34% 68%, #fff 55%, transparent 60%),
    radial-gradient(2px 2px at 55% 35%, #fff 55%, transparent 60%),
    radial-gradient(1.2px 1.2px at 71% 80%, #fff 55%, transparent 60%),
    radial-gradient(1.6px 1.6px at 86% 15%, #fff 55%, transparent 60%),
    radial-gradient(1.2px 1.2px at 24% 90%, #fff 55%, transparent 60%),
    radial-gradient(2px 2px at 92% 55%, #fff 55%, transparent 60%),
    radial-gradient(1.4px 1.4px at 45% 8%, #fff 55%, transparent 60%);
  background-size: 90px 110px;
  background-position: calc(var(--gx, 50%) * 0.25) calc(var(--gy, 50%) * 0.25);
  -webkit-mask-image: radial-gradient(30% 24% at var(--gx, 50%) var(--gy, 40%), #000 30%, transparent 75%);
  mask-image: radial-gradient(30% 24% at var(--gx, 50%) var(--gy, 40%), #000 30%, transparent 75%);
}
.pouch.shine .pouch-sparkle { opacity: 1; animation: twinkle 0.85s linear infinite; }
@keyframes twinkle {
  0%, 100% { filter: brightness(1) drop-shadow(0 0 2px rgba(255,255,255,0.8)); }
  50% { filter: brightness(2.1) drop-shadow(0 0 5px rgba(255,255,255,1)); }
}

/* --- 開封ステージ --- */
.pack-stage { padding-top: 6px; }
/* 「やめる」は袋 (3D時の canvas は袋より上下4%・左右16%大きい) や封の当たり判定より常に上に */
.stage-head { display: flex; align-items: center; gap: 14px; min-width: 0; position: relative; z-index: 5; }
.stage-title {
  font-size: 14px; font-weight: 700; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* 袋の長押し/ドラッグで iOS の画像コールアウト・ネイティブ画像ドラッグが出て
   pointercancel で回転が止まらないように (ロゴ <img> がヒット対象になる) */
.stage-3d, .pack-choice {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.stage-3d {
  position: relative;
  height: min(66vh, 600px);
  display: grid; place-items: center;
  perspective: 1000px;
  touch-action: none;
  overflow: visible;
}
/* 袋をステージ (高さ min(66vh,600px)) 内に収める。高さ = 幅×1.986、3D時の canvas はその108%、
   浮遊アニメで上へ12px動くので上下に各15pxの余裕を取る。高さ基準で決めないと、背の低い画面
   (iPhone のブラウザ表示/横向き) で袋が上の「やめる」と下の操作ヒントに被さる */
.stage-pack .pouch3d { --pw: min(62vw, 250px, calc((min(66vh, 600px) - 30px) / 1.986 / 1.08)); }
.stage-pack .pouch { animation: hover-float 3.6s ease-in-out infinite; }
@keyframes hover-float {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -12px; }
}
.stage-hint {
  text-align: center; font-size: 12px; color: var(--dim);
  letter-spacing: 0.06em; min-height: 18px;
}

.burst { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.burst span {
  position: absolute;
  width: 9px; height: 9px; border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, var(--accent) 70%);
  animation: burst-fly 0.9s ease-out forwards;
}
@keyframes burst-fly {
  from { transform: translate(0, 0) scale(1); opacity: 1; }
  to { transform: translate(var(--tx), var(--ty)) scale(0.15); opacity: 0; }
}

.stage-cards {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  perspective: 1200px;
}
.pack-card {
  position: absolute;
  width: min(66vw, 288px, 40vh); /* 横長画面でもステージ内に収める (高さ=幅×1.4) */
  container-type: inline-size;
  transform: translate(calc(var(--i) * 2px), calc(var(--i) * -3px));
  perspective: 1200px;           /* めくり(rotateY)に遠近感を付ける */
}
.pack-card.rise { animation: card-rise 0.55s cubic-bezier(0.2, 0.8, 0.3, 1.1) backwards; animation-delay: calc(var(--i) * 90ms); }
@keyframes card-rise {
  from { transform: translateY(190px) scale(0.55); opacity: 0; }
}
.pack-card.dismissed {
  transition: transform 0.45s ease-in, opacity 0.45s;
  transform: translateX(-120vw) rotate(-16deg) !important;
  opacity: 0;
}
.reveal-dots {
  position: absolute; bottom: 8px; left: 0; right: 0;
  display: flex; justify-content: center; gap: 7px;
}
.reveal-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.reveal-dots span.cur { background: var(--accent); }

.pack-summary { text-align: center; padding: 14px 0 30px; }
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px; margin-top: 20px;
  max-width: 820px; margin-left: auto; margin-right: auto;
}
.summary-grid .card-slot { animation: card-rise 0.5s cubic-bezier(0.2, 0.8, 0.3, 1.1) backwards; }
.summary-grid .card-slot:nth-child(2) { animation-delay: 70ms; }
.summary-grid .card-slot:nth-child(3) { animation-delay: 140ms; }
.summary-grid .card-slot:nth-child(4) { animation-delay: 210ms; }
.summary-grid .card-slot:nth-child(5) { animation-delay: 280ms; }
.summary-actions { display: flex; justify-content: center; gap: 12px; margin-top: 26px; }

/* ---------------- トースト ---------------- */
#toast {
  position: fixed; left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 22px); z-index: 90;
  transform: translateX(-50%) translateY(16px);
  background: #22242f; color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 20px; font-size: 13px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  /* left:50% のままだと縮小幅が画面の半分 (195px) に制限されて細長く折り返すので、
     幅は文の長さに合わせ、上限だけ画面幅の90%に */
  width: max-content; max-width: min(90vw, 420px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
/* デッキ編集中は、タブバーの上に浮いているボタン列 (戻る/保存・高さ約144px) より上へ */
body.is-building #toast { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 170px); }
/* シート表示中は画面の上端へ。下端のままだとシート (z-index 85) のボタン列に重なり、
   主ボタンのラベルが読めなくなる */
body.sheet-open #toast {
  top: calc(env(safe-area-inset-top, 0px) + 12px); bottom: auto;
  transform: translateX(-50%) translateY(-16px);
}
body.sheet-open #toast.show { transform: translateX(-50%); }

/* ---------------- 生成パネル ---------------- */
.gen-fab {
  position: fixed; right: 18px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 20px); z-index: 55;
  height: 50px; border-radius: 999px; padding: 0 18px 0 14px;
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: #fff;
  border: none; font: inherit; font-size: 14px; font-weight: 700; letter-spacing: 0.02em;
  box-shadow: 0 8px 22px rgba(254, 0, 0, 0.4); /* 公式の赤に合わせる (旧ピンクの名残を修正) */
  cursor: pointer;
}
.gen-fab .gf-plus { font-size: 24px; line-height: 1; font-weight: 700; }
.gen-fab:hover { filter: brightness(1.08); }
/* 準備中 (生成サーバー未接続・app.js の setFabPrep): 同じピルを控えめな色にして「準備中」の札を
   付ける。押すと説明のシートが出るので、disabled の見た目 (半透明) にはしない */
.gen-fab.is-prep {
  padding-right: 11px;
  background: #22252f; color: #cfd2dc;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5), inset 0 0 0 1.5px rgba(254, 0, 0, 0.42);
}
.gen-fab.is-prep .gf-plus { color: #ff6b6b; }
.gen-fab .gf-badge {
  display: inline-flex; align-items: center; height: 24px; padding: 0 9px;
  border-radius: 999px; white-space: nowrap;
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  color: #ffc266; background: rgba(255, 170, 0, 0.12); border: 1px solid rgba(255, 170, 0, 0.4);
}
.gen-fab.is-checking .gf-badge { animation: gf-pulse 0.8s ease-in-out infinite alternate; }
@keyframes gf-pulse { to { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { .gen-fab.is-checking .gf-badge { animation: none; } }
/* デッキ編集中は下端の戻る/保存を、パック開封中は袋・進行ドット・操作ヒントを優先 */
body.is-building .gen-fab, body.is-pack-scene .gen-fab { display: none; }
/* 生成ボタンが出ている間 (app.js の showGenFab) は、一番下までスクロールした時にフッターの
   クレジット表記がボタンの帯 (タブバー + 20〜70px) より上に来るよう余白を足す。
   body の下余白 (タブバー + 24px) + 70px = ボタンの上端 + 24px */
body.has-gen-fab .site-footer { padding-bottom: 70px; }

/* 生成パネルの手順表示 */
.gen-intro { font-size: 12.5px; color: var(--dim); line-height: 1.7; margin: -8px 0 10px; }
.gen-step { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700;
  margin: 14px 0 8px; letter-spacing: 0.04em; }
.gs-no { display: inline-flex; width: 20px; height: 20px; border-radius: 50%; flex: none;
  background: var(--accent); color: #fff; align-items: center; justify-content: center; font-size: 11px; }
.hint code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px;
  background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 4px; }
.modal {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(5, 6, 10, 0.82);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; overflow-y: auto;
  padding: max(18px, env(safe-area-inset-top, 0px)) max(18px, env(safe-area-inset-right, 0px)) max(18px, env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px));
}
.modal-card {
  position: relative; margin: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  width: min(480px, 94vw); padding: 24px;
}
.modal-card h2 { font-size: 17px; margin-bottom: 16px; }
.mode-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.mode-tab {
  flex: 1; background: var(--panel2); color: var(--dim);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 0; font-size: 12px;
}
.mode-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.mode-pane { margin-bottom: 14px; }
.mode-pane input[type="text"], .mode-pane textarea {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  font-size: 16px; /* iOSのフォーカス時ズーム防止 */
  margin-bottom: 8px;
}
.mode-pane label { font-size: 12px; color: var(--dim); }
.mode-pane input[type="number"] {
  width: 68px; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin-left: 6px;
  font-size: 16px; /* iOSのフォーカス時ズーム防止 */
}
.gen-opts {
  display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center;
  margin: 4px 0 12px; font-size: 12px; color: var(--dim);
}
.gen-opts select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin-left: 6px;
  font-size: 16px; /* iOSのフォーカス時ズーム防止 */
}
/* 生成パネルの研究員アカウント欄 (残高・クーポン・購入) */
.gen-acct { font-size: 12px; line-height: 1.7; margin-bottom: 12px; padding: 10px 12px;
  border: 1px solid rgba(255,255,255,.12); border-radius: 10px; background: rgba(255,255,255,.03); }
.gen-acct .ga-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 6px; }
.gen-acct .ga-row:last-of-type { margin-bottom: 0; }
.gen-acct input, .gen-acct select { flex: 1 1 150px; min-width: 0; height: 44px; padding: 0 14px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,.16); background: rgba(0,0,0,.35); color: inherit; font: inherit;
  font-size: 16px; /* iOSのフォーカス時ズーム防止 */ }
.gen-acct input:focus, .gen-acct select:focus { outline: none; border-color: var(--accent); }
.gen-acct select { flex: 0 1 auto; }
.gen-acct .ga-credits { font-weight: 700; }
.gen-acct .ga-lead { font-size: 13px; line-height: 1.7; color: var(--text); margin-bottom: 12px; }
.gen-acct .ga-warn { padding: 12px; margin-bottom: 10px; border-radius: 14px; background: rgba(255, 170, 0, 0.1); border: 1px solid rgba(255, 170, 0, 0.4); }
.gen-acct .ga-warn p { margin-bottom: 12px; }
.gen-acct .ga-credits.zero { color: #ff7d7d; }
.gen-acct .hint.small { margin-top: 6px; }
.hint { font-size: 12px; color: var(--dim); margin-bottom: 8px; }
.hint.small { font-size: 10px; margin-top: 10px; margin-bottom: 0; }
.gen-run { margin-top: 4px; }   /* 見た目は .btn .btn-primary */
/* 残高0の時: ボタンは「クレジット不足」の1行にして、次にやることはボタンの上に書く */
.gen-run-warn {
  margin: 4px 0 10px; padding: 10px 14px; border-radius: 14px;
  font-size: 13px; line-height: 1.6; color: #ffc266;
  background: rgba(255, 170, 0, 0.08); border: 1px solid rgba(255, 170, 0, 0.32);
  word-break: auto-phrase; text-wrap: pretty;
}
.gen-log {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; font-size: 11px; line-height: 1.6; color: var(--dim);
  max-height: 300px; overflow: auto; white-space: pre-wrap;
}
.spinner {
  width: 26px; height: 26px; margin: 4px auto 12px;
  border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.gen-mini {
  position: fixed; z-index: 80;
  top: calc(12px + env(safe-area-inset-top, 0px));   /* ノッチ/ステータスバーを避ける */
  left: calc(12px + env(safe-area-inset-left, 0px));
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 12px; width: 250px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}
.gm-spin {
  flex: none; width: 18px; height: 18px;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
.gm-spin.done { border-color: #3fbf7f; animation: none; }
.gm-body { flex: 1; min-width: 0; }
.gm-title { font-size: 12px; font-weight: 700; }
.gm-msg { font-size: 10px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.gm-bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.gm-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.4s; }
.gm-x { background: none; border: none; color: var(--dim); font-size: 16px; flex: none; }

/* ---------------- フッター / 書き出し ---------------- */
.site-footer {
  text-align: center; padding: 34px 16px 12px;
  font-family: var(--eu); font-size: 9px; letter-spacing: 0.14em; color: #565b6b;
}
.export-stage {
  position: fixed; left: -9999px; top: 0;
  width: 630px;
}
.export-stage .kcard, .export-stage .k-face { box-shadow: none; transition: none; }
.export-stage .foil { display: none; }

/* ---------------- レスポンシブ ---------------- */
@media (max-width: 640px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 11px; }
  .select-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-box { flex-direction: column; align-items: center; }
  .detail-card { width: min(300px, 78vw); }
  .detail-info { width: 100%; }
  .deck-actions { margin-left: 0; width: 100%; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------------- アカウント (デッキ同期) ---------------- */
.acct-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; margin-bottom: 14px;
  font-size: 12px; color: var(--dim);
}
/* 未ログイン: 説明 + 「ログイン」「新規登録（無料）」を縦に積む */
.acct-row.acct-cta { flex-direction: column; align-items: stretch; gap: 14px; padding: 16px; border-radius: 18px; }
.acct-cta-text { font-size: 13px; line-height: 1.7; color: var(--dim); }
.acct-cta-text b { display: block; font-size: 15px; color: var(--text); margin-bottom: 2px; }
@media (min-width: 641px) {
  .acct-row.acct-cta { flex-direction: row; align-items: center; gap: 24px; padding: 18px 20px; }
  .acct-row.acct-cta .btn-stack { width: 300px; flex: none; }
}
.acct-sub { font-size: 12px; color: var(--dim); margin-bottom: 12px; line-height: 1.7; }   /* admin.html */
.acct-err {
  color: #ff9a9a; font-size: 13px; line-height: 1.6;
  margin-top: 14px; padding: 10px 14px;
  background: rgba(255, 80, 80, 0.10); border: 1px solid rgba(255, 80, 80, 0.28); border-radius: 12px;
}

/* ================= ボタン (ダイアログ/ボトムシート共通) =================
   全幅のピルを縦に積む (.btn-stack)。上=戻る/補助(secondary)、下=主操作(primary)。
   min-height 56px・ラベル17px太字・間隔10px。押下で僅かに縮む */
.btn {
  --btn-bg: rgba(255, 255, 255, 0.10);
  --btn-fg: var(--text);
  position: relative;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  width: 100%; min-height: 56px; padding: 12px 24px;
  border: 0; border-radius: 999px;
  background: var(--btn-bg); color: var(--btn-fg);
  font: inherit; font-size: 17px; font-weight: 700; line-height: 1.3; letter-spacing: 0.02em;
  text-align: center; text-decoration: none; white-space: normal;
  word-break: auto-phrase; text-wrap: balance;   /* 折り返す時も文節の途中で切らない */
  cursor: pointer;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: transform 0.12s ease, background-color 0.15s ease, opacity 0.15s ease;
}
.btn-primary { --btn-bg: var(--accent); --btn-fg: #fff; }
.btn-secondary { --btn-bg: rgba(255, 255, 255, 0.10); --btn-fg: var(--text); }
.btn-danger { --btn-bg: rgba(255, 90, 90, 0.12); --btn-fg: #ff7d7d; }
@media (hover: hover) {
  .btn-primary:hover:not(:disabled) { --btn-bg: #ff2626; }
  .btn-secondary:hover:not(:disabled) { --btn-bg: rgba(255, 255, 255, 0.15); }
  .btn-danger:hover:not(:disabled) { --btn-bg: rgba(255, 90, 90, 0.18); }
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn-primary:active:not(:disabled) { --btn-bg: #dc0000; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus { outline: none; }
.btn:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.btn-ico { width: 20px; height: 20px; flex: none; margin-left: -8px; }
.btn-stack { display: flex; flex-direction: column; gap: 10px; width: 100%; }
/* 入力欄の横に置く小さいボタン (クーポン「適用」など)。同じピルの系統で高さだけ詰める */
.btn-sm { width: auto; flex: none; min-height: 44px; padding: 8px 20px; font-size: 15px; }

/* ================= シート (スマホ=ボトムシート / 広い画面=中央ダイアログ) =================
   位置と高さは visualViewport に合わせる (app.js が --vv-top/--vv-h を入れる)。
   ソフトキーボードが出ても下端のボタンが隠れず、中身(.sh-body)だけがスクロールする */
.sheet-ov {
  position: fixed; left: 0; right: 0;
  top: var(--vv-top, 0px); height: var(--vv-h, 100%);
  z-index: 85;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(5, 6, 10, 0.74);
  opacity: 0; transition: opacity 0.22s ease;
  overscroll-behavior: contain;
}
.sheet-ov.in { opacity: 1; }
.sheet-ov.out { opacity: 0; pointer-events: none; }
.sheet {
  position: relative;
  width: 100%;
  max-height: calc(100% - 10px - env(safe-area-inset-top, 0px));
  display: flex; flex-direction: column; overflow: hidden;
  background: #12141c;
  border: 1px solid rgba(255, 255, 255, 0.08); border-bottom: 0;
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -18px 60px rgba(0, 0, 0, 0.55);
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
  outline: none;
}
.sheet-ov.in .sheet { transform: none; }
.sheet-ov.out .sheet { transform: translateY(100%); transition-duration: 0.24s; }
.sheet-grip { flex: none; width: 40px; height: 5px; margin: 10px auto 0; border-radius: 3px; background: rgba(255, 255, 255, 0.18); }
.sh-screen { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.sh-screen.sh-fwd { animation: sh-in-fwd 0.26s cubic-bezier(0.2, 0.8, 0.2, 1); }
.sh-screen.sh-back { animation: sh-in-back 0.26s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes sh-in-fwd { from { opacity: 0; transform: translateX(32px); } }
@keyframes sh-in-back { from { opacity: 0; transform: translateX(-32px); } }
.sh-body {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 16px max(16px, env(safe-area-inset-right, 0px)) 4px max(16px, env(safe-area-inset-left, 0px));
}
.sh-foot {
  flex: none;
  padding: 14px max(16px, env(safe-area-inset-right, 0px)) max(16px, calc(env(safe-area-inset-bottom, 0px) + 6px)) max(16px, env(safe-area-inset-left, 0px));
}
.sheet-ov.kb .sh-foot { padding-bottom: 12px; }   /* キーボード表示中はホームバー分の余白が不要 */
.sheet-ov.kb .sh-foot .sh-link { display: none; }   /* 入力中は画面切替リンクより入力欄の高さを優先 */
.sh-body[data-more] {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 32px), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 32px), transparent);
}
.sh-kicker { font-family: var(--eu); font-size: 10px; letter-spacing: 0.24em; color: var(--accent); margin-bottom: 8px; }
.sh-title { font-size: 24px; font-weight: 900; letter-spacing: 0.04em; line-height: 1.3; outline: none; }
.sh-sub { font-size: 14px; line-height: 1.7; color: var(--dim); margin-top: 6px; }
.sh-sub, .sh-note, .acct-cta-text, .gen-acct .ga-lead, .gen-acct .ga-warn p { word-break: auto-phrase; text-wrap: pretty; }
.sh-note { font-size: 12px; line-height: 1.65; color: var(--dim); margin-top: 14px; }
.sh-link {
  display: block; margin: 12px auto 0; min-height: 44px; padding: 8px 14px;
  background: none; border: 0; border-radius: 999px;
  color: var(--dim); font: inherit; font-size: 14px;
  -webkit-tap-highlight-color: transparent;
}
.sh-link b { color: var(--text); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.sh-link:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.sh-link-inline { margin: 6px 0 0 auto; min-height: 40px; padding: 6px 2px; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.sh-link:disabled { opacity: 0.45; }
@media (min-width: 641px) {
  .sheet-ov { align-items: center; padding: 24px; }
  .sheet {
    width: min(440px, 100%); max-height: 100%;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08); border-radius: 28px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
    opacity: 0; transform: translateY(18px) scale(0.98);
    transition: transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.2s ease;
  }
  .sheet-ov.in .sheet { opacity: 1; }
  .sheet-ov.out .sheet { opacity: 0; transform: translateY(18px) scale(0.98); }
  .sheet-grip { display: none; }
  .sh-body { padding: 26px 26px 4px; }
  .sh-foot { padding: 16px 26px 24px; }
}
@media (prefers-reduced-motion: reduce) {
  .sheet-ov, .sheet, .btn { transition: none; }
  .sh-screen.sh-fwd, .sh-screen.sh-back { animation: none; }
}
/* 背の低い画面 (.tight: 横向きのスマホ / 小さい端末でキーボード表示中。app.js が付ける):
   シート全体をスクロールさせ、ボタン列は横1列(戻る|主操作)に詰めて下端に貼り付ける。
   入力欄が1つも見えない・主ボタンが切れて押せない、を防ぐ */
.sheet-ov.tight .sheet { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sheet-ov.tight .sh-screen { flex: 1 0 auto; }
.sheet-ov.tight .sh-body { flex: 1 0 auto; overflow: visible; padding-top: 12px; -webkit-mask-image: none; mask-image: none; }
.sheet-ov.tight .sh-foot {
  position: sticky; bottom: 0; z-index: 1;
  padding-top: 10px; padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  background: #12141c; border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.sheet-ov.tight .sh-foot .btn-stack:not(:has(> :nth-child(3))) { flex-direction: row; }
.sheet-ov.tight .sh-foot .btn { min-height: 48px; padding: 8px 16px; font-size: 16px; }
.sheet-ov.tight .sh-foot .sh-link { margin-top: 4px; min-height: 36px; padding: 6px 14px; }
@media (min-width: 641px) {
  .sheet-ov.tight { padding: 8px; }
}

/* シートを開いた理由 (「生成には研究員登録が必要です」等) と、送信できた時の知らせ */
.sh-notice, .sh-ok {
  margin-top: 12px; padding: 10px 14px; border-radius: 12px;
  font-size: 13px; line-height: 1.6; word-break: auto-phrase; text-wrap: pretty;
}
.sh-notice { color: #ffc266; background: rgba(255, 170, 0, 0.08); border: 1px solid rgba(255, 170, 0, 0.32); }
.sh-ok:not([hidden]) + .sh-sub { display: none; }   /* 知らせを出している間は定型の説明文と入れ替える */
.sh-ok { color: #8fe0b0; background: rgba(63, 191, 127, 0.10); border: 1px solid rgba(63, 191, 127, 0.32); overflow-wrap: anywhere; }

/* 入力欄 (ラベル付き・16px以上でiOSのズームを防ぐ) */
.fld { margin-top: 16px; }
.fld-l { display: block; font-size: 13px; font-weight: 700; color: #c7cad6; margin-bottom: 7px; }
.fld-opt {
  display: inline-block; margin-left: 4px; padding: 0 7px;
  font-size: 11px; font-weight: 500; color: var(--dim);
  border: 1px solid var(--line); border-radius: 999px; vertical-align: 1px;
}
.fld input {
  display: block; width: 100%; height: 52px; padding: 0 16px;
  background: rgba(255, 255, 255, 0.06); color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 14px;
  font: inherit; font-size: 16px;
  outline: none; -webkit-appearance: none; appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.fld input::placeholder { color: #6b7082; }
.fld input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(254, 0, 0, 0.22); }
.fld input:-webkit-autofill {   /* 自動入力の黄色背景をダークに合わせる */
  -webkit-text-fill-color: var(--text); caret-color: var(--text);
  box-shadow: 0 0 0 1000px #1c1f2b inset;
}
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 56px; }
.pw-eye {
  position: absolute; top: 4px; right: 4px;
  width: 44px; height: 44px; display: grid; place-items: center;
  background: none; border: 0; border-radius: 999px; color: var(--dim);
  -webkit-tap-highlight-color: transparent;
}
.pw-eye svg { width: 22px; height: 22px; }
.pw-eye[aria-pressed="true"] { color: var(--text); }
.pw-eye:focus-visible { outline: 2px solid #fff; outline-offset: -3px; }
@media (hover: hover) { .pw-eye:hover { color: var(--text); } }

/* アカウント画面の登録情報 */
.acct-info { margin-top: 16px; padding: 2px 16px; background: rgba(255, 255, 255, 0.05); border-radius: 16px; }
.acct-info > div { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 13px 0; font-size: 14px; }
.acct-info > div + div { border-top: 1px solid rgba(255, 255, 255, 0.07); }
.acct-info dt { flex: none; color: var(--dim); }
.acct-info dd { min-width: 0; text-align: right; font-weight: 700; overflow-wrap: anywhere; }
.acct-info dd.warn { color: #ffc266; }

/* ================= チュートリアル (tutorial.js) ================= */
/* transform/opacity だけを動かす。backdrop-filter はモバイルで重いので使わない */
/* 箱は margin:auto で中央寄せ (align-items:center だと、画面より高い時に上端が
   スクロールしても戻らない領域へはみ出し、「n / 4」とスキップに届かなくなる) */
.tt { position: fixed; inset: 0; z-index: 90; display: flex; align-items: flex-start; justify-content: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: radial-gradient(120% 120% at 50% 0%, rgba(40, 8, 14, 0.94), rgba(5, 6, 10, 0.96));
  opacity: 0; transition: opacity 0.22s ease; overflow-y: auto;
  overscroll-behavior: contain; }   /* 端までスクロールしても背後の図鑑へ連鎖させない */
.tt.tt-in { opacity: 1; }
.tt.tt-out-anim { opacity: 0; }
.tt-box { width: min(560px, 100%); margin: auto; background: #0f1118; border: 1px solid rgba(255,255,255,0.1); border-radius: 18px;
  padding: 14px 16px 16px; box-shadow: 0 30px 80px rgba(0,0,0,0.6); transform: translateY(14px) scale(0.98);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); outline: none; }
/* スマホは箱を下端に揃える: 本文の行数や最終ステップの「論文を怪獣にする」で箱の高さが
   変わっても「次へ / はじめる」が同じ位置に留まる (連続タップで別のボタンを押さない) */
@media (max-width: 640px) { .tt-box { margin: auto auto 0; } }
/* 横向きなど背の低い画面: 絵を小さく、ボタンを横1列にして1画面に収める */
@media (max-height: 500px) {
  .tt-stage { width: min(100%, calc(40vh * 16 / 9)); margin: 0 auto; }
  .tt-text { min-height: 0; }
  .tt-btns { flex-direction: row; }
  .tt-btns .btn { flex: 1 1 0; min-height: 48px; padding: 8px 14px; font-size: 16px; }
}
.tt.tt-in .tt-box { transform: none; }
.tt-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--dim); margin-bottom: 10px; }
.tt-skip { background: none; border: none; color: var(--dim); font: inherit; font-size: 12px; cursor: pointer; padding: 4px 6px; }
.tt-skip:hover { color: #fff; }
.tt-title { font-size: 18px; font-weight: 900; margin: 14px 0 6px; letter-spacing: 0.04em; }
.tt-text { font-size: 13.5px; line-height: 1.8; color: #d8dae3; margin: 0 0 14px; min-height: 4.6em; }
.tt-foot { display: flex; flex-direction: column; align-items: stretch; gap: 16px; }
.tt-dots { display: flex; justify-content: center; gap: 6px; }
.tt-dot { width: 8px; height: 8px; border-radius: 50%; border: none; background: rgba(255,255,255,0.22); padding: 0; cursor: pointer; transition: transform 0.2s, background 0.2s; }
.tt-dot.on { background: var(--accent); transform: scale(1.35); }
.tt-btns { margin: 0; }   /* .btn-stack: 戻る(上) → 次へ/はじめる(下) */

/* --- ステージ (16:9) --- */
.tt-stage { --kj-main: #d8313b; --kj-dark: #6e1016; --kj-belly: #f5cfa6; --kj-accent: #ffd166;
  position: relative; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; isolation: isolate;
  background:
    linear-gradient(rgba(255,255,255,0.045) 1px, transparent 1px) 0 0 / 100% 22px,
    linear-gradient(90deg, rgba(255,255,255,0.045) 1px, transparent 1px) 0 0 / 22px 100%,
    linear-gradient(180deg, #171a26 0%, #0b0d14 100%); }
.tt-ground { position: absolute; left: 0; right: 0; bottom: 0; height: 22%; background: linear-gradient(180deg, rgba(216,49,59,0.18), rgba(216,49,59,0.02)); border-top: 1px solid rgba(216,49,59,0.45); }

/* --- 怪獣 --- */
.tt-kaiju { position: absolute; bottom: 10%; right: 6%; width: 46%; will-change: transform; }
.tt-kaiju .kj { width: 100%; height: auto; display: block; overflow: visible; }
.tt-kaiju.tt-small { width: 30%; right: auto; left: 4%; bottom: 8%; }
.tt-kaiju.tt-tiny { width: 22%; }
.kj-bob { animation: kj-bob 0.6s ease-in-out infinite; transform-origin: 100px 100px; }
.kj-leg { animation: kj-step 0.6s ease-in-out infinite; }
.kj-leg-f { transform-origin: 122px 114px; }
.kj-leg-b { transform-origin: 80px 112px; animation-direction: reverse; }
.kj-tail { transform-origin: 58px 100px; animation: kj-tail 0.8s ease-in-out infinite; }
.kj-head { transform-origin: 150px 90px; animation: kj-nod 1.6s ease-in-out infinite; }
.kj-jaw { transform-origin: 152px 98px; }
.kj-eye { transform-origin: 180px 76px; animation: kj-blink 3.4s ease-in-out infinite; }
.kj-rings circle { fill: none; stroke: var(--kj-accent); stroke-width: 3; opacity: 0; transform-origin: 196px 88px; }
@keyframes kj-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes kj-step { 0%, 100% { transform: rotate(-24deg); } 50% { transform: rotate(24deg); } }
@keyframes kj-tail { 0%, 100% { transform: rotate(7deg); } 50% { transform: rotate(-9deg); } }
@keyframes kj-nod { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes kj-blink { 0%, 90%, 100% { transform: scaleY(1); } 94% { transform: scaleY(0.08); } }
/* 登場: 右から歩いてきて止まる */
.tt-enter { animation: tt-enter 1.5s cubic-bezier(0.2, 0.8, 0.25, 1) both; }
@keyframes tt-enter { from { transform: translateX(110%); } to { transform: translateX(0); } }
.tt-enter .kj-leg, .tt-enter .kj-bob { animation-iteration-count: 3; }
/* 咆哮: 登場後に顎を開け、衝撃波リングが広がる */
.tt-roar .kj-head { animation: kj-nod 1.6s ease-in-out infinite, kj-rear 2.6s ease-out 1.5s both; }
.tt-roar .kj-jaw { animation: kj-jaw 2.6s ease-out 1.5s both; }
.tt-roar .kj-rings circle { animation: kj-ring 1.3s ease-out 1.9s both; }
.tt-roar .kj-rings circle:nth-child(2) { animation-delay: 2.1s; }
.tt-roar .kj-rings circle:nth-child(3) { animation-delay: 2.3s; }
@keyframes kj-rear { 0%, 20% { transform: rotate(0); } 35%, 75% { transform: rotate(-14deg); } 100% { transform: rotate(0); } }
@keyframes kj-jaw { 0%, 20% { transform: rotate(0); } 35%, 75% { transform: rotate(22deg); } 100% { transform: rotate(0); } }
@keyframes kj-ring { 0% { opacity: 0.9; transform: scale(0.4); } 100% { opacity: 0; transform: scale(4.5); } }
/* 巡回: 左右を往復 (向きは scaleX で反転) */
.tt-patrol { animation: tt-patrol 6s ease-in-out infinite; }
@keyframes tt-patrol { 0% { transform: translateX(0) scaleX(1); } 45% { transform: translateX(120%) scaleX(1); } 50% { transform: translateX(120%) scaleX(-1); } 95% { transform: translateX(0) scaleX(-1); } 100% { transform: translateX(0) scaleX(1); } }
/* 飛び出し: カードから跳ね上がる */
.tt-pop { animation: tt-pop 0.9s cubic-bezier(0.34, 1.56, 0.64, 1) 2.6s both; transform-origin: 50% 100%; }
@keyframes tt-pop { from { transform: translateY(40%) scale(0.2); opacity: 0; } 60% { opacity: 1; } to { transform: translateY(0) scale(1); opacity: 1; } }
/* 歓声: 小さく跳ねる */
.tt-cheer { animation: tt-cheer 1.1s ease-in-out 1.2s infinite; right: 3%; bottom: 10%; width: 32%; }
@keyframes tt-cheer { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-16%); } }

/* --- 漂う論文 (intro) --- */
.tt-sheet { position: absolute; width: 11%; aspect-ratio: 3 / 4; background: #f6f3ea; color: #30323c; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; border-radius: 2px; box-shadow: 0 6px 16px rgba(0,0,0,0.4);
  background-image: repeating-linear-gradient(180deg, transparent 0 7px, rgba(0,0,0,0.12) 7px 8px); background-size: 70% 60%; background-position: 50% 70%; background-repeat: no-repeat; }
.tt-float { animation: tt-float 4s ease-in-out infinite; }
.tt-sheet.f1 { left: 8%; top: 14%; animation-delay: 0s; }
.tt-sheet.f2 { left: 24%; top: 30%; animation-delay: -1.3s; transform: rotate(-8deg); }
.tt-sheet.f3 { left: 40%; top: 10%; animation-delay: -2.6s; transform: rotate(6deg); }
@keyframes tt-float { 0%, 100% { translate: 0 0; rotate: -4deg; } 50% { translate: 0 -10px; rotate: 4deg; } }

/* --- ミニカード --- */
.tt-card { position: absolute; width: 17%; aspect-ratio: 63 / 88; border-radius: 6px; background: #14161f; border: 1.5px solid rgba(255,255,255,0.18); overflow: hidden; box-shadow: 0 8px 20px rgba(0,0,0,0.45); }
.tt-card-art { height: 56%; margin: 7% 7% 5%; border-radius: 3px; background: linear-gradient(135deg, #d8313b, #4b1120 60%, #0b0d14); position: relative; overflow: hidden; }
.tt-card-art::after { content: ""; position: absolute; inset: -40%; background: linear-gradient(115deg, transparent 40%, rgba(255,255,255,0.45) 50%, transparent 60%); animation: tt-shine 2.6s linear infinite; }
@keyframes tt-shine { from { transform: translateX(-60%); } to { transform: translateX(60%); } }
.tt-card-line { height: 5%; margin: 0 10% 5%; border-radius: 3px; background: rgba(255,255,255,0.3); }
.tt-card-line.short { width: 55%; }
/* 図鑑: 棚に並ぶ */
.tt-shelf .tt-card { bottom: 24%; animation: tt-slide-up 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.tt-shelf .s1 { left: 36%; animation-delay: 0.1s; } .tt-shelf .s2 { left: 51%; animation-delay: 0.25s; }
.tt-shelf .s3 { left: 66%; animation-delay: 0.4s; } .tt-shelf .s4 { left: 81%; animation-delay: 0.55s; }
@keyframes tt-slide-up { from { transform: translateY(60%); opacity: 0; } to { transform: none; opacity: 1; } }
/* 印刷: 論文が入り、カードが出て、怪獣が飛び出す */
.tt-printer { position: absolute; inset: 0; }
.tt-printer-body { position: absolute; left: 50%; bottom: 20%; width: 54%; height: 32%; transform: translateX(-50%); background: linear-gradient(180deg, #2a2e3d, #171a26); border-radius: 10px 10px 6px 6px; border: 1px solid rgba(255,255,255,0.12); }
.tt-slot { position: absolute; left: 12%; right: 12%; top: 14%; height: 6%; background: #05060a; border-radius: 3px; }
.tt-brand { position: absolute; left: 12%; bottom: 10%; font-family: var(--eu); font-size: 9px; letter-spacing: 0.3em; color: var(--dim); }
.tt-feed { position: absolute; left: 50%; top: 2%; width: 30%; aspect-ratio: 3 / 2; margin-left: -15%; background: #f6f3ea; color: #30323c; font-size: 9px; font-weight: 700; padding: 6px; border-radius: 2px; transform-origin: 50% 100%;
  animation: tt-feed 1.6s cubic-bezier(0.4, 0, 0.6, 1) 0.4s both; }
@keyframes tt-feed { from { transform: translateY(-60%); opacity: 0; } 20% { opacity: 1; } to { transform: translateY(78%) scaleY(0.85); opacity: 1; } }
.tt-out { position: absolute; left: 50%; bottom: 8%; width: 20%; margin-left: -10%; height: 40%; }
.tt-out .tt-card { position: absolute; left: 0; bottom: 0; width: 100%; animation: tt-out 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) 1.9s both; }
@keyframes tt-out { from { transform: translateY(80%) scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }
.tt-printer .tt-kaiju { left: 50%; right: auto; bottom: 50%; margin-left: -13%; width: 26%; }
/* パック: 上部がちぎれ、カードが扇状に */
.tt-pack { position: absolute; left: 8%; bottom: 14%; width: 24%; aspect-ratio: 70 / 110; }
.tt-pack-body { position: absolute; inset: 0; border-radius: 8px; background: linear-gradient(160deg, #ececf1, #c9ccd6 60%, #a9adb9); display: flex; align-items: flex-end; justify-content: center; padding-bottom: 12%; color: #d8313b; font-weight: 900; font-size: 11px; letter-spacing: 0.1em; box-shadow: 0 10px 24px rgba(0,0,0,0.45); }
.tt-pack-top { position: absolute; left: 0; right: 0; top: 0; height: 18%; background: linear-gradient(160deg, #ececf1, #c9ccd6); border-radius: 8px 8px 2px 2px; z-index: 1; transform-origin: 0 100%;
  animation: tt-tear 0.9s cubic-bezier(0.3, 0.7, 0.4, 1) 0.6s both; }
@keyframes tt-tear { to { transform: translate(40%, -140%) rotate(28deg); opacity: 0; } }
.tt-fan .tt-card { left: 44%; bottom: 20%; transform-origin: 50% 120%; animation: tt-fan 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) 1.0s both; }
.tt-fan .p1 { --r: -16deg; --x: -60%; } .tt-fan .p2 { --r: 0deg; --x: 0%; animation-delay: 1.15s; } .tt-fan .p3 { --r: 16deg; --x: 60%; animation-delay: 1.3s; }
@keyframes tt-fan { from { transform: translate(0, 60%) rotate(0) scale(0.6); opacity: 0; } to { transform: translate(var(--x), 0) rotate(var(--r)); opacity: 1; } }

/* 動きを抑える設定: すべて最終状態で静止 */
.tt-static .tt-stage *, .tt-static .tt-stage *::after { animation-duration: 0s !important; animation-delay: 0s !important; }
@media (prefers-reduced-motion: reduce) { .tt, .tt-box, .tt-dot { transition: none; } }

/* ヘッダーの「？」 */
.help-btn { margin-left: auto; width: 32px; height: 32px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.22); background: transparent; color: inherit; font: inherit; font-weight: 700; cursor: pointer; }
.help-btn:hover { background: rgba(255,255,255,0.08); }
