:root {
  --bg: #14121c;
  --panel: #1f1c2b;
  --text: #f2eee6;
  --muted: #9a94a8;
  --gold: #e8c45a;
  --gold-dark: #9c7a1e;
  --devil: #2a2433;
  --devil-edge: #0b0a0f;
  --off: #3a3548;
  --gold-line: rgba(232, 196, 90, 0.45);  /* 神殿の柱と同じ、金を透かした細い線（記録欄・アイテムの枠） */
  --stage0: #f2eee6;
  --stage1: #8fd3ff;
  --stage2: #ffb36b;
  --stage3: #9cf0a8;
  --stage4: #ff6b8b;
  /* オートのマーク ▶▶（スマホのオートボタンと入り口の遊び方で使う） */
  --auto-mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 10'%3E%3Cpath d='M0 0L7 5L0 10ZM7 0L14 5L7 10Z'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  /* 文字入力欄はないので、キャレットブラウズ等で出る点滅カーソルを隠す */
  caret-color: transparent;
}

/* 連打しても文字が選択状態にならないように */
button, .streak, .coin-wrap, .memory { user-select: none; }

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.title {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.08em;
  color: var(--gold);
}

/* 小さなカギはタイトルの右に並べる。数字は押したとき（PC は乗せたとき）だけ右に出す（上は画面の端で切れ、下はカーソルに隠れる） */
.title-wrap { display: flex; align-items: center; gap: 6px; }
.title-keys { display: flex; gap: 2px; }
.title-keys:empty { display: none; }
.key { position: relative; display: block; width: 20px; height: 20px; padding: 0; border: 0; background: none; color: inherit; cursor: pointer; }
.key svg { display: block; width: 100%; height: 100%; fill: none; stroke: var(--gold); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.key.got svg { animation: rarePop 0.6s ease-out; }
.key.locked svg { stroke: var(--muted); opacity: 0.6; }
.key-tip {
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  padding: 2px 8px;
  border: 1px solid var(--gold);
  border-radius: 6px;
  background: var(--panel);
  font-size: 0.75rem;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
}
.key-tip.below { left: 50%; top: calc(100% + 6px); transform: translateX(-50%); }
.key-num { color: var(--gold); font-weight: 700; }

.icon-btn {
  background: none;
  border: 1px solid var(--off);
  color: var(--text);
  border-radius: 8px;
  font-size: 1.1rem;
  padding: 4px 10px;
  cursor: pointer;
}

/* ---- volume ---- */
.volume-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 10;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--off);
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}

.volume-panel[hidden] { display: none; }
/* 右上のボタン（⚙️ 設定・🔊 音量）。小窓はどちらも右上から開く（.volume-panel の形を共用） */
.header-btns { display: flex; gap: 8px; }

