/* ============================================================
   TRAIN CONTROL — JR東日本アプリ風 未来的UI
   ============================================================ */

:root {
  --jr-green: #009944;        /* JR東日本ブランドグリーン */
  --jr-green-light: #00b850;
  --bg-0: #060a14;
  --bg-1: #0b1220;
  --bg-2: #111a2e;
  --panel: rgba(20, 30, 52, 0.72);
  --panel-solid: #141e34;
  --border: rgba(120, 160, 220, 0.16);
  --border-strong: rgba(120, 160, 220, 0.32);
  --text: #eaf1ff;
  --text-dim: #8fa3c7;
  --text-faint: #5c6f92;
  --accent: #2fd6ff;
  --accent-2: #7c5cff;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --radius-sm: 12px;
  font-synthesis: none;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Yu Gothic UI',
               'Noto Sans JP', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-0);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* 背景の未来的グラデーション + グリッド */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: -2;
  background:
    radial-gradient(1200px 800px at 15% -10%, rgba(47,214,255,0.10), transparent 55%),
    radial-gradient(1000px 700px at 110% 20%, rgba(124,92,255,0.12), transparent 50%),
    radial-gradient(900px 900px at 50% 120%, rgba(0,153,68,0.10), transparent 55%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
}
body::after {
  content: '';
  position: fixed; inset: 0; z-index: -1; opacity: 0.4;
  background-image:
    linear-gradient(rgba(120,160,220,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120,160,220,0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 50% 40%, #000 0%, transparent 85%);
}

#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }

/* ===================== ヘッダー ===================== */
.top-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px;
  background: linear-gradient(180deg, rgba(9,14,24,0.9), rgba(9,14,24,0.55));
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 11px;
  background: linear-gradient(135deg, var(--jr-green), var(--jr-green-light));
  display: grid; place-items: center;
  box-shadow: 0 4px 18px rgba(0,153,68,0.45), inset 0 1px 0 rgba(255,255,255,0.25);
}
.brand-logo i { color: #fff; font-size: 20px; }
.brand-title { line-height: 1.1; }
.brand-title .t1 { font-size: 16px; font-weight: 800; letter-spacing: 0.06em; }
.brand-title .t2 { font-size: 10px; color: var(--text-dim); letter-spacing: 0.22em; font-weight: 600; }

.top-metrics { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.metric-chip {
  display: flex; flex-direction: column; align-items: center;
  min-width: 74px; padding: 6px 12px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-sm); backdrop-filter: blur(10px);
}
.metric-chip .mv { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.metric-chip .ml { font-size: 9px; color: var(--text-dim); letter-spacing: 0.12em; margin-top: 1px; }
.metric-chip.good .mv { color: var(--good); }
.metric-chip.warn .mv { color: var(--warn); }
.metric-chip.bad .mv { color: var(--bad); }

.clock {
  font-variant-numeric: tabular-nums; font-weight: 800; font-size: 20px;
  letter-spacing: 0.04em; color: var(--accent);
  text-shadow: 0 0 18px rgba(47,214,255,0.5);
  padding: 4px 12px; border: 1px solid var(--border-strong); border-radius: 12px;
  background: rgba(47,214,255,0.06);
}

/* ===================== メインレイアウト ===================== */
.main { flex: 1; display: grid; grid-template-columns: 1fr 340px; overflow: hidden; }
.board-wrap { position: relative; overflow-y: auto; padding: 14px 16px 20px; }
.side-panel {
  border-left: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(11,18,32,0.6), rgba(6,10,20,0.85));
  backdrop-filter: blur(14px);
  display: flex; flex-direction: column; overflow: hidden;
}

/* ===================== 路線ボード ===================== */
.line-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px 16px;
  margin-bottom: 13px;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.line-block::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--lc, var(--accent));
  box-shadow: 0 0 20px var(--lc, var(--accent));
}
.line-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.line-badge {
  font-weight: 900; font-size: 12px; letter-spacing: 0.06em;
  padding: 3px 9px; border-radius: 8px; min-width: 34px; text-align: center;
}
.line-name { font-weight: 800; font-size: 15px; }
.line-stat { margin-left: auto; display: flex; gap: 7px; align-items: center; font-size: 11px; color: var(--text-dim); }
.line-stat .pill {
  padding: 2px 8px; border-radius: 20px; font-weight: 700;
  background: rgba(255,255,255,0.05); border: 1px solid var(--border);
}
.line-stat .pill.on { color: var(--good); }
.line-stat .pill.late { color: var(--warn); }

