/* ============================================
   カウントアップ - Count Up
   ============================================ */
:root {
  --bg-deep: #0d1030;
  --bg-mid: #171b4a;
  --accent: #3ec9ff;
  --accent2: #ff5c7a;
  --accent3: #ffe14d;
  --text: #f2f5ff;
  --text-dim: #9aa3d0;
  --font-num: 'Avenir Next', 'Futura', 'Segoe UI', 'Verdana', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-jp: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Yu Gothic UI', Meiryo, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  font-family: var(--font-jp);
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#game-container {
  position: fixed;
  inset: 0;
  /* フッター固定バナー広告ぶんだけ縮める（広告なしのときは 0px） */
  /* 共通ヘッダーぶんだけ下げる */
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  overflow: hidden;
  background:
    radial-gradient(ellipse 120% 80% at 50% -10%, #232a6b 0%, transparent 55%),
    radial-gradient(ellipse 100% 70% at 50% 110%, #1c1450 0%, transparent 55%),
    radial-gradient(circle at 20% 35%, rgba(62, 201, 255, .07) 0%, transparent 30%),
    radial-gradient(circle at 80% 65%, rgba(255, 92, 122, .07) 0%, transparent 30%),
    linear-gradient(180deg, var(--bg-deep) 0%, var(--bg-mid) 100%);
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.hidden { display: none !important; }

/* ============ HUD ============ */
#hud {
  position: absolute;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  right: 0;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  pointer-events: none;
  z-index: 10;
}

.hud-label {
  display: block;
  font-family: var(--font-num);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .18em;
  color: var(--text-dim);
}

#hud-next, #hud-miss {
  min-width: 64px;
  text-align: center;
  background: rgba(13, 16, 48, .55);
  border: 1px solid rgba(154, 163, 208, .25);
  border-radius: 12px;
  padding: 5px 10px 7px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#hud-next-num {
  font-family: var(--font-num);
  font-size: 24px;
  font-weight: 900;
  color: var(--accent3);
  line-height: 1.05;
  text-shadow: 0 0 12px rgba(255, 225, 77, .5);
}

#hud-miss-count {
  font-family: var(--font-num);
  font-size: 24px;
  font-weight: 900;
  color: var(--accent2);
  line-height: 1.05;
}

#hud-time {
  font-family: var(--font-num);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--text);
  text-shadow: 0 0 16px rgba(62, 201, 255, .55);
  font-variant-numeric: tabular-nums;
}

/* ============ ミュートボタン ============ */
.icon-btn {
  position: absolute;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(154, 163, 208, .35);
  background: rgba(13, 16, 48, .6);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  transition: transform .15s, background .15s;
}
.icon-btn:active { transform: scale(.9); }
.icon-btn.muted { opacity: .5; }

/* ============ カウントダウン ============ */
#countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  pointer-events: none;
  font-family: var(--font-num);
  font-size: min(38vw, 200px);
  font-weight: 900;
  color: var(--accent3);
  text-shadow: 0 0 40px rgba(255, 225, 77, .6), 0 6px 0 rgba(0, 0, 0, .25);
}
#countdown.go { color: #4dd97a; text-shadow: 0 0 40px rgba(77, 217, 122, .7), 0 6px 0 rgba(0,0,0,.25); }
#countdown span {
  display: block;
  animation: cd-pop .9s cubic-bezier(.2, 1.6, .4, 1) both;
}
@keyframes cd-pop {
  0% { transform: scale(2.2); opacity: 0; }
  25% { transform: scale(1); opacity: 1; }
  80% { transform: scale(.96); opacity: 1; }
  100% { transform: scale(.7); opacity: 0; }
}

/* ============ 画面共通 ============ */
.screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* 中央寄せは先頭・末尾の auto マージンで行う（justify-content: center だと、
     中身が画面より高いときに上端が切れてスクロールでも戻れなくなる） */
  justify-content: flex-start;
  gap: 18px;
  padding: 24px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  background: rgba(10, 12, 38, .82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
  animation: screen-in .35s ease both;
}
@keyframes screen-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.screen > :first-child { margin-top: auto; }
.screen > :last-child { margin-bottom: auto; }

/* ============ タイトル ============ */
.title-logo { text-align: center; position: relative; }

