/* ==========================================================================
 * なぜ南武線は混んでるのか？ - スタイルシート
 * ========================================================================== */

:root {
  --nambu-yellow: #ffd400;
  --nambu-orange: #f97316;
  --nambu-brown: #78350f;
  --lcd-bg: #0f172a;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Noto Sans JP', 'Inter', sans-serif;
  background: #0b1120;
  color: #f8fafc;
}

.font-round {
  font-family: 'M PLUS Rounded 1c', 'Noto Sans JP', sans-serif;
}

/* LED行先表示器風ボタン（トップの電車行先選択） */
.led-dest-btn {
  font-family: 'DotGothic16', 'Noto Sans JP', monospace;
  background-color: #06080c;
  background-image: radial-gradient(rgba(255, 255, 255, 0.07) 1px, transparent 0);
  background-size: 4px 4px;
  color: #f8fafc;
  border: 2px solid #334155;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.85);
}

.led-dest-btn:hover {
  border-color: #64748b;
}

.led-dest-btn.is-active {
  border-color: #ffd400;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.85), 0 0 0 1px #ffd400, 0 0 10px rgba(255, 212, 0, 0.3);
}

.led-text {
  color: #ffffff;
  text-shadow: 0 0 5px rgba(255, 255, 255, 0.45);
  letter-spacing: 0.04em;
}

.led-rapid {
  color: #fb7185;
  text-shadow: 0 0 6px rgba(251, 113, 133, 0.65);
}

.led-local {
  color: #fde047;
  text-shadow: 0 0 6px rgba(253, 224, 71, 0.55);
}

/* ゲーム画面上部のLED行先表示器風パネル */
.led-header-panel {
  font-family: 'DotGothic16', 'Noto Sans JP', monospace;
  background-color: #06080c;
  background-image: radial-gradient(rgba(255, 255, 255, 0.07) 1px, transparent 0);
  background-size: 4px 4px;
  color: #f8fafc;
  border: 2px solid #334155;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.85);
}

/* LED種別表示ボックス：各駅停車（黄地・黒字・2段右ずれ） */
.led-type-local {
  background-color: #fde047;
  background-image: radial-gradient(rgba(0, 0, 0, 0.14) 0.7px, transparent 0);
  background-size: 3px 3px;
  color: #0a0a0a;
  box-shadow: 0 0 8px rgba(250, 204, 21, 0.45);
  border: 1px solid #facc15;
  line-height: 1.05;
  font-weight: 900;
}

/* LED種別表示ボックス：快速（赤地・白字黒縁取り） */
.led-type-rapid {
  background-color: #dc2626;
  background-image: radial-gradient(rgba(0, 0, 0, 0.16) 0.7px, transparent 0);
  background-size: 3px 3px;
  color: #ffffff;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.55);
  border: 1px solid #ef4444;
  font-weight: 900;
  text-shadow:
    -1.2px -1.2px 0 #000000,
     1.2px -1.2px 0 #000000,
    -1.2px  1.2px 0 #000000,
     1.2px  1.2px 0 #000000,
     0px   -1.2px 0 #000000,
     0px    1.2px 0 #000000,
    -1.2px  0px   0 #000000,
     1.2px  0px   0 #000000;
}

/* 南武線カラーの3色帯 */
.nambu-stripe {
  background: linear-gradient(
    to bottom,
    #ffd400 0%,
    #ffd400 50%,
    #f97316 50%,
    #f97316 78%,
    #78350f 78%,
    #78350f 100%
  );
}

/* パズル盤面ラッパー（利用可能領域に対して8:5の最大サイズを算出） */
#grid-stage {
  container-type: size;
}

/* パズル盤面コンテナ（全40マスを常に均一な1:1正方形に固定） */
#puzzle-grid {
  touch-action: none;
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  width: min(100cqw, calc(100cqh * 8 / 5));
  height: min(100cqh, calc(100cqw * 5 / 8));
  aspect-ratio: 8 / 5;
  gap: 4px;
  background: #cbd5e1;
  border-radius: 12px;
  padding: 6px;
  box-shadow: inset 0 2px 8px rgba(15, 23, 42, 0.25);
}

