/* ==========================================================================
   3Dマッチ - style.css
   ========================================================================== */

:root {
  --bg-deep: #0a0a1c;
  --bg-mid: #141433;
  --panel: rgba(22, 24, 54, 0.82);
  --panel-border: rgba(120, 140, 255, 0.22);
  --text: #eef0ff;
  --text-dim: #9aa2c8;
  --accent: #6c8cff;
  --accent-2: #ff6bcb;
  --gold: #ffd60a;
  --danger: #ff5566;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

.hidden { display: none !important; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(120% 90% at 20% 0%, #1d1550 0%, rgba(29, 21, 80, 0) 55%),
    radial-gradient(110% 90% at 85% 100%, #0e2a4d 0%, rgba(14, 42, 77, 0) 60%),
    linear-gradient(160deg, var(--bg-mid) 0%, var(--bg-deep) 70%);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* --------------------------------------------------------------------------
   ヘッダー
   -------------------------------------------------------------------------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(6px + var(--safe-top)) 12px 6px;
  background: rgba(10, 10, 30, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(120, 140, 255, 0.14);
  z-index: 10;
}

#logo {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: linear-gradient(120deg, #8fb0ff 0%, #d18bff 55%, #ff8fd4 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
}

#stats-bar {
  display: flex;
  gap: 14px;
  flex: 1;
  justify-content: center;
  min-width: 0;
}

.stat { display: flex; flex-direction: column; align-items: center; min-width: 44px; }
.stat-label { font-size: 10px; color: var(--text-dim); letter-spacing: 0.08em; }
.stat-value {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
#stat-combo.hot { color: var(--gold); text-shadow: 0 0 10px rgba(255, 214, 10, 0.55); }
#stat-time.warn { color: #ffd60a; }
#stat-time.danger {
  color: #ff5566;
  animation: time-pulse 0.5s ease-in-out infinite alternate;
}

#topbar-buttons { display: flex; gap: 6px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(40, 44, 90, 0.55);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s;
}
.icon-btn:hover { background: rgba(70, 76, 140, 0.65); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn:focus-visible, .primary-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   残り時間バー
   -------------------------------------------------------------------------- */

#time-wrap {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  z-index: 9;
}

#time-bar {
  height: 100%;
  width: 100%;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(90deg, #38e0a0, #6c8cff);
  transition: background-color 0.3s;
}
#time-bar.warn { background: linear-gradient(90deg, #ffd60a, #ff9f1a); }
#time-bar.danger {
  background: linear-gradient(90deg, #ff5566, #ff2244);
  animation: time-pulse 0.5s ease-in-out infinite alternate;
}
@keyframes time-pulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.6); }
}

/* --------------------------------------------------------------------------
   3Dステージ
   -------------------------------------------------------------------------- */

#stage-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#gl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
  outline: none;
}
#gl:focus-visible { box-shadow: inset 0 0 0 2px rgba(108, 140, 255, 0.6); }

#gl-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.8;
}

/* 浮遊スコア表示レイヤー */
#fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 5;
}

.float-score {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 12px rgba(108, 140, 255, 0.9), 0 2px 4px rgba(0, 0, 0, 0.6);
  animation: float-up 0.9s ease-out forwards;
  white-space: nowrap;
}
.float-score.combo { color: var(--gold); text-shadow: 0 0 14px rgba(255, 214, 10, 0.8), 0 2px 4px rgba(0, 0, 0, 0.6); }
.float-score.penalty { color: var(--danger); text-shadow: 0 0 12px rgba(255, 85, 102, 0.8), 0 2px 4px rgba(0, 0, 0, 0.6); }

@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -55%) scale(1.15); }
  30% { transform: translate(-50%, -70%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(0.95); }
}

/* レベルクリア等のバナー */
#banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  /* left: 50% の絶対配置は、何もしないと幅が「親の右半分」までに縮む。
     スマホ幅では「レベル N クリア！」が「クリ／ア！」と折り返していたので、中身の幅で決める */
  width: max-content;
  max-width: 92%;
  box-sizing: border-box;
  z-index: 6;
  padding: 16px 34px;
  border-radius: 18px;
  background: rgba(16, 18, 46, 0.88);
  border: 1px solid var(--panel-border);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.55), 0 0 40px rgba(108, 140, 255, 0.25);
  text-align: center;
  pointer-events: none;
}
#banner.hidden { display: none; }
#banner .banner-main {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.06em;
  background: linear-gradient(120deg, #8fb0ff, #ff8fd4);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
#banner .banner-sub { margin-top: 6px; font-size: 15px; font-weight: 700; color: var(--gold); }
#banner.show { animation: banner-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1); }
@media (max-width: 380px) {
  /* 幅320pxでも「レベル 100 クリア！」が1行に収まるようにする */
  #banner { padding: 14px 20px; }
  #banner .banner-main { font-size: 23px; }
  #banner .banner-sub { font-size: 14px; }
}
@keyframes banner-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* --------------------------------------------------------------------------
   フッター
   -------------------------------------------------------------------------- */

#footer {
  padding: 7px 12px calc(7px + var(--safe-bottom));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
  background: rgba(10, 10, 30, 0.55);
  border-top: 1px solid rgba(120, 140, 255, 0.14);
  flex-wrap: wrap;
}
/* 右の著作表記（もう一方のサイトへのリンクつき）が 1 行に収まらない幅では、右側だけを 2 行に折る（左のタイトルは折らない） */
#footer > div:first-child { flex: none; white-space: nowrap; }
#footer > div:last-child { text-align: right; }