.title-numbers {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 10px;
}
.tn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  font-family: var(--font-num);
  font-size: 26px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .25);
  animation: tn-bob 2.4s ease-in-out infinite;
}
.tn-1 {
  background: linear-gradient(160deg, #ff8aa0, #ff5c7a);
  border-radius: 50%;
  box-shadow: 0 0 22px rgba(255, 92, 122, .55);
}
.tn-2 {
  background: linear-gradient(160deg, #7fdcff, #3ec9ff);
  border-radius: 12px;
  box-shadow: 0 0 22px rgba(62, 201, 255, .55);
  animation-delay: .3s;
}
.tn-3 {
  background: linear-gradient(160deg, #ffec85, #ffc93e);
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
  animation-delay: .6s;
  padding-top: 14px;
}
@keyframes tn-bob {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-8px) rotate(3deg); }
}

.title-jp {
  font-size: min(11vw, 46px);
  font-weight: 800;
  letter-spacing: .06em;
  background: linear-gradient(180deg, #fff 30%, #9fd8ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 18px rgba(62, 201, 255, .45));
}

.title-en {
  font-family: var(--font-num);
  font-size: min(4.6vw, 19px);
  font-weight: 700;
  letter-spacing: .5em;
  margin-left: .5em;
  color: var(--text-dim);
  margin-top: 4px;
}

.title-desc {
  text-align: center;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.75;
  color: var(--text);
}
.title-desc strong { color: var(--accent3); }

.title-best {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: rgba(62, 201, 255, .08);
  border: 1px solid rgba(62, 201, 255, .3);
  border-radius: 14px;
  padding: 8px 22px;
}
.best-label {
  font-family: var(--font-num);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .2em;
  color: var(--accent);
}
#title-best-time {
  font-family: var(--font-num);
  font-size: 30px;
  font-weight: 900;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.best-unit { font-size: 13px; color: var(--text-dim); }

/* ============ ボタン ============ */
.btn {
  font-family: var(--font-jp);
  font-weight: 800;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, filter .15s;
}
.btn:active { transform: scale(.94); }

.btn-primary {
  font-size: 20px;
  padding: 15px 64px;
  color: #06122a;
  background: linear-gradient(180deg, #8fe0ff 0%, #3ec9ff 55%, #1fa8e6 100%);
  box-shadow: 0 6px 0 #0d6ea3, 0 10px 26px rgba(62, 201, 255, .4);
}
.btn-primary:active { box-shadow: 0 2px 0 #0d6ea3, 0 4px 12px rgba(62, 201, 255, .4); }

.btn-sub {
  font-size: 15px;
  font-weight: 700;
  padding: 11px 26px;
  color: var(--text);
  background: rgba(154, 163, 208, .16);
  border: 1px solid rgba(154, 163, 208, .4);
}
.btn-sub:hover { background: rgba(154, 163, 208, .28); }

.controls-hint {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-dim);
}

/* ============ ランキング ============ */
.ranking {
  list-style: none;
  min-width: min(78vw, 300px);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ranking:empty { display: none; }
.ranking li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--font-num);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-dim);
  background: rgba(154, 163, 208, .08);
  border-radius: 8px;
  padding: 5px 14px;
  font-variant-numeric: tabular-nums;
}
.ranking li .rank-pos { width: 2.2em; font-weight: 700; }
.ranking li .rank-time { margin-left: auto; color: var(--text); font-weight: 700; }
.ranking li.rank-top .rank-pos { color: var(--accent3); }
.ranking li.rank-new {
  background: rgba(255, 225, 77, .12);
  border: 1px solid rgba(255, 225, 77, .45);
  color: var(--text);
}

/* ============ リザルト ============ */
.result-title {
  font-family: var(--font-num);
  font-size: min(13vw, 56px);
  font-weight: 900;
  letter-spacing: .08em;
  background: linear-gradient(180deg, #fff 25%, #4dd97a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 22px rgba(77, 217, 122, .5));
  animation: result-pop .5s cubic-bezier(.2, 1.6, .4, 1) both;
}
@keyframes result-pop {
  from { transform: scale(.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.new-record {
  font-family: var(--font-num);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--accent3);
  text-shadow: 0 0 14px rgba(255, 225, 77, .7);
  animation: record-blink 1s ease-in-out infinite;
}
@keyframes record-blink {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .65; transform: scale(1.06); }
}

.result-time {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
#result-time {
  font-family: var(--font-num);
  font-size: min(19vw, 84px);
  font-weight: 900;
  color: var(--text);
  text-shadow: 0 0 26px rgba(62, 201, 255, .55);
  font-variant-numeric: tabular-nums;
}
.result-unit { font-size: 20px; color: var(--text-dim); }

.result-rating {
  font-size: 19px;
  font-weight: 800;
  color: var(--accent3);
}

.result-stats {
  display: flex;
  gap: 12px;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: rgba(154, 163, 208, .1);
  border-radius: 12px;
  padding: 9px 16px;
  min-width: 88px;
}
.stat-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: .08em;
}
.stat span:last-child {
  font-family: var(--font-num);
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.result-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

/* ============ フッター ============ */
.title-footer {
  margin-top: 6px;
  text-align: center;
  font-size: 11.5px;
  line-height: 1.8;
  color: var(--text-dim);
}
.title-footer a {
  color: var(--accent);
  text-decoration: none;
}
.title-footer a:hover { text-decoration: underline; }

/* ============ 低身長画面の調整 ============ */
@media (max-height: 640px) {
  .screen { gap: 12px; }
  .title-numbers { margin-bottom: 4px; }
  .tn { width: 40px; height: 40px; font-size: 20px; }
  .controls-hint { display: none; }
  #result-time { font-size: 56px; }
  .result-title { font-size: 40px; }
}

/* ---------- 全国ランキング（SGRanking 共通モジュール） ---------- */
.sgr-hidden {
  display: none !important;
}

.sgr-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(10, 12, 38, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, #1c2158 0%, var(--bg-mid) 100%);
  color: var(--text);
  border: 1px solid rgba(154, 163, 208, 0.35);
  border-radius: 16px;
  padding: 20px 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 30px rgba(62, 201, 255, 0.12);
}

.sgr-title {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  text-align: center;
}

.sgr-tabs {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.sgr-tab {
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  background: rgba(154, 163, 208, 0.16);
  color: var(--text);
  cursor: pointer;
}

.sgr-tab-active {
  background: var(--accent);
  color: #06122a;
}

.sgr-register-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  color: var(--accent3);
}

.sgr-form {
  display: flex;
  gap: 8px;
}

.sgr-name {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-family: var(--font-jp);
  padding: 8px 10px;
  border: 2px solid rgba(154, 163, 208, 0.45);
  border-radius: 8px;
  background: rgba(13, 16, 48, 0.65);
  color: var(--text);
}

.sgr-name::placeholder {
  color: var(--text-dim);
}

.sgr-name:focus {
  outline: none;
  border-color: var(--accent);
}

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: linear-gradient(180deg, #8fe0ff 0%, var(--accent) 60%, #1fa8e6 100%);
  color: #06122a;
  cursor: pointer;
}

.sgr-submit:hover {
  filter: brightness(1.08);
}

.sgr-submit:disabled {
  opacity: 0.5;
  cursor: default;
}

.sgr-error {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--accent2);
}

.sgr-status {
  margin: 0;
  font-size: 13px;
  text-align: center;
  color: var(--text-dim);
}

.sgr-list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.sgr-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.sgr-row:nth-child(even) {
  background: rgba(154, 163, 208, 0.1);
}

.sgr-row.sgr-row-me {
  background: var(--accent);
  color: #06122a;
}

.sgr-rank {
  width: 2em;
  text-align: right;
  font-weight: bold;
  flex-shrink: 0;
}


.sgr-row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sgr-row-score {
  font-weight: bold;
  flex-shrink: 0;
}

.sgr-close {
  border: 1px solid rgba(154, 163, 208, 0.4);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(154, 163, 208, 0.16);
  color: var(--text);
  cursor: pointer;
}

.sgr-close:hover {
  background: rgba(154, 163, 208, 0.28);
}

.sgr-cta {
  margin: 0;
  text-align: center;
}

.sgr-cta-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  color: var(--accent3);
  text-shadow: 0 0 12px rgba(255, 225, 77, 0.4);
}

.sgr-cta-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 15px;
  font-weight: 800;
  font-family: var(--font-jp);
  background: linear-gradient(180deg, #fff0a0 0%, var(--accent3) 55%, #ffc93e 100%);
  color: #3a2c00;
  cursor: pointer;
  box-shadow: 0 4px 0 #b8892a, 0 8px 22px rgba(255, 225, 77, 0.35);
  transition: transform 0.15s, box-shadow 0.15s;
}

.sgr-cta-btn:active {
  transform: scale(0.94);
  box-shadow: 0 2px 0 #b8892a, 0 4px 12px rgba(255, 225, 77, 0.35);
}

.sgr-cta-link {
  border: none;
  background: none;
  padding: 6px;
  font-size: 13px;
  color: var(--text-dim);
  text-decoration: underline;
  cursor: pointer;
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / js/ad-banner.js が挿入する）
   --ad-h    : 広告そのものの高さ。広告なしのときは 0px
   --ad-space: レイアウトが空けるべき高さ（広告 + セーフエリア）
   ========================================================================== */
:root {
  --ad-h: 0px;
  --ad-space: 0px;
}
html.has-ad-banner {
  --ad-space: calc(var(--ad-h, 0px) + env(safe-area-inset-bottom, 0px));
}

.ad-banner {
  /* height は広告そのものの高さ。セーフエリアぶんの padding は外側に足す */
  box-sizing: content-box;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  /* ランキング・リザルト等の全画面オーバーレイ（2147483000）よりは下に置く */
  z-index: 2147482000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: var(--ad-h, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow: hidden;
  background: rgba(14, 16, 20, 0.86);
  /* border ではなく inset shadow にして、枠線ぶん高さがずれないようにする */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.ad-banner__frame {
  display: block;
  width: 100%;
  height: var(--ad-h, 0px);
  border: 0;
  color-scheme: light;
}

@media print {
  .ad-banner { display: none; }
}
