:root {
  --bg: #12142a;
  --text: #f4f1ea;
  --muted: #a9a9c4;
  --accent: #ffd166;
  --accent2: #ef476f;
  --card: #1d2042;
  --bar-h: 84px; /* 広告バーの高さ（すき間・ラベル込み） */
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif; }
button { font: inherit; }

#game {
  position: relative; margin: 0 auto;
  width: 100%; max-width: 560px;
  height: calc(88svh - var(--bar-h)); min-height: 420px;
  overflow: hidden; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  background: #f6c8a8;
}
@media (min-width: 700px) { #game { height: calc(min(92svh, 960px) - var(--bar-h)); border-radius: 0 0 18px 18px; } }
#c { display: block; width: 100%; height: 100%; }

/* ゲーム画面の下の広告バー */
.ad-bar { max-width: 560px; margin: 0 auto; padding: 18px 8px 0; height: var(--bar-h);
  /* 連打したときに指がはみ出しても、文字が選ばれたり画面がずれたりしないように */
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; }
.ad-bar-label { display: block; font-size: 10px; line-height: 12px; color: var(--muted); }
.ad-bar-box { height: 50px; border-radius: 6px; overflow: hidden; background: rgba(255,255,255,.04);
  border: 1px dashed rgba(255,255,255,.15); }
.ad-bar-box .adsbygoogle { display: block; width: 100%; height: 50px; }
.ad-bar-box:has(ins[data-ad-status="filled"]) { border: 0; background: transparent; }

#hud { position: absolute; inset: 0 0 auto 0; padding: 14px 16px; pointer-events: none;
  display: flex; justify-content: space-between; align-items: flex-start; }
#score { font-size: 52px; font-weight: 900; line-height: 1; color: #fff;
  text-shadow: 0 3px 0 rgba(0,0,0,.25); font-variant-numeric: tabular-nums; }
#gems { display: flex; align-items: center; gap: 6px; font-size: 22px; font-weight: 800; color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,.25); margin-top: 6px; margin-right: 44px; }
.gem-ico { width: 16px; height: 16px; background: #4cc9f0; transform: rotate(45deg); border-radius: 3px;
  box-shadow: 0 0 10px #4cc9f0; display: inline-block; }
#gems.bump { animation: bump .25s; }
@keyframes bump { 50% { transform: scale(1.3); } }

#popups { position: absolute; inset: 0; pointer-events: none; }
.pop { position: absolute; left: 50%; top: 38%; transform: translateX(-50%);
  font-weight: 900; font-size: 26px; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.3);
  animation: pop .8s ease-out forwards; white-space: nowrap; }
.pop.edge { color: var(--accent); }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, 10px) scale(.7); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -40px) scale(1); } }

.icon-btn { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.25); color: #fff; font-size: 18px; cursor: pointer; z-index: 5; }
.icon-btn.off { opacity: .45; text-decoration: line-through; }

.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; padding: 24px; gap: 8px;
  background: linear-gradient(180deg, rgba(18,20,42,.15), rgba(18,20,42,.55)); }
.overlay[hidden], #hud[hidden] { display: none; }
.logo { margin: 0; font-size: 64px; line-height: .9; font-weight: 900; letter-spacing: 2px; color: #fff;
  text-shadow: 0 5px 0 var(--accent2), 0 10px 24px rgba(0,0,0,.3); }
