:root {
  /* システムUI: 明るい単色背景・墨色の文字・アクセントは深いプラム1色（ベタ塗り） */
  --bg: #FAF7F2;
  --panel: #ffffff;
  --text: #1D1A16;
  --muted: #6B645B;
  --line: #E4DED4;
  --line-strong: #CFC7BA;
  --accent: #7A1F3D;
  --accent-ink: #5E1730;    /* 押下時 */
  --accent-wash: #F4E9EC;   /* 選択状態の淡い面 */
  --radius: 8px;
  --tap: 44px;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", serif;
  --oshi: #b061ff;          /* 推し色（JSで上書き） */
  --oshi-dark: #5a2a99;
  --oshi-light: #dcc0ff;
  --gold: #f0c75e;
  --gold-light: #fff1c2;
  /* 星型（宝石・粒子で共用） */
  --star-poly: polygon(50% 0%, 62.34% 33.01%, 97.55% 34.55%, 69.97% 56.49%, 79.39% 90.45%, 50% 71%, 20.61% 90.45%, 30.03% 56.49%, 2.45% 34.55%, 37.66% 33.01%);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex; flex-direction: column;
  overflow-x: clip;             /* 万一のはみ出しでも横スクロールを出さない */
  -webkit-tap-highlight-color: transparent;
}
main { flex: 1 0 auto; }
img { max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ボタン: ベタ塗り・角丸8px・影なし。ラベルは1行（折り返しは並びで吸収する） */
button {
  min-height: var(--tap); padding: .5em 1.1em;
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  font-weight: 600; white-space: nowrap; cursor: pointer;
  transition: background-color .15s, border-color .15s;
}
button:hover { border-color: var(--text); }
button:active { background: #F2EEE7; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
button.link {
  min-height: 0; padding: 0; background: none; border: 0; font-weight: inherit;
  text-decoration: underline; text-underline-offset: .2em; color: inherit; display: inline;
}

/* ---------- header / footer ---------- */
.topbar {
  display: flex; align-items: center; gap: .5em;
  padding: .25em max(12px, env(safe-area-inset-right)) .25em max(12px, env(safe-area-inset-left));
  padding-top: calc(.25em + env(safe-area-inset-top));
  background: var(--bg);
  position: sticky; top: 0; z-index: 10; border-bottom: 1px solid var(--line);
}
.topbar .brand {
  border: 0; background: none; padding: 0 .2em; gap: .1em;
  font-family: var(--serif); font-weight: 700; font-size: 1.15rem; letter-spacing: .04em;
}
.topbar .brand:active { background: none; }
.topbar .brand small, h1 small { font-family: var(--serif); font-size: .6em; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.topbar nav { margin-left: auto; display: flex; gap: .25em; }
.topbar nav button { border: 0; background: none; padding: 0 .6em; font-size: .85rem; font-weight: 600; }
.topbar nav button:hover { text-decoration: underline; text-underline-offset: .3em; }
.count {
  min-width: 1.6em; padding: 0 .35em; border-radius: 4px;
  background: var(--accent); color: #fff; font-size: .75rem; line-height: 1.6; text-align: center;
  font-variant-numeric: tabular-nums;
}
/* 狭い幅（〜440px）: ロゴの（仮称）を省いてナビを1行に収める */
@media (max-width: 440px) {
  .topbar { gap: .3em; }
  .topbar .brand small { display: none; }
  .topbar nav button { padding: 0 .45em; font-size: .8rem; }
}
.badge {
  display: inline-block; font-size: .68rem; font-weight: 700; letter-spacing: .12em; line-height: 1.5;
  border: 1px solid var(--text); color: var(--text); border-radius: 3px; padding: 0 .4em; vertical-align: middle;
}
.foot {
  text-align: center; color: var(--muted); font-size: .75rem; letter-spacing: .04em;
  border-top: 1px solid var(--line); margin-top: 3em;
  padding: 1.6em 16px calc(1.6em + env(safe-area-inset-bottom));
}

.foot button.link { padding: .9em .3em; } /* インライン要素の上下 padding は行高を変えずにタップ領域だけ広げる */

main {
  width: 100%; max-width: 980px; margin: 0 auto;
  padding: 1.25em max(16px, env(safe-area-inset-right)) 1em max(16px, env(safe-area-inset-left));
}
.screen { display: none; }
.screen.active { display: block; }

/* タイポグラフィの階層: 見出し=明朝・太字・大 / ラベル=小・字間広め / 本文=ゴシック */
h1, h2, h3 { font-family: var(--serif); line-height: 1.35; letter-spacing: .02em; }
h1 { font-size: clamp(2rem, 9vw, 2.75rem); font-weight: 700; margin: .1em 0 .35em; }
h2 { font-size: 1.4rem; font-weight: 700; margin: 1.6em 0 .7em; }
h3 { font-size: 1.05rem; font-weight: 700; margin: 1.8em 0 .5em; }
.eyebrow, .section-label, .controls legend, .controls label {
  font-family: inherit; font-size: .72rem; font-weight: 700; letter-spacing: .16em; color: var(--muted);
}
.eyebrow { margin: 0; color: var(--accent); }
h2.section-label {
  margin: 2em 0 .8em; padding-bottom: .5em; border-bottom: 1px solid var(--text); line-height: 1.4;
}
.note { color: var(--muted); font-size: .8rem; line-height: 1.7; margin: .5em 0; }
.lead { font-size: 1.05rem; font-weight: 600; line-height: 1.75; margin: 0 0 .6em; max-width: 34em; }
.sub { color: var(--muted); font-size: .88rem; margin: 0 0 1em; max-width: 36em; }
.unofficial {
  display: inline-block; margin: 0; padding: .15em .6em; border-radius: 3px;
  border: 1px solid var(--accent); color: var(--accent); font-size: .78rem; font-weight: 700; letter-spacing: .06em;
}

/* ---------- start ---------- */
.hero { padding: .5em 0 .25em; }
.sample-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.sample {
  min-height: 0; padding: 0; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; align-items: stretch; white-space: normal;
}
.sample img { width: 100%; aspect-ratio: 63 / 80; object-fit: cover; object-position: 50% 20%; display: block; background: #E9E3D9; }
.sample span {
  display: block; padding: .5em .4em; font-size: .75rem; font-weight: 600; line-height: 1.35; text-align: center;
  border-top: 1px solid var(--line);
}
.sample:hover, .sample:focus-visible { border-color: var(--text); }
.file-pick { display: block; margin: 12px 0 .4em; }
.file-pick input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.file-pick span {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 56px; padding: .6em 1em; border-radius: var(--radius); cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 700; text-align: center; line-height: 1.4;
}
.file-pick span small { font-size: .72rem; font-weight: 400; opacity: .85; letter-spacing: .04em; }
.file-pick span:hover { background: var(--accent-ink); }
.file-pick input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- edit layout ---------- */
.edit-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px); gap: 1.5em; align-items: start; }
@media (max-width: 760px) { .edit-layout { grid-template-columns: minmax(0, 1fr); gap: 1em; } }
.stage { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.hint { color: var(--muted); font-size: .78rem; text-align: center; margin: .2em 0 .8em; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; width: 100%; max-width: 420px; }
.card-actions button { flex: 1 1 9em; }
.toast { min-height: 1.6em; color: var(--accent); font-size: .85rem; font-weight: 700; margin: .5em 0 0; text-align: center; }

.controls {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 16px 16px; display: flex; flex-direction: column; min-width: 0;
}
/* セクションは1px の罫線で区切る */
.controls > * { padding-top: 14px; }
.controls > * + * { border-top: 1px solid var(--line); margin-top: 14px; }
.controls fieldset { border: 0; margin: 0; padding: 14px 0 0; min-width: 0; }
.controls > * + fieldset { border-top: 1px solid var(--line); margin-top: 14px; }
.controls legend { float: left; width: 100%; padding: 0; margin-bottom: 8px; line-height: 1.4; }
.controls legend + * { clear: both; }
.controls label { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-row { display: flex; flex-wrap: wrap; gap: 10px 12px; }
.field-row > label { flex: 1 1 7rem; }
.field-row > .rarity-field { flex: 0 1 6.5rem; }
.field-row > .date-field { flex: 1 1 7rem; }
.field-row > .grow { flex: 2 1 9rem; }
.controls input[type=text], .controls select {
  width: 100%; min-width: 0; min-height: var(--tap);
  font-size: 16px;              /* iOS がフォーカス時にズームしない最小サイズ */
  font-weight: 400; letter-spacing: normal; color: var(--text);
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 6px; padding: .4em .6em;
}
.controls select {
  -webkit-appearance: none; appearance: none; padding-right: 2em;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%231D1A16' stroke-width='1.4'/%3E%3C/svg%3E") no-repeat right .7em center / .7em;
}
.controls input[type=text]:focus, .controls select:focus { border-color: var(--text); outline: none; box-shadow: 0 0 0 1px var(--text); }

.swatches { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.swatch {
  min-height: var(--tap); padding: 6px 0 4px; border-radius: 6px; border: 1px solid transparent; background: none;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 400;
}
.swatch::before {
  content: ""; width: 28px; height: 28px; border-radius: 50%; background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
}
.swatch span { font-size: .68rem; line-height: 1.2; color: var(--muted); white-space: nowrap; }
.swatch:hover { border-color: var(--line); }
.swatch[aria-pressed=true] { border-color: var(--text); background: var(--bg); }
.swatch[aria-pressed=true] span { color: var(--text); font-weight: 700; }

.seg { display: flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg label { flex: 1 1 0; min-width: 0; position: relative; letter-spacing: normal; color: var(--text); font-size: inherit; }
.seg label + label { border-left: 1px solid var(--line-strong); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: flex; align-items: center; justify-content: center; min-height: var(--tap); padding: 0 .3em;
  cursor: pointer; background: var(--panel); font-size: .82rem; font-weight: 600; white-space: nowrap;
}
.seg input:checked + span { background: var(--accent); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -4px; }

.nav-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 1.25em; }
.nav-row button { flex: 1 1 10em; }
.controls .nav-row { margin-top: 14px; }

/* ---------- card ---------- */
/* カードは em 単位で組み、font-size だけで拡大縮小（バインダーの縮小表示にも使う） */
.card-scene {
  font-size: clamp(12px, 3.8vw, 16px);
  perspective: 60em;
  padding: 1.5em;
  position: relative;
  touch-action: none;           /* タッチのドラッグでスクロールさせない */
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;  /* 長押しで画像メニューを出さない */
  cursor: grab;
  max-width: 100%;
}
.card-scene.dragging { cursor: grabbing; }

/* JS が傾きから更新する変数:
   --rx/--ry/--flip（3D回転）, --tilt（0=正面〜1=最大傾き。正面でほぼ0になるよう補正済み）,
   --px/--py（光の帯の位置）, --mx/--my（光源の位置）, --lx/--ly（粒子・細線の視差） */
.card {
  --rx: 0deg; --ry: 0deg; --flip: 0deg;
  --tilt: 0; --mx: 50%; --my: 50%; --px: 50%; --py: 50%; --lx: 0em; --ly: 0em;
  --thick: .34em;
  /* レアリティ別の強さ（data-rarity で上書き） */
  --holo-k: .6; --frame-k: .25; --spark-k: .55;
  width: 18em; aspect-ratio: 63 / 88; position: relative;
  transform-style: preserve-3d;
  transform: rotateX(var(--rx)) rotateY(calc(var(--ry) + var(--flip)));
  will-change: transform;
  touch-action: none;
}
.card[data-rarity="1"] { --holo-k: .3;  --frame-k: .1;  --spark-k: .2; }
.card[data-rarity="2"] { --holo-k: .45; --frame-k: .16; --spark-k: .38; }
.card[data-rarity="3"] { --holo-k: .62; --frame-k: .24; --spark-k: .55; }
.card[data-rarity="4"] { --holo-k: .8;  --frame-k: .32; --spark-k: .75; }
.card[data-rarity="5"] { --holo-k: 1;   --frame-k: .5;  --spark-k: 1; }

.face {
  position: absolute; inset: 0; border-radius: .9em; overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.front { transform: translateZ(calc(var(--thick) / 2)); }
.back  { transform: rotateY(180deg) translateZ(calc(var(--thick) / 2)); }

/* 厚み: 表裏の間に薄板を重ね、傾けた/裏返したときに暗い側面として見せる */
.edge {
  position: absolute; inset: 0; border-radius: .9em;
  transform: translateZ(calc(var(--thick) * (var(--i) / 8 - .5)));
  background:
    linear-gradient(90deg, rgba(0,0,0,.7), rgba(255,255,255,.08) 50%, rgba(0,0,0,.7)),
    linear-gradient(var(--oshi-dark), #120c1c);
}

/* 影: カードとは別要素。JS が --sx/--sy/--sb/--so/--ssx を scene に設定 */
.card-shadow {
  --sx: 0em; --sy: 1.1em; --sb: 1.2em; --so: .26; --ssx: 1;
  position: absolute; left: 1.5em; top: 1.5em; width: 18em; aspect-ratio: 63 / 88;
  border-radius: .9em; background: #3A2A1E; pointer-events: none;   /* 明るい机に落ちる薄い暖色の影 */
  opacity: var(--so);
  filter: blur(var(--sb));
  transform: translate(var(--sx), var(--sy)) scale(calc(var(--ssx) * .94), .94);
}

/* ---- 表面: 外枠（推し色グラデ）＋箔パターン（★2〜） ---- */
.front .frame {
  position: absolute; inset: 0;
  background: linear-gradient(155deg, var(--oshi-light) 0%, var(--oshi) 38%, var(--oshi-dark) 100%);
}
.card[data-rarity="1"] .frame { background: linear-gradient(160deg, var(--oshi) 0%, var(--oshi-dark) 130%); }
.card[data-rarity="2"] .frame {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.08) 0 .04em, transparent .04em .24em),
    linear-gradient(155deg, var(--oshi-light) 0%, var(--oshi) 38%, var(--oshi-dark) 100%);
}
.card[data-rarity="3"] .frame, .card[data-rarity="4"] .frame {
  background:
    radial-gradient(circle, rgba(255,255,255,.42) 0 .05em, transparent .085em) 0 0 / .36em .36em,
    repeating-linear-gradient(45deg, rgba(255,255,255,.1) 0 .04em, transparent .04em .22em),
    linear-gradient(155deg, var(--oshi-light) 0%, var(--oshi) 38%, var(--oshi-dark) 100%);
}
.card[data-rarity="5"] .frame {
  background:
    radial-gradient(circle, rgba(255,246,210,.55) 0 .05em, transparent .085em) 0 0 / .36em .36em,
    repeating-linear-gradient(45deg, rgba(255,255,255,.1) 0 .04em, transparent .04em .22em),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.07) 0 .04em, transparent .04em .22em),
    linear-gradient(155deg, var(--oshi-light) 0%, var(--oshi) 38%, var(--oshi-dark) 100%);
  /* 枠の縁に金のアウトライン */
  box-shadow: inset 0 0 0 .14em var(--gold), inset 0 0 0 .2em rgba(255,241,194,.6);
}

/* 枠のホロ（弱・常時）: 写真やプレートの下にあるので枠の部分だけ光る */
.frame-sheen {
  position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(115deg, transparent 32%, rgba(255,255,255,.85) 46%, rgba(255,255,255,0) 56%),
    linear-gradient(115deg, #ff9ac0, #ffe39a, #a8ffd0, #9adfff, #d2a8ff, #ff9ac0);
  background-size: 260% 260%, 220% 220%;
  background-position: var(--px) var(--py), var(--mx) var(--my);
  mix-blend-mode: soft-light;
  opacity: calc(var(--frame-k) * (.55 + var(--tilt) * 1.2));
}
.card[data-rarity="5"] .frame-sheen { mix-blend-mode: overlay; }

/* 内側の細いライン枠（白 → ★4以上で金） */
.inner-line {
  position: absolute; inset: .32em; border-radius: .64em; pointer-events: none;
  border: .07em solid rgba(255,255,255,.7);
}
.card[data-rarity="1"] .inner-line { border-color: rgba(255,255,255,.4); }
.card[data-rarity="4"] .inner-line,
.card[data-rarity="5"] .inner-line { border-color: var(--gold); box-shadow: 0 0 0 .05em rgba(255,241,194,.35); }

/* 上部のタグバー */
.tag-bar {
  position: absolute; left: .75em; right: .75em; top: .58em; height: 1.2em;
  display: flex; align-items: center; justify-content: space-between; gap: .5em;
  color: #fff; line-height: 1;
}
.tag {
  font-size: .58em; font-weight: 800; letter-spacing: .12em; padding: .34em .7em .3em .82em; white-space: nowrap;
  border-radius: 999px; background: rgba(0,0,0,.32);
  box-shadow: inset 0 0 0 .1em rgba(255,255,255,.55);
}
.series { font-size: .5em; font-weight: 800; letter-spacing: .3em; opacity: .85; text-shadow: 0 0 .3em rgba(0,0,0,.35); }
.card[data-rarity="1"] .tag { box-shadow: none; }
.card[data-rarity="4"] .tag, .card[data-rarity="5"] .tag { box-shadow: inset 0 0 0 .1em var(--gold); color: var(--gold-light); }

/* 写真面 */
.front .photo {
  position: absolute; inset: 2.05em .75em 4.3em; border-radius: .45em; overflow: hidden;
  background: #000;
}
/* 会場の自撮りは顔が上寄りに来やすいので、上寄せでトリミング */
.front .photo img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 20%; display: block; pointer-events: none; }
.front .photo::after { /* 写真の縁線（ホロより手前に描く） */
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  box-shadow: inset 0 0 0 .1em rgba(255,255,255,.85), inset 0 0 .8em rgba(0,0,0,.25);
}
.card[data-rarity="1"] .front .photo::after { box-shadow: inset 0 0 0 .08em rgba(255,255,255,.55); }
.card[data-rarity="4"] .front .photo::after,
.card[data-rarity="5"] .front .photo::after { box-shadow: inset 0 0 0 .1em var(--gold), inset 0 0 0 .16em rgba(255,241,194,.5), inset 0 0 .8em rgba(0,0,0,.25); }

/* ---------- ホログラム（写真面: 傾けたときだけ強く） ----------
   外側 .holo-film: 幅の広い「光の通り道」を mask で作り、傾きで流す。
   内側 i: 色（分光）を細線/ドット/星の形に mask で切り抜く。
   2段の mask が掛け算になり、「細い光の帯が通り道の中だけ光る」質感になる。
   強さ = --tilt（正面で0）× --holo-k（レアリティ）。 */
.holo-film {
  position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  mix-blend-mode: color-dodge;
  opacity: calc(var(--tilt) * var(--holo-k));
  -webkit-mask-image: linear-gradient(115deg, transparent 22%, #000 42%, #000 58%, transparent 78%);
          mask-image: linear-gradient(115deg, transparent 22%, #000 42%, #000 58%, transparent 78%);
  -webkit-mask-size: 260% 260%; mask-size: 260% 260%;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: var(--px) var(--py); mask-position: var(--px) var(--py);
}
.holo-film i {
  position: absolute; inset: 0;
  background: linear-gradient(115deg, #ff5f8f, #ffc35f, #fff36b, #5fffa8, #5fd6ff, #8f6bff, #ff5fd6, #ff5f8f);
  background-size: 300% 300%;
  background-position: var(--mx) var(--my);
  /* レインボー: 2方向の細線（回折格子っぽい筋） */
  -webkit-mask-image:
    repeating-linear-gradient(115deg, transparent 0 .48em, #000 .54em .58em, transparent .64em .7em),
    repeating-linear-gradient(65deg, transparent 0 .9em, rgba(0,0,0,.45) .93em .96em, transparent .99em 1.05em);
          mask-image:
    repeating-linear-gradient(115deg, transparent 0 .48em, #000 .54em .58em, transparent .64em .7em),
    repeating-linear-gradient(65deg, transparent 0 .9em, rgba(0,0,0,.45) .93em .96em, transparent .99em 1.05em);
  -webkit-mask-position: var(--lx) 0, calc(var(--lx) * -.6) 0;
          mask-position: var(--lx) 0, calc(var(--lx) * -.6) 0;
}
/* ドット: 分光を細かい水玉に */
.card[data-holo=dots] .holo-film i {
  -webkit-mask-image: radial-gradient(circle, #000 0 .1em, transparent .15em);
          mask-image: radial-gradient(circle, #000 0 .1em, transparent .15em);
  -webkit-mask-size: .5em .5em; mask-size: .5em .5em;
  -webkit-mask-position: var(--lx) var(--ly); mask-position: var(--lx) var(--ly);
}
/* スター: 星形SVGを並べたマスク */
.card[data-holo=stars] .holo-film i {
  --star: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M10 2l2.4 5.6L18 8.2l-4.3 3.9 1.3 5.9L10 15l-5 3 1.3-5.9L2 8.2l5.6-.6z'/%3E%3Cpath d='M30 20l1.6 3.8 4 .4-3 2.7.9 4-3.5-2.1-3.5 2.1.9-4-3-2.7 4-.4z'/%3E%3C/svg%3E");
  -webkit-mask-image: var(--star); mask-image: var(--star);
  -webkit-mask-size: 1.8em 1.8em; mask-size: 1.8em 1.8em;
  -webkit-mask-position: var(--lx) var(--ly); mask-position: var(--lx) var(--ly);
}

/* 瞬く粒子: 大きさ・間隔の違う点を重ね、2層を交互に明滅させる */
.sparkle {
  position: absolute; inset: 0; pointer-events: none;
  mix-blend-mode: screen;
  opacity: calc(var(--tilt) * var(--spark-k));
}
.sparkle::before, .sparkle::after {
  content: ""; position: absolute; inset: -1em;
  animation: twinkle 1.6s ease-in-out infinite alternate;
}
.sparkle::before {
  background-image:
    radial-gradient(circle, #fff 0 .045em, rgba(255,255,255,0) .11em),
    radial-gradient(circle, #fff6d0 0 .06em, rgba(255,255,255,0) .14em);
  background-size: 1.7em 2.1em, 3.1em 2.7em;
  background-position: calc(.3em + var(--lx) * .5) calc(.6em + var(--ly) * .5), calc(1.2em + var(--lx) * .5) calc(1.5em + var(--ly) * .5);
}
.sparkle::after {
  background-image:
    radial-gradient(circle, #fff 0 .05em, rgba(255,255,255,0) .12em),
    radial-gradient(circle, #d8f4ff 0 .04em, rgba(255,255,255,0) .1em);
  background-size: 2.3em 1.9em, 4.3em 3.7em;
  background-position: calc(1em + var(--lx) * .8) calc(.2em + var(--ly) * .8), calc(2.6em + var(--lx) * .8) calc(.9em + var(--ly) * .8);
  animation-delay: -.8s;
}
@keyframes twinkle { from { opacity: .15; } to { opacity: 1; } }

/* 光源（白いハイライト）: 正面ではほぼ消える */
.glare {
  position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background: radial-gradient(circle at var(--mx) var(--my), rgba(255,255,255,.85) 0%, rgba(255,255,255,.25) 25%, transparent 55%);
  mix-blend-mode: overlay;
  opacity: calc(.05 + var(--tilt) * .5);
}

/* 参戦スタンプ */
.stamp {
  position: absolute; right: 1.15em; bottom: 4.7em; width: 6em; height: 6em; border-radius: 50%;
  border: .2em double rgba(255,255,255,.95); color: #fff; background: rgba(0,0,0,.28);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  transform: rotate(-12deg); line-height: 1.15; padding: .4em; text-shadow: 0 0 .3em rgba(0,0,0,.6);
}
.stamp-label { font-weight: 800; font-size: .85em; letter-spacing: .2em; }
.stamp-date { font-size: .62em; }
.stamp-venue { font-size: .62em; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stamp.hidden { display: none; }
.card[data-rarity="5"] .stamp { border-color: var(--gold-light); }

/* ---- 下部の名前プレート（枠と同系色） ---- */
.name-plate {
  position: absolute; left: .75em; right: .75em; bottom: 1.05em; height: 2.85em;
  border-radius: .42em; color: #fff;
  display: flex; align-items: center; gap: .55em; padding: 0 .65em;
  background:
    linear-gradient(180deg, rgba(255,255,255,.22), rgba(255,255,255,0) 55%),
    linear-gradient(90deg, var(--oshi-dark), var(--oshi) 160%);
  box-shadow: inset 0 0 0 .07em rgba(255,255,255,.35), 0 .12em .3em rgba(0,0,0,.35);
}
.name { font-weight: 800; font-size: 1.08em; line-height: 1.2; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 .06em .2em rgba(0,0,0,.4); }
/* ★1: 地味（ハイライト・装飾なし） */
.card[data-rarity="1"] .name-plate { background: var(--oshi-dark); box-shadow: none; }
/* ★3〜: 箔の斜線＋内側のライン装飾＋右端の菱形 */
.card[data-rarity="3"] .name-plate, .card[data-rarity="4"] .name-plate, .card[data-rarity="5"] .name-plate {
  padding-right: 1.5em;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.07) 0 .04em, transparent .04em .2em),
    linear-gradient(180deg, rgba(255,255,255,.22), rgba(255,255,255,0) 55%),
    linear-gradient(90deg, var(--oshi-dark), var(--oshi) 160%);
}
.card[data-rarity="3"] .name-plate::before, .card[data-rarity="4"] .name-plate::before, .card[data-rarity="5"] .name-plate::before {
  content: ""; position: absolute; inset: .2em; border-radius: .28em; pointer-events: none;
  border: .055em solid rgba(255,255,255,.5);
}
.card[data-rarity="3"] .name-plate::after, .card[data-rarity="4"] .name-plate::after, .card[data-rarity="5"] .name-plate::after {
  content: ""; position: absolute; right: .62em; top: 50%; width: .42em; height: .42em; margin-top: -.21em;
  transform: rotate(45deg); border: .07em solid rgba(255,255,255,.75); background: rgba(255,255,255,.2);
}
/* ★5: 金のアウトライン */
.card[data-rarity="5"] .name-plate { box-shadow: inset 0 0 0 .1em var(--gold), 0 .12em .3em rgba(0,0,0,.35); }
.card[data-rarity="5"] .name-plate::before { border-color: rgba(255,241,194,.7); }
.card[data-rarity="5"] .name-plate::after { border-color: var(--gold); background: rgba(240,199,94,.45); }

/* ---- レアリティ: 星型の宝石＋数 ----
   形は共通、色と数で段階を表す（1 銀 / 2 アクア / 3 ローズ / 4 アメジスト / 5 金）。
   [data-rarity] を持つ祖先（カード・バインダーの見出し）で色が決まる。 */
.rarity {
  display: inline-flex; align-items: center; gap: .18em; flex: none; line-height: 1;
  filter: drop-shadow(0 0 .05em rgba(0,0,0,.7));
}
.name-plate .rarity { padding-right: .5em; border-right: .06em solid rgba(255,255,255,.35); }
.rarity-num { font-weight: 900; font-size: 1em; color: #fff; }
.gem {
  --ga: #f6f8fc; --gb: #8e97aa;
  display: inline-block; width: 1.35em; height: 1.35em; flex: none; position: relative;
  clip-path: var(--star-poly);
  background:
    linear-gradient(160deg, rgba(255,255,255,.7), rgba(255,255,255,0) 45%),
    repeating-conic-gradient(from -90deg at 50% 50%, var(--ga) 0 36deg, var(--gb) 36deg 72deg);
}
.gem::after { /* 中央の小さな面 */
  content: ""; position: absolute; inset: 31%; clip-path: var(--star-poly);
  background: linear-gradient(160deg, #fff, var(--ga));
  opacity: .75;
}
[data-rarity="2"] .gem { --ga: #d6fbff; --gb: #2f9cc4; }
[data-rarity="3"] .gem { --ga: #ffe0f0; --gb: #d0478f; }
[data-rarity="4"] .gem { --ga: #ecdcff; --gb: #7a3fd0; }
[data-rarity="5"] .gem { --ga: #fff4c4; --gb: #c08a22; }
[data-rarity="5"] .rarity { filter: drop-shadow(0 0 .05em rgba(0,0,0,.7)) drop-shadow(0 0 .25em rgba(255,214,110,.8)); }
[data-rarity="5"] .rarity-num { color: var(--gold-light); }

.fanmade-mini {
  position: absolute; left: 0; right: 0; bottom: .2em; text-align: center;
  font-size: .55em; color: rgba(255,255,255,.95); letter-spacing: .1em; text-shadow: 0 0 .2em rgba(0,0,0,.5);
}

/* ★5: 浮遊する星粒子 */
.floaters { position: absolute; inset: 0; pointer-events: none; display: none; border-radius: inherit; }
.card[data-rarity="5"] .floaters { display: block; }
.floaters i {
  position: absolute; left: var(--x); bottom: -1em; width: var(--s); height: var(--s);
  clip-path: var(--star-poly);
  background: radial-gradient(circle, #fff 0 25%, #ffe8a0 60%, var(--gold));
  opacity: 0; mix-blend-mode: screen;
  animation: float-up var(--dur) linear var(--d) infinite;
}
.floaters i:nth-child(1) { --x: 8%;  --s: .55em; --dur: 6.5s; --d: 0s; }
.floaters i:nth-child(2) { --x: 22%; --s: .8em;  --dur: 8s;   --d: -2.2s; }
.floaters i:nth-child(3) { --x: 37%; --s: .45em; --dur: 5.5s; --d: -4.1s; }
.floaters i:nth-child(4) { --x: 51%; --s: .7em;  --dur: 7.2s; --d: -1.3s; }
.floaters i:nth-child(5) { --x: 64%; --s: .5em;  --dur: 6s;   --d: -3.4s; }
.floaters i:nth-child(6) { --x: 76%; --s: .9em;  --dur: 8.6s; --d: -5.6s; }
.floaters i:nth-child(7) { --x: 88%; --s: .5em;  --dur: 5.8s; --d: -2.9s; }
.floaters i:nth-child(8) { --x: 45%; --s: .4em;  --dur: 6.8s; --d: -6.1s; }
@keyframes float-up {
  0%   { transform: translateY(0) rotate(0deg) scale(.6); opacity: 0; }
  15%  { opacity: .95; }
  70%  { opacity: .75; }
  100% { transform: translateY(-26em) rotate(200deg) scale(1); opacity: 0; }
}

/* ---------- 裏面（全カード共通のブランドの顔） ---------- */
.back { background: linear-gradient(170deg, var(--oshi) 0%, var(--oshi-dark) 85%); color: #fff; }
.back-art {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 50% 32%, rgba(255,255,255,.5) 0, rgba(255,255,255,0) 32%),
    repeating-conic-gradient(from 0deg at 50% 32%, rgba(255,255,255,.13) 0 3deg, rgba(255,255,255,0) 3deg 10deg),
    radial-gradient(circle at 50% 32%, var(--oshi-light) 0, transparent 72%);
}
.back-art::before { /* 小さな星の散らし */
  content: ""; position: absolute; inset: 0;
  background-image:
    radial-gradient(circle, rgba(255,255,255,.85) 0 .05em, transparent .1em),
    radial-gradient(circle, rgba(255,246,210,.6) 0 .04em, transparent .09em);
  background-size: 1.9em 2.3em, 2.9em 2.6em;
  background-position: .3em .5em, 1.1em 1.6em;
  opacity: .65;
}
.back-art::after { /* 周辺を少し落として中央に視線を集める */
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 42%, transparent 50%, rgba(0,0,0,.35));
}
.back-rim {
  position: absolute; inset: .5em; border-radius: .56em; pointer-events: none;
  border: .1em solid rgba(255,232,160,.9);
}
.back-rim::after {
  content: ""; position: absolute; inset: .22em; border-radius: .4em;
  border: .05em solid rgba(255,255,255,.45);
}
.back-word {
  position: absolute; left: 1.4em; right: 1.4em;
  display: flex; align-items: center; gap: .6em;
  font-size: .95em; font-weight: 900; line-height: 1;
}
.back-word::before, .back-word::after {
  content: ""; flex: 1; height: .07em;
  background: linear-gradient(90deg, transparent, var(--gold-light));
}
.back-word::after { background: linear-gradient(90deg, var(--gold-light), transparent); }
.back-word span {
  letter-spacing: .42em; padding-left: .42em;
  background: linear-gradient(90deg, var(--gold-light), var(--gold), var(--gold-light));
  -webkit-background-clip: text; background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 .05em .1em rgba(0,0,0,.4));
}
.back-word.top { top: 1.2em; }
.back-word.bottom { bottom: 1.2em; transform: rotate(180deg); }
.emblem {
  position: absolute; left: 3.5em; top: 2.75em; width: 11em; height: 11em;
  filter: drop-shadow(0 .2em .4em rgba(0,0,0,.35));
}
.back-plate {
  position: absolute; left: 1.3em; right: 1.3em; top: 14.5em; bottom: 2.75em;
  border-radius: .5em; background: rgba(15,6,30,.38);
  box-shadow: inset 0 0 0 .06em rgba(255,255,255,.35);
  overflow: hidden;
}
.back-plate-body {
  font-size: .6em; line-height: 1.35; padding: .9em 1.2em;
  display: flex; flex-direction: column; gap: .6em; height: 100%;
}
.back-record { display: grid; grid-template-columns: 2.4em minmax(0, 1.4fr) 2.4em minmax(0, 1fr); gap: .3em .5em; margin: 0; }
.back-record dt { color: rgba(255,255,255,.65); letter-spacing: .1em; }
.back-record dd { margin: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-record dd.rarity { display: flex; font-size: 1.1em; }
.back-record .gem { width: 1.1em; height: 1.1em; }
.back-msg { border-top: .06em solid rgba(255,255,255,.25); padding-top: .5em; }
.back-title { color: rgba(255,255,255,.65); letter-spacing: .1em; }
.back-hint { color: rgba(255,255,255,.45); margin-left: .4em; }
.dummy-lines i { display: block; height: .45em; margin: .45em 0; border-radius: 1em; background: rgba(255,255,255,.22); }
.dummy-lines i:nth-child(2) { width: 65%; }
.back-fanmade { margin-top: auto; text-align: center; font-weight: 800; letter-spacing: .05em; opacity: .9; }
/* 裏面のホロは控えめ */
.back-film { opacity: calc(var(--tilt) * .4); }

/* ---------- バインダー ---------- */
#screen-binder h2 { display: flex; flex-wrap: wrap; align-items: baseline; gap: .2em .8em; }
.binder-count {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: .72rem; font-weight: 700; letter-spacing: .14em; color: var(--muted);
}
.binder-count b { color: var(--accent); font-size: 1.6em; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.binder {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
  margin-top: 1em;
}
.binder:empty { display: none; }
.pocket {
  min-width: 0; border-radius: 6px; background: var(--bg); padding: 10px 6px 8px;
  border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.pocket .card-scene { font-size: 6.6px; padding: 0; cursor: default; perspective: none; touch-action: auto; }
.pocket .card { transform: none; touch-action: auto; }
/* 縮小表示は側面の代わりに下側の縁で厚みを出す（明るい背景向けに影は薄め） */
.pocket .face { box-shadow: 0 .3em 0 #2a1f18, 0 .8em 1.2em rgba(58,42,30,.22); overflow: hidden; }
.pocket .no {
  font-size: .72rem; font-weight: 700; letter-spacing: .1em; color: var(--muted);
  display: flex; align-items: center; gap: .5em; font-variant-numeric: tabular-nums;
}
.pocket .no .rarity { font-size: 1.1em; letter-spacing: 0; }
.pocket .no .rarity-num { color: var(--text); }
.pocket .no[data-rarity="5"] .rarity-num { color: #9A6B12; }
.empty {
  color: var(--muted); font-size: .9rem; margin: 1em 0 0; padding: 1.4em 1em; text-align: center;
  background: var(--panel); border: 1px dashed var(--line-strong); border-radius: var(--radius);
}

/* ---------- クレジット ---------- */
#screen-credits > p { max-width: 40em; }
.credit-list { list-style: none; padding: 0; margin: 1em 0 0; border-top: 1px solid var(--line); }
.credit-list li { padding: 14px 0; border-bottom: 1px solid var(--line); font-size: .85rem; line-height: 1.7; min-width: 0; }
.credit-list li > div:first-child { display: flex; align-items: center; gap: .6em; margin-bottom: .4em; }
.credit-list li > div:first-child b { min-width: 0; overflow-wrap: anywhere; }
.credit-list a { color: var(--accent); overflow-wrap: anywhere; word-break: break-word; }
.credit-list .thumbs { flex: none; width: 3em; aspect-ratio: 1; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); }
.caution { padding-left: 1.2em; margin: 0; max-width: 42em; }
.caution li { color: var(--muted); font-size: .85rem; margin-bottom: .4em; }

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .sparkle::before, .sparkle::after { animation: none; opacity: .7; }
  .floaters i { animation: none; opacity: .8; bottom: calc(var(--s) * 20); }
}
