:root {
  --bg: #08070b;
  --surface: rgba(255,255,255,0.06);
  --border: rgba(255,255,255,0.14);
  --red: #e8132b;
  --red2: #ff4757;
  --gold: #ffd700;
  --text: #fff;
  --dim: #a89fae;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%; width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}
body {
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none;
  touch-action: none;
  font-feature-settings: "palt" 1;
}
button { font-family: inherit; color: inherit; border: none; background: none; cursor: pointer; }

/* ===== デスクトップは縦長フレームを中央に ===== */
#app {
  position: fixed; inset: 0;
  max-width: 560px;
  margin: 0 auto;
  overflow: hidden;
  background: #0c0a12;
  box-shadow: 0 0 90px rgba(232,19,43,0.22);
}
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ===== HUD ===== */
.hud {
  position: absolute; inset: 0;
  pointer-events: none;
  padding: calc(var(--safe-t) + 10px) 12px 0;
  display: flex; flex-direction: column; gap: 7px;
}
.hud button { pointer-events: auto; }

.hud-row { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 38px; height: 38px; flex: none;
  border-radius: 12px;
  background: rgba(10,8,14,0.55);
  border: 1px solid var(--border);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-size: 1rem; line-height: 1;
  display: grid; place-items: center;
  transition: transform 0.12s, background 0.15s;
}
.icon-btn:active { transform: scale(0.9); background: rgba(232,19,43,0.35); }
.icon-btn.off { opacity: 0.5; }

.timer {
  margin-left: auto;
  display: flex; align-items: baseline; gap: 4px;
  padding: 5px 14px 6px;
  border-radius: 14px;
  background: rgba(10,8,14,0.55);
  border: 1px solid var(--border);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-variant-numeric: tabular-nums;
}
.timer .t-num { font-size: 1.5rem; font-weight: 900; letter-spacing: -0.02em; line-height: 1; }
.timer .t-unit { font-size: 0.62rem; color: var(--dim); font-weight: 700; }
.timer.warn { border-color: rgba(255,71,87,0.85); background: rgba(80,6,16,0.6); }
.timer.warn .t-num { color: #ff5b7c; animation: tick 0.5s steps(2, jump-none) infinite; }
@keyframes tick { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.14); } }

.score-line { display: flex; align-items: baseline; gap: 8px; padding-left: 4px; }
.score-line .sc {
  font-size: 2.15rem; font-weight: 900; letter-spacing: -0.03em; line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 14px rgba(0,0,0,0.85), 0 0 26px rgba(255,215,0,0.35);
}
.score-line .lives { margin-left: auto; font-size: 1rem; letter-spacing: 1px; filter: drop-shadow(0 2px 5px rgba(0,0,0,0.8)); }
.stage-chip {
  font-size: 0.6rem; font-weight: 900; letter-spacing: 0.1em;
  border: 1px solid currentColor; border-radius: 999px;
  padding: 3px 9px; opacity: 0.95;
  transition: color 0.5s, border-color 0.5s;
}