/* 線路トラック */
.track {
  position: relative; height: 68px; margin: 4px 2px 0;
  border-radius: 10px;
}
.rail {
  position: absolute; left: 8px; right: 8px; top: 34px; height: 4px;
  background: linear-gradient(90deg, rgba(255,255,255,0.14), rgba(255,255,255,0.06));
  border-radius: 4px;
}
.station-dot {
  position: absolute; top: 30px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--bg-2); border: 2.5px solid rgba(255,255,255,0.35);
  transform: translate(-50%, 0); z-index: 2;
}
.station-dot.major { width: 15px; height: 15px; top: 28px; border-color: var(--lc); box-shadow: 0 0 10px var(--lc); }

/* 列車アイコン */
.train {
  position: absolute; top: 12px;
  width: 30px; height: 22px; border-radius: 7px;
  transform: translate(-50%, 0);
  display: grid; place-items: center;
  font-size: 10px; font-weight: 900; color: #05121f;
  cursor: pointer; z-index: 5;
  transition: left 0.45s linear, box-shadow 0.3s, transform 0.15s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.4);
  border: 1.5px solid rgba(255,255,255,0.55);
}
.train::after {
  content: ''; position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%);
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-top: 6px solid currentColor; opacity: 0.5;
}
.train.selected { transform: translate(-50%, 0) scale(1.28); z-index: 9;
  box-shadow: 0 0 0 3px var(--accent), 0 6px 20px rgba(47,214,255,0.5); }
.train.rapid { border-radius: 4px; }
.train .rq { position: absolute; top: -8px; right: -6px; font-size: 8px; }

