/* ============================================================
   ブロック88 (Block 88) — スタイルシート
   ============================================================ */

:root {
  --bg-1: #1b1035;
  --bg-2: #2c1a58;
  --panel: rgba(255, 255, 255, 0.07);
  --panel-border: rgba(255, 255, 255, 0.12);
  --cell-empty: rgba(255, 255, 255, 0.06);
  --cell-border: rgba(255, 255, 255, 0.10);
  --text: #f4f1ff;
  --text-dim: #b9aee0;
  --accent: #ffb340;
  --accent-2: #ef5da8;
  --radius: 14px;
  --cell-gap: 4px;
}

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

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(120% 90% at 50% 0%, var(--bg-2) 0%, var(--bg-1) 55%, #120a26 100%);
  color: var(--text);
  min-height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  display: flex;
  justify-content: center;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* ---- 背景の飾りブロック ---- */
#bgDecor { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
#bgDecor .float-block {
  position: absolute;
  border-radius: 22%;
  opacity: 0.08;
  animation: floatUp linear infinite;
}
@keyframes floatUp {
  from { transform: translateY(110vh) rotate(0deg); }
  to   { transform: translateY(-20vh) rotate(200deg); }
}

/* ---- レイアウト ---- */
#app {
  position: relative;
  z-index: 1;
  width: min(480px, 100vw);
  padding: 14px 14px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---- ヘッダー ---- */
#topBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#logo { display: flex; align-items: center; gap: 8px; }
#logo h1 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-shadow: 0 2px 12px rgba(255, 179, 64, 0.35);
  white-space: nowrap;
}
.logo-88 {
  color: var(--accent);
  font-size: 1.5rem;
  margin-left: 2px;
}
.logo-block {
  width: 12px; height: 12px;
  border-radius: 3px;
  display: inline-block;
  animation: logoPulse 2.4s ease-in-out infinite;
}
.logo-block.b1 { background: #ffb340; animation-delay: 0s; }
.logo-block.b2 { background: #4fc3f7; animation-delay: 0.3s; }
.logo-block.b3 { background: #ef5da8; animation-delay: 0.6s; }
.logo-block.b4 { background: #7ed957; animation-delay: 0.9s; }
@keyframes logoPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.35); }
}

#scores { display: flex; gap: 8px; }
.score-box {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 5px 10px;
  text-align: center;
  min-width: 66px;
  backdrop-filter: blur(6px);
}
.score-label {
  display: block;
  font-size: 0.62rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.score-value {
  display: block;
  font-size: 1.15rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.score-box.best .score-value { color: var(--accent); }
.score-value.bump { animation: scoreBump 0.3s ease; }
@keyframes scoreBump {
  0% { transform: scale(1); }
  40% { transform: scale(1.3); color: #fff; }
  100% { transform: scale(1); }
}

#controls { display: flex; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}
.icon-btn:active { transform: scale(0.9); background: rgba(255,255,255,0.16); }

/* ---- コンボ表示 ---- */
#comboBanner {
  height: 1.6em;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 0 14px rgba(255, 179, 64, 0.6);
  opacity: 0;
  transition: opacity 0.2s ease;
}
#comboBanner.show { opacity: 1; animation: comboPop 0.45s ease; }
@keyframes comboPop {
  0% { transform: scale(0.5); }
  55% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* ---- 盤面 ---- */
#boardWrap {
  position: relative;
  width: 100%;
}
#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: var(--cell-gap);
  width: 100%;
  aspect-ratio: 1;
  padding: 8px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: inset 0 2px 14px rgba(0, 0, 0, 0.45), 0 8px 30px rgba(0, 0, 0, 0.35);
}
#board.shake { animation: boardShake 0.4s ease; }
@keyframes boardShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}

.cell {
  border-radius: 22%;
  background: var(--cell-empty);
  box-shadow: inset 0 0 0 1px var(--cell-border);
  position: relative;
  transition: background 0.1s ease;
}
.cell.filled {
  background: var(--c);
  box-shadow:
    inset 0 2px 2px rgba(255, 255, 255, 0.45),
    inset 0 -3px 3px rgba(0, 0, 0, 0.28),
    0 1px 4px rgba(0, 0, 0, 0.35);
  animation: cellPop 0.18s ease;
}
@keyframes cellPop {
  0% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* ドロップ位置プレビュー */
.cell.preview {
  background: color-mix(in srgb, var(--c) 42%, transparent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--c) 85%, white 15%);
}
/* 揃って消える予定のライン */
.cell.will-clear {
  animation: willClearPulse 0.7s ease-in-out infinite;
}
.cell.will-clear.filled {
  filter: brightness(1.5) saturate(1.2);
}
@keyframes willClearPulse {
  0%, 100% { filter: brightness(1.35); }
  50% { filter: brightness(1.8); }
}

/* 消去アニメーション */
.cell.clearing {
  animation: cellClear 0.3s ease forwards;
}
@keyframes cellClear {
  0% { transform: scale(1.15); filter: brightness(2.2); }
  100% { transform: scale(0); filter: brightness(2.2); opacity: 0; }
}

/* エフェクト用キャンバス */
#fx {
  position: absolute;
  inset: -60px;
  width: calc(100% + 120px);
  height: calc(100% + 120px);
  pointer-events: none;
  z-index: 5;
}