/* グリッドのセル */
.grid-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: 8px;
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, transform 0.12s ease;
}

/* 座席エリア (Row 0, Col 1..6) */
.cell-seat {
  background: linear-gradient(180deg, #bae6fd 0%, #7dd3fc 65%, #38bdf8 100%);
  border-color: #0284c7;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.6);
}

.cell-seat::after {
  content: 'SEAT';
  position: absolute;
  top: 2px;
  font-size: 7px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: rgba(3, 105, 161, 0.45);
  pointer-events: none;
}

/* ドア前エリア (Row 4, Col 1,2,5,6) */
.cell-door {
  background: linear-gradient(180deg, #fef9c3 0%, #fde047 100%);
  border: 1.5px dashed #ca8a04;
}

.cell-door::after {
  content: '▼ DOOR';
  position: absolute;
  bottom: 1px;
  font-size: 7px;
  font-weight: 900;
  color: rgba(161, 98, 7, 0.65);
  pointer-events: none;
}

/* 優先スペース (下左端: Row 3-4 Col 0 / 下右端: Row 3-4 Col 7) */
.cell-priority {
  background: linear-gradient(180deg, #fdf2f8 0%, #fbcfe8 100%);
  border: 1.5px dashed #ec4899;
}

.cell-priority::after {
  content: '優先';
  position: absolute;
  bottom: 1px;
  font-size: 7px;
  font-weight: 900;
  color: rgba(190, 24, 93, 0.65);
  pointer-events: none;
}

/* 乗客トークン（案1：実機LCD・駅サインカード型） */
.passenger {
  width: 96%;
  height: 96%;
  min-width: 0;
  min-height: 0;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  background: #ffffff;
  color: #0f172a;
  border: 2px solid var(--st-color, #475569);
  position: relative;
  cursor: grab;
  overflow: visible;
  box-shadow: 0 2px 0 rgba(15, 23, 42, 0.18), 0 3px 6px rgba(15, 23, 42, 0.14);
  transition: transform 0.12s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.12s ease, opacity 0.2s ease;
  z-index: 2;
  line-height: 1;
}

.passenger:active {
  cursor: grabbing;
}

.passenger-header {
  background: var(--st-color, #475569);
  color: #ffffff;
  width: 100%;
  padding: 2px 2px 3px;
  border-radius: 3px 3px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  flex-shrink: 0;
}

.passenger-num {
  font-size: clamp(9px, min(2.4cqw, 3.8cqh), 15px);
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1;
}

.passenger-body {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 1px;
  min-height: 0;
  overflow: hidden;
  color: #0f172a;
}

/* 駅名：2文字がギリギリ収まる最大サイズ＋3〜4文字は長体（横幅縮小・盤面コンテナ基準） */
.passenger-name {
  font-size: clamp(11px, min(3.2cqw, 5.1cqh), 20px);
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  display: inline-block;
  transform-origin: center center;
  letter-spacing: -0.04em;
}

.passenger-name.len-3 {
  transform: scaleX(0.68);
}

.passenger-name.len-4 {
  transform: scaleX(0.52);
}

/* 選択中 / ドラッグ中 */
.passenger.is-selected {
  transform: scale(1.08);
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #facc15, 0 8px 16px rgba(0, 0, 0, 0.35);
  z-index: 20;
}

.passenger.is-stroller-top.is-selected {
  z-index: 22;
}

.passenger.is-dragging {
  transform: scale(1.12);
  box-shadow: 0 0 0 2px #ffffff, 0 10px 20px rgba(0, 0, 0, 0.4);
  z-index: 30;
}

.passenger.is-stroller-top.is-dragging {
  z-index: 32;
}

/* ドア前地蔵（反転配色：ダークストーン地＋白文字＋大きめピクト） */
.passenger.is-jizo {
  cursor: not-allowed;
  background: linear-gradient(160deg, #334155 0%, #0f172a 100%);
  border-color: #94a3b8;
  color: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 2px 0 rgba(15, 23, 42, 0.45);
}

.passenger.is-jizo .passenger-header {
  background: #475569;
  color: #ffffff;
  padding-left: clamp(11px, min(2.2cqw, 3.5cqh), 16px);
}

.passenger.is-jizo .passenger-body {
  color: #ffffff;
}

/* ベビーカー（反転配色：鮮やかなピンク地＋白枠＋白文字＋特大ピクト） */
.passenger.is-stroller-top {
  background: linear-gradient(180deg, #ec4899 0%, #db2777 100%);
  border-radius: 6px 6px 2px 2px;
  border-color: #ffffff;
  border-bottom-width: 1px;
  color: #ffffff;
  height: 98%;
  align-self: flex-end;
  box-shadow: 0 0 0 1.5px #be185d, 0 2px 5px rgba(15, 23, 42, 0.25);
  z-index: 4;
}

.passenger.is-stroller-bottom {
  background: linear-gradient(180deg, #db2777 0%, #be185d 100%);
  border-radius: 2px 2px 6px 6px;
  border-color: #ffffff;
  border-top-width: 1px;
  color: #ffffff;
  height: 98%;
  align-self: flex-start;
  box-shadow: 0 0 0 1.5px #be185d, 0 2px 0 rgba(15, 23, 42, 0.3);
  z-index: 2;
}

.passenger.is-stroller-top .passenger-body,
.passenger.is-stroller-bottom .passenger-body {
  color: #ffffff;
}

/* 反転配色（ベビーカー・御老人）で同系色駅でも上部帯と本体を判別しやすい細い白区切り線 */
.passenger.is-stroller-top .passenger-header,
.passenger.is-elderly .passenger-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.72);
}

/* 御老人（反転配色：鮮やかな青地＋白枠＋白文字＋大きめピクト） */
.passenger.is-elderly {
  background: linear-gradient(160deg, #0284c7 0%, #0369a1 100%);
  border-color: #e0f2fe;
  color: #ffffff;
  box-shadow: 0 0 0 1.5px #0284c7, 0 2px 0 rgba(15, 23, 42, 0.28);
}

.passenger.is-elderly .passenger-body {
  color: #ffffff;
}

/* 特殊客ピクトバッジ（!詰と同じくコマ左上角に重ねて表示・狭小画面でも駅番号に被らないよう盤面幅連動） */
.pict-badge {
  position: absolute;
  top: clamp(-5px, min(-0.65cqw, -1.0cqh), -3px);
  left: clamp(-5px, min(-0.65cqw, -1.0cqh), -3px);
  width: clamp(14px, min(3.2cqw, 5.1cqh), 22px);
  height: clamp(14px, min(3.2cqw, 5.1cqh), 22px);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  z-index: 12;
  pointer-events: none;
}

.pict-badge svg {
  width: 74%;
  height: 74%;
}

.pict-badge-elderly {
  background: #0284c7;
  color: #ffffff;
}

.pict-badge-jizo {
  background: #334155;
  color: #ffffff;
}

/* 次駅降車ターゲットのハイライト＆パルス */
@keyframes targetPulse {
  0%,
  100% {
    box-shadow: 0 0 0 2px #ffffff, 0 0 8px 2px rgba(250, 204, 21, 0.9), 0 2px 0 rgba(15, 23, 42, 0.22);
    transform: scale(1.0);
  }
  50% {
    box-shadow: 0 0 0 2.5px #fef08a, 0 0 14px 3px rgba(250, 204, 21, 1), 0 2px 0 rgba(15, 23, 42, 0.22);
    transform: scale(1.03);
  }
}

.passenger.is-target {
  animation: targetPulse 1.1s infinite ease-in-out;
  z-index: 5;
}

.passenger.is-stroller-top.is-target {
  z-index: 7;
}

.passenger.is-target.is-dragging,
.passenger.is-target.is-selected {
  animation: none;
  transform: scale(1.12);
  z-index: 30;
}

.passenger.is-stroller-top.is-target.is-dragging,
.passenger.is-stroller-top.is-target.is-selected {
  z-index: 32;
}

/* ステータスバッジ (OK / !詰 — 右下くっきり視認性強化) */
.status-badge {
  position: absolute;
  bottom: -5px;
  right: -5px;
  font-size: clamp(9.5px, min(2.2cqw, 3.2cqh), 12px);
  font-weight: 900;
  padding: 2px 5px;
  border-radius: 5px;
  line-height: 1.1;
  letter-spacing: 0.03em;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.48);
  border: 1.5px solid #ffffff;
  z-index: 10;
  pointer-events: none;
}

.badge-ok {
  background: #16a34a;
  color: #ffffff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}

.badge-blocked {
  background: #dc2626;
  color: #ffffff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
  animation: badgeShake 0.6s infinite;
}

@keyframes badgeShake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-1.5px);
  }
  75% {
    transform: translateX(1.5px);
  }
}

/* 降車フラッシュアニメーション */
@keyframes alightFlash {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  40% {
    transform: scale(1.25) translateY(-6px);
    opacity: 1;
    filter: brightness(1.4);
  }
  100% {
    transform: scale(0.4) translateY(30px);
    opacity: 0;
  }
}

.anim-alight-ok {
  animation: alightFlash 0.36s forwards ease-in;
  pointer-events: none;
}

/* かき分け降車アニメーション */
@keyframes alightBlocked {
  0% {
    transform: translateX(0);
    background-color: #dc2626;
  }
  20% {
    transform: translateX(-5px) scale(1.08);
  }
  40% {
    transform: translateX(5px) scale(1.08);
  }
  60% {
    transform: translateX(-4px);
    opacity: 0.9;
  }
  100% {
    transform: translateY(24px) scale(0.5);
    opacity: 0;
  }
}

.anim-alight-blocked {
  animation: alightBlocked 0.48s forwards ease-in;
  pointer-events: none;
}

/* 新規乗車ポップインアニメーション */
@keyframes boardPop {
  0% {
    transform: translateY(22px) scale(0.5);
    opacity: 0;
  }
  70% {
    transform: translateY(-3px) scale(1.06);
    opacity: 1;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.anim-board {
  animation: boardPop 0.32s ease-out;
}

/* 画面振動（遅延発生時） */
@keyframes boardShake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-5px);
  }
  40% {
    transform: translateX(5px);
  }
  60% {
    transform: translateX(-3px);
  }
  80% {
    transform: translateX(3px);
  }
}

.shake-effect {
  animation: boardShake 0.35s ease-in-out;
}

/* フローティングテキスト */
@keyframes floatUp {
  0% {
    transform: translate(-50%, 0) scale(0.8);
    opacity: 0;
  }
  20% {
    transform: translate(-50%, -10px) scale(1.1);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -44px) scale(0.95);
    opacity: 0;
  }
}

.float-text {
  position: absolute;
  pointer-events: none;
  font-weight: 900;
  white-space: nowrap;
  z-index: 60;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.75);
  animation: floatUp 0.9s forwards ease-out;
}

/* 両開きドアのアニメーション */
.door-leaf-left,
.door-leaf-right {
  transition: transform 0.55s cubic-bezier(0.25, 1, 0.5, 1);
}

.doors-open .door-leaf-left {
  transform: translateX(-86%);
}

.doors-open .door-leaf-right {
  transform: translateX(86%);
}

/* スクロールバー装飾（モーダル内） */
.custom-scroll::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.custom-scroll::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.4);
  border-radius: 999px;
}

.custom-scroll::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.5);
  border-radius: 999px;
}

/* ボタンのゲーム風立体感 */
.game-btn {
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease;
}

.game-btn:active:not(:disabled) {
  transform: translateY(2px);
}

.game-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* 出発進行ワンクッション演出 */
@keyframes departurePop {
  0% {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
  }
  18% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
  84% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
  100% {
    opacity: 0;
    transform: scale(1.03);
  }
}

.departure-pop {
  animation: departurePop 1.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* スクリーンショット撮影時のアニメーション静止（ブレ・途中拡大・文字ズレ防止） */
.is-capturing,
.is-capturing *,
.is-capturing *::before,
.is-capturing *::after {
  animation: none !important;
  transition: none !important;
}

.is-capturing .passenger.is-target {
  box-shadow: 0 0 0 2px #ffffff, 0 0 10px 2px rgba(250, 204, 21, 0.95), 0 2px 0 rgba(15, 23, 42, 0.22);
}