.sub { margin: 4px 0 18px; font-weight: 700; color: #fff; opacity: .9; }
.how { background: rgba(0,0,0,.3); border-radius: 14px; padding: 12px 18px; line-height: 1.9; color: #fff; }
.how b { color: var(--accent); }
.best-line { margin: 10px 0 0; color: #fff; font-weight: 700; }
.tap { margin-top: 26px; font-size: 22px; font-weight: 900; color: #fff; }
.blink { animation: blink 1.1s infinite; }
@keyframes blink { 50% { opacity: .35; } }

.over-label { margin: 0; font-weight: 900; letter-spacing: 3px; color: #fff; opacity: .9; }
.final { font-size: 88px; font-weight: 900; line-height: 1; color: #fff; text-shadow: 0 5px 0 rgba(0,0,0,.25); }
.newrec { margin: 0; color: var(--accent); font-weight: 900; font-size: 20px; animation: blink .6s infinite; }
.btns { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; width: min(280px, 100%); }
.btn { border: 0; border-radius: 999px; padding: 14px 18px; font-weight: 900; font-size: 17px; cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,.25); }
.btn:disabled { opacity: .6; cursor: default; }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.btn-main { background: var(--accent); color: #2b2100; }
.btn-ad { background: var(--accent2); color: #fff; }
.btn-sub { background: rgba(255,255,255,.9); color: #1b1f3b; }

.below { max-width: 640px; margin: 0 auto; padding: 18px 16px 40px; line-height: 1.8; }
.below h2 { font-size: 1.15rem; margin: 28px 0 6px; border-left: 4px solid var(--accent); padding-left: 10px; }
.below a { color: var(--accent); }
.below ul { padding-left: 1.3em; }
.ad-slot { min-height: 100px; margin: 18px 0; border: 1px dashed rgba(255,255,255,.15); border-radius: 8px; }
footer { margin-top: 40px; display: flex; justify-content: space-between; color: var(--muted); font-size: .9rem; }

.policy { max-width: 720px; margin: 0 auto; padding: 24px 16px 60px; line-height: 1.85; }
.policy h2 { font-size: 1.05rem; margin-top: 28px; }
.policy a { color: var(--accent); }

/* ===== インクリメンタル版の追加 ===== */
#score small, .final small { font-size: .45em; margin-left: 2px; opacity: .85; }
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; margin-right: 44px; }
.coin-line { display: flex; align-items: center; gap: 6px; font-size: 24px; font-weight: 900; color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,.25); font-variant-numeric: tabular-nums; }
#gems { margin: 0; font-size: 18px; }
#shields { margin-top: 6px; font-size: 18px; letter-spacing: 2px; }
.coin-ico { width: 18px; height: 18px; border-radius: 50%; display: inline-block; flex: none;
  background: radial-gradient(circle at 35% 35%, #fff3b0, #ffd166 45%, #e09f1f); box-shadow: 0 0 0 2px rgba(0,0,0,.15); }

.wallet { display: inline-flex; align-items: center; gap: 8px; background: rgba(0,0,0,.35); color: #fff;
  border-radius: 999px; padding: 6px 14px; font-weight: 900; font-size: 20px; font-variant-numeric: tabular-nums; }
#title .wallet { position: absolute; top: 12px; left: 12px; }
.inf { color: var(--accent); }
.how-small { font-size: 13px; opacity: .85; }
#starLine { margin-left: 10px; color: var(--accent); }
.btn-shop { background: #7cf2c9; color: #0d3b2e; position: relative; margin-top: 14px; min-width: 200px; }
.shop-badge { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent2); color: #fff; font-size: 14px; line-height: 22px; animation: blink 1s infinite; }
.shop-badge[hidden] { display: none; }
#title .tap { margin-top: 16px; }

.earn { background: rgba(0,0,0,.3); border-radius: 14px; padding: 10px 16px; color: #fff; min-width: 220px; margin-top: 6px; }
.earn-rows { font-size: 14px; line-height: 1.7; }
.earn-rows div { display: flex; justify-content: space-between; gap: 16px; }
.earn-total { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 28px; font-weight: 900;
  color: var(--accent); margin-top: 4px; font-variant-numeric: tabular-nums; }
.earn-total.big { font-size: 38px; margin: 10px 0; }
#over .btns { margin-top: 12px; }
/* リザルト画面：上に広告、下に結果とボタン（あいだを空けて押し間違いを防ぐ） */
#over { justify-content: space-between; padding: 54px 16px 20px; gap: 16px; overflow-y: auto; }
.over-main { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
#over .final { font-size: 72px; }
.over-ad { width: 100%; max-width: 468px; flex-shrink: 0; }
.over-ad-label { display: block; text-align: left; font-size: 10px; color: rgba(255,255,255,.75); margin-bottom: 2px; }
.over-ad-box { width: 100%; height: 100px; border-radius: 8px; overflow: hidden;
  background: rgba(0,0,0,.25); border: 1px dashed rgba(255,255,255,.25); }
.over-ad-box .adsbygoogle { display: block; width: 100%; height: 100px; }
.over-ad-box:has(ins[data-ad-status="filled"]) { border: 0; background: transparent; }
#over .btn-row { display: flex; gap: 10px; }
.next-goal { font-size: 12px; font-weight: 700; color: rgba(255,255,255,.85); margin-top: 2px; }
.next-goal.ready { color: #7cf2c9; }
#over .btn-row .btn { flex: 1; min-width: 0; margin-top: 0; padding-left: 8px; padding-right: 8px; }
/* リザルト画面を小さいスマホでも1画面に収める（ゲーム画面の高さで判定） */
#game { container: game / size; }
@container game (max-height: 760px) {
  #over { padding-top: 50px; gap: 10px; }
  .over-main { gap: 4px; }
  #over .final { font-size: 52px; }
  #over .earn { padding: 6px 14px; }
  #over .earn-total { font-size: 22px; }
  #over .btn { padding: 11px 14px; font-size: 16px; }
  #over .btns { gap: 8px; margin-top: 8px; }
  #over .btn-row { gap: 8px; }
}
@container game (max-height: 540px) {
  #over { padding-top: 48px; padding-bottom: 12px; gap: 6px; }
  .over-ad-box, .over-ad-box .adsbygoogle { height: 60px; }
  #over .over-label { font-size: 13px; }
  #over .final { font-size: 40px; }
  #over .newrec { font-size: 16px; }
  #over .earn-rows { display: none; }
  #over .earn-total { font-size: 20px; }
  #over .btn { padding: 9px 12px; font-size: 15px; }
  #over .btns { gap: 6px; margin-top: 6px; }
  #title { justify-content: flex-start; padding-top: 52px; gap: 4px; }
  #title .logo { font-size: 46px; }
  #title .sub { margin: 2px 0 8px; }
  #title .mode-tag { margin: 2px 0 8px; font-size: 19px; }
  #title .how { padding: 6px 14px; line-height: 1.5; }
  #title .best-line { margin-top: 6px; }
  #title .title-btns { margin-top: 8px; gap: 8px; }
  #title .how-small { display: none; }
  #title .btn-endless { padding: 8px 14px; font-size: 19px; }
  #title .title-btns .btn-row .btn { padding: 10px 8px; font-size: 16px; }
  #title .tap { margin-top: 8px; font-size: 18px; }
}
#over .btn-shop { margin-top: 0; }

.panel { position: absolute; inset: 0; z-index: 10; background: rgba(14,16,36,.94); color: #fff;
  display: flex; flex-direction: column; touch-action: pan-y; }
.panel[hidden] { display: none; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 12px; }
.btn-close { width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.12); color: #fff;
  font-size: 24px; cursor: pointer; }
.panel-body { overflow-y: auto; padding: 0 12px 24px; -webkit-overflow-scrolling: touch; }
.panel-body h2 { font-size: 16px; margin: 10px 4px 8px; color: var(--muted); }
.upg { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; }
.upg-ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 22px; flex: none;
  background: rgba(255,255,255,.08); }
.upg-main { flex: 1; min-width: 0; }
.upg-name { font-weight: 900; }
.upg-name small { color: var(--muted); font-weight: 700; margin-left: 6px; }
.upg-desc { font-size: 12px; color: var(--muted); line-height: 1.5; }
.upg-desc b { color: #7cf2c9; }
.upg-buy { flex: none; min-width: 92px; border: 0; border-radius: 12px; padding: 10px 8px; font-weight: 900; cursor: pointer;
  background: var(--accent); color: #2b2100; display: flex; align-items: center; justify-content: center; gap: 5px;
  font-variant-numeric: tabular-nums; }
.upg-buy .coin-ico { width: 14px; height: 14px; }
.upg-buy:disabled { background: #3a3d63; color: #8d8fb0; cursor: default; }
.upg-buy.max { background: #2e5e4f; color: #7cf2c9; }
.upg.flash { animation: flash .35s; }
@keyframes flash { 50% { background: #35407a; } }

.prestige { background: var(--card); border-radius: 14px; padding: 12px 14px; font-size: 14px; line-height: 1.7; }
.prestige p { margin: 0 0 8px; }
.prestige b { color: var(--accent); }
.pres-info { color: #fff; font-weight: 700; }
.btn-prestige { background: linear-gradient(90deg, #ffd166, #ef476f); color: #fff; width: 100%; }
.btn-prestige:disabled { background: #3a3d63; color: #8d8fb0; }

.modal { align-items: center; justify-content: center; padding: 20px; background: rgba(14,16,36,.8); }
.modal-box { background: var(--card); border-radius: 18px; padding: 22px 20px; text-align: center; width: min(340px, 100%); }
.modal-box h2 { margin: 0 0 10px; font-size: 20px; }
.modal-box p { margin: 0; line-height: 1.7; }
.modal-box .btns { margin: 16px auto 0; }

/* ===== エンドレスモード ===== */
/* タイトルのボタン（エンドレスを大きく、強化とランキングを横に並べる） */
/* タイトル画面のモード切り替え（エンドレスを押すと、エンドレス用のタイトルになる） */
#title:not(.endless) .endless-only { display: none; }
#title.endless .normal-only { display: none; }
.mode-tag { margin: 4px 0 14px; font-weight: 900; font-size: 22px; letter-spacing: .12em; color: #fff;
  text-shadow: 0 2px 0 #ef476f; text-align: center; }
.mode-tag small { display: block; margin-top: 2px; font-size: 12px; letter-spacing: 0; font-weight: 700; text-shadow: none; opacity: .9; }
.title-btns { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 14px; width: min(280px, 100%); }
.title-btns .btn-row { display: flex; gap: 10px; width: 100%; }
.title-btns .btn-row .btn { flex: 1; min-width: 0; margin-top: 0; padding: 12px 8px; }
.btn-endless { width: 100%; background: linear-gradient(90deg, #ef476f, #ff9f68); color: #fff; font-size: 21px;
  padding: 10px 18px; line-height: 1.25; }
.btn-endless small { display: block; font-size: 11px; font-weight: 700; opacity: .95; }

/* 走っている間の表示：距離を大きく、コインと宝石は出さない */
#endTag { margin-top: 6px; font-size: 12px; font-weight: 900; letter-spacing: 2px; color: var(--accent);
  text-shadow: 0 2px 0 rgba(0,0,0,.25); }
#endTag span { margin-left: 8px; letter-spacing: 0; color: #fff; font-weight: 700; }
#hud:not(.endless) #endTag { display: none; }
#hud.endless .hud-right { display: none; }

/* 結果画面：通常とエンドレスで中身を切りかえる */
#over:not(.endless) .endless-only { display: none; }
#over.endless .normal-only { display: none; }
.end-best { margin: 0; min-height: 1.4em; color: #fff; font-weight: 800; font-size: 15px; }
#over .btn-row.endless-only .btn { white-space: nowrap; }


/* 起動に失敗したときの案内（index.html の __bootFail） */
#bootErr { position: absolute; inset: 0; z-index: 50; display: flex; flex-direction: column; justify-content: center;
  gap: 4px; padding: 24px; background: rgba(18,20,42,.96); color: #fff; text-align: center; line-height: 1.7; }
#bootErr p { margin: 0 0 8px; }
#bootErr .boot-err-detail { font-size: 11px; color: var(--muted); word-break: break-all; }
#bootErr button { align-self: center; padding: 10px 20px; border: 0; border-radius: 999px; background: var(--accent);
  color: #1b1f3b; font-weight: 800; }
/* リザルト画面の広告をコメントアウトしている間は、中身を画面の中央に置く（広告を戻すと元の配置に戻る） */
#over:not(:has(.over-ad)) { justify-content: center; }
/* ゲーム画面が最小の高さ（420px 前後）のときは、タイトルの「画面をタップでスタート」まで収まるようにさらに詰める */
@container game (max-height: 450px) {
  #title { padding-top: 44px; gap: 2px; }
  #title .logo { font-size: 38px; }
  #title .sub, #title .mode-tag { margin: 0 0 4px; }
  #title .how { padding: 4px 12px; font-size: 14px; }
  #title .best-line { margin-top: 2px; }
  #title .title-btns { margin-top: 4px; gap: 6px; }
  #title .tap { margin-top: 4px; font-size: 16px; }
}
