/* ==================== CSS 変数 ==================== */
:root {
  --tile-size: 48px;

  /* 盤面 (木製ボード風) */
  --board-bg: #f5e6d3;
  --board-line: rgba(120, 78, 30, 0.15);
  --board-border: #a97c50;

  /* 車の色 (target 赤 + 8 色循環) */
  --car-target: #e74c3c;
  --car-target-dark: #c0392b;
  --car-c0: #3498db;
  --car-c1: #27ae60;
  --car-c2: #f39c12;
  --car-c3: #9b59b6;
  --car-c4: #f1c40f;
  --car-c5: #16a085;
  --car-c6: #e67e22;
  --car-c7: #7f8c8d;

  /* 出口 */
  --exit-glow: #ffd166;
  --exit-glow-dark: #d99f00;

  /* 共通 (SOKOBAN 継承) */
  --bg-gradient-1: #eef1f5;
  --bg-gradient-2: #dde1e8;
  --accent: #ffd166;
  --accent-dark: #d69f00;
  --ink: #2e3a4a;
  --panel: rgba(61, 74, 92, 0.88);
  --btn-glass: rgba(61, 74, 92, 0.08);
  --btn-glass-hover: rgba(61, 74, 92, 0.16);
}

/* ==================== リセット ==================== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Yu Gothic UI", "Hiragino Sans", "Meiryo", sans-serif;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  background: linear-gradient(135deg, var(--bg-gradient-1) 0%, var(--bg-gradient-2) 100%);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-width: 500px;
  position: relative;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex: 1;
  width: 100%;
  padding: 12px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  min-height: 0; /* flex 子要素の内側スクロールを機能させる */
}

.screen.active {
  display: flex;
}

/* ==================== タイトル画面 ==================== */
.title {
  font-size: clamp(2.2rem, 10vw, 3.5rem);
  font-weight: 900;
  text-shadow: 0 2px 6px rgba(61, 74, 92, 0.15);
  letter-spacing: 0.1em;
}

.subtitle {
  font-size: 1.05rem;
  text-align: center;
  line-height: 1.7;
  opacity: 0.95;
  max-width: 420px;
}

.target-hint {
  color: var(--car-target);
  font-weight: bold;
}

.exit-hint {
  color: var(--accent-dark);
  font-weight: bold;
}

/* タイトル画面の左上「← ゲームせんたくへ」戻りボタン */
#screen-title {
  position: relative;
}

.title-back-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 6px 12px;
  font-size: 0.8rem;
  background: rgba(61, 74, 92, 0.08);
  color: var(--ink);
  border: 1px solid rgba(61, 74, 92, 0.22);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  min-height: 34px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: transform 0.05s, background 0.1s;
  z-index: 2;
}

.title-back-btn:active {
  background: rgba(61, 74, 92, 0.16);
  transform: scale(0.96);
}

/* ==================== ボタン共通 ==================== */
.btn-primary, .btn-secondary {
  border: none;
  border-radius: 16px;
  font-weight: bold;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.05s, background 0.1s;
}

.btn-primary {
  padding: 16px 32px;
  font-size: 1.25rem;
  background: var(--accent);
  color: #333;
  min-width: 200px;
  min-height: 56px;
  box-shadow: 0 4px 0 var(--accent-dark), 0 8px 16px rgba(0, 0, 0, 0.2);
}

.btn-primary:active {
  box-shadow: 0 1px 0 var(--accent-dark), 0 3px 6px rgba(0, 0, 0, 0.15);
  transform: translateY(3px);
}

.btn-secondary {
  padding: 10px 14px;
  font-size: 0.95rem;
  background: var(--btn-glass);
  color: var(--ink);
  min-height: 42px;
  min-width: 96px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(61, 74, 92, 0.22);
}

.btn-secondary:active {
  background: var(--btn-glass-hover);
  transform: scale(0.97);
}

/* ==================== ゲーム画面 ==================== */
#screen-game {
  padding: 8px;
  justify-content: space-between;
  gap: 8px;
  position: relative;
}