#footer a { color: var(--accent); text-decoration: none; }
#footer a:hover { text-decoration: underline; }

/* --------------------------------------------------------------------------
   モーダル
   -------------------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5, 6, 18, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal.hidden { display: none; }
/* 遊び方は共通ヘッダーから結果画面の上でも開くので、他のモーダルより上に出す */
#modal-help { z-index: 101; }

.modal-box {
  width: 100%;
  max-width: 420px;
  max-height: calc((100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px)) - 40px);
  overflow-y: auto;
  padding: 26px 24px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6), 0 0 60px rgba(108, 140, 255, 0.12);
  text-align: center;
  animation: modal-in 0.35s cubic-bezier(0.2, 1.3, 0.4, 1);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(24px) scale(0.94); }
  to { opacity: 1; transform: none; }
}

.modal-title { font-size: 22px; font-weight: 800; margin-bottom: 14px; }

.title-3d {
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 0.02em;
  line-height: 1.1;
  margin-bottom: 12px;
  background: linear-gradient(120deg, #8fb0ff 0%, #d18bff 55%, #ff8fd4 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 10px 30px rgba(108, 140, 255, 0.25);
}
.title-3d span { display: block; font-size: 30px; letter-spacing: 0.3em; }

.modal-lead { font-size: 14px; line-height: 1.9; margin-bottom: 14px; }
.modal-lead strong, .rule-list strong { color: var(--gold); }

.rule-list {
  text-align: left;
  font-size: 13px;
  line-height: 1.9;
  color: var(--text-dim);
  margin: 0 auto 16px;
  padding-left: 1.4em;
  max-width: 330px;
}

.best-line { font-size: 13px; color: var(--text-dim); margin-bottom: 14px; }
.best-line span { color: var(--gold); font-weight: 700; font-size: 15px; }
.best-line.hidden { display: none; }

.primary-btn {
  display: inline-block;
  min-width: 180px;
  padding: 13px 30px;
  border: none;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(120deg, #5a7cff, #a55eea);
  box-shadow: 0 6px 22px rgba(90, 124, 255, 0.45);
  transition: transform 0.12s, box-shadow 0.12s;
}
.primary-btn:hover { transform: translateY(-2px); box-shadow: 0 9px 28px rgba(90, 124, 255, 0.55); }
.primary-btn:active { transform: scale(0.96); }

.secondary-btn {
  /* 幅によって「スタート」と並んだり折り返したりしないよう、常に次の行に置く */
  display: block;
  margin: 12px auto 0;
  padding: 10px 22px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(40, 44, 90, 0.5);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s, color 0.12s;
}
.secondary-btn:hover { background: rgba(70, 76, 140, 0.6); color: var(--text); }
.secondary-btn:active { transform: scale(0.96); }
.secondary-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 遊び方 */
.help-body {
  text-align: left;
  font-size: 13px;
  line-height: 1.9;
  color: var(--text);
  margin-bottom: 18px;
}
.help-body p { margin-bottom: 10px; }
.help-body ol { padding-left: 1.5em; margin-bottom: 10px; }
.help-body strong { color: var(--gold); }
.help-note { color: var(--text-dim); font-size: 12px; }

/* ゲームオーバー */
.new-record {
  font-size: 16px;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 12px;
  animation: record-pop 0.7s cubic-bezier(0.2, 1.5, 0.4, 1);
}
.new-record.hidden { display: none; }
@keyframes record-pop {
  from { opacity: 0; transform: scale(0.4); }
  to { opacity: 1; transform: scale(1); }
}

.result-grid { margin: 4px auto 20px; max-width: 280px; }
.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 4px;
  font-size: 14px;
  color: var(--text-dim);
  border-bottom: 1px solid rgba(120, 140, 255, 0.14);
}
.result-row:last-child { border-bottom: none; }
.result-value {
  font-size: 19px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   レスポンシブ
   -------------------------------------------------------------------------- */

@media (max-width: 480px) {
  #logo { font-size: 16px; }
  #stats-bar { gap: 10px; }
  .stat { min-width: 40px; }
  .stat-value { font-size: 14px; }
  .icon-btn { width: 33px; height: 33px; font-size: 14px; }
  .title-3d { font-size: 38px; }
  .title-3d span { font-size: 26px; }
}

@media (max-height: 460px) {
  /* 横持ちスマホ */
  #topbar { padding-top: calc(3px + var(--safe-top)); padding-bottom: 3px; }
  .stat-label { display: none; }
  #footer { padding-top: 4px; padding-bottom: calc(4px + var(--safe-bottom)); }
}

/* ==========================================================================
   全国ランキング（js/ranking.js が作る共通UI。クラスは sgr- プレフィックス）
   このゲームの見た目に合わせて指定する。
   ゲーム側の button / input / ol の指定に影響されないよう、
   効かせたいプロパティは省略せず明示する。
   ========================================================================== */

.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-top: calc(16px + var(--sgh-top, 0px));
  padding-bottom: calc(16px + max(var(--ad-space, 0px), env(safe-area-inset-bottom, 0px)));
  background: rgba(5, 6, 18, 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  overscroll-behavior: contain;
}

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 16px 16px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6), 0 0 60px rgba(108, 140, 255, 0.12);
  color: var(--text);
  font-family: inherit;
  text-align: center;
}

