/* narabe (並べ) - 色のグラデーションを並べ直すタップ式パズル */

:root {
  --bg: #20212b;
  --panel: #2a2c3a;
  --text: #e8e6f0;
  --text-dim: #9a97ab;
  --accent: #d9b26f;
  --complete: #84a59d;
}

* {
  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;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100%;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  transition: opacity 0.3s ease;
}

/* journey 再生中は盤面と棒グラフ以外を薄く暗くする。
   フィルターボタンは journey 中も押せるので対象外にする。
   journey ボタン（再生中は stop）は Complete パネル内にあるが、中断に使うので
   パネル全体ではなく他の要素だけを暗くする（パネルに pointer-events:none を
   掛けると stop が押せなくなる）。 */
#app.journey-dim #hint-button,
#app.journey-dim #giveup-button,
#app.journey-dim #complete-text,
#app.journey-dim #complete-stats,
#app.journey-dim #restart-button {
  opacity: 0.35;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* ========================================
   タイトル
   ======================================== */

#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 20px;
}

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

#board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

#board {
  position: relative;
  width: min(92vw, 420px);
  height: min(92vw, 420px);
  background: var(--panel);
  border-radius: 16px;
  padding: 6px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.tile {
  position: absolute;
  /* opacity の 0.3s は game.js の CONFIG.journeyResetMs と手動で同期している
     （yose と同じ手動同期方式）。変更する場合は両方合わせること。 */
  transition: top 0.26s ease, left 0.26s ease, opacity 0.3s ease, filter 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile.tile-nomove {
  transition: none;
}

.tile.tile-fading {
  opacity: 0;
}

/* 固定セル（四隅）の印: 明暗二重のリングで背景の明るさに依存しない */
.tile.tile-fixed {
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.55),
    inset 0 0 0 4px rgba(0, 0, 0, 0.55);
}

/* 選択中タイルの強調枠 */
.tile.tile-selected {
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.9),
    inset 0 0 0 6px rgba(0, 0, 0, 0.7);
}

/* hint で「ずれている」ことを示す常時表示の枠（ONの間、交換のたびに付け外し
   される）。選択枠・固定印と見分けがつくようアクセントカラーの明るいリング
   にする（rgbフィルター表示中でも見える）。 */
.tile.tile-hint {
  box-shadow:
    inset 0 0 0 3px var(--accent),
    inset 0 0 0 6px rgba(0, 0, 0, 0.6);
}

/* 選択枠とhint枠が同時に付く場合、box-shadowは上書きされ合成されないため、
   両方が見えるよう専用のリング構成を用意する
   （内側から: 選択の白リング → hintのアクセントリング → 縁取りの黒リング）。 */
.tile.tile-selected.tile-hint {
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.9),
    inset 0 0 0 6px var(--accent),
    inset 0 0 0 9px rgba(0, 0, 0, 0.6);
}

.tile.tile-flash::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.75);
  opacity: 1;
  animation: flash-fade 0.2s ease forwards;
}

@keyframes flash-fade {
  from { opacity: 0.75; }
  to   { opacity: 0; }
}

/* journey 中は rAF が直接 left/top/transform を書き換えるため通常の transition を切る */
.tile.tile-journeying {
  transition: none;
  z-index: 5;
}

/* ========================================
   スコア（滑らかさ）バー
   ======================================== */

#score-bar-wrap {
  width: min(92vw, 420px);
  height: 6px;
  background: var(--panel);
  border-radius: 4px;
  /* タイトル→棒グラフ→盤面の順。手の影にならないよう盤面の上に置く。
     margin-top はタイトルの下マージンに任せ、盤面との間だけ空ける。 */
  margin: 0 0 18px;
  overflow: hidden;
}

#score-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--text-dim);
  border-radius: 4px;
  transition: width 0.3s ease, background 0.3s ease;
}

#score-bar-fill.complete {
  background: var(--complete);
}

/* ========================================
   完成パネル（盤面は隠さない）
   ======================================== */

#complete-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}

#complete-panel.hidden {
  display: none;
}

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

#complete-stats {
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

#complete-buttons {
  display: flex;
  gap: 12px;
}

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

#journey-button {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

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

/* ========================================
   途中リスタート（yose と同じ配置: 画面右上に小さく）
   / hint（左右対称に画面左上に小さく）
   ======================================== */

#giveup-button,
#hint-button {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  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;
}

#giveup-button {
  right: 16px;
}

#hint-button {
  left: 16px;
}

/* hintがONのときの見た目（restartボタンのスタイルは変えない） */
#hint-button.hint-on {
  opacity: 1;
  color: var(--accent);
  text-decoration: underline;
}

/* ========================================
   色フィルターボタン（盤面のすぐ下、棒グラフの下に大きめに配置）
   ======================================== */

#filter-button {
  margin-top: 18px;
  min-height: 44px;
  min-width: 100px;
  padding: 10px 32px;
  font-size: 15px;
  letter-spacing: 0.08em;
  border: none;
  border-radius: 999px;
  background: var(--panel);
  color: var(--text-dim);
  font-weight: 600;
  cursor: pointer;
}

#filter-button:active {
  transform: scale(0.97);
}