.game-header {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 14px;
  background: var(--panel);
  color: #fff;
  border-radius: 12px;
  font-size: 0.95rem;
  gap: 2px;
}

.stage-info,
.moves-info {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.label {
  font-size: 0.78rem;
  opacity: 0.75;
  margin-right: 2px;
}

.separator {
  opacity: 0.5;
  margin: 0 6px;
}

#stage-num, #moves-num, #best-num {
  font-size: 1.2rem;
  font-weight: bold;
}

.stage-name {
  font-size: 0.95rem;
  opacity: 0.9;
  margin-left: 8px;
}

.world-remaining {
  font-size: 0.75rem;
  opacity: 0.85;
  margin-left: 6px;
  padding: 1px 6px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 6px;
}

.moves-info {
  font-size: 0.85rem;
  opacity: 0.85;
}

.moves-info #moves-num,
.moves-info #best-num {
  font-size: 1rem;
}

/* ==================== 盤面 (Rush Hour 6x6) ==================== */
.board {
  display: grid;
  grid-template-columns: repeat(6, var(--tile-size));
  grid-template-rows: repeat(6, var(--tile-size));
  gap: 0;
  position: relative;
  background: var(--board-bg);
  border: 4px solid var(--board-border);
  border-radius: 8px;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.15),
    inset 0 0 30px rgba(120, 78, 30, 0.08);
  touch-action: none; /* ドラッグ中にページスクロールしない */
}

/* クリア確定後は board を完全に無効化。
   iOS Safari で touch-action: none の要素上で pointer 操作した後、
   pointer state が subsequent tap まで生き続けて button click を
   吸ってしまう現象を防ぐ (Sokoban には無い症状の真犯人) */
.board.finished,
.board.finished .car {
  pointer-events: none;
  touch-action: auto;
}

.board .cell {
  border: 1px solid var(--board-line);
  min-width: 0;
  min-height: 0;
  position: relative;
}

/* ゴールマス (row=2 右端 2 マス = 17, 18 番目の cell) */
/* 金色薄塗り + 上下破線枠 + ▶ の透かし表示 */
.board .cell:nth-child(17),
.board .cell:nth-child(18) {
  background:
    linear-gradient(90deg,
      rgba(255, 209, 102, 0.15) 0%,
      rgba(255, 209, 102, 0.5) 100%);
  border-top: 2px dashed var(--exit-glow-dark);
  border-bottom: 2px dashed var(--exit-glow-dark);
  border-left: none;
  border-right: none;
}

.board .cell:nth-child(17)::before,
.board .cell:nth-child(18)::before {
  content: '▶';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(217, 159, 0, 0.5);
  font-size: 1.5rem;
  font-weight: bold;
  pointer-events: none;
  animation: goal-arrow 1.8s ease-in-out infinite;
}

.board .cell:nth-child(18)::before {
  animation-delay: 0.2s;
}

@keyframes goal-arrow {
  0%, 100% { opacity: 0.35; transform: translateX(0); }
  50%      { opacity: 0.8;  transform: translateX(3px); }
}

/* 出口マーカー (row=2 の外側に矢印) */
.exit-marker {
  position: absolute;
  top: calc(var(--tile-size) * 2);
  right: -22px;
  width: 24px;
  height: var(--tile-size);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-dark);
  font-size: 1.6rem;
  font-weight: bold;
  animation: exit-pulse 1.6s ease-in-out infinite;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

@keyframes exit-pulse {
  0%, 100% { transform: translateX(0); opacity: 0.75; }
  50%      { transform: translateX(4px); opacity: 1; }
}

/* ==================== 車 sprite ==================== */
.car {
  position: absolute;
  top: 0;
  left: 0;
  transition: transform 0.18s ease-out;
  border-radius: 10px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  z-index: 2;
  box-shadow:
    0 3px 6px rgba(0, 0, 0, 0.25),
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    inset 0 -3px 0 rgba(0, 0, 0, 0.2);
}

.car:active {
  cursor: grabbing;
}