.sgr-title {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text);
}

.sgr-tabs { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.sgr-tab {
  appearance: none;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(40, 44, 90, 0.55);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.sgr-tab-active {
  background: rgba(108, 140, 255, 0.28);
  border-color: rgba(108, 140, 255, 0.7);
  color: var(--text);
}

.sgr-register {
  padding: 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 214, 10, 0.32);
  background: rgba(255, 214, 10, 0.08);
}
.sgr-register-msg {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 800;
  color: var(--gold);
}
.sgr-form { display: flex; gap: 8px; }
.sgr-name {
  flex: 1;
  min-width: 0;
  /* 16px 未満だと iOS でフォーカス時に画面が拡大される */
  font-size: 16px;
  font-family: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(10, 10, 28, 0.72);
  color: var(--text);
}
.sgr-name::placeholder { color: rgba(154, 162, 200, 0.7); }
.sgr-name:focus { outline: none; border-color: var(--accent); }
.sgr-submit {
  appearance: none;
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: linear-gradient(120deg, #5a7cff, #a55eea);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(90, 124, 255, 0.45);
  transition: transform 0.12s;
}
.sgr-submit:active { transform: scale(0.96); }
.sgr-submit:disabled { opacity: 0.5; cursor: default; box-shadow: none; }

.sgr-error { margin: 8px 0 0; font-size: 12px; font-weight: 700; color: var(--danger); }
.sgr-status { margin: 0; font-size: 13px; color: var(--text-dim); }

.sgr-list {
  margin: 0;
  padding: 0;
  list-style: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  text-align: left;
}
.sgr-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 14px;
}
.sgr-row:nth-child(even) { background: rgba(255, 255, 255, 0.05); }
.sgr-row-me {
  background: rgba(108, 140, 255, 0.26);
  box-shadow: inset 0 0 0 1px rgba(108, 140, 255, 0.6);
}
.sgr-rank {
  width: 2.2em;
  flex-shrink: 0;
  text-align: right;
  font-weight: 800;
  color: var(--text-dim);
}
.sgr-rank-top1 { color: var(--gold); }
.sgr-rank-top2 { color: #d9e2f2; }
.sgr-rank-top3 { color: #e2a15c; }
.sgr-row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sgr-row-score {
  flex-shrink: 0;
  font-weight: 800;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.sgr-close {
  appearance: none;
  padding: 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(40, 44, 90, 0.55);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s;
}
.sgr-close:hover { background: rgba(70, 76, 140, 0.65); }
.sgr-close:active { transform: scale(0.96); }

/* 結果画面に差し込まれる「登録する」CTA */
.sgr-cta { margin: 4px 0 16px; text-align: center; }
.sgr-cta-msg {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 800;
  color: var(--gold);
}
.sgr-cta-btn {
  appearance: none;
  padding: 13px 22px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: linear-gradient(120deg, #ffd76b, #ffab3d);
  color: #3a2410;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(255, 180, 70, 0.38);
  transition: transform 0.12s;
}
.sgr-cta-btn:active { transform: scale(0.96); }
.sgr-cta-link {
  appearance: none;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.sgr-cta-link:hover { color: var(--text); }
.sgr-cta-link:active { transform: scale(0.96); }

.sgr-submit:focus-visible,
.sgr-close:focus-visible,
.sgr-tab:focus-visible,
.sgr-cta-btn:focus-visible,
.sgr-cta-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 380px) {
  .sgr-form { flex-wrap: wrap; }
  .sgr-submit { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .sgr-panel, .sgr-submit, .sgr-close, .sgr-cta-btn { transition: none; }
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / 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; }
}