/* ---- 手持ちブロックのトレイ ---- */
#tray {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  min-height: 108px;
}
.tray-slot {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  min-height: 104px;
  transition: opacity 0.2s ease, transform 0.15s ease;
  touch-action: none;
}
.tray-slot.empty { opacity: 0.35; }
.tray-slot.dragging-src .piece { opacity: 0.25; }
.tray-slot .piece { animation: pieceIn 0.3s ease backwards; }
.tray-slot[data-slot="1"] .piece { animation-delay: 0.07s; }
.tray-slot[data-slot="2"] .piece { animation-delay: 0.14s; }
@keyframes pieceIn {
  from { transform: scale(0.3); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.tray-slot.unplaceable .piece { opacity: 0.3; filter: grayscale(0.8); }

/* ピース（トレイ内・ドラッグ中共通） */
.piece {
  display: grid;
  gap: 3px;
  pointer-events: none;
}
.piece .pcell { border-radius: 22%; }
.piece .pcell.on {
  background: var(--c);
  box-shadow:
    inset 0 2px 2px rgba(255, 255, 255, 0.45),
    inset 0 -3px 3px rgba(0, 0, 0, 0.28),
    0 1px 4px rgba(0, 0, 0, 0.35);
}

/* ドラッグ中のピース */
#dragGhost {
  position: fixed;
  left: 0; top: 0;
  z-index: 50;
  pointer-events: none;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.5));
  will-change: transform;
}

/* ---- ヒント ---- */
#hint {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* ---- スコアのフロート表示 ---- */
.score-float {
  position: fixed;
  z-index: 60;
  font-weight: 900;
  font-size: 1.5rem;
  color: #fff;
  text-shadow: 0 0 10px var(--accent), 0 2px 6px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  animation: floatScore 0.9s ease-out forwards;
  transform: translate(-50%, -50%);
}
.score-float.big { font-size: 2rem; color: var(--accent); }
.score-float.bonus { color: var(--accent-2); text-shadow: 0 0 12px var(--accent-2); }
@keyframes floatScore {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}

/* ---- ゲームオーバー ---- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 5, 25, 0.78);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s ease, visibility 0s;
}
/* 隠している間は visibility も落とし、「もう一度プレイ」に Tab でフォーカスが入らないようにする
   （フェードアウトが終わってから隠す） */
#overlay.hidden { opacity: 0; pointer-events: none; visibility: hidden; transition: opacity 0.3s ease, visibility 0s linear 0.3s; }
#overlayCard {
  background: linear-gradient(160deg, #33206b, #221244);
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  padding: 32px 36px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  animation: cardIn 0.4s cubic-bezier(0.2, 1.4, 0.4, 1);
  max-width: 320px;
  width: 100%;
}
@keyframes cardIn {
  from { transform: scale(0.7) translateY(30px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
#overlayTitle { font-size: 1.5rem; margin-bottom: 8px; }
#overlayNewBest {
  color: var(--accent);
  font-weight: 800;
  margin-bottom: 4px;
  animation: comboPop 0.5s ease 0.2s backwards;
}
/* ベスト更新でないときは JS が .hidden を付ける（このルールが無く、毎回「ベストスコア更新!」と出ていた） */
#overlayNewBest.hidden { display: none; }
.final-scores {
  display: flex;
  justify-content: center;
  gap: 26px;
  margin: 18px 0 24px;
}
.final-scores span { display: block; font-size: 0.72rem; color: var(--text-dim); }
.final-scores strong { font-size: 1.7rem; font-variant-numeric: tabular-nums; }
#playAgainBtn {
  background: linear-gradient(160deg, var(--accent), #ff8f2b);
  color: #3a2200;
  border: none;
  border-radius: 14px;
  font-size: 1.05rem;
  font-weight: 800;
  padding: 13px 30px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(255, 179, 64, 0.4);
  transition: transform 0.12s ease;
  font-family: inherit;
}
#playAgainBtn:active { transform: scale(0.94); }

/* ---- フッター ---- */
#siteFooter {
  margin-top: 6px;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.7;
}
#siteFooter a {
  color: var(--text-dim);
  text-decoration: underline;
  text-underline-offset: 2px;
}
#siteFooter a:hover { color: var(--accent); }

/* ---- 小さい画面調整 ---- */
@media (max-width: 380px) {
  #logo h1 { font-size: 1.05rem; }
  .logo-88 { font-size: 1.25rem; }
  .score-box { min-width: 62px; padding: 4px 8px; }
}

/* ---------- 全国ランキング（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, 5, 25, 0.78);
  backdrop-filter: blur(8px);
}

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(160deg, #33206b, #221244);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  padding: 20px 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

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

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

.sgr-tab {
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}

.sgr-tab-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #3a2200;
}

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

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

.sgr-name {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  padding: 8px 10px;
  border: 2px solid var(--panel-border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font-family: inherit;
  -webkit-user-select: text;
  user-select: 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;
  background: linear-gradient(160deg, var(--accent), #ff8f2b);
  color: #3a2200;
  cursor: pointer;
  font-family: inherit;
}

.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: #ff8a80;
}

.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;
}

.sgr-row:nth-child(even) {
  background: rgba(255, 255, 255, 0.06);
}

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

.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;
  font-variant-numeric: tabular-nums;
}

.sgr-close {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}

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

.sgr-cta-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  color: var(--accent);
}

.sgr-cta-btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: bold;
  background: linear-gradient(160deg, var(--accent), #ff8f2b);
  color: #3a2200;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(255, 179, 64, 0.4);
  font-family: inherit;
}

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

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

/* このゲームは body 自身がレイアウトの高さを持ち（html, body { height: 100% }）、
   #app がそれに合わせて伸びるので、body を広告ぶん縮めてフッターを持ち上げる */
html.has-ad-banner body {
  height: calc(100% - var(--ad-space, 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; }
}