/* 選択中: 金色の太フチ */
.car.selected {
  outline: 3px solid var(--exit-glow);
  outline-offset: -2px;
  filter: brightness(1.1);
  z-index: 3;
}

/* target 車 (X) は Gemini 生成の PNG で描画 (透明背景で車だけ表示) */
/* box-shadow は none で .car のグローバル inset ハイライト (透明枠の上辺として見える) を消す */
/* 影は filter: drop-shadow で PNG の車の輪郭に沿った形にする */
.car--target {
  background: url("../assets/car_target.png?v=5") center/contain no-repeat;
  z-index: 4;
  box-shadow: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

/* PNG にフロントガラスやディテールが含まれているので疑似要素は消す */
.car--target::before {
  display: none;
}

/* 8 色循環 */
.car--c0 { background: linear-gradient(180deg, #3498db, #216a94); }
.car--c1 { background: linear-gradient(180deg, #27ae60, #1a7d43); }
.car--c2 { background: linear-gradient(180deg, #f39c12, #a9690c); }
.car--c3 { background: linear-gradient(180deg, #9b59b6, #6c3f80); }
.car--c4 { background: linear-gradient(180deg, #f1c40f, #a68a0a); }
.car--c5 { background: linear-gradient(180deg, #16a085, #0f6f5c); }
.car--c6 { background: linear-gradient(180deg, #e67e22, #a15818); }
.car--c7 { background: linear-gradient(180deg, #7f8c8d, #5a6465); }

/* 非 target 車も控えめなフロントガラス */
.car--c0::before, .car--c1::before, .car--c2::before, .car--c3::before,
.car--c4::before, .car--c5::before, .car--c6::before, .car--c7::before {
  content: '';
  position: absolute;
  inset: 22% 10%;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 4px;
  pointer-events: none;
}

.car--v::before {
  inset: 10% 22%;
}

/* デフォルトサイズ (render.js が inline width/height で上書きする) */
.car {
  width: var(--tile-size);
  height: var(--tile-size);
}

/* ==================== 下部パネル ==================== */
.bottom-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.btn-main {
  width: 100%;
  padding: 14px 12px;
  font-size: 1.05rem;
  background: var(--accent);
  color: #333;
  border: none;
  border-radius: 14px;
  font-weight: bold;
  min-height: 54px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--accent-dark), 0 5px 10px rgba(0, 0, 0, 0.15);
  font-family: inherit;
  transition: transform 0.05s;
}

/* 「つぎのステージ」ボタン: 常時 DOM 存在、disabled 属性で状態切替 */
/*   → 要素の登場・退場を無くして iOS の tap 吸収問題を根本回避 */
.btn-next {
  width: 100%;
  padding: 14px 12px;
  font-size: 1.1rem;
  border: none;
  border-radius: 14px;
  font-weight: 900;
  min-height: 56px;
  font-family: inherit;
  letter-spacing: 0.06em;
  transition: transform 0.05s, background 0.15s, box-shadow 0.2s;
}

/* クリア前: グレーアウト、押せない */
.btn-next[disabled] {
  background: rgba(120, 130, 145, 0.22);
  color: rgba(46, 58, 74, 0.4);
  cursor: not-allowed;
  box-shadow: none;
  animation: none;
}

/* クリア後: 明るい緑光、押せる */
.btn-next:not([disabled]) {
  background: linear-gradient(180deg, #4ade80 0%, #22c55e 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 3px 0 #16a34a, 0 5px 14px rgba(34, 197, 94, 0.4);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  animation: btn-next-glow 1.4s ease-in-out infinite;
}

.btn-next:not([disabled]):active {
  box-shadow: 0 1px 0 #16a34a, 0 2px 6px rgba(34, 197, 94, 0.35);
  transform: translateY(2px);
}

@keyframes btn-next-glow {
  0%, 100% { box-shadow: 0 3px 0 #16a34a, 0 4px 12px rgba(34, 197, 94, 0.35); }
  50%      { box-shadow: 0 3px 0 #16a34a, 0 4px 24px rgba(34, 197, 94, 0.85); }
}

/* クリア時のヘッダー右バッジ (残り X → クリア! に切替) */
.world-remaining.cleared {
  background: rgba(74, 222, 128, 0.35);
  color: #fff;
  font-weight: 900;
  padding: 2px 10px;
}

/* ==================== クリア オーバーレイ (盤面中央、貫通型) ==================== */
/* pointer-events: none で下の要素 tap を邪魔しない = iOS の tap 判定に無害 */
.clear-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  pointer-events: none;
  opacity: 0;
  z-index: 15;
}

.clear-overlay.active {
  animation: co-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes co-pop {
  0%   { transform: translate(-50%, -50%) scale(0.4) rotate(-6deg); opacity: 0; }
  60%  { transform: translate(-50%, -50%) scale(1.15) rotate(3deg); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
}

.co-badge {
  padding: 14px 24px;
  background: linear-gradient(135deg,
    rgba(255, 230, 130, 0.98) 0%,
    rgba(255, 180, 60, 0.98) 60%,
    rgba(255, 130, 40, 0.98) 100%);
  color: #3d2200;
  border: 4px solid #fff;
  border-radius: 20px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4), 0 0 0 3px rgba(255, 230, 130, 0.5);
  text-align: center;
}

.co-title {
  font-size: 1.8rem;
  font-weight: 900;
  color: #7a3800;
  letter-spacing: 0.08em;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.5);
  white-space: nowrap;
}

.co-star {
  font-size: 1.4rem;
  margin: 0 4px;
  display: inline-block;
  animation: co-star-spin 1.6s ease-in-out infinite;
}

.co-star:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes co-star-spin {
  0%, 100% { transform: rotate(-8deg) scale(1); }
  50%      { transform: rotate(8deg)  scale(1.15); }
}

.co-stats {
  font-size: 0.95rem;
  color: #4d2c00;
  margin-top: 4px;
  font-weight: bold;
}

.co-stats span {
  color: #b8420b;
  font-size: 1.05rem;
  font-weight: 900;
  margin: 0 2px;
}

.btn-main:active {
  box-shadow: 0 1px 0 var(--accent-dark);
  transform: translateY(2px);
}

/* 「一つもどる」クリア後 disabled: グレーアウトで押せない
   (クリア確定 → もどっても意味ないので btn-next と対称的に切替) */
.btn-main[disabled] {
  background: rgba(120, 130, 145, 0.22);
  color: rgba(46, 58, 74, 0.4);
  cursor: not-allowed;
  box-shadow: none;
  pointer-events: none;
}

.sub-actions {
  display: flex;
  gap: 6px;
}

.btn-mini {
  flex: 1;
  padding: 6px 6px;
  font-size: 0.75rem;
  background: rgba(61, 74, 92, 0.08);
  color: var(--ink);
  border: 1px solid rgba(61, 74, 92, 0.2);
  border-radius: 8px;
  min-height: 34px;
  min-width: 0;
  cursor: pointer;
  font-family: inherit;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: transform 0.05s, background 0.1s;
}

.btn-mini:active {
  background: rgba(61, 74, 92, 0.18);
  transform: scale(0.96);
}

/* ==================== クリアパネル ==================== */
.clear-panel {
  display: none;
  width: 100%;
  padding: 14px 12px;
  background: linear-gradient(135deg, rgba(255, 219, 128, 0.96) 0%, rgba(255, 180, 74, 0.96) 100%);
  color: #333;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  flex-direction: column;
  align-items: center;
  gap: 8px;
  /* animation の transform: scale で pointer 当たり判定が縮み、見た目位置
     をタップしてもヒットしない現象を防ぐため、translateY + opacity のみに */
  animation: clear-pop 0.2s ease-out;
}

.clear-panel.active {
  display: flex;
}

@keyframes clear-pop {
  0%   { transform: translateY(14px); opacity: 0; }
  100% { transform: translateY(0);    opacity: 1; }
}

.clear-panel .clear-header {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
}

.clear-panel .clear-star-mini {
  font-size: 1.6rem;
  line-height: 1;
}

.clear-panel .clear-title {
  font-size: 1.5rem;
  color: #7a4d00;
  margin: 0;
  text-shadow: none;
  letter-spacing: 0.05em;
}

.clear-panel .clear-stats {
  font-size: 0.95rem;
  color: #444;
  margin: 0;
  line-height: 1.4;
  text-align: center;
}

.clear-panel .clear-stats span {
  font-weight: bold;
  color: #7a4d00;
  margin-left: 3px;
}

.clear-buttons {
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
}

.btn-tertiary {
  padding: 6px 14px;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.4);
  color: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(0, 0, 0, 0.28);
  border-radius: 10px;
  min-height: 32px;
  min-width: 90px;
  cursor: pointer;
  font-family: inherit;
}

.btn-tertiary:active {
  background: rgba(255, 255, 255, 0.6);
}

.clear-panel .btn-primary {
  min-width: 140px;
  min-height: 46px;
  padding: 10px 18px;
  font-size: 1rem;
}

/* ==================== ワールドクリアパネル ==================== */
/* 盤面の上に浮かべる overlay (iPad 縦向きだとゲーム画面下端に押し出されて
   ボタンが見切れるため absolute 中央配置に変更) */
.world-clear-panel {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 20;
  width: calc(100% - 32px);
  max-width: 380px;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 14px;
  background: linear-gradient(135deg,
    rgba(255, 230, 130, 0.98) 0%,
    rgba(255, 180, 60, 0.98) 60%,
    rgba(255, 130, 40, 0.98) 100%);
  color: #3d2200;
  border-radius: 18px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35), 0 0 0 3px rgba(255, 230, 130, 0.5);
  flex-direction: column;
  align-items: center;
  gap: 10px;
  animation: world-clear-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.world-clear-panel.active {
  display: flex;
}

/* animation で translate(-50%, -50%) を保持しつつ scale/rotate を重ねる */
@keyframes world-clear-pop {
  0%   { transform: translate(-50%, -50%) scale(0.6) rotate(-4deg); opacity: 0; }
  50%  { transform: translate(-50%, -50%) scale(1.1) rotate(2deg); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
}

.wc-emoji {
  font-size: 3rem;
  line-height: 1;
  animation: wc-emoji-bounce 0.8s ease-out infinite alternate;
}

@keyframes wc-emoji-bounce {
  from { transform: translateY(0) scale(1); }
  to   { transform: translateY(-6px) scale(1.1); }
}

.wc-title {
  font-size: 1.6rem;
  color: #7a3800;
  margin: 0;
  letter-spacing: 0.05em;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.5);
}

.wc-title #wc-num {
  font-size: 2rem;
  color: #e0451c;
  margin: 0 4px;
}

.wc-subtitle {
  font-size: 0.9rem;
  color: #4d2c00;
  line-height: 1.5;
  margin: 0;
}

.wc-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  align-items: center;
  margin-top: 6px;
}

.wc-buttons .btn-primary {
  min-width: 200px;
  min-height: 50px;
  padding: 12px 22px;
  font-size: 1.05rem;
}

.wc-buttons .btn-tertiary {
  padding: 6px 14px;
  font-size: 0.85rem;
}

/* ==================== ワールド選択画面 ==================== */
#screen-world {
  justify-content: flex-start;
  gap: 10px;
  padding: 12px 8px;
}

.world-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px;
  flex: 1 1 0;
  min-height: 0;
  align-content: start;
}

.world-card {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(61, 74, 92, 0.07);
  border: 1px solid rgba(61, 74, 92, 0.18);
  color: var(--ink);
  border-radius: 14px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: transform 0.05s, background 0.1s;
  min-height: 68px;
}

.world-card:not(.locked):active {
  transform: scale(0.98);
}

.world-card.locked {
  cursor: not-allowed;
  opacity: 0.4;
  background: rgba(61, 74, 92, 0.04);
  filter: grayscale(0.5);
}

.world-card.cleared {
  background: linear-gradient(90deg, rgba(255, 209, 102, 0.28), rgba(255, 209, 102, 0.12));
  border-color: rgba(255, 209, 102, 0.6);
}

.world-card.next {
  background: linear-gradient(90deg, rgba(255, 209, 102, 0.4), rgba(255, 209, 102, 0.2));
  border-color: var(--accent);
  animation: next-pulse 1.6s ease-in-out infinite;
}

.world-card-badge {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--accent-dark);
  min-width: 46px;
  text-align: center;
  line-height: 1.1;
}

.world-card-badge-num {
  display: block;
  font-size: 0.7rem;
  color: var(--ink);
  opacity: 0.7;
  font-weight: normal;
  letter-spacing: 0.05em;
}

.world-card-title {
  font-size: 1.05rem;
  font-weight: bold;
  color: var(--ink);
}

.world-card-range {
  font-size: 0.78rem;
  color: var(--ink);
  opacity: 0.7;
  margin-top: 2px;
}

.world-card-status {
  font-size: 0.9rem;
  color: var(--accent-dark);
  font-weight: bold;
  min-width: 60px;
  text-align: right;
}

.world-card.locked .world-card-status {
  font-size: 1.4rem;
  opacity: 0.7;
}

.world-card.cleared .world-card-status::after {
  content: ' ★';
  color: var(--accent-dark);
}

/* ワールドクリア直後: 「クリア！」スタンプがポン！と押される */
.world-card.just-cleared {
  overflow: visible;
}

.world-card.just-cleared::after {
  content: 'クリア！';
  position: absolute;
  top: 50%;
  left: 50%;
  padding: 6px 22px;
  background: rgba(231, 76, 60, 0.94);
  color: #fff;
  font-weight: 900;
  font-size: 1.4rem;
  letter-spacing: 0.08em;
  border: 3px solid #fff;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(-14deg) scale(3);
  animation: cleared-stamp 1.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes cleared-stamp {
  0%   { transform: translate(-50%, -50%) rotate(-14deg) scale(3); opacity: 0; }
  15%  { opacity: 1; }
  35%  { transform: translate(-50%, -50%) rotate(-14deg) scale(1); opacity: 1; }
  90%  { transform: translate(-50%, -50%) rotate(-14deg) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -50%) rotate(-14deg) scale(1); opacity: 0.95; }
}

/* 次ワールドが解禁された瞬間: 光るシャインアニメ (0.5s 遅延で始まる) */
.world-card.just-unlocked {
  animation: unlocked-shine 1.4s ease-out 0.5s;
}

@keyframes unlocked-shine {
  0%   { box-shadow: 0 0 0 rgba(255, 209, 102, 0); filter: brightness(1); }
  25%  { box-shadow: 0 0 40px rgba(255, 209, 102, 0.95); filter: brightness(1.3); }
  100% { box-shadow: 0 0 8px rgba(255, 209, 102, 0.3); filter: brightness(1); }
}

/* ==================== ステージセレクト ==================== */
#screen-select {
  justify-content: flex-start;
  gap: 10px;
  padding: 12px 8px;
}

.select-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 0 4px;
}

.select-header h2 {
  font-size: 1.3rem;
  flex: 1;
  text-align: center;
  color: var(--accent-dark);
}

.select-progress {
  font-size: 0.8rem;
  opacity: 0.9;
  padding: 4px 10px;
  background: rgba(61, 74, 92, 0.08);
  border-radius: 8px;
  border: 1px solid rgba(61, 74, 92, 0.18);
}

.select-progress #select-cleared {
  color: var(--accent-dark);
  font-weight: bold;
}

/* ワールドタブ */
.world-tabs {
  display: flex;
  gap: 6px;
  width: 100%;
  overflow-x: auto;
  padding: 4px 2px 6px;
  scrollbar-width: none;
}

.world-tabs::-webkit-scrollbar { display: none; }

.world-tab {
  position: relative;
  padding: 4px 6px;
  background: rgba(61, 74, 92, 0.07);
  border: 1px solid rgba(61, 74, 92, 0.18);
  color: rgba(61, 74, 92, 0.85);
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 42px;
  font-size: 0.7rem;
  transition: background 0.1s, transform 0.05s;
  flex-shrink: 0;
}

.world-tab .world-name {
  font-size: 0.95rem;
  font-weight: bold;
  color: var(--ink);
  line-height: 1;
}

.world-tab .world-stars {
  color: var(--accent-dark);
  font-size: 0.62rem;
  letter-spacing: -1.2px;
  line-height: 1;
}

/* 次にプレイすべき面のある world タブに赤ドット */
.world-tab .world-next-dot {
  position: absolute;
  top: 3px;
  right: 4px;
  width: 6px;
  height: 6px;
  background: var(--car-target);
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(231, 76, 60, 0.65);
  animation: next-dot-pulse 1.5s ease-in-out infinite;
}

@keyframes next-dot-pulse {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50%      { opacity: 1; transform: scale(1.15); }
}

.world-tab.active {
  background: var(--accent);
  color: #333;
  border-color: var(--accent);
  font-weight: bold;
  transform: translateY(-1px);
}

.world-tab.active .world-name {
  color: #4a2f00;
}

.world-tab.active .world-stars {
  color: #7a4d00;
}

/* ステージカード */
.stage-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  overflow-y: auto;
  padding: 4px;
  flex: 1;
  align-content: start;
}

.stage-card {
  position: relative;
  aspect-ratio: 1;
  background: rgba(61, 74, 92, 0.07);
  border: 1px solid rgba(61, 74, 92, 0.18);
  color: var(--ink);
  border-radius: 12px;
  cursor: pointer;
  padding: 5px 5px 3px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  gap: 3px;
  font-family: inherit;
  overflow: hidden;
  /* 未クリア (next / cleared / locked どれでもない) はくすませて「まだ」を表現 */
  opacity: 0.55;
  filter: grayscale(0.35);
  transition: transform 0.05s, background 0.1s;
}

.stage-card:not(.locked):active {
  transform: scale(0.96);
}

.stage-card.locked {
  opacity: 0.35;
  cursor: not-allowed;
  background: rgba(61, 74, 92, 0.04);
  filter: none;
}

.stage-card.cleared {
  opacity: 1;
  filter: none;
  background: rgba(255, 209, 102, 0.25);
  border-color: rgba(255, 209, 102, 0.55);
}

.stage-card.cleared::after {
  content: '★';
  position: absolute;
  top: 2px;
  right: 6px;
  color: var(--accent-dark);
  font-size: 0.85rem;
}

/* 「次にプレイすべきステージ」= 未クリア最小 */
/* 金色濃いめ + パルス glow で明示 */
.stage-card.next {
  opacity: 1;
  filter: none;
  background: rgba(255, 209, 102, 0.42);
  border-color: var(--accent);
  animation: next-pulse 1.6s ease-in-out infinite;
}

@keyframes next-pulse {
  0%, 100% { box-shadow: 0 0 6px rgba(255, 209, 102, 0.45); }
  50%      { box-shadow: 0 0 16px rgba(255, 209, 102, 0.85); }
}

.stage-num-small {
  font-size: 0.9rem;
  font-weight: bold;
  text-align: center;
  color: var(--ink);
  order: 1;
  flex-shrink: 0;
}

.stage-lock {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  opacity: 0.5;
  order: 2;
}

/* 面プレビュー: 6x6 grid で車の色を敷く */
.preview-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 1px;
  aspect-ratio: 1;
  order: 2;
  background: var(--board-bg);
  border-radius: 3px;
}

.preview-cell {
  background: transparent;
  min-width: 0;
  min-height: 0;
}

.preview-cell.pv-target { background: var(--car-target); }
.preview-cell.pv-c0 { background: var(--car-c0); }
.preview-cell.pv-c1 { background: var(--car-c1); }
.preview-cell.pv-c2 { background: var(--car-c2); }
.preview-cell.pv-c3 { background: var(--car-c3); }
.preview-cell.pv-c4 { background: var(--car-c4); }
.preview-cell.pv-c5 { background: var(--car-c5); }
.preview-cell.pv-c6 { background: var(--car-c6); }
.preview-cell.pv-c7 { background: var(--car-c7); }
