/* ピクセルハント - Pixel Hunt */

:root {
  --bg: #0d1128;
  --bg2: #131a3d;
  --panel: #1a2148;
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #eef1ff;
  --text-dim: #9aa3c7;
  --accent: #4dc3ff;
  --accent2: #ffd166;
  --magenta: #ff6ec7;
  --good: #3ddc84;
  --danger: #ff5d6c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", Meiryo, sans-serif;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.022) 0 1px, transparent 1px 28px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.022) 0 1px, transparent 1px 28px),
    radial-gradient(1200px 600px at 50% -100px, #1c2a63 0%, var(--bg) 60%);
  background-attachment: fixed;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  touch-action: manipulation;
}

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

/* ===================== ホーム画面 ===================== */

#screen-home {
  flex: 1;
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 18px 16px 8px;
}

#home-head {
  position: relative;
  text-align: center;
  padding-top: 6px;
}

#home-head-btns {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { transform: scale(0.94); }

#logo {
  margin: 10px 0 0;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 0.04em;
  background: linear-gradient(92deg, #4dc3ff 10%, #7aa8ff 45%, #ff6ec7 90%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 12px rgba(77, 195, 255, 0.35));
}

#tagline {
  margin: 4px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
}

#home-main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 18px;
}

.mode-card {
  background: linear-gradient(180deg, rgba(38, 48, 96, 0.9), rgba(26, 33, 72, 0.9));
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.mode-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.mode-emoji {
  font-size: 28px;
  line-height: 1.2;
  flex-shrink: 0;
}

.mode-name {
  margin: 0;
  font-size: 17px;
  font-weight: 900;
}

.mode-desc {
  margin: 4px 0 0;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text-dim);
}
.mode-desc b { color: var(--accent2); }

.ta-btns {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.start-btn {
  border: none;
  border-radius: 14px;
  padding: 12px 8px;
  font-size: 16px;
  font-weight: 900;
  color: #04223a;
  background: linear-gradient(180deg, #6fd2ff, #2f9de0);
  box-shadow: 0 5px 16px rgba(77, 195, 255, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.start-btn:hover { filter: brightness(1.06); }
.start-btn:active { transform: scale(0.97); }
.start-btn.wide { width: 100%; margin-top: 12px; }

.best-chip {
  font-size: 10.5px;
  font-weight: 800;
  color: rgba(4, 34, 58, 0.75);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diff-seg {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 12px;
}

.diff-btn {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 8px 2px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.diff-btn small {
  font-size: 9.5px;
  font-weight: 700;
  color: var(--text-dim);
}
.diff-btn.active {
  border-color: var(--accent);
  background: rgba(77, 195, 255, 0.16);
  color: var(--accent);
}
.diff-btn.active small { color: var(--accent); }

#howto-card .mode-name { font-size: 15px; }

#howto {
  margin: 10px 0 0;
  padding-left: 18px;
  font-size: 12.5px;
  line-height: 1.8;
  color: var(--text-dim);
}
#howto b { color: var(--accent2); }
#howto li + li { margin-top: 4px; }

/* ===================== ゲーム画面 ===================== */

#screen-game {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: min(640px, 100%);
  margin: 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  min-height: 0;
}

#game-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

#game-mode-label {
  flex: 1;
  font-size: 15px;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#game-top-btns { display: flex; gap: 8px; }

/* ---- HUD ---- */

#hud {
  display: flex;
  gap: 12px;
  align-items: stretch;
  margin-top: 10px;
}

#target-box {
  position: relative;
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid var(--accent2);
  border-radius: 14px;
  padding: 8px 10px 10px;
  flex-shrink: 0;
  box-shadow: 0 0 18px rgba(255, 209, 102, 0.18);
}

.target-label {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.2em;
  color: var(--accent2);
  text-align: center;
  margin-bottom: 6px;
}

#target-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
}

.tcell {
  width: 42px;
  height: 42px;
  background: #232b57;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  line-height: 1;
}

#target-cover {
  position: absolute;
  inset: 0;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, #2a3468, #1d2450);
  color: var(--accent2);
  font-size: 30px;
  font-weight: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}
#target-cover small {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-dim);
}

#hud-stats {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}

.stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 4px 12px;
}

.stat-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-dim);
  flex-shrink: 0;
}

.stat-value {
  font-size: 17px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- 盤面 ---- */

#grid-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
}

#grid {
  display: grid;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

#grid.shake { animation: shake 0.35s; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.cell {
  background: #232b57;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--cell-radius, 8px);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  cursor: pointer;
}

@media (hover: hover) {
  .cell:hover { background: #2d3768; }
}

.cell.cursor {
  outline: 3px solid var(--accent);
  outline-offset: -2px;
  z-index: 1;
}

.cell.good {
  animation: goodFlash 0.5s;
  background: rgba(61, 220, 132, 0.55);
  border-color: var(--good);
  box-shadow: 0 0 14px rgba(61, 220, 132, 0.6);
  z-index: 1;
}

@keyframes goodFlash {
  0% { transform: scale(1); }
  35% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.cell.bad {
  animation: badFlash 0.45s;
  background: rgba(255, 93, 108, 0.55);
  border-color: var(--danger);
}

@keyframes badFlash {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(0.88); }
}

/* 超級エフェクト */
.cell.fx-blink { animation: blink 2.1s ease-in-out infinite; }
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.12; }
}