.train.d-ontime { background: linear-gradient(180deg,#4ade80,#22c55e); }
.train.d-minor  { background: linear-gradient(180deg,#fcd34d,#f59e0b); }
.train.d-major  { background: linear-gradient(180deg,#fb7185,#ef4444); color:#fff; animation: pulseBad 1.1s infinite; }
@keyframes pulseBad { 0%,100%{box-shadow:0 4px 12px rgba(239,68,68,0.4);} 50%{box-shadow:0 0 18px 3px rgba(239,68,68,0.75);} }

.train-delay-tag {
  position: absolute; top: -15px; left: 50%; transform: translateX(-50%);
  font-size: 9px; font-weight: 800; padding: 1px 5px; border-radius: 6px;
  background: rgba(0,0,0,0.7); white-space: nowrap; pointer-events: none;
}

/* ===================== サイドパネル ===================== */
.panel-section { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.panel-section .ps-title {
  font-size: 11px; letter-spacing: 0.16em; color: var(--text-dim);
  font-weight: 700; margin-bottom: 10px; display: flex; align-items: center; gap: 7px;
}

/* 選択中列車の詳細 */
.sel-card { background: rgba(47,214,255,0.05); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 12px; }
.sel-empty { text-align: center; color: var(--text-faint); font-size: 13px; padding: 24px 0; }
.sel-empty i { font-size: 30px; display: block; margin-bottom: 10px; opacity: 0.5; }
.sel-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; margin: 5px 0; }
.sel-row .k { color: var(--text-dim); }
.sel-row .v { font-weight: 700; }
.sel-name { font-size: 16px; font-weight: 800; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }

/* アクションボタン */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.act-btn {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  padding: 10px 11px; border-radius: 12px; cursor: pointer;
  background: var(--panel-solid); border: 1px solid var(--border);
  color: var(--text); text-align: left; font-family: inherit;
  transition: transform 0.12s, border-color 0.2s, box-shadow 0.2s;
}
.act-btn:not(:disabled):hover { transform: translateY(-2px); border-color: var(--ac); box-shadow: 0 6px 18px rgba(0,0,0,0.35); }
.act-btn:not(:disabled):active { transform: translateY(0) scale(0.98); }
.act-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.act-btn .ab-head { display: flex; align-items: center; gap: 7px; font-weight: 800; font-size: 12.5px; }
.act-btn .ab-head i { color: var(--ac); font-size: 13px; }
.act-btn .ab-desc { font-size: 9.5px; color: var(--text-dim); line-height: 1.35; }
.act-btn .cd-bar {
  position: absolute; left: 0; bottom: 0; height: 3px; background: var(--ac);
  width: 0%; transition: width 0.1s linear;
}
.act-btn.full { grid-column: 1 / -1; }

/* イベントログ */
.event-log { flex: 1; overflow-y: auto; padding: 10px 14px; }
.log-item {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 9px 11px; margin-bottom: 7px; border-radius: 11px;
  background: var(--panel); border: 1px solid var(--border);
  font-size: 12px; animation: slideIn 0.35s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
.log-item .li-icon { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; }
.log-item .li-body { flex: 1; line-height: 1.35; }
.log-item .li-body .li-t { font-weight: 700; }
.log-item .li-body .li-s { color: var(--text-dim); font-size: 10.5px; margin-top: 1px; }
.log-item .li-time { font-size: 9px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.log-item.resolved { opacity: 0.55; }

/* ===================== コンボ / トースト ===================== */
.combo-flash {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%) scale(0.6);
  font-size: 46px; font-weight: 900; letter-spacing: 0.05em; pointer-events: none;
  z-index: 90; opacity: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 40px rgba(47,214,255,0.5);
}
.combo-flash.show { animation: comboPop 0.9s ease forwards; }
@keyframes comboPop {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(0.4) rotate(-6deg); }
  30% { opacity: 1; transform: translate(-50%,-50%) scale(1.15) rotate(2deg); }
  70% { opacity: 1; transform: translate(-50%,-58%) scale(1); }
  100% { opacity: 0; transform: translate(-50%,-80%) scale(0.9); }
}

.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  padding: 10px 18px; border-radius: 30px; font-size: 13px; font-weight: 700;
  background: var(--panel-solid); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow); backdrop-filter: blur(10px);
  display: flex; align-items: center; gap: 8px; animation: toastIn 0.3s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.toast.good { border-color: rgba(34,197,94,0.5); } .toast.good i { color: var(--good); }
.toast.warn { border-color: rgba(245,158,11,0.5); } .toast.warn i { color: var(--warn); }
.toast.bad  { border-color: rgba(239,68,68,0.5); }  .toast.bad i  { color: var(--bad); }

/* ===================== オーバーレイ（開始/結果） ===================== */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 20px;
  background: radial-gradient(circle at 50% 30%, rgba(6,10,20,0.85), rgba(6,10,20,0.97));
  backdrop-filter: blur(8px);
}
.overlay.hidden { display: none; }
.modal {
  width: min(520px, 94vw); max-height: 92vh; overflow-y: auto;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--border-strong); border-radius: 24px;
  padding: 30px 28px; box-shadow: 0 30px 90px rgba(0,0,0,0.7);
  text-align: center; animation: modalIn 0.4s cubic-bezier(.2,.8,.2,1);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(24px) scale(0.96); } to { opacity: 1; transform: none; } }
.modal-logo {
  width: 78px; height: 78px; border-radius: 22px; margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--jr-green), var(--jr-green-light));
  display: grid; place-items: center;
  box-shadow: 0 10px 40px rgba(0,153,68,0.5), inset 0 2px 0 rgba(255,255,255,0.3);
}
.modal-logo i { font-size: 38px; color: #fff; }
.modal h1 { font-size: 27px; font-weight: 900; letter-spacing: 0.04em; margin-bottom: 4px; }
.modal .sub { color: var(--text-dim); font-size: 13px; letter-spacing: 0.14em; margin-bottom: 22px; }
.modal p.lead { color: var(--text-dim); font-size: 13.5px; line-height: 1.7; margin-bottom: 22px; }

.stage-select { display: grid; gap: 9px; margin-bottom: 22px; }
.stage-opt {
  display: flex; align-items: center; gap: 13px; text-align: left;
  padding: 13px 15px; border-radius: 14px; cursor: pointer; font-family: inherit;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  transition: transform 0.12s, border-color 0.2s;
}
.stage-opt:hover { transform: translateX(4px); border-color: var(--accent); }
.stage-opt .so-num {
  width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 900; font-size: 17px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #05121f;
}
.stage-opt .so-body { flex: 1; }
.stage-opt .so-name { font-weight: 800; font-size: 15px; }
.stage-opt .so-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.stage-opt .so-arrow { color: var(--text-faint); }

.btn-primary {
  width: 100%; padding: 15px; border-radius: 15px; border: none; cursor: pointer;
  font-family: inherit; font-size: 16px; font-weight: 800; letter-spacing: 0.06em;
  color: #05121f; background: linear-gradient(135deg, var(--accent), var(--jr-green-light));
  box-shadow: 0 8px 30px rgba(47,214,255,0.35); transition: transform 0.12s, box-shadow 0.2s;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 12px 40px rgba(47,214,255,0.5); }
.btn-primary:active { transform: translateY(0) scale(0.99); }
.btn-ghost {
  width: 100%; margin-top: 10px; padding: 13px; border-radius: 14px; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 700; color: var(--text-dim);
  background: transparent; border: 1px solid var(--border); transition: 0.2s;
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }

/* 結果画面 */
.result-grade {
  font-size: 76px; font-weight: 900; line-height: 1; margin: 6px 0 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 50px rgba(124,92,255,0.5);
}
.result-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 20px 0; }
.rs-item { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.rs-item .rv { font-size: 26px; font-weight: 900; font-variant-numeric: tabular-nums; }
.rs-item .rl { font-size: 11px; color: var(--text-dim); margin-top: 3px; letter-spacing: 0.08em; }
.rs-item.hl { border-color: var(--accent); background: rgba(47,214,255,0.06); }

/* プログレスバー（残り時間） */
.time-bar { height: 4px; background: rgba(255,255,255,0.08); position: relative; }
.time-bar .fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--jr-green-light)); width: 100%; transition: width 1s linear; }