.volume { display: flex; align-items: center; gap: 10px; }
.volume input { width: 180px; accent-color: var(--gold); }
.volume-label { font-size: 0.85rem; color: var(--muted); }
.volume-text { min-width: 3em; text-align: right; font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.volume-icon { font-size: 1.1rem; }
#settingsPanel { max-width: 100%; }
#settingsPanel input[type="range"] { min-width: 0; }
.skip-result { margin-top: 10px; }
.skip-result[hidden] { display: none; }
/* 23連続に届いて ⚙️ に設定が増えたら、一度開くまで金の枠で明暗させる */
.icon-btn.notice { border-color: var(--gold); box-shadow: 0 0 8px rgba(232, 196, 90, 0.7); animation: gearGlow 1.6s ease-in-out infinite; }
@keyframes gearGlow { 50% { box-shadow: 0 0 2px rgba(232, 196, 90, 0.2); } }
.skip-result input { width: auto; flex: none; margin: 0; }
.skip-result .volume-label { min-width: 0; line-height: 1.5; }
/* チェックボックスの行で小窓が広がっても、「演出」の字は縦に折り返さない */
#settingsPanel .volume:not(.skip-result) .volume-label { flex: none; }

/* ---- memory ---- */
.memory { position: relative; }

.memory-row {
  list-style: none;
  margin: 0;
  padding: 0 0 26px;
  display: grid;
  grid-template-columns: repeat(23, minmax(0, 1fr));
  gap: 3px;
}

.cell {
  position: relative;
  height: 22px;
  border-radius: 4px;
  background: var(--off);
  /* 動かすのは色だけ（background 全部だと、虹色を塗った瞬間に切り出し位置が左端から流れてフラッシュに見える） */
  transition: background-color 0.15s;
}

.cell.on { background: var(--gold); box-shadow: 0 0 6px var(--gold); }
.cell.best { background: rgba(232, 196, 90, 0.5); }

/* 節目の区切り線は置かない（線があると隣のマスとつながって見えるため。目安は下のメダル・教会だけ） */
/* DEMON BUSTER MODE で塗ったマス：連続数の「23」と同じ虹色を、動かさずに並び全体へ 1 本で敷き、マスごとに切り出す */
.cell.rb {
  background: linear-gradient(90deg, #ff5e5e, #ffb65e, #fff35e, #6bff7a, #5ec8ff, #9b6bff, #ff5ec8);
  /* 下地はグレーのまま（透明だと、虹色が外れた瞬間に色の変化の間だけ暗く抜けてフラッシュに見える） */
  background-color: var(--off);
  background-size: 2300% 100%;
  background-position: calc(var(--i) / 22 * 100%) 0;
}
/* モードに入るとき、黄色のマスをゆっくりグレーへ戻す */
.memory-row.fade .cell { transition: background-color 0.6s, box-shadow 0.6s; }

.preview {
  position: absolute;
  top: 26px;
  right: -9px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  overflow: hidden;
  font-size: 0;
}

.cell:last-child .preview { right: 0; }

.preview .face-art { width: 100%; height: 100%; }
/* 補給の位置の教会マーク（メダルと同じ箱に金の線の絵）。次の補給だけ光らせ、通り過ぎたら灰色 */
.preview.church { border-radius: 0; overflow: visible; }
.preview.church svg { width: 100%; height: 100%; fill: none; stroke: var(--gold); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.preview.church.next svg { filter: drop-shadow(0 0 3px var(--gold)); }
.preview.church.past svg { stroke: var(--muted); }

/* マスに合わせると出る確率（showCellTip で位置を決める） */
.cell-tip {
  position: absolute;
  z-index: 5;
  padding: 3px 8px;
  border: 1px solid var(--gold);
  border-radius: 6px;
  background: var(--panel);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

/* ---- coin ---- */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.coin-wrap {
  width: min(60vw, 240px);
  aspect-ratio: 1;
  perspective: 900px;
  cursor: pointer;              /* クリック・タップでもトスできる */
  touch-action: manipulation;   /* スマホの連続タップで拡大しない */
  -webkit-tap-highlight-color: transparent;  /* タップした瞬間の四角い強調表示を出さない */
}

.coin {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

/* 高速オート：抽選とは切り離して回り続ける演出 */
.coin.whirl { animation: whirl 0.3s linear infinite; }
@keyframes whirl { from { transform: rotateY(0deg); } to { transform: rotateY(360deg); } }

.face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  backface-visibility: hidden;
  overflow: hidden;
}

.face.back { transform: rotateY(180deg); }

.face-art {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 700;
  line-height: 1.2;
}

.face-art img { width: 100%; height: 100%; object-fit: contain; display: block; }

.face-art.angel {
  background: radial-gradient(circle at 35% 30%, #fff3c4, var(--gold) 55%, var(--gold-dark));
  color: #4a3500;
  border: 6px solid var(--gold-dark);
}

.face-art.devil {
  background: radial-gradient(circle at 35% 30%, #5a4d6b, var(--devil) 55%, var(--devil-edge));
  color: #e9e2f5;
  border: 6px solid var(--devil-edge);
}

.face-art.has-img { background: none; border: none; }

.face-art .ph-icon { font-size: clamp(2rem, 12vw, 4rem); }
.face-art .ph-label { font-size: clamp(0.8rem, 3.5vw, 1rem); }

.streak {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.streak-num {
  font-size: clamp(3rem, 14vw, 5rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--stage0);
}

.streak-num.s1 { color: var(--stage1); }
.streak-num.s2 { color: var(--stage2); }
.streak-num.s3 { color: var(--stage3); }
.streak-num.s4 { color: var(--stage4); }
.streak-num.bump { animation: bump 0.25s; }
/* 23到達時はポンと弾ませつつ、レインボーも止めない */
.streak-num.rainbow.bump { animation: bump 0.25s, rainbow 2s linear infinite; }

.streak-goal { font-size: 1.4rem; color: var(--muted); }

/* 行の高さを字体まかせにすると、日本語の字体で行が伸びて下の箱が押されるので固定する */
.result-text { margin: 0; min-height: 1.4em; line-height: 1.4; color: var(--muted); }
/* 結果文は中央寄せで常に1行。オートのアイコンはその行の左端に置く（PC もスマホも同じ） */
.result-row { position: relative; align-self: stretch; }
.result-row .result-text { text-align: center; white-space: nowrap; }
/* 状態の行に上から下りてくる知らせ（ロザリオがきしむ・崩れた）。行の外にはみ出す間は見せない */
.items-status.dropping { overflow: hidden; }
.result-drop { display: inline-block; }

.rainbow {
  background: linear-gradient(90deg, #ff5e5e, #ffb65e, #fff35e, #6bff7a, #5ec8ff, #9b6bff, #ff5ec8, #ff5e5e);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent !important;
  animation: rainbow 2s linear infinite;
}

@keyframes rainbow { to { background-position: 200% 0; } }
@keyframes bump { 50% { transform: scale(1.15); } }

/* ---- stats ---- */
.stats dl {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

@media (max-width: 640px) {
  .stats dl { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* 記録を見る操作だと分かるよう、箱全体をボタンにする */
.stats dl > div.stat-action { padding: 0; }
.stat-action button {
  width: 100%;
  height: 100%;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: none;
  border: 1px solid var(--gold);  /* ほかの箱の線より明るくして、押せる箱だと分かるようにする */
  border-radius: 10px;
  cursor: pointer;
}
.stat-action button:hover { border-color: var(--gold); }
/* 「記録を見る」は1行だけなので、箱の真ん中に置く */
.stat-action button { align-items: center; justify-content: center; text-align: center; }
.stat-value { font-size: 1.1rem; font-weight: 700; color: var(--gold); }

.stats dl > div, .clear dl > div {
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 12px;
}
/* 記録欄の箱は金の細い線で囲む。線の分だけ余白を減らして、箱の大きさは変えない */
.stats dl > div:not(.stat-action) { border: 1px solid var(--gold-line); padding: 7px 11px; }

/* 行の高さは px で固定する。字体まかせだと、fitText で文字が縮むたびに日本語の字体で行が変わり、箱が伸び縮みする */
dt { font-size: 0.75rem; line-height: 16px; color: var(--muted); }
dd { margin: 2px 0 0; font-size: 1.1rem; line-height: 23px; font-weight: 700; font-variant-numeric: tabular-nums; word-break: break-all; }
/* 目標が書き換わるとき、ラベルの N が金色で跳ねる */
.reach-n { display: inline-block; }
.reach-n.pop { animation: reachPop 0.4s ease-out; color: var(--gold); }
@keyframes reachPop { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }

/* 累計投資額・確率2つは折り返さず、入りきらないときは文字を小さくする（fitText） */
#cost, #prob, #reach { white-space: nowrap; }
/* 経過日数・最高連続・悪魔の最長連続も括弧の補足ごと1行にし、入りきらなければ fitText で縮める。
   補足の行の高さは 1 にして、補足が付いても箱の高さを変えない（PC のオートで箱ががたつかないように） */
#days, #best, #bestTails { white-space: nowrap; }
.dd-sub { margin-left: 4px; font-size: 0.8rem; line-height: 1; font-weight: 500; color: var(--muted); white-space: nowrap; display: inline-block; }

/* ---- items ---- */
.items-body { display: flex; flex-direction: column; gap: 8px; }
.items[hidden] { display: none; }
/* 神殿の柱の飾り（PC だけ）。アイテム欄の真下につながった帯で、23連続まではこちらを見せておく */
.items-deco { display: none; }
@media (min-width: 481px) {
  .items, .items[hidden] { display: block; overflow: hidden; }
  .items-reel { position: relative; }
  .items[hidden] .items-reel { transform: translateY(-100%); }
  .items-deco { display: block; position: absolute; left: 0; top: 100%; width: 100%; height: 100%; }
  .items-deco .g { fill: none; stroke: var(--gold); stroke-width: 1.5; stroke-linejoin: round; opacity: 0.55; }
  .items-deco .m { fill: none; stroke: var(--muted); stroke-width: 1; opacity: 0.35; }
  /* 状態表示はアイテムを重ねると2行になるので、最初から2行分取っておく（欄の高さを変えない） */

}
.items-status { margin: 0; text-align: center; color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; }
/* 状態表示の数字は変わるたびに跳ねる（記録欄の N と同じ reachPop） */
.status-n { display: inline-block; }
.status-n.pop { animation: reachPop 0.4s ease-out; }
/* 状態の行は1行・高さ固定（アイコンが増えても、文章を出しても、下のタイルを動かさない） */
.items-status { height: 28px; display: flex; align-items: center; justify-content: center; }
.status-row { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.status-medal { width: 22px; height: 22px; }
.status-pct { font-size: 1.05rem; margin-right: 4px; }
.status-arrow { margin: 0 2px; }  /* 確定中の「100→85%」。数字と同じ金色 */
.status-item { position: relative; display: inline-flex; align-items: center; gap: 1px; }
.status-item svg { width: 20px; height: 20px; fill: none; stroke: var(--gold); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.status-item.rare svg { stroke: url(#rareStroke); }
.status-item.lose svg { stroke: #ff6b6b; }    /* 背徳の契約に失敗（天使 20%） */
.status-item.creak .status-badge { color: #ff6b6b; }  /* 永遠のロザリオが崩れ始めた */
.status-badge { font-size: 0.7rem; color: var(--gold); }
/* ロザリオがきしむ・崩れた。うれしい知らせではないので金色にしない。残り回数はアイコンの横の「あと N」で分かるので文には入れない */
.status-msg { white-space: nowrap; }
.status-msg.creak { color: #ef5350; }    /* 熱い…〜もう限界だ！：危うさを朱赤で */
.status-msg.crumble { color: #90a5bb; }  /* 崩れた：力が抜けた冷たい青灰 */
/* PC は前と同じ高さ（2行分 44px）を取っておく。アイテム欄と神殿の柱を縮めないため */
@media (min-width: 481px) {
  .items-status { height: 44px; }
}
.items-title { margin: 0; text-align: center; font-size: 0.875rem; letter-spacing: 0.15em; color: var(--muted); }
/* 5つを1行に並べる（スマホ幅でも折り返さない） */
.items-list { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.item {
  position: relative;
  border-radius: 10px;
  border: 1px solid var(--gold-line);
  background: var(--panel);
  touch-action: pan-y;  /* 横のスワイプで版を切り替える */
}
.item:has(.item-use:not(:disabled)):hover { border-color: var(--gold); }
.item-use {
  font: inherit;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 2px;
  border: 0;
  background: none;
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.item-use:disabled { opacity: 0.4; cursor: default; }
.item svg { width: 28px; height: 28px; fill: none; stroke: var(--gold); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.item-name { font-size: 0.75rem; line-height: 18px; font-weight: 700; white-space: nowrap; }
/* 6文字以上（黄金の砂時計など）はスマホ幅のタイルに入るよう小さくする。行の高さは px で固定して、版を切り替えても欄の高さを変えない */
.item-name.long { font-size: 0.5625rem; }
.item-note { font-size: 0.625rem; line-height: 15px; color: var(--muted); white-space: nowrap; }
/* 9文字以上（天使80%か20%）も同じく小さくする。行の高さは変えない */
.item-note.long { font-size: 0.5625rem; }
.item-count { font-size: 0.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
/* 降りきったら見出しを一度光らせる。入手した種類はアイコンと名前を跳ねさせる（レア版は大きく） */
/* 見出しは0.3秒で白く光り、そのまま1.5秒保ってから金色に落ち着き、モードの間ゆっくり明暗を続ける */
.items-title.flash { animation: titleFlash 2.8s ease-out forwards, titleBreathe 3s ease-in-out 2.8s infinite; }
/* 欄が隠れている間（PC で上へ引っ込んだ後）は描き続けない */
.items[hidden] .items-title.flash { animation-play-state: paused; }
@keyframes titleFlash {
  0% { color: var(--muted); text-shadow: none; }
  11%, 64% { color: #fff; text-shadow: 0 0 8px #fff, 0 0 24px #fff3c4, 0 0 48px var(--gold), 0 0 80px var(--gold); }
  100% { color: var(--gold); text-shadow: 0 0 6px rgba(232, 196, 90, 0.6); }
}
@keyframes titleBreathe {
  0%, 100% { color: var(--gold); text-shadow: 0 0 6px rgba(232, 196, 90, 0.6); }
  50% { color: #f6dc8a; text-shadow: 0 0 4px rgba(255, 255, 255, 0.5), 0 0 16px var(--gold); }
}
.item.got svg, .item.got .item-name { animation: reachPop 0.4s ease-out; }
.item.got .item-name { color: var(--gold); }
/* レア版：枠・アイコン・名前を「23」の数字と同じ虹色で光らせる。入手したときは大きく跳ねる */
.item.rare {
  border-color: transparent;
  background: linear-gradient(var(--panel), var(--panel)) padding-box,
    linear-gradient(90deg, #ff5e5e, #ffb65e, #fff35e, #6bff7a, #5ec8ff, #9b6bff, #ff5ec8) border-box;
}
.item.rare svg { stroke: #ff5e5e; animation: rareGlow 2s linear infinite; }
@keyframes rareGlow {
  from { filter: hue-rotate(0deg) drop-shadow(0 0 3px #ff5e5e); }
  to { filter: hue-rotate(360deg) drop-shadow(0 0 3px #ff5e5e); }
}
.item.rare.got svg, .item.rare.got .item-name { animation: rarePop 0.6s ease-out, rareGlow 2s linear infinite; }
@keyframes rarePop { 0% { transform: scale(1); } 40% { transform: scale(1.6); } 100% { transform: scale(1); } }
/* ふつう版とレア版の切り替え（PC は右上の太い ›、スマホは点）。
   › は裏の版の色：ふつう版の表では虹色（裏にレア版がある）、レア版の表では灰色 */
.item-flip {
  position: absolute;
  top: 2px;
  right: 2px;
  padding: 3px;
  display: flex;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.item-flip:hover { color: var(--gold); }
.item .item-flip svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 3; animation: none; filter: none; }
.item:not(.rare) .item-flip svg { stroke: #ff5e5e; animation: rareGlow 2s linear infinite; }
.item-dots { display: flex; gap: 3px; margin-top: 2px; }
.item-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--off); }
.item-dots i.on { background: var(--gold); }
.item-dots i.rare {
  background: conic-gradient(#ff5e5e, #ffb65e, #fff35e, #6bff7a, #5ec8ff, #9b6bff, #ff5ec8, #ff5e5e);
  animation: rareGlow 2s linear infinite;
}
/* リザルトの「使ったアイテム」：アイコンだけを使った順に並べる */
/* 1 段の数は共有画像と同じ（--per-row、game.js の USED_PER_ROW）。幅が狭いときはアイコンを小さくする */
.used-items { display: grid; grid-template-columns: repeat(var(--per-row, 13), minmax(0, 22px)); gap: 4px; padding-top: 2px; }
.used-items svg { width: 100%; height: auto; aspect-ratio: 1; fill: none; stroke: var(--gold); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.used-items svg.rare { stroke: #ff5e5e; animation: rareGlow 2s linear infinite; }
/* リザルトのカギはほかのアイコンと同じ大きさ。行内のままだと文字の行の高さで下にずれる */
.used-items .key { width: auto; height: auto; aspect-ratio: 1; cursor: default; }
.used-items .key svg { stroke-width: 1.6; }

/* ---- controls ---- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.btn {
  font: inherit;
  font-weight: 700;
  padding: 12px 20px;
  border-radius: 10px;
  border: 1px solid var(--off);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--gold); color: #3a2a00; border-color: var(--gold-dark); flex: 1 1 140px; }
.btn.ghost { background: none; color: var(--muted); margin-left: auto; }
.btn.running { background: var(--stage4); color: #2a0010; }
/* オートは文字の後ろにマークを添える（止まっているとき ▶▶、動いているとき ■）。スマホと同じ形 */
#autoBtn::after {
  content: "";
  display: inline-block;
  width: 14px;
  height: 10px;
  margin-left: 6px;
  background: currentColor;
  -webkit-mask: var(--auto-mark) center / contain no-repeat;
  mask: var(--auto-mark) center / contain no-repeat;
}
#autoBtn.running::after { width: 10px; -webkit-mask: none; mask: none; }
/* 結果文の行の左端のオート：マークだけのボタン（PC もスマホも出す）。
   箱は透明で、押せる範囲だけ上下に広げて結果文の行の中央に合わせる（44 = 24 + 10 × 2）。
   文字の ▶ ■ は字体で上下位置がずれるため図形で描く。2026-11-11 に大きくした（前：▶▶ 14×10px、■ 10×10px） */
.auto-icon {
  position: absolute;
  left: 0;
  bottom: -10px;
  width: 52px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  color: var(--text);  /* 動いていることはマークで分かるので、動作中も色は変えない */
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;  /* タップした瞬間の青い強調表示を出さない */
}
.auto-icon:disabled { opacity: 0.4; cursor: default; }
.auto-icon::before {
  content: "";
  width: 18px;
  height: 13px;
  background: currentColor;
  -webkit-mask: var(--auto-mark) center / contain no-repeat;
  mask: var(--auto-mark) center / contain no-repeat;
}
.auto-icon.running::before { width: 13px; -webkit-mask: none; mask: none; }
/* PC は下のオートボタンだけにする（2026-11-14）。アイコンはスマホだけ */
@media (min-width: 481px) {
  .auto-icon { display: none; }
}

.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.75rem; color: var(--muted); }

.field select {
  font: inherit;
  font-size: 1rem;
  padding: 10px;
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--off);
}

/* ---- intro ---- */
.intro {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  overflow-y: auto;
}

.intro.hidden { display: none; }

.intro-inner {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 16px 40px;
  line-height: 1.7;
}

.intro-coin { display: block; width: 120px; height: 120px; margin: 8px auto 0; }
.intro-title { margin: 8px 0 0; text-align: center; color: var(--gold); letter-spacing: 0.08em; font-size: 2rem; }
.intro-lead { margin: 0 0 8px; text-align: center; color: var(--muted); }
.intro h2 { margin: 24px 0 8px; font-size: 1.05rem; color: var(--gold); border-bottom: 1px solid var(--off); padding-bottom: 4px; }
.intro p { margin: 0 0 10px; }
.intro ul { margin: 0; padding-left: 1.2em; }
.intro li { margin-bottom: 6px; }
.intro strong { color: var(--gold); }
.intro-note { margin-top: 20px; text-align: center; color: var(--muted); font-size: 0.85rem; }
.intro-volume { justify-content: center; margin: 0 auto 12px; }
.intro-start { display: block; width: 100%; margin-top: 8px; font-size: 1.1rem; }
/* 「はじめる」の下に小さく出すクレジット */
.intro-credits { margin-top: 28px; color: var(--muted); font-size: 0.75rem; }
.intro .intro-credits p { margin: 0 0 4px; }
.intro .intro-credits ul { margin: 0 0 8px; padding-left: 1em; list-style: none; }
.intro .intro-credits li { margin-bottom: 2px; }
/* 一番下の制作者表記。左にロゴの絵（文字なし、クレジットと同じ灰色・透過） */
.intro .intro-maker { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 32px 0 8px; color: var(--muted); font-size: 0.8rem; letter-spacing: 0.04em; }
.intro-maker img { height: 32px; width: auto; }
/* 語の途中（「ゲ／ーム」「1／つ伸び」）で折れないよう、文節の切れ目で折り返し、最終行に1語だけ残さない */
.intro-inner { word-break: auto-phrase; text-wrap: pretty; }
/* 説明文は1行ずつ span に分け、スマホ幅（1行約20字）で収まる所で改行する */
.intro-s { display: block; }
/* PC 幅では、続けて読む行を同じ行に並べる */
.intro-s.intro-join { display: inline; }
/* オートの後ろにマーク ▶▶ を添えて、ゲーム画面で探しやすくする */
.intro-auto-icon {
  display: inline-block;
  width: 18px;
  height: 13px;
  margin: 0 4px;
  vertical-align: -1px;
  background: var(--text);
  -webkit-mask: var(--auto-mark) center / contain no-repeat;
  mask: var(--auto-mark) center / contain no-repeat;
}

@media (max-width: 640px) {
  .intro-s.intro-join { display: block; }
}

/* ---- probability dialog ---- */
.prob {
  background: var(--bg);
  color: var(--text);
  border: 2px solid var(--gold-dark);
  border-radius: 16px;
  padding: 20px;
  width: min(92vw, 460px);
}
.prob::backdrop { background: rgba(0, 0, 0, 0.7); }
.prob h2 { margin: 0 0 12px; color: var(--gold); font-size: 1.2rem; text-align: center; }
.prob-note { font-size: 0.75rem; color: var(--muted); margin: 12px 0; line-height: 1.6; }
.prob .btn { width: 100%; }

/* ---- clear dialog ---- */
.clear {
  background: var(--bg);
  color: var(--text);
  border: 2px solid var(--gold);
  border-radius: 16px;
  padding: 20px;
  width: min(92vw, 420px);
  text-align: center;
}

.clear::backdrop { background: rgba(0, 0, 0, 0.7); }
.clear h2 { margin: 0; font-size: 2rem; white-space: nowrap; }
/* 見出しの左右に最終形態の天使・悪魔メダル */
.clear-head { display: flex; align-items: center; justify-content: center; gap: clamp(8px, 5vw, 24px); margin: 0 0 12px; }
.clear-medal { width: clamp(44px, 13vw, 64px); height: auto; flex: none; }
/* 手動だけの23連続・オート22＋手動23の45連続のときだけ、見出しの上に筆記体で出す。
   字体は Great Vibes（OFL、fonts/GreatVibes-OFL.txt）から「Congratulations!」の文字だけ切り出したもの */
@font-face {
  font-family: "Great Vibes";
  src: url("fonts/great-vibes-congrats.woff2") format("woff2");
  font-display: block;
}
.clear-congrats { margin: 0 0 4px; font-family: "Great Vibes", cursive; font-size: 2.6rem; line-height: 1.25; white-space: nowrap; }
.clear-congrats[hidden] { display: none; }
.clear.congrats h2 { font-size: 1.6rem; }
.clear dl { margin: 0 0 16px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; text-align: left; }
/* 共有画像と同じ並び：値の短い項目（.half）は2つずつ横に、ほかは横いっぱい。.half の値は1行のまま縮める（fitText） */
.clear dl > div { min-width: 0; grid-column: 1 / -1; }
.clear dl > div.half { grid-column: auto; }
/* 値は折り返さず、入りきらなければ fitText で縮める（共有画像と同じ） */
.clear dl > div:not(.used) dd { white-space: nowrap; word-break: normal; }
.clear .btn { width: 100%; }
/* 切り替えがないときは閉じるだけで全幅を使う */
.clear-actions { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; }
.clear-actions .btn { min-width: 0; }
.clear-actions [hidden] { display: none; }

@media (max-width: 480px) {
  .memory-row { gap: 2px; }
  .cell { height: 16px; }
  .preview { width: 16px; height: 16px; right: -7px; top: 20px; }
  .memory-row { padding-bottom: 20px; }

  /* 停止設定・速度を2列に並べ、リセットは右の列へ */
  .app { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 8px; }
  .header, .memory, .stage, .items, .stats { grid-column: 1 / -1; }
  .controls { display: contents; }
  /* トスはコイン、オートは結果文の行のアイコンで押す */
  #tossBtn, #autoBtn { display: none; }

  /* 箱幅は内容に左右させず、行間を8pxに揃える */
  .stats dl { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stats dl > div { min-width: 0; }
  /* 悪魔の最長連続と最高記録のリザルトもスマホで出す（2026-11-15。トスはコインのタップ・オートはメダルの近くになったので、
     記録欄が下に伸びても遊びにくくならない。前は2つを隠していた） */
  /* 経過日数・最高連続は括弧の補足ごと1行にし、入りきらなければ fitText で縮める（補足も em で一緒に縮む）。
     確率2つの見出しも、N の桁が増えたら折り返さずに縮める */
  .stats #days, .stats #best, #reachLabel, #probLabel { white-space: nowrap; }
  .stats .dd-sub { font-size: 0.73em; line-height: 1; }

  .controls .field { min-width: 0; }
  .controls .field select { width: 100%; min-width: 0; min-height: 44px; padding-inline: 6px; font-size: 0.875rem; }
  #resetBtn { grid-column: 2; justify-self: end; margin-top: -6px; }
}

@media (prefers-reduced-motion: reduce) {
  .rainbow, .streak-num.rainbow.bump { animation: none; }
  .item.rare svg, .item.got svg, .item.got .item-name, .used-items svg.rare, .item:not(.rare) .item-flip svg, .item-dots i.rare, .status-n.pop { animation: none; }
  .reach-n.pop, .key.got svg, .icon-btn.notice { animation: none; }
  .items-title.flash { animation: none; color: var(--gold); }
  .item.rare svg, .used-items svg.rare, .item:not(.rare) .item-flip svg { stroke: url(#rareStroke); }
}
/* 演出の重さ（⚙️の小窓のスライダー。古いスマホで重いとき用、2026-11-14）。初めは HI（下の指定なし）
   LOW（html.lite）：何もしていない間も流れ続ける虹色・光を止める。虹色そのものは止めた形で残す
   MID（html.fx-mid）：アイコンは光と色の回転をやめて止まった虹色の線にし、文字の虹色の流れを 1 秒 10 コマにする
   どちらも、コインの回転・昇降・跳ねるなど、操作に応える動きはそのまま */
html:is(.lite, .fx-mid) .item.rare svg, html:is(.lite, .fx-mid) .used-items svg.rare,
html:is(.lite, .fx-mid) .item:not(.rare) .item-flip svg {
  animation: none; filter: none; stroke: url(#rareStroke);
}
html:is(.lite, .fx-mid) .item.rare.got svg, html:is(.lite, .fx-mid) .item.rare.got .item-name { animation: rarePop 0.6s ease-out; }
html:is(.lite, .fx-mid) .item-dots i.rare { animation: none; }
html.lite .rainbow, html.lite .icon-btn.notice { animation: none; }
@media (prefers-reduced-motion: no-preference) {
  html.lite .items-title.flash { animation: titleFlash 2.8s ease-out forwards; }
}
html.lite .streak-num.rainbow.bump { animation: bump 0.25s; }
html.fx-mid .rainbow { animation-timing-function: steps(20); }

.clear-share { display: flex; gap: 8px; margin-top: 10px; }
.clear-share .btn { flex: 1; }
.clear-note { margin: 8px 0 0; font-size: 0.75rem; color: var(--muted); }

/* ---- result image dialog ---- */
.image-dialog { width: min(94vw, 460px); }
.image-dialog .result-image { border: none; }
.result-image { display: block; width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--off); }
.image-dialog .clear-share .btn { width: auto; }
#imageClose { margin-top: 4px; }
