/* surinuke（すり抜け）- 周期的に赤くなるタイルをすり抜けてゴールを目指すパズル */

:root {
  --bg: #20212b;
  --panel: #2a2c3a;
  --cell: #343650;
  --text: #e8e6f0;
  --text-dim: #9a97ab;
  --accent: #d9b26f;
  --blue: #6f9bd9;
  --red: #c9636d;
  --start: #7fb08a;
  --goal: #d9b26f;
  --player: #f0eee8;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  touch-action: manipulation;
  overscroll-behavior: none;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100dvh;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px calc(env(safe-area-inset-bottom, 0px) + 12px);
}

/* ========================================
   ヘッダー・タイトル
   ======================================== */

#header {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  flex: 0 0 auto;
}

#game-title {
  font-family: Georgia, "Times New Roman", "Hiragino Mincho ProN", serif;
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.4em;
  text-indent: 0.4em; /* letter-spacing 分の中央ずれ補正 */
  color: var(--text-dim);
  margin: 8px 0 0;
}

#header-restart-button {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: 16px;
  padding: 6px 12px;
  font-size: 11px;
  letter-spacing: 0.1em;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-dim);
  opacity: 0.6;
  cursor: pointer;
  z-index: 50; /* #pop-overlay（z-index 40）より上。ポップ表示中も押せる */
}

/* ========================================
   時計表示（記録ではなく現在状態の表示。localStorageは使わない）
   ======================================== */

.clock-display {
  flex: 0 0 auto;
  margin: 10px 0 4px;
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* ========================================
   盤面
   ======================================== */

#board-wrap {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

#board {
  --board-size: min(92vw, 62dvh, 420px);
  --gap: 6px;
  --pad: 8px;
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: var(--gap);
  background: var(--panel);
  border-radius: 16px;
  padding: var(--pad);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  transition: filter 0.15s ease;
}

.board.blurred {
  filter: blur(6px);
}

/* clear成功時の一斉発光（CONFIG.clearGlowMs=300 と同期） */
.board.clear-glow .cell-face {
  box-shadow: 0 0 14px rgba(127, 176, 138, 0.85);
}

.cell {
  position: relative;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.cell-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--cell);
  font-weight: 700;
  font-size: calc((var(--board-size) - var(--pad) * 2) / 5 * 0.4);
  color: var(--text-dim);
  /* 色・形の変化（CONFIG.tileMs=150 と同期） */
  transition: background 0.15s ease, box-shadow 0.3s ease, clip-path 0.15s ease;
}

/* ---- スタート／ゴール（常に安全、周期を持たない） ---- */

.cell.kind-start .cell-face {
  background: var(--start);
  color: #16321f;
}

.cell.kind-goal .cell-face {
  background: var(--goal);
  color: #3a2c0a;
}

/* ---- 通常タイル: 青の四角 か 赤のバツ の二値 ---- */

/* 青: 四角（デフォルト形状のまま） */
.cell.color-blue .cell-face {
  background: var(--blue);
  clip-path: none;
}

/* 赤: バツ（背景を暗くし、斜めの2本のバーでXを描く） */
.cell.color-red .cell-face {
  background: #3a2226;
  clip-path: none;
}

.cell.color-red .cell-face::before,
.cell.color-red .cell-face::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 78%;
  height: 16%;
  background: var(--red);
  border-radius: 3px;
}

.cell.color-red .cell-face::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.cell.color-red .cell-face::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

/* ========================================
   プレイヤー
   ======================================== */

/* プレイヤー = 今いるタイルを覆う白い丸そのもの（タイルより一回り大きく、下のタイルの
   状態を隠す。JS側でタイル一辺 * CONFIG.playerScale のサイズにしている）。 */
#player {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 50%;
  background: var(--player);
  box-shadow: 0 0 8px rgba(240, 238, 232, 0.6);
  pointer-events: none;
  /* タイル間の移動（CONFIG.moveMs=160 と同期） */
  transition: transform 0.16s ease;
  z-index: 5;
}

/* ========================================
   Clear! ポップオーバーレイ（kokonotと同じ方式）
   ======================================== */

#pop-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-size: clamp(32px, 11vw, 56px);
  font-weight: 800;
  letter-spacing: 0.02em;
  opacity: 0;
  transform: scale(0.3);
}

#pop-overlay.pop-active {
  pointer-events: auto;
  cursor: pointer;
}

#pop-overlay.pop-clear {
  color: var(--start);
  text-shadow: 0 2px 12px rgba(127, 176, 138, 0.5);
}

/* ポップイン（CONFIG.popMs=450 と同期） */
@keyframes pop-in {
  0%   { transform: scale(0.3); opacity: 0; }
  60%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

#pop-overlay.pop-show {
  animation: pop-in 0.45s ease forwards;
}

/* ポップアウト（CONFIG.popFadeMs=150 と同期） */
#pop-overlay.pop-fade {
  transition: opacity 0.15s ease;
  /* opacity 自体は game.js の dismissPop が inline で 0 にする */
}

/* ========================================
   結果パネル（盤面は隠さない。常時高さを確保する）
   ======================================== */

#result-panel {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 20px;
  min-height: 56px;
  margin-top: 10px;
  visibility: hidden;
}

#result-panel.show {
  visibility: visible;
}

#result-text {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--red);
}

#next-button,
#over-restart-button {
  padding: 10px 28px;
  font-size: 16px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #2a2410;
  font-weight: 600;
  cursor: pointer;
}

#next-button:active,
#over-restart-button:active {
  transform: scale(0.97);
}