/* スクロールバー */
.board-wrap::-webkit-scrollbar, .event-log::-webkit-scrollbar, .modal::-webkit-scrollbar { width: 8px; }
.board-wrap::-webkit-scrollbar-thumb, .event-log::-webkit-scrollbar-thumb, .modal::-webkit-scrollbar-thumb { background: rgba(120,160,220,0.25); border-radius: 8px; }

/* ヘルプヒント */
.hint-bar {
  display: flex; gap: 14px; flex-wrap: wrap; justify-content: center;
  font-size: 11px; color: var(--text-faint); margin-top: 14px;
}
.hint-bar span { display: flex; align-items: center; gap: 5px; }

/* ===================== レスポンシブ ===================== */
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side-panel {
    border-left: none; border-top: 1px solid var(--border);
    flex-direction: row; overflow-x: auto; max-height: 240px;
  }
  .side-panel .panel-section { border-bottom: none; border-right: 1px solid var(--border); min-width: 280px; }
  .side-panel .event-log { min-width: 240px; }
  .top-metrics { gap: 6px; }
  .metric-chip { min-width: 58px; padding: 5px 8px; }
  .metric-chip .mv { font-size: 15px; }
  .brand-title .t2 { display: none; }
}
@media (max-width: 560px) {
  .top-metrics .metric-chip:nth-child(n+4) { display: none; }
  .clock { font-size: 16px; }
}