.cell.fx-move { animation: wobble 3s ease-in-out infinite alternate; }
@keyframes wobble {
  0% { transform: translate(0, 0); }
  25% { transform: translate(3px, -2px); }
  50% { transform: translate(-2px, 3px); }
  75% { transform: translate(-3px, -2px); }
  100% { transform: translate(2px, 2px); }
}

#grid-wrap.fx-drift #grid { animation: drift 7s ease-in-out infinite; }
@keyframes drift {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(6px, 4px); }
  50% { transform: translate(-5px, 7px); }
  75% { transform: translate(-6px, -4px); }
}

/* ランキング・共通ヘッダーのメニュー表示中（時計を止めている間）は盤面を隠す */
#grid-wrap.is-paused #grid { visibility: hidden; }

#ready-cover {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.3em;
  color: var(--text-dim);
  background: rgba(13, 17, 40, 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  border-radius: 16px;
}

/* フロートテキスト */
.float-text {
  position: absolute;
  z-index: 5;
  transform: translateX(-50%);
  font-size: 20px;
  font-weight: 900;
  color: var(--good);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  animation: floatUp 0.9s ease-out forwards;
}
.float-text.float-bad { color: var(--danger); }

@keyframes floatUp {
  0% { opacity: 0; margin-top: 0; }
  15% { opacity: 1; }
  100% { opacity: 0; margin-top: -46px; }
}

/* ===================== カウントダウン ===================== */

#countdown {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#countdown-num {
  font-size: 92px;
  font-weight: 900;
  color: var(--accent2);
  text-shadow: 0 6px 30px rgba(255, 209, 102, 0.5);
}

#countdown-num.pop { animation: pop 0.6s ease-out; }
@keyframes pop {
  0% { transform: scale(1.7); opacity: 0; }
  35% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.92); opacity: 0.9; }
}

/* ===================== 結果 ===================== */

#result-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 12, 24, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#result-box {
  width: min(380px, 100%);
  max-height: min(86vh, 640px);
  overflow-y: auto;
  background: linear-gradient(180deg, #223154, #16203a);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 22px 20px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

#result-title {
  font-size: 24px;
  font-weight: 900;
}

#result-sub {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 900;
  color: var(--accent2);
  animation: bestPulse 1.2s ease-in-out infinite;
}
@keyframes bestPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

#result-main {
  margin: 12px 0 14px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
}

#result-value {
  font-size: 48px;
  font-weight: 900;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

#result-unit {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-dim);
}

#result-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.rstat {
  display: flex;
  justify-content: space-between;
  font-size: 13.5px;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 8px;
  padding: 7px 12px;
}

.rstat-label { color: var(--text-dim); }

#result-buttons {
  display: flex;
  gap: 10px;
}

.btn {
  flex: 1;
  border: none;
  border-radius: 13px;
  padding: 13px 8px;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(180deg, #6fd2ff, #2f9de0);
  color: #04223a;
  box-shadow: 0 5px 16px rgba(77, 195, 255, 0.35);
}

.btn-sub {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
}

/* ===================== トースト ===================== */

#toast {
  position: fixed;
  left: 50%;
  /* フッター固定バナー広告に隠れないよう持ち上げる（広告なしのときは 0px） */
  bottom: calc(80px + env(safe-area-inset-bottom, 0px) + var(--ad-space, 0px));
  transform: translateX(-50%);
  z-index: 70;
  background: rgba(10, 14, 32, 0.92);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  border-radius: 999px;
  padding: 9px 18px;
  white-space: nowrap;
  pointer-events: none;
}

/* ===================== フッター ===================== */

#footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.9;
  padding: 18px 12px calc(14px + env(safe-area-inset-bottom, 0px));
}

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

body.playing #footer { display: none; }

/* ===================== PC向け調整 ===================== */

@media (min-width: 700px) {
  #logo { font-size: 42px; }
  .tcell { width: 48px; height: 48px; font-size: 30px; }
  .stat-value { font-size: 19px; }
}

/* ---------- 全国ランキング（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(8, 12, 24, 0.72);
  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, #223154, #16203a);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 20px 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

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

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

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

.sgr-tab-active {
  background: rgba(77, 163, 255, 0.18);
  border-color: var(--accent);
  color: var(--accent);
}

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

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

.sgr-name {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 16px;
  padding: 8px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
}

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

.sgr-submit {
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  background: linear-gradient(180deg, #5db1ff, #2f7fe0);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(77, 163, 255, 0.35);
}

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

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

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

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

.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: 8px;
  font-size: 14px;
}

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

.sgr-row.sgr-row-me {
  background: rgba(77, 163, 255, 0.25);
  color: #fff;
}

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

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

.sgr-row-score {
  font-weight: 800;
  color: var(--accent2);
  flex-shrink: 0;
}

.sgr-row.sgr-row-me .sgr-row-score {
  color: #fff;
}

.sgr-close {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.sgr-close:active { transform: scale(0.97); }

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

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

.sgr-cta-btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  background: linear-gradient(180deg, #ffd166, #f0a93b);
  color: #3a2503;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(255, 209, 102, 0.35);
}
.sgr-cta-btn:active { transform: scale(0.97); }

.sgr-cta-link {
  border: none;
  background: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  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; }
}