/* コンボゲージ */
.combo {
  padding-left: 4px;
  height: 22px;
  display: flex; align-items: center; gap: 8px;
  opacity: 0; transform: translateY(-6px);
  transition: opacity 0.2s, transform 0.2s;
}
.combo.on { opacity: 1; transform: none; }
.combo-bar {
  flex: 1; height: 5px; border-radius: 99px;
  background: rgba(255,255,255,0.14); overflow: hidden;
}
.combo-fill { height: 100%; width: 100%; border-radius: 99px; background: linear-gradient(90deg, #ffd700, #ff4757); transform-origin: left; }
.combo-txt { font-size: 0.8rem; font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; text-shadow: 0 2px 8px rgba(0,0,0,0.8); }
.combo-mul { font-size: 0.68rem; font-weight: 900; color: #fff; background: linear-gradient(135deg, #ff4757, #ffd700); border-radius: 6px; padding: 2px 7px; }

/* パワーアップ表示 */
.pw-row { display: flex; gap: 6px; padding-left: 4px; }
.pw-chip {
  display: flex; align-items: center; gap: 5px;
  font-size: 0.66rem; font-weight: 900;
  border-radius: 99px; padding: 3px 10px 4px;
  background: rgba(10,8,14,0.6); border: 1px solid currentColor;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}

/* ===== オーバーレイ共通 ===== */
.ov {
  position: absolute; inset: 0; z-index: 5;
  display: none; flex-direction: column; align-items: center;
  /* justify-content:center は中身が画面より高いと上が切れるので使わない。
     先頭/末尾の margin:auto なら short=中央寄せ / tall=先頭から表示 になる */
  justify-content: flex-start;
  padding: calc(var(--safe-t) + 18px) 22px calc(var(--safe-b) + 18px);
  text-align: center;
  background: rgba(6,5,9,0.82);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  overflow-y: auto; overscroll-behavior: contain;
  touch-action: pan-y;                      /* body の touch-action:none を上書き */
  -webkit-overflow-scrolling: touch;
}
/* 上下に伸縮するスペーサーを挟んで中央寄せする。
   :first-child/:last-child に margin:auto を付ける手もあるが、
   末尾の要素が hidden だとフレックスアイテムから外れて下寄りになるので使わない */
.ov::before, .ov::after { content: ''; display: block; flex: 1 1 0; min-height: 0; }
.ov.show { display: flex; animation: ovIn 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
@keyframes ovIn { from { opacity: 0; transform: scale(1.04); } to { opacity: 1; transform: none; } }

.brand-logo { width: min(58%, 210px); filter: drop-shadow(0 6px 20px rgba(232,19,43,0.5)); }

.big-title {
  font-size: clamp(1.9rem, 9vw, 2.6rem); font-weight: 900; letter-spacing: -0.02em;
  background: linear-gradient(to bottom, #fff 20%, #ffd700 55%, #ff9f1a);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 10px rgba(255,140,0,0.45));
}
.lead { font-size: 0.82rem; color: var(--dim); line-height: 1.75; }

/* ===== タイトルロゴ ===== */
.title-logo-wrap {
  position: relative; width: min(94%, 400px);
  animation: logoIn 0.85s cubic-bezier(0.16, 1.2, 0.3, 1) both, logoFloat 3.4s ease-in-out 0.85s infinite;
}
.title-logo {
  display: block; width: 100%; height: auto;
  filter: drop-shadow(0 8px 26px rgba(255,150,0,0.45)) drop-shadow(0 0 46px rgba(255,60,120,0.3));
  animation: logoGlow 2.6s ease-in-out infinite;
}
/* 斜めの光がロゴの形だけを走る（マスクはJSでロゴのsrcを流し込む） */
.title-shine {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(105deg,
    transparent 38%, rgba(255,255,255,0.16) 46%, rgba(255,255,255,0.85) 50%,
    rgba(255,255,255,0.16) 54%, transparent 62%);
  background-size: 260% 100%;
  mix-blend-mode: screen;
  -webkit-mask-size: 100% 100%; mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  animation: logoShine 3.6s ease-in-out 1s infinite;
  opacity: 0;
}
.title-shine.ready { opacity: 1; }
@keyframes logoIn {
  0%   { transform: scale(0.55) rotate(-7deg); opacity: 0; }
  60%  { transform: scale(1.08) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
@keyframes logoFloat {
  0%, 100% { transform: translateY(0) rotate(-0.6deg); }
  50%      { transform: translateY(-9px) rotate(0.6deg); }
}
@keyframes logoGlow {
  0%, 100% { filter: drop-shadow(0 8px 26px rgba(255,150,0,0.45)) drop-shadow(0 0 40px rgba(255,60,120,0.26)); }
  50%      { filter: drop-shadow(0 8px 30px rgba(255,190,40,0.7))  drop-shadow(0 0 62px rgba(255,90,160,0.5)); }
}
@keyframes logoShine {
  0%   { background-position: 190% 0; }
  55%  { background-position: -90% 0; }
  100% { background-position: -90% 0; }
}

/* ===== 遊び方（既定では畳んでおく） ===== */
.how-toggle {
  font-size: 0.74rem; font-weight: 900; letter-spacing: 0.06em;
  color: var(--dim); padding: 8px 16px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
}
.how-toggle:active { background: rgba(255,255,255,0.14); }
.rules[hidden] { display: none; }

.btn-main {
  width: 100%; max-width: 330px;
  padding: 16px 20px;
  border-radius: 16px;
  font-size: 1.05rem; font-weight: 900; letter-spacing: 0.06em;
  color: #fff;
  background: linear-gradient(to bottom, #ff4757, #d1071e);
  box-shadow: 0 5px 0 #7d0413, 0 12px 30px rgba(232,19,43,0.5);
  transition: transform 0.12s, box-shadow 0.12s;
}
.btn-main:active { transform: translateY(4px); box-shadow: 0 1px 0 #7d0413, 0 5px 16px rgba(232,19,43,0.4); }
.btn-main.gold {
  background: linear-gradient(to bottom, #ffe680, #f0a500);
  color: #40260a; box-shadow: 0 5px 0 #8a5c00, 0 12px 30px rgba(255,190,0,0.45);
}
.btn-main.gold:active { box-shadow: 0 1px 0 #8a5c00, 0 5px 16px rgba(255,190,0,0.4); }
.btn-main.line {
  background: linear-gradient(to bottom, #3ee07f, #06B44F);
  color: #fff; box-shadow: 0 5px 0 #04722f, 0 12px 30px rgba(6,180,79,0.45);
  display: flex; align-items: center; justify-content: center; gap: 9px;
}
.btn-main.line:active { box-shadow: 0 1px 0 #04722f, 0 5px 16px rgba(6,180,79,0.4); }
.btn-main.line::before {
  content: 'LINE';
  font-size: 0.62rem; font-weight: 900; letter-spacing: 0.04em;
  color: #06B44F; background: #fff;
  border-radius: 7px; padding: 3px 7px 4px; line-height: 1;
}
.btn-sub {
  width: 100%; max-width: 330px;
  padding: 12px 18px; border-radius: 13px;
  font-size: 0.84rem; font-weight: 900; letter-spacing: 0.05em;
  color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
}
.btn-sub:active { background: rgba(255,255,255,0.16); }

/* ===== タイトル ===== */
.rules { display: grid; gap: 7px; width: 100%; max-width: 330px; }
.rule {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 9px 13px;
  font-size: 0.76rem; text-align: left; line-height: 1.45;
}
.rule .ic { font-size: 1.15rem; flex: none; width: 1.5em; text-align: center; }
.rule b { color: var(--gold); }
.rule .ng { color: #ff8fa3; }
.best-line { font-size: 0.78rem; color: var(--dim); font-weight: 700; }
.best-line b { color: var(--gold); font-size: 1.05rem; }

/* ===== カウントダウン ===== */
#ovCount { background: rgba(6,5,9,0.55); }
.count-num {
  font-size: clamp(5rem, 34vw, 9rem); font-weight: 900; line-height: 1;
  color: #fff; text-shadow: 0 0 50px rgba(255,215,0,0.85), 0 8px 24px rgba(0,0,0,0.7);
  animation: countPop 0.72s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
@keyframes countPop {
  0% { transform: scale(2.1); opacity: 0; }
  22% { transform: scale(1); opacity: 1; }
  75% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.72); opacity: 0; }
}

/* ===== リザルト ===== */
/* 花火を透かせたいので、リザルトだけ背景を薄く（上下だけ濃くして文字を守る） */
#ovResult {
  background: linear-gradient(180deg,
    rgba(6,5,9,0.92) 0%, rgba(6,5,9,0.5) 26%, rgba(6,5,9,0.5) 72%, rgba(6,5,9,0.92) 100%);
  backdrop-filter: none; -webkit-backdrop-filter: none;
}
.res-wrap { width: 100%; max-width: 360px; display: flex; flex-direction: column; align-items: center; gap: 13px; }
.res-head { font-size: 1.5rem; font-weight: 900; letter-spacing: 0.06em; color: #ff5b7c; text-shadow: 0 2px 14px rgba(0,0,0,0.9); }
.res-head.timeup { color: var(--gold); }
.title-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 20px 10px; border-radius: 999px;
  font-size: 1rem; font-weight: 900; letter-spacing: 0.04em;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.3);
  color: #e9e6ee;
}
.title-badge .ic { font-size: 1.25rem; }

/* ===== 称号の等級ごとの見た目 ===== */
.title-badge.r {
  color: #bcd8ff; border-color: rgba(122,180,255,0.7);
  background: linear-gradient(135deg, rgba(60,120,255,0.2), rgba(120,200,255,0.16));
  box-shadow: 0 0 20px rgba(90,160,255,0.28);
}
.title-badge.sr {
  color: #ffe680; border-color: rgba(255,215,0,0.75);
  background: linear-gradient(135deg, rgba(255,215,0,0.22), rgba(255,140,0,0.18));
  box-shadow: 0 0 26px rgba(255,190,0,0.35);
}
.title-badge.ssr {
  color: #e2c0ff; border-color: rgba(192,132,252,0.8);
  background: linear-gradient(135deg, rgba(160,60,255,0.28), rgba(255,80,190,0.2));
  box-shadow: 0 0 30px rgba(180,90,255,0.45);
}
/* UR以上は虹。文字自体を虹グラデーションで流す */
.title-badge.ur, .title-badge.lr {
  border: none;
  background:
    linear-gradient(rgba(10,8,14,0.9), rgba(10,8,14,0.9)) padding-box,
    linear-gradient(90deg, #ff5b5b, #ffd700, #5bff7e, #2ee5ff, #c15bff, #ff5b5b) border-box;
  border: 2px solid transparent;
  background-size: auto, 300% 100%;
  animation: urBorder 3s linear infinite;
  box-shadow: 0 0 30px rgba(255,120,220,0.4);
}
.title-badge.ur span:not(.ic), .title-badge.lr span:not(.ic) {
  background: linear-gradient(90deg, #ff8a8a, #ffe066, #7dff9e, #66e9ff, #d68aff, #ff8a8a);
  background-size: 300% 100%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: urText 3s linear infinite;
}
.title-badge.lr {
  box-shadow: 0 0 44px rgba(255,150,240,0.6), 0 0 90px rgba(120,200,255,0.35);
  animation: urBorder 1.6s linear infinite, lrPulse 1.5s ease-in-out infinite;
}
.title-badge.lr span:not(.ic) { animation: urText 1.6s linear infinite; }
@keyframes urBorder { from { background-position: 0 0, 0% 50%; } to { background-position: 0 0, 300% 50%; } }
@keyframes urText   { from { background-position: 0% 50%; } to { background-position: 300% 50%; } }
@keyframes lrPulse  { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.045); } }
/* タイトル画面のベスト表示用の小さいバッジ */
.title-badge.sm { font-size: 0.78rem; padding: 5px 13px 6px; margin-top: 7px; }
.title-badge.sm .ic { font-size: 0.95rem; }
.res-score { font-size: 3.6rem; font-weight: 900; line-height: 1; letter-spacing: -0.04em; font-variant-numeric: tabular-nums;
  background: linear-gradient(to bottom, #fff, #ffd700 70%, #ff9f1a);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 12px rgba(0,0,0,0.95)); }
.res-score-cap { font-size: 0.62rem; letter-spacing: 0.3em; color: var(--dim); font-weight: 900; text-shadow: 0 2px 8px rgba(0,0,0,0.9); }
.res-stats { display: flex; gap: 7px; width: 100%; }
.res-stat {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 9px 4px 10px;
}
.res-stat .v { font-size: 1.05rem; font-weight: 900; color: #fff; font-variant-numeric: tabular-nums; }
.res-stat .k { font-size: 0.58rem; color: var(--dim); letter-spacing: 0.08em; font-weight: 700; margin-top: 2px; }
.next-title {
  font-size: 0.72rem; color: var(--dim); font-weight: 700;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9);
}
.next-title b { color: var(--gold); }
.next-title:empty { display: none; }
.res-new {
  font-size: 0.88rem; font-weight: 900; color: #40260a;
  background: linear-gradient(90deg, #ffe680, #ffb300);
  border-radius: 999px; padding: 6px 18px;
  animation: newPulse 1.1s ease-in-out infinite;
}
@keyframes newPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }

/* ===== ランキング登録フォーム ===== */
.entry {
  width: 100%; border-radius: 14px; padding: 13px 14px 14px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,215,0,0.55);
  box-shadow: 0 0 24px rgba(255,190,0,0.18);
  display: flex; flex-direction: column; gap: 9px;
}
.entry[hidden] { display: none; }
.entry-head { font-size: 0.82rem; font-weight: 900; letter-spacing: 0.04em; color: var(--gold); }
.entry-note { font-size: 0.68rem; color: var(--dim); line-height: 1.6; }
.entry-note b { color: #fff; }
.entry-input {
  width: 100%; padding: 12px 14px;
  font-size: 1rem; font-family: inherit;
  color: #fff; background: rgba(0,0,0,0.45);
  border: 1px solid var(--border); border-radius: 11px;
  -webkit-user-select: text; user-select: text;
}
.entry-input::placeholder { color: rgba(255,255,255,0.32); }
.entry-input:focus { outline: none; border-color: var(--gold); background: rgba(0,0,0,0.6); }
.entry-input[hidden] { display: none; }
.entry-link {
  font-size: 0.68rem; color: var(--dim); text-decoration: underline;
  background: none; border: none; padding: 2px;
}
.entry-link[hidden] { display: none; }
.entry-msg { font-size: 0.72rem; font-weight: 700; line-height: 1.5; }
.entry-msg.ok { color: #7dffb0; }
.entry-msg.ng { color: #ff8fa3; }
.entry-msg:empty { display: none; }

/* ===== 賞品告知 ===== */
.prize {
  width: 100%; border-radius: 14px; padding: 12px 14px 11px;
  background: linear-gradient(135deg, rgba(0,200,140,0.2), rgba(255,215,0,0.16));
  border: 1px solid rgba(90,255,200,0.6);
  box-shadow: 0 0 26px rgba(0,220,150,0.22);
}
.prize-head { font-size: 0.7rem; font-weight: 900; letter-spacing: 0.06em; color: #a9ffe2; }
.prize-item {
  font-size: 1rem; font-weight: 900; line-height: 1.35; margin-top: 3px;
  background: linear-gradient(90deg, #7dffd0, #ffe680, #7dffd0);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  animation: prizeShine 3.2s linear infinite;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.8));
}
.prize-note { font-size: 0.62rem; color: rgba(255,255,255,0.66); margin-top: 5px; }
@keyframes prizeShine { from { background-position: 0% 50%; } to { background-position: 220% 50%; } }

.rank-box { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 11px 13px 12px; }
.rank-title { font-size: 0.62rem; font-weight: 900; letter-spacing: 0.16em; color: var(--gold); margin-bottom: 7px; text-align: left; }
.rank-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.rank-list li { display: flex; align-items: center; gap: 9px; font-size: 0.74rem; padding: 4px 6px; border-radius: 8px; }
.rank-list li.me { background: rgba(255,215,0,0.14); box-shadow: inset 0 0 0 1px rgba(255,215,0,0.45); }
.rank-list .no { width: 1.6em; font-weight: 900; color: var(--dim); text-align: left; }
.rank-list .tt { color: var(--dim); font-size: 0.68rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-list .pt { margin-left: auto; font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }
.rank-empty { font-size: 0.72rem; color: var(--dim); text-align: left; padding: 2px; }

.foot-link { font-size: 0.68rem; color: var(--dim); text-decoration: none; border-bottom: 1px solid rgba(255,255,255,0.2); padding-bottom: 1px; }
.copy { font-size: 0.6rem; color: var(--dim); opacity: 0.6; }

/* ===== ローディング ===== */
#ovLoad { background: var(--bg); }
.load-bar { width: min(64%, 230px); height: 4px; border-radius: 99px; background: rgba(255,255,255,0.13); overflow: hidden; }
.load-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--red), var(--gold)); transition: width 0.2s; }
.load-txt { font-size: 0.66rem; letter-spacing: 0.24em; color: var(--dim); font-weight: 900; }

.toast {
  position: absolute; left: 50%; bottom: calc(var(--safe-b) + 24px); transform: translateX(-50%);
  z-index: 9; padding: 10px 18px; border-radius: 999px;
  background: rgba(10,8,14,0.92); border: 1px solid var(--border);
  font-size: 0.76rem; font-weight: 700; white-space: nowrap;
  opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, -8px); }

.gap-s { height: 2px; }
.gap-m { height: 10px; }