/* ============================================================
   論文怪獣 | 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; }
.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); }

/* --- 表面 (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;
  background-color: #16161a;
  background-size: cover; background-position: center;
  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-typebar {
  align-self: flex-start; flex: none; position: relative; z-index: 1;
  margin: -2.4cqw 0 0.7cqw; padding: 0.4cqw 2.4cqw 0.5cqw 1.3cqw;
  background: #e9e3a6; color: #0b0b0d;
  font-size: 2.9cqw; font-weight: 800; line-height: 1.35; letter-spacing: 0.04em;
  border-radius: 0.5cqw;
  clip-path: polygon(0 0, 100% 0, calc(100% - 1.7cqw) 100%, 0 100%);
}
.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で中央寄せ: 縦長でも先頭が切れずスクロールできる */
  padding: 18px;
  overflow-y: auto;
  animation: fade-in 0.2s;
}
.detail-box, .picker-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;
}
.detail-x {
  position: absolute; top: 10px; right: 12px; z-index: 2;
  background: none; border: none; color: var(--dim); font-size: 26px; line-height: 1;
}
.detail-card { flex: none; width: min(330px, 42vw); perspective: 1000px; }
.detail-card .card-slot { width: 100%; }
.flip-btn {
  width: 100%; margin-top: 14px;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px; font-size: 13px;
}
.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 { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

.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-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 22px; width: min(420px, 92vw);
}
.picker-box h3 { font-size: 15px; margin-bottom: 14px; }
.picker-list { display: flex; flex-direction: column; gap: 8px; }
.picker-item {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; font-size: 14px;
}
.picker-item span { color: var(--dim); font-size: 12px; }
.picker-item.new { color: var(--accent); font-weight: 700; }

/* ---------------- タブバー ---------------- */
.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 { display: flex; gap: 10px; align-items: center; padding: 8px 0 6px; }
#bd-name {
  flex: 1; min-width: 0;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
  font-size: 16px; /* iOSのフォーカス時ズーム防止 */
}
.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);
}

.pouch-title {                       /* RONBUN KAIJU (y 67.2-74%, x 25.4-) */
  position: absolute; top: 65.6%; left: 25.4%; right: 6%;
  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;
  z-index: 2;
}
.pouch-kanji {                       /* 論文怪獣 (y 75.6-79.6%) */
  position: absolute; top: 74.6%; left: 25.2%; right: 6%;
  font-size: calc(var(--u) * 10); font-weight: 900; letter-spacing: 0.02em;
  z-index: 2;
}
.pouch-held {                        /* HELD IN CONTAINMENT BY R・K LAB (y 81.6%) */
  position: absolute; top: 81.8%; left: 25.4%; right: 4%;
  font-family: "Zen Kaku Gothic New", Helvetica, Arial, sans-serif; font-weight: 900;
  font-size: calc(var(--u) * 2.8); letter-spacing: 0.01em;
  z-index: 2;
}
.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; }
.stage-head { display: flex; align-items: center; gap: 14px; min-width: 0; }
.stage-title {
  font-size: 14px; font-weight: 700; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stage-3d {
  position: relative;
  height: min(66vh, 600px);
  display: grid; place-items: center;
  perspective: 1000px;
  touch-action: none;
  overflow: visible;
}
.stage-pack .pouch3d { --pw: min(62vw, 250px, 38vh); } /* 横長画面でもステージ内に収める */
.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;
  max-width: min(90vw, 420px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------------- 生成パネル ---------------- */
.gen-fab {
  position: fixed; right: 18px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 20px); z-index: 55;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--accent); color: #fff;
  border: none; font-size: 26px; font-weight: 700;
  box-shadow: 0 8px 22px rgba(254, 0, 0, 0.4); /* 公式の赤に合わせる (旧ピンクの名残を修正) */
}
.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; padding: 18px; overflow-y: auto;
}
.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; }
.modal-close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; color: var(--dim); font-size: 24px;
}
.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のフォーカス時ズーム防止 */
}
.hint { font-size: 12px; color: var(--dim); margin-bottom: 8px; }
.hint.small { font-size: 10px; margin-top: 10px; margin-bottom: 0; }
.gen-run {
  width: 100%; background: var(--accent); color: #fff;
  border: none; border-radius: 10px; padding: 12px; font-size: 14px; font-weight: 700;
}
.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-sub { font-size: 12px; color: var(--dim); margin-bottom: 12px; line-height: 1.7; }
.acct-box input {
  width: 100%; margin-bottom: 10px;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font-size: 14px;
}
.acct-err { color: #ff7d7d; font-size: 12px; margin: 2px 0 8px; }
.acct-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.acct-link {
  background: none; border: none; color: var(--dim); font-size: 12px;
  text-decoration: underline; margin-top: 12px; padding: 0;
}
