/* =========================================================================
 * 1. デザインシステム＆ベースレイアウト（外部ライブラリ不使用・純CSS）
 * ========================================================================= */
:root {
  --bg-outer-1: #1e293b;
  --bg-outer-2: #0f172a;
  --surface: #f8fafc;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-sub: #475569;
  --ink-muted: #64748b;
  --border: #e2e8f0;
  --navy: #0f172a;
  --navy-soft: #1e293b;

  /* 統一3種別カラー */
  --local: #2563eb;
  --local-bg: #dbeafe;
  --semi: #059669;
  --semi-bg: #d1fae5;
  --express: #dc2626;
  --express-bg: #fee2e2;

  /* 判定カラー */
  --ok-bg: #ecfdf5;
  --ok-bd: #a7f3d0;
  --ok-tx: #065f46;
  --ng-bg: #fff1f2;
  --ng-bd: #fecdd3;
  --ng-tx: #9f1239;
  --amber-bg: #fffbeb;
  --amber-bd: #fde68a;
  --amber-tx: #92400e;
}

* {
  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: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at top, var(--bg-outer-1) 0%, var(--bg-outer-2) 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  color: var(--ink);
  display: flex;
  justify-content: center;
  align-items: center;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

/* スマホ縦長フレーム (9:16最適化・最大幅430px) / PC横長フレーム (2倍幅860px) */
#app-shell {
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  max-height: 932px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.55);
  transition: max-width 0.18s ease;
}

#app-shell.pc-mode {
  max-width: 860px;
  max-height: 940px;
}

@media (min-width: 450px) {
  #app-shell {
    height: min(96dvh, 912px);
    border-radius: 26px;
    border: 3px solid rgba(255, 255, 255, 0.16);
  }
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  transition: transform 0.08s ease, background-color 0.14s ease, border-color 0.14s ease, opacity 0.14s ease;
}

button:active:not(:disabled) {
  transform: translateY(1px) scale(0.96);
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.hidden {
  display: none !important;
}

/* ==================== 1. ヘッダー＆2階層ステージ選択UI ==================== */
.app-header {
  background: var(--navy);
  color: #ffffff;
  padding: 6px 9px 6px;
  flex-shrink: 0;
  z-index: 20;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.28);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 5px;
}

.btn-header-reset {
  padding: 3px 7px;
  height: 25px;
  border-radius: 7px;
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(248, 113, 113, 0.48);
  color: #fecaca;
  font-size: 10px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-header-reset:hover {
  background: rgba(239, 68, 68, 0.32);
  border-color: rgba(248, 113, 113, 0.78);
  color: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  flex: 1;
}

.brand-icon {
  width: 21px;
  height: 21px;
  border-radius: 6px;
  background: linear-gradient(135deg, #38bdf8, #2563eb);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 900;
  color: #ffffff;
  flex-shrink: 0;
}

.brand-title {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
  white-space: nowrap;
}

.ver-badge {
  padding: 1.5px 5px;
  border-radius: 5px;
  font-size: 8.8px;
  font-weight: 800;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(30, 41, 59, 0.9);
  color: #cbd5e1;
  white-space: nowrap;
  flex-shrink: 0;
}

.clear-count-pill {
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 9.5px;
  font-weight: 800;
  border: 1px solid #334155;
  background: #1e293b;
  color: #94a3b8;
  white-space: nowrap;
  flex-shrink: 0;
}

.clear-count-pill.has-clear {
  background: rgba(16, 185, 129, 0.22);
  border-color: rgba(52, 211, 153, 0.55);
  color: #6ee7b7;
}

.clear-count-pill.all-clear {
  background: rgba(245, 158, 11, 0.24);
  border-color: rgba(251, 191, 36, 0.65);
  color: #fcd34d;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn {
  width: 25px;
  height: 25px;
  border-radius: 7px;
  background: #1e293b;
  border: 1px solid #334155;
  color: #e2e8f0;
  font-size: 11.5px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { background: #334155; }
.icon-btn.help { color: #7dd3fc; }

/* Tier 1 カテゴリタブ：入門･初級 / 中級 / 上級 / 達人 */
.cat-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(71, 85, 105, 0.65);
  border-radius: 9px;
  padding: 2px;
  margin-bottom: 4px;
}

.cat-tab {
  padding: 3.5px 2px;
  border-radius: 7px;
  background: transparent;
  color: #cbd5e1;
  font-size: 9.8px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  white-space: nowrap;
}

.cat-tab.active {
  background: #38bdf8;
  color: #0f172a;
  box-shadow: 0 2px 6px rgba(56, 189, 248, 0.35);
}

.cat-prog {
  font-size: 8.4px;
  font-weight: 800;
  padding: 0.5px 3.5px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.35);
  color: #e2e8f0;
}

.cat-tab.active .cat-prog {
  background: rgba(15, 23, 42, 0.16);
  color: #0f172a;
}

/* Tier 2 ステージタブ（常に1行・ステージ名のみ） */
.stage-subtabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 3px;
}

.stage-subtabs.cols-1 { grid-template-columns: 1fr; }
.stage-subtabs.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stage-subtabs.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stage-subtabs.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stage-subtabs.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stage-subtabs.cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }

.stage-btn {
  padding: 3px 3px 2.5px;
  border-radius: 7px;
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid rgba(71, 85, 105, 0.55);
  color: #cbd5e1;
  font-size: 9.6px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.15;
  min-width: 0;
}

.stage-btn.active {
  background: #ffffff;
  border-color: #ffffff;
  color: #0f172a;
  font-weight: 800;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);
}

.stage-btn-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.stage-btn-stars {
  font-size: 8.2px;
  height: 10px;
  color: #64748b;
  letter-spacing: -0.5px;
}

.stage-btn-stars.earned { color: #f59e0b; }

/* ==================== 2. 上段：条件バー ＋ 「何がダメ？」ボタン ＋ ミニ路線図 ==================== */
.top-panel {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 5px 9px 4px;
  flex-shrink: 0;
  z-index: 15;
}

.cond-row {
  display: flex;
  align-items: stretch;
  gap: 5px;
  margin-bottom: 4px;
}

.cond-grid {
  flex: 1;
  display: grid;
  gap: 3.5px;
  min-width: 0;
}

.cond-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cond-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cond-grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
.cond-grid.cols-5,
.cond-grid.cols-6 { grid-template-columns: repeat(3, 1fr); }

.cond-chip {
  padding: 2.5px 5px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f8fafc;
  min-width: 0;
}

.cond-chip.ok {
  background: var(--ok-bg);
  border-color: var(--ok-bd);
  color: var(--ok-tx);
}

.cond-chip.ng {
  background: var(--ng-bg);
  border-color: var(--ng-bd);
  color: var(--ng-tx);
}

.cond-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 8.3px;
  font-weight: 700;
  opacity: 0.9;
  white-space: nowrap;
}

.cond-val {
  font-size: 10px;
  font-weight: 800;
  line-height: 1.15;
  margin-top: 0.5px;
  white-space: nowrap;
}

.cond-val small {
  font-size: 8px;
  font-weight: 700;
  opacity: 0.78;
}

@keyframes subtlePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.28); }
  50% { box-shadow: 0 0 0 4px rgba(220, 38, 38, 0); }
}

.btn-diag {
  flex-shrink: 0;
  padding: 4px 7px;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  line-height: 1.1;
  border: 1.5px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  min-width: 78px;
}

.btn-diag.has-error {
  background: linear-gradient(180deg, #fff1f2, #ffe4e6);
  border-color: #fb7185;
  color: #9f1239;
  animation: subtlePulse 2.2s infinite;
}

.btn-diag.has-warn {
  background: linear-gradient(180deg, #fffbeb, #fef3c7);
  border-color: #fbbf24;
  color: #92400e;
}

.btn-diag.all-ok {
  background: linear-gradient(180deg, #ecfdf5, #d1fae5);
  border-color: #34d399;
  color: #065f46;
}

.btn-diag-top {
  display: flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
}

.diag-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 15px;
  height: 14px;
  padding: 0 3.5px;
  border-radius: 999px;
  background: #dc2626;
  color: #ffffff;
  font-size: 9px;
  font-weight: 900;
}

.btn-diag.has-warn .diag-count-badge { background: #d97706; }

.btn-diag-sub {
  font-size: 8px;
  font-weight: 700;
  opacity: 0.85;
}

.routemap-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 2.5px 6px 2px;
}

.routemap-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1px;
  padding: 0 2px;
  gap: 6px;
}

.routemap-caption {
  font-size: 9px;
  font-weight: 700;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clock-badge {
  font-size: 9px;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 5px;
  background: #e2e8f0;
  color: #475569;
  flex-shrink: 0;
}

.clock-badge.running {
  background: #fee2e2;
  color: #b91c1c;
}

#routemap-canvas {
  display: block;
  width: 100%;
  height: 42px;
}

#routemap-canvas.branch-tall {
  height: 56px;
}

/* ==================== 上側フローティング別窓：「何がダメ？」 ==================== */
.diag-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.38);
  backdrop-filter: blur(1.5px);
  z-index: 35;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 96px 10px 10px;
}

@keyframes slideDownPanel {
  0% { opacity: 0; transform: translateY(-10px) scale(0.98); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.diag-window {
  width: 100%;
  max-height: 48dvh;
  background: #ffffff;
  border-radius: 15px;
  border: 1.5px solid #cbd5e1;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideDownPanel 0.15s ease-out;
}

.diag-win-head {
  background: #0f172a;
  color: #ffffff;
  padding: 8px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.diag-win-title {
  font-size: 12px;
  font-weight: 800;
}

.diag-win-hint {
  font-size: 9px;
  font-weight: 600;
  color: #94a3b8;
}

.diag-win-close {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: #1e293b;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.diag-win-body {
  padding: 8px 9px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #f8fafc;
}

.diag-group-title {
  font-size: 10px;
  font-weight: 800;
  color: #475569;
  padding: 2px 2px 0;
  letter-spacing: 0.02em;
}

.diag-item {
  width: 100%;
  text-align: left;
  padding: 7.5px 9px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.diag-item:hover { border-color: #94a3b8; }
.diag-item.cat-safety  { border-left: 4px solid #dc2626; background: #fffbfb; }
.diag-item.cat-wait    { border-left: 4px solid #ea580c; background: #fffdf9; }
.diag-item.cat-star3   { border-left: 4px solid #f59e0b; background: #fffef7; }
.diag-item.cat-perfect { border-left: 4px solid #059669; background: #f0fdf4; cursor: default; }

.diag-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.diag-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 9px;
  font-weight: 800;
}

.diag-tag.safety { background: #fee2e2; color: #b91c1c; }
.diag-tag.wait   { background: #ffedd5; color: #c2410c; }
.diag-tag.star3  { background: #fef3c7; color: #92400e; }
.diag-tag.ok     { background: #d1fae5; color: #065f46; }

.diag-jump {
  font-size: 9px;
  font-weight: 800;
  color: #2563eb;
  white-space: nowrap;
}

.diag-item-text {
  font-size: 10.8px;
  font-weight: 700;
  line-height: 1.42;
  color: #1e293b;
}

.diag-item-sub {
  font-size: 9.5px;
  font-weight: 600;
  color: #64748b;
}

/* ==================== 3. 中段：種別フィルタバー ＋ ダイヤグラムCanvas ==================== */
.main-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  position: relative;
  overflow: hidden;
}

.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 3.5px 7px;
  background: #f1f5f9;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.filter-pills {
  display: flex;
  align-items: center;
  gap: 3.5px;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.dir-seg {
  display: inline-flex;
  align-items: center;
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  padding: 1px;
  gap: 1px;
  flex-shrink: 0;
}

.dir-btn {
  padding: 2px 5px;
  border-radius: 5.5px;
  font-size: 9.2px;
  font-weight: 800;
  background: transparent;
  color: #475569;
  white-space: nowrap;
}

.dir-btn.active {
  background: #0f172a;
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.22);
}

.filter-btn {
  padding: 2.5px 6.5px;
  border-radius: 7px;
  font-size: 9.8px;
  font-weight: 800;
  border: 1.5px solid #cbd5e1;
  background: #ffffff;
  color: #64748b;
  display: inline-flex;
  align-items: center;
  gap: 3.5px;
  white-space: nowrap;
}

.filter-btn .dot {
  width: 6.5px;
  height: 6.5px;
  border-radius: 999px;
  display: inline-block;
}

.filter-btn.active-freight { background: #fef3c7;           border-color: #78350f;         color: #78350f; }
.filter-btn.active-local   { background: var(--local-bg);   border-color: var(--local);   color: #1e40af; }
.filter-btn.active-semi    { background: var(--semi-bg);    border-color: var(--semi);    color: #065f46; }
.filter-btn.active-express { background: var(--express-bg); border-color: var(--express); color: #991b1b; }
.filter-btn.active-rapid   { background: #f3e8ff;           border-color: #9333ea;         color: #6b21a8; }
.filter-btn.active-all     { background: var(--navy);       border-color: var(--navy);    color: #ffffff; }

.zoom-btn {
  padding: 2.5px 6px;
  border-radius: 7px;
  font-size: 9.5px;
  font-weight: 800;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #334155;
  white-space: nowrap;
  flex-shrink: 0;
}

.zoom-btn.zoomed {
  background: #e0f2fe;
  border-color: #38bdf8;
  color: #0369a1;
}

#diagram-wrap {
  flex: 1;
  min-height: 120px;
  width: 100%;
  position: relative;
  background: #ffffff;
}

#diagram-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ==================== 4. 下段：操作パネル ==================== */
.bottom-panel {
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 5px 9px 7px;
  flex-shrink: 0;
  z-index: 10;
  box-shadow: 0 -4px 14px rgba(15, 23, 42, 0.06);
}

.train-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 3.5px;
  margin-bottom: 5px;
  min-height: 31px;
  align-items: stretch;
}

.train-chip {
  flex: 1 1 15%;
  min-width: 44px;
  max-width: 86px;
  padding: 3px 2px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: #ffffff;
  color: var(--ink-muted);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
}

.train-chip.selected {
  color: var(--ink);
  box-shadow: 0 2px 5px rgba(15, 23, 42, 0.12);
}

.train-chip-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2.5px;
  font-size: 9.8px;
  font-weight: 800;
}

.train-chip-dot {
  width: 5.5px;
  height: 5.5px;
  border-radius: 999px;
  flex-shrink: 0;
}

.train-chip-badge {
  font-size: 7.2px;
  font-weight: 800;
  padding: 0.5px 2.5px;
  border-radius: 3px;
  background: #0f172a;
  color: #ffffff;
  line-height: 1.1;
}

.train-chip-badge.dir-down {
  background: #0284c7;
}

.train-chip-badge.dir-up {
  background: #7c3aed;
}

.train-chip-sub {
  font-size: 8.4px;
  font-weight: 700;
  opacity: 0.82;
  margin-top: 1.5px;
}

.empty-filter-msg {
  width: 100%;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-muted);
  padding: 7px;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 9px;
}

.edit-area { margin-bottom: 5px; }

.dep-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 4.5px;
}

.dep-info {
  width: 68px;
  flex-shrink: 0;
  line-height: 1.12;
}

.dep-label {
  font-size: 9px;
  font-weight: 800;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dep-val {
  font-size: 12px;
  font-weight: 800;
  color: var(--ink);
}

.dep-btns {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3.5px;
}

.step-btn {
  padding: 6px 2px;
  border-radius: 9px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  color: #0f172a;
  font-size: 10.2px;
  font-weight: 800;
}

.step-btn:hover:not(:disabled) { background: #e2e8f0; }
.step-btn.wide { color: #475569; }

/* 待避時間調整（最大3駅横並び） */
.siding-row {
  display: grid;
  gap: 4px;
  min-height: 31px;
}

.siding-row.cols-1 { grid-template-columns: 1fr; }
.siding-row.cols-2 { grid-template-columns: repeat(2, 1fr); }
.siding-row.cols-3 { grid-template-columns: repeat(3, 1fr); }

.siding-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
  padding: 3px 4px;
  border-radius: 9px;
  background: var(--amber-bg);
  border: 1px solid var(--amber-bd);
  min-width: 0;
}

.siding-card.freight-disabled {
  background: #f1f5f9;
  border-color: #cbd5e1;
  opacity: 0.72;
}

.siding-card.freight-disabled .siding-mid-lbl {
  color: #64748b;
}

.siding-card.freight-disabled .siding-mid-val {
  color: #64748b;
  font-size: 9.2px;
}

.siding-card.freight-disabled .siding-pm {
  border-color: #cbd5e1;
  color: #94a3b8;
}

.siding-pm {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: #ffffff;
  border: 1px solid #fcd34d;
  color: var(--amber-tx);
  font-size: 13px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.siding-mid {
  flex: 1;
  text-align: center;
  line-height: 1.1;
  min-width: 0;
}

.siding-mid-lbl {
  font-size: 8.5px;
  font-weight: 800;
  color: var(--amber-tx);
  white-space: nowrap;
}

.siding-mid-val {
  font-size: 10.5px;
  font-weight: 800;
  color: var(--ink);
}

.info-banner {
  border-radius: 9px;
  padding: 7px 9px;
  text-align: center;
  font-size: 10px;
  font-weight: 800;
}

.info-banner.express-note {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.info-banner.locked-box {
  background: #fff1f2;
  border: 1px solid #fecdd3;
  color: #be123c;
  margin-bottom: 5px;
  padding: 8.5px;
}

.info-banner.locked-box .sub {
  font-size: 9.5px;
  font-weight: 700;
  opacity: 0.9;
  margin-top: 2px;
}

.info-banner.none-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  color: var(--ink-muted);
  margin-bottom: 5px;
  padding: 9px;
}

.action-bar {
  display: flex;
  align-items: center;
  gap: 4.5px;
}

.btn-play {
  flex: 1;
  padding: 8px 10px;
  border-radius: 10px;
  background: linear-gradient(180deg, #1e293b, #0f172a);
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  box-shadow: 0 3px 8px rgba(15, 23, 42, 0.25);
}

.btn-play.playing {
  background: linear-gradient(180deg, #ef4444, #dc2626);
}

.btn-sub {
  padding: 8px 9px;
  border-radius: 10px;
  background: #f1f5f9;
  border: 1px solid var(--border);
  color: #334155;
  font-size: 10.5px;
  font-weight: 800;
  white-space: nowrap;
}

.btn-sub:hover { background: #e2e8f0; }
.btn-hint { background: #fffbeb; border-color: #fde68a; color: #92400e; }

/* ==================== モーダル共通 ==================== */
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.62);
  backdrop-filter: blur(2px);
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

@keyframes modalPop {
  0% { opacity: 0; transform: scale(0.94) translateY(8px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-card {
  width: 100%;
  max-width: 368px;
  max-height: 85dvh;
  background: #ffffff;
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalPop 0.16s ease-out;
}

.modal-head {
  background: var(--navy);
  color: #ffffff;
  padding: 10px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.modal-head.danger {
  background: #9f1239;
}

.modal-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 6px;
}

.modal-close {
  width: 25px;
  height: 25px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.45);
  color: #e2e8f0;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.modal-body {
  padding: 11px 13px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 11px;
  line-height: 1.52;
  color: #334155;
}

.rule-item {
  padding: 8px 9.5px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: #f8fafc;
}

.rule-item.rose  { background: #fff1f2; border-color: #fecdd3; }
.rule-item.amber { background: #fffbeb; border-color: #fde68a; }
.rule-item.green { background: #ecfdf5; border-color: #a7f3d0; }

.rule-item-title {
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 2px;
  font-size: 11.2px;
}

.modal-foot {
  padding: 9px 13px;
  background: #f8fafc;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 7px;
  flex-shrink: 0;
}

.btn-primary-full {
  width: 100%;
  padding: 9.5px;
  border-radius: 11px;
  background: var(--navy);
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 800;
}

.btn-modal-cancel {
  flex: 1;
  padding: 9.5px 10px;
  border-radius: 11px;
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
  color: #334155;
  font-size: 11.5px;
  font-weight: 800;
}

.btn-modal-cancel:hover { background: #cbd5e1; }

.btn-modal-danger {
  flex: 1;
  padding: 9.5px 10px;
  border-radius: 11px;
  background: linear-gradient(180deg, #ef4444, #dc2626);
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 800;
  box-shadow: 0 3px 8px rgba(220, 38, 38, 0.28);
}

.btn-modal-danger:hover {
  background: linear-gradient(180deg, #dc2626, #b91c1c);
}

/* クリア祝福モーダル */
.clear-card {
  padding: 18px 16px 15px;
  text-align: center;
}

@keyframes starPop {
  0% { transform: scale(0.3) rotate(-20deg); opacity: 0; }
  70% { transform: scale(1.22) rotate(6deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.clear-stars {
  font-size: 30px;
  letter-spacing: 3px;
  margin-bottom: 4px;
}

.star-anim {
  display: inline-block;
  animation: starPop 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.clear-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  margin-bottom: 6px;
}

.clear-badge.s2 { background: #d1fae5; color: #065f46; }
.clear-badge.s3 { background: #fef3c7; color: #92400e; }

.clear-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 900;
  color: #0f172a;
}

.clear-desc {
  margin: 0 0 11px;
  font-size: 11px;
  line-height: 1.5;
  color: #475569;
}

.clear-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
  gap: 6px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 8px 6px;
  margin-bottom: 12px;
}

.rule-danger-text {
  color: #881337;
  font-weight: 700;
}

.metric-lbl {
  font-size: 9px;
  font-weight: 700;
  color: #64748b;
}

.metric-val {
  font-size: 13px;
  font-weight: 900;
  margin-top: 2px;
}

.clear-btns {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn-next-stage {
  width: 100%;
  padding: 10px;
  border-radius: 11px;
  background: linear-gradient(180deg, #0ea5e9, #2563eb);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.btn-watch {
  width: 100%;
  padding: 9px;
  border-radius: 11px;
  background: var(--navy);
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 800;
}


/* ==================== モード切替バー ＆ カスタムプレイヘッダ ==================== */
.mode-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  margin-bottom: 4px;
}

.mode-seg {
  display: inline-flex;
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(71, 85, 105, 0.65);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.mode-btn {
  padding: 3px 6.5px;
  border-radius: 6px;
  font-size: 9.4px;
  font-weight: 800;
  background: transparent;
  color: #cbd5e1;
  white-space: nowrap;
}

.mode-btn.active {
  background: #f8fafc;
  color: #0f172a;
}

.passphrase-entry-btn {
  padding: 3.5px 9px;
  border-radius: 8px;
  font-size: 9.8px;
  font-weight: 800;
  background: rgba(245, 158, 11, 0.22);
  border: 1px solid rgba(251, 191, 36, 0.55);
  color: #fde68a;
  white-space: nowrap;
}

.passphrase-entry-btn:hover {
  background: rgba(245, 158, 11, 0.36);
  color: #ffffff;
}

.custom-play-bar {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(71, 85, 105, 0.7);
  border-radius: 9px;
  padding: 5px 7px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.custom-play-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.custom-play-title {
  font-size: 11px;
  font-weight: 800;
  color: #ffffff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-author-pill {
  font-size: 9px;
  font-weight: 800;
  padding: 1.5px 6px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.2);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #7dd3fc;
  white-space: nowrap;
}

.custom-author-pill.verified {
  background: rgba(16, 185, 129, 0.24);
  border-color: rgba(52, 211, 153, 0.6);
  color: #a7f3d0;
}

.custom-play-btns {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.custom-bar-btn {
  padding: 3.5px 7px;
  border-radius: 7px;
  font-size: 9.5px;
  font-weight: 800;
  background: #334155;
  border: 1px solid #475569;
  color: #f1f5f9;
}

.custom-bar-btn.issue {
  margin-left: auto;
  background: linear-gradient(135deg, #059669, #10b981);
  border-color: #34d399;
  color: #ffffff;
}

.custom-bar-btn.issue.locked {
  background: #1e293b;
  border-color: #334155;
  color: #94a3b8;
  opacity: 0.72;
}

/* ==================== 作問エディタシェル（4ステップUI） ==================== */
.creator-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #f8fafc;
}

.creator-topbar {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 6px 9px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}

.creator-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.creator-title-text {
  font-size: 12px;
  font-weight: 900;
  color: #0f172a;
}

.creator-ver-pill {
  font-size: 9px;
  font-weight: 800;
  padding: 1.5px 6px;
  border-radius: 999px;
  background: #fee2e2;
  color: #991b1b;
}

.creator-ver-pill.verified {
  background: #d1fae5;
  color: #065f46;
}

.creator-io-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.cr-mini-btn {
  padding: 4px 4px;
  border-radius: 7px;
  font-size: 9.2px;
  font-weight: 800;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #334155;
  white-space: nowrap;
}

.cr-mini-btn.primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #ffffff;
}

.creator-stepper {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  padding: 5px 8px;
  background: #e2e8f0;
  border-bottom: 1px solid #cbd5e1;
  flex-shrink: 0;
}

.cr-step-btn {
  padding: 4.5px 2px;
  border-radius: 7px;
  font-size: 9.4px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.72);
  color: #475569;
  white-space: nowrap;
}

.cr-step-btn.active {
  background: #0f172a;
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(15, 23, 42, 0.22);
}

.cr-step-btn.blocked {
  color: #b91c1c;
  background: #fee2e2;
}

.creator-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 9px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.creator-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  background: #ffffff;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.cr-nav-btn {
  flex: 1;
  padding: 9px 8px;
  font-size: 11px;
}

.cr-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 10px;
}

.cr-card-title {
  font-size: 10.8px;
  font-weight: 900;
  color: #0f172a;
  margin-bottom: 6px;
}

.cr-field-lbl {
  font-size: 9.5px;
  font-weight: 700;
  color: #475569;
  margin-bottom: 4px;
}

.cr-btn-pair {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 7px;
}

.cr-action-btn {
  padding: 7px 6px;
  border-radius: 9px;
  background: #f8fafc;
  border: 1.5px solid #cbd5e1;
  color: #0f172a;
  font-size: 10.5px;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.cr-action-btn small {
  font-size: 8.6px;
  font-weight: 700;
  color: #64748b;
}

.cr-action-btn.accent {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #1d4ed8;
}

.cr-clone-row {
  display: flex;
  gap: 5px;
  align-items: center;
}

.cr-select {
  flex: 1;
  padding: 5px 6px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  font-size: 10.2px;
  font-weight: 700;
  color: #0f172a;
  min-width: 0;
}

.cr-title-pickers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.cr-textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  border-radius: 9px;
  border: 1.5px solid #cbd5e1;
  background: #ffffff;
  font-size: 10.5px;
  color: #0f172a;
  resize: vertical;
  font-family: inherit;
}

.passphrase-box {
  background: #fffbeb;
  border-color: #f59e0b;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.55;
  text-align: center;
}

.passphrase-copy-msg {
  text-align: center;
  font-size: 10.5px;
  font-weight: 800;
  color: #059669;
}

.cr-seg-row {
  display: grid;
  gap: 4px;
}
.cr-seg-row.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cr-seg-row.cols-3 { grid-template-columns: repeat(3, 1fr); }

.cr-seg-btn {
  padding: 5.5px 4px;
  border-radius: 8px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #475569;
  font-size: 9.8px;
  font-weight: 800;
}

.cr-seg-btn.active {
  background: #0f172a;
  border-color: #0f172a;
  color: #ffffff;
}

.cr-inline-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 10.4px;
  font-weight: 700;
  color: #1e293b;
}

.cr-pm-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.cr-help-note {
  font-size: 9px;
  color: #64748b;
  line-height: 1.4;
  margin-bottom: 6px;
}

.cr-route-map {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 2px;
  padding: 6px 4px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 9px;
}

.cr-node {
  min-width: 28px;
  padding: 4px 2px;
  border-radius: 8px;
  border: 1.5px solid #cbd5e1;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  flex-shrink: 0;
}

.cr-node.equip-pass    { background: #fef3c7; border-color: #f59e0b; color: #92400e; }
.cr-node.equip-freight { background: #e2e8f0; border-color: #64748b; color: #334155; }
.cr-node.equip-shared  { background: #ede9fe; border-color: #8b5cf6; color: #5b21b6; }
.cr-node.is-end        { background: #0f172a; border-color: #0f172a; color: #ffffff; opacity: 0.9; }

.cr-node-name { font-size: 10px; font-weight: 900; }
.cr-node-eq   { font-size: 8.2px; font-weight: 800; }

.cr-seg-link {
  min-width: 20px;
  height: 20px;
  border-radius: 5px;
  font-size: 8.5px;
  font-weight: 800;
  flex-shrink: 0;
  background: #e2e8f0;
  color: #334155;
}

.cr-seg-link.single {
  background: #fde68a;
  color: #92400e;
  border: 1px solid #f59e0b;
}

.cr-legend-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.cr-eq-pill {
  font-size: 8.8px;
  font-weight: 800;
  padding: 1.5px 6px;
  border-radius: 999px;
}
.cr-eq-pill.equip-pass    { background: #fef3c7; color: #92400e; }
.cr-eq-pill.equip-freight { background: #e2e8f0; color: #334155; }
.cr-eq-pill.equip-shared  { background: #ede9fe; color: #5b21b6; }

.cr-check-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 700;
  color: #334155;
  margin-top: 4px;
}

.cr-train-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.cr-train-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 9px;
  padding: 5.5px 7px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cr-train-top,
.cr-train-sub {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.cr-tr-id {
  font-size: 10.5px;
  font-weight: 900;
  min-width: 28px;
  color: #0f172a;
}

.cr-mini-sel {
  padding: 2.5px 4px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  font-size: 9.5px;
  font-weight: 700;
}

.cr-dir-pill,
.cr-lock-pill {
  padding: 2.5px 6px;
  border-radius: 6px;
  font-size: 9.2px;
  font-weight: 800;
  background: #e0f2fe;
  color: #0369a1;
}

.cr-dir-pill.up { background: #ede9fe; color: #6d28d9; }
.cr-lock-pill { background: #e2e8f0; color: #475569; }
.cr-lock-pill.locked { background: #fee2e2; color: #991b1b; }

.cr-del-btn {
  margin-left: auto;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 10px;
  font-weight: 900;
}

.cr-dep-adj {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 9.5px;
  font-weight: 800;
}

.cr-tiny-pm {
  padding: 2px 5px;
  border-radius: 5px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  font-size: 9px;
  font-weight: 800;
}

.cr-auto-hint {
  font-size: 8.8px;
  color: #64748b;
  margin-left: auto;
}

.cr-slider-row {
  margin-bottom: 7px;
}

.cr-sl-head {
  display: flex;
  justify-content: space-between;
  font-size: 9.8px;
  font-weight: 700;
  color: #334155;
  margin-bottom: 2px;
}

.cr-slider-row input[type="range"] {
  width: 100%;
  margin: 0;
}

.cr-val-box {
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 10px;
  font-weight: 800;
}

.cr-val-box.ok {
  background: #ecfdf5;
  border: 1.5px solid #6ee7b7;
  color: #065f46;
}

.cr-val-box.ng {
  background: #fef2f2;
  border: 1.5px solid #fca5a5;
  color: #991b1b;
}

.cr-val-box ul {
  margin: 4px 0 0;
  padding-left: 16px;
  font-weight: 700;
  line-height: 1.45;
}

.drafts-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.draft-slot-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 8px;
  border-radius: 9px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
}

.draft-slot-info {
  min-width: 0;
  flex: 1;
}

.draft-slot-title {
  font-size: 10.8px;
  font-weight: 800;
  color: #0f172a;
}

.draft-slot-sub {
  font-size: 8.8px;
  color: #64748b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast-banner {
  position: fixed;
  bottom: 64px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92);
  color: #ffffff;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 800;
  z-index: 90;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.35);
}

/* ==================== v.0.15 折りたたみ / PCモード / トップ画面 / About ==================== */
.collapse-head-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 1.5px 2px 3px;
}

.collapse-head-bar.light {
  padding: 0 0 3px;
}

.collapse-summary {
  font-size: 9.2px;
  font-weight: 800;
  color: #cbd5e1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.collapse-summary.dark {
  color: #475569;
}

.collapse-toggle-btn {
  padding: 1.5px 7px;
  border-radius: 999px;
  font-size: 8.8px;
  font-weight: 800;
  background: rgba(51, 65, 85, 0.85);
  border: 1px solid rgba(100, 116, 139, 0.6);
  color: #e2e8f0;
  white-space: nowrap;
  flex-shrink: 0;
}

.collapse-toggle-btn:hover {
  background: rgba(71, 85, 105, 0.95);
}

.collapse-toggle-btn.light {
  background: #e2e8f0;
  border-color: #cbd5e1;
  color: #334155;
}

.collapse-toggle-btn.light:hover {
  background: #cbd5e1;
}

.routemap-bar-right {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.routemap-box.is-collapsed {
  padding-bottom: 3px;
}

.routemap-box.is-collapsed .routemap-bar {
  margin-bottom: 0;
}

.bottom-panel.is-collapsed {
  padding: 4px 9px;
}

.bottom-panel.is-collapsed .bottom-collapse-bar {
  padding-bottom: 0;
}

/* プレイワークスペース（スマホ縦 / PC左ダイヤ右コントロール） */
.play-workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#app-shell.pc-mode .play-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 316px;
  grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-areas:
    "top top"
    "diag filter"
    "diag bottom";
}

#app-shell.pc-mode .top-panel {
  grid-area: top;
}

#app-shell.pc-mode .main-area {
  display: contents;
}

#app-shell.pc-mode #diagram-wrap {
  grid-area: diag;
  min-height: 0;
  height: 100%;
}

#app-shell.pc-mode .filter-bar {
  grid-area: filter;
  flex-wrap: wrap;
  gap: 4px;
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

#app-shell.pc-mode .filter-pills {
  flex-wrap: wrap;
  overflow-x: visible;
}

#app-shell.pc-mode .bottom-panel {
  grid-area: bottom;
  border-top: none;
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 6px 10px 8px;
}

#app-shell.pc-mode .bottom-panel.is-collapsed {
  padding: 5px 10px;
}

#app-shell.pc-mode .train-chip {
  flex: 1 1 28%;
  max-width: none;
}

#app-shell.pc-mode .dep-info {
  width: 58px;
}

#app-shell.pc-mode .siding-row.cols-3 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

#app-shell.pc-mode .top-stage-grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

#app-shell.pc-mode .top-stage-grid.cols-6 {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

/* トップ画面（ダイヤグラムモチーフ・スマホ版スクロール無し最適化） */
.top-screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 7px 9px 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 5.5px;
  background-color: #f1f5f9;
  background-image:
    linear-gradient(to right, rgba(148, 163, 184, 0.11) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(148, 163, 184, 0.11) 1px, transparent 1px);
  background-size: 24px 24px;
}

.top-hero-card {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #0f172a 0%, #172554 62%, #1e293b 100%);
  color: #ffffff;
  border-radius: 13px;
  padding: 7px 9px;
  border: 1px solid rgba(56, 189, 248, 0.28);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.2);
}

.top-hero-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      152deg,
      transparent 0px,
      transparent 28px,
      rgba(56, 189, 248, 0.06) 28px,
      rgba(56, 189, 248, 0.06) 30px
    );
  pointer-events: none;
}

.top-hero-main {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.top-hero-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.top-diagram-emblem {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 10px;
  box-shadow: 0 3px 10px rgba(2, 132, 199, 0.32);
  display: flex;
  align-items: center;
  justify-content: center;
}

.top-diagram-icon {
  display: block;
  width: 44px;
  height: 44px;
  aspect-ratio: 1 / 1;
}

.top-hero-titles {
  min-width: 0;
}

.top-hero-title {
  font-size: 12.2px;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #f8fafc;
  white-space: nowrap;
}

.top-hero-sub {
  font-size: 9px;
  color: #cbd5e1;
  margin-top: 2px;
  white-space: nowrap;
}

.top-hero-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.top-hero-star {
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 9.6px;
  font-weight: 800;
  background: rgba(245, 158, 11, 0.22);
  border: 1px solid rgba(251, 191, 36, 0.55);
  color: #fde68a;
  white-space: nowrap;
}

.top-display-seg {
  display: inline-flex;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(100, 116, 139, 0.55);
  border-radius: 8px;
  padding: 1.5px;
  gap: 2px;
}

.top-disp-btn {
  padding: 2.5px 7px;
  border-radius: 6px;
  font-size: 9px;
  font-weight: 800;
  background: transparent;
  color: #cbd5e1;
  white-space: nowrap;
}

.top-disp-btn.active {
  background: #38bdf8;
  color: #0f172a;
  box-shadow: 0 1px 4px rgba(56, 189, 248, 0.45);
}

.top-stage-groups {
  display: flex;
  flex-direction: column;
  gap: 5.5px;
}

.top-cat-card {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid #cbd5e1;
  border-left: 4px solid #38bdf8;
  border-radius: 10px;
  padding: 5.5px 7px 6px;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.05);
}

.top-cat-card[data-cat="beginner"]     { border-left-color: #059669; }
.top-cat-card[data-cat="intermediate"] { border-left-color: #2563eb; }
.top-cat-card[data-cat="advanced"]     { border-left-color: #9333ea; }
.top-cat-card[data-cat="master"]       { border-left-color: #dc2626; }

.top-cat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.top-cat-name {
  font-size: 10.6px;
  font-weight: 900;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.top-cat-prog {
  font-size: 8.8px;
  font-weight: 800;
  padding: 1px 5.5px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.top-stage-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.top-stage-grid.cols-6 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.top-stage-btn {
  text-align: left;
  padding: 5px 5.5px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: linear-gradient(160deg, #ffffff 0%, #f1f5f9 100%);
  box-shadow: 0 2px 0 #cbd5e1, 0 2px 5px rgba(15, 23, 42, 0.05);
  display: flex;
  flex-direction: column;
  gap: 1.5px;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.top-stage-btn::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  background: linear-gradient(135deg, transparent 55%, rgba(56, 189, 248, 0.16) 55%);
  pointer-events: none;
}

.top-stage-btn:hover {
  border-color: #0284c7;
  background: linear-gradient(160deg, #ffffff 0%, #e0f2fe 100%);
  transform: translateY(-1px);
  box-shadow: 0 3px 0 #7dd3fc, 0 4px 8px rgba(2, 132, 199, 0.14);
}

.top-stage-btn.is-cleared {
  border-color: #34d399;
  background: linear-gradient(160deg, #ecfdf5 0%, #d1fae5 100%);
  box-shadow: 0 2px 0 #6ee7b7, 0 2px 5px rgba(5, 150, 105, 0.1);
}

.top-stage-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
}

.top-stage-name {
  font-size: 10.2px;
  font-weight: 900;
  color: #0f172a;
  white-space: nowrap;
}

.top-stage-stars {
  font-size: 8.2px;
  color: #94a3b8;
  flex-shrink: 0;
  letter-spacing: -0.6px;
}

.top-stage-stars.earned {
  color: #d97706;
}

.top-stage-desc {
  font-size: 8.5px;
  font-weight: 700;
  color: #475569;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-extra-stack {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.top-action-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6.5px 10px;
  border-radius: 10px;
  border: 1.5px solid #cbd5e1;
  background: #ffffff;
  text-align: left;
  box-shadow: 0 2px 0 rgba(15, 23, 42, 0.08), 0 3px 8px rgba(15, 23, 42, 0.05);
}

.top-action-card.create {
  border-color: #60a5fa;
  background: linear-gradient(135deg, #dbeafe 0%, #eff6ff 55%, #ffffff 100%);
}

.top-action-card.passphrase {
  border-color: #fbbf24;
  background: linear-gradient(135deg, #fef3c7 0%, #fffbeb 55%, #ffffff 100%);
}

.top-action-icon {
  font-size: 15px;
  flex-shrink: 0;
}

.top-action-body {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 7px;
  flex: 1;
  min-width: 0;
}

.top-action-title {
  font-size: 11px;
  font-weight: 900;
  color: #0f172a;
  white-space: nowrap;
}

.top-action-sub {
  font-size: 9px;
  font-weight: 700;
  color: #475569;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-action-arrow {
  font-size: 12px;
  font-weight: 900;
  color: #475569;
}

.top-about-btn {
  width: 100%;
  padding: 5.5px 10px;
  border-radius: 9px;
  border: 1px solid #cbd5e1;
  background: #e2e8f0;
  color: #1e293b;
  font-size: 9.8px;
  font-weight: 800;
  text-align: center;
}

.top-about-btn:hover {
  background: #cbd5e1;
}

/* UI設定モーダル */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.setting-label {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.setting-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--ink);
}

.setting-sub {
  font-size: 8.8px;
  font-weight: 700;
  color: var(--ink-muted);
}

.setting-seg {
  display: inline-flex;
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}

.setting-seg-btn {
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 9.8px;
  font-weight: 800;
  background: transparent;
  color: #475569;
  white-space: nowrap;
}

.setting-seg-btn.active {
  background: #0f172a;
  color: #ffffff;
}

.setting-toggle-btn {
  min-width: 64px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 10.2px;
  font-weight: 900;
  border: 1.5px solid #cbd5e1;
  background: #e2e8f0;
  color: #475569;
  flex-shrink: 0;
}

.setting-toggle-btn.on {
  background: #059669;
  border-color: #059669;
  color: #ffffff;
}

/* このゲームについてモーダル */
.about-meta-table {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--card);
  margin-bottom: 8px;
}

.about-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 10.5px;
}

.about-meta-row:last-child {
  border-bottom: none;
}

.about-meta-k {
  font-weight: 800;
  color: var(--ink-muted);
}

.about-meta-v {
  font-weight: 800;
  color: var(--ink);
  text-align: right;
}

.about-note-p {
  margin: 4px 0;
  font-size: 10.2px;
  line-height: 1.5;
  color: var(--ink-sub);
}

/* ==================== ダークモード (#app-shell.dark-mode) ==================== */
#app-shell.dark-mode {
  --surface: #0b1120;
  --card: #111827;
  --ink: #f1f5f9;
  --ink-sub: #cbd5e1;
  --ink-muted: #94a3b8;
  --border: #334155;
  background: #0b1120;
  color: #f1f5f9;
}

#app-shell.dark-mode .top-screen {
  background-color: #0b1120;
  background-image:
    linear-gradient(to right, rgba(56, 189, 248, 0.08) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(56, 189, 248, 0.08) 1px, transparent 1px);
}

#app-shell.dark-mode .top-cat-card {
  background: rgba(17, 24, 39, 0.94);
  border-color: #334155;
}

#app-shell.dark-mode .top-cat-prog {
  background: #1e293b;
  color: #cbd5e1;
  border-color: #334155;
}

#app-shell.dark-mode .top-stage-btn {
  background: linear-gradient(160deg, #1e293b 0%, #0f172a 100%);
  border-color: #334155;
  box-shadow: 0 2px 0 #020617, 0 2px 6px rgba(0, 0, 0, 0.35);
}

#app-shell.dark-mode .top-stage-btn:hover {
  border-color: #38bdf8;
  background: linear-gradient(160deg, #1e3a5f 0%, #0f172a 100%);
}

#app-shell.dark-mode .top-stage-btn.is-cleared {
  border-color: #10b981;
  background: linear-gradient(160deg, #064e3b 0%, #052e26 100%);
  box-shadow: 0 2px 0 #022c22;
}

#app-shell.dark-mode .top-stage-name { color: #f8fafc; }
#app-shell.dark-mode .top-stage-desc { color: #94a3b8; }

#app-shell.dark-mode .top-action-card {
  background: #111827;
  border-color: #334155;
}
#app-shell.dark-mode .top-action-card.create {
  border-color: #2563eb;
  background: linear-gradient(135deg, #172554 0%, #0f172a 100%);
}
#app-shell.dark-mode .top-action-card.passphrase {
  border-color: #d97706;
  background: linear-gradient(135deg, #451a03 0%, #0f172a 100%);
}
#app-shell.dark-mode .top-action-title { color: #f8fafc; }
#app-shell.dark-mode .top-action-sub,
#app-shell.dark-mode .top-action-arrow { color: #cbd5e1; }

#app-shell.dark-mode .top-about-btn {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}

#app-shell.dark-mode .cond-chip,
#app-shell.dark-mode .routemap-box,
#app-shell.dark-mode .siding-card,
#app-shell.dark-mode .none-box {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}

#app-shell.dark-mode .cond-chip.ok {
  background: rgba(6, 95, 70, 0.35);
  border-color: #059669;
  color: #6ee7b7;
}
#app-shell.dark-mode .cond-chip.ng {
  background: rgba(159, 18, 57, 0.35);
  border-color: #e11d48;
  color: #fda4af;
}
#app-shell.dark-mode .cond-chip.warn {
  background: rgba(146, 64, 14, 0.35);
  border-color: #d97706;
  color: #fcd34d;
}

#app-shell.dark-mode .filter-bar {
  background: #0f172a;
  border-color: #334155;
}

#app-shell.dark-mode .dir-seg,
#app-shell.dark-mode .setting-seg {
  background: #1e293b;
  border-color: #334155;
}
#app-shell.dark-mode .dir-btn,
#app-shell.dark-mode .setting-seg-btn { color: #94a3b8; }
#app-shell.dark-mode .dir-btn.active,
#app-shell.dark-mode .setting-seg-btn.active {
  background: #38bdf8;
  color: #0f172a;
}

#app-shell.dark-mode .filter-btn,
#app-shell.dark-mode .zoom-btn,
#app-shell.dark-mode .collapse-toggle-btn.light,
#app-shell.dark-mode .step-btn,
#app-shell.dark-mode .btn-sub,
#app-shell.dark-mode .siding-pm,
#app-shell.dark-mode .cr-mini-btn:not(.primary),
#app-shell.dark-mode .cr-seg-btn:not(.active),
#app-shell.dark-mode .cr-action-btn:not(.accent),
#app-shell.dark-mode .btn-modal-cancel {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}

#app-shell.dark-mode .filter-btn.active-all {
  background: #38bdf8;
  border-color: #38bdf8;
  color: #0f172a;
}

#app-shell.dark-mode #diagram-wrap,
#app-shell.dark-mode .main-area {
  background: #0f172a;
}

#app-shell.dark-mode .train-chip {
  background: #1e293b;
  border-color: #334155;
  color: #cbd5e1;
}
#app-shell.dark-mode .train-chip.selected {
  color: #0f172a;
}

#app-shell.dark-mode .collapse-summary.dark {
  color: #cbd5e1;
}

#app-shell.dark-mode .siding-mid-lbl {
  color: #fbbf24;
}

#app-shell.dark-mode .clock-badge {
  background: #334155;
  color: #e2e8f0;
}
#app-shell.dark-mode .clock-badge.running {
  background: #7f1d1d;
  color: #fecaca;
}

#app-shell.dark-mode .modal-card,
#app-shell.dark-mode .diag-window,
#app-shell.dark-mode .diag-win-body,
#app-shell.dark-mode .diag-item,
#app-shell.dark-mode .draft-slot-row,
#app-shell.dark-mode .cr-card,
#app-shell.dark-mode .creator-shell {
  background: #111827;
  border-color: #334155;
  color: #f1f5f9;
}

#app-shell.dark-mode .modal-body,
#app-shell.dark-mode .modal-foot {
  background: #111827;
  border-color: #334155;
}

#app-shell.dark-mode .rule-item {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}
#app-shell.dark-mode .rule-item-title {
  color: #f8fafc;
}
#app-shell.dark-mode .cr-textarea,
#app-shell.dark-mode .cr-input,
#app-shell.dark-mode .cr-select {
  background: #0f172a;
  color: #f8fafc;
  border-color: #334155;
}

#app-shell.dark-mode .diag-item-text,
#app-shell.dark-mode .clear-title,
#app-shell.dark-mode .creator-title-text,
#app-shell.dark-mode .cr-card-title,
#app-shell.dark-mode .cr-inline-between,
#app-shell.dark-mode .cr-tr-id,
#app-shell.dark-mode .draft-slot-title {
  color: #f8fafc;
}

#app-shell.dark-mode .diag-item-sub,
#app-shell.dark-mode .diag-group-title,
#app-shell.dark-mode .clear-desc,
#app-shell.dark-mode .metric-lbl,
#app-shell.dark-mode .cr-field-lbl,
#app-shell.dark-mode .cr-sl-head,
#app-shell.dark-mode .cr-check-row,
#app-shell.dark-mode .cr-help-note,
#app-shell.dark-mode .draft-slot-sub {
  color: #cbd5e1;
}

#app-shell.dark-mode .clear-metrics,
#app-shell.dark-mode .creator-topbar,
#app-shell.dark-mode .creator-footer,
#app-shell.dark-mode .cr-train-card,
#app-shell.dark-mode .cr-route-map,
#app-shell.dark-mode .empty-filter-msg {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}

#app-shell.dark-mode .creator-stepper {
  background: #0f172a;
  border-color: #334155;
}

#app-shell.dark-mode .cr-step-btn:not(.active):not(.blocked) {
  background: #1e293b;
  color: #cbd5e1;
}

#app-shell.dark-mode .cr-mini-sel,
#app-shell.dark-mode .cr-tiny-pm {
  background: #0f172a;
  border-color: #475569;
  color: #f8fafc;
}

#app-shell.dark-mode .rule-item.rose {
  background: rgba(159, 18, 57, 0.28);
  border-color: #e11d48;
}

#app-shell.dark-mode .rule-danger-text {
  color: #fecdd3;
}

#app-shell.dark-mode .rule-item.amber {
  background: rgba(146, 64, 14, 0.28);
  border-color: #d97706;
}

#app-shell.dark-mode .rule-item.green {
  background: rgba(6, 95, 70, 0.30);
  border-color: #059669;
}

.modal-note-text {
  font-size: 10px;
  color: var(--ink-muted);
  line-height: 1.45;
}

#app-shell.dark-mode .cr-node {
  background: #1e293b;
  border-color: #475569;
  color: #f1f5f9;
}
#app-shell.dark-mode .cr-node.equip-pass {
  background: rgba(180, 83, 9, 0.35);
  border-color: #f59e0b;
  color: #fde68a;
}
#app-shell.dark-mode .cr-node.equip-freight {
  background: #334155;
  border-color: #94a3b8;
  color: #e2e8f0;
}
#app-shell.dark-mode .cr-node.equip-shared {
  background: rgba(109, 40, 217, 0.35);
  border-color: #a78bfa;
  color: #ddd6fe;
}
#app-shell.dark-mode .cr-node.is-end {
  background: #020617;
  border-color: #475569;
  color: #f8fafc;
}
#app-shell.dark-mode .cr-seg-link {
  background: #334155;
  color: #e2e8f0;
}
#app-shell.dark-mode .cr-seg-link.single {
  background: rgba(180, 83, 9, 0.45);
  border-color: #f59e0b;
  color: #fde68a;
}
#app-shell.dark-mode .info-banner.express-note,
#app-shell.dark-mode .info-banner.locked-box {
  background: rgba(159, 18, 57, 0.28);
  border-color: #e11d48;
  color: #fecdd3;
}

#app-shell.dark-mode .siding-card.freight-disabled {
  background: #0f172a;
  border-color: #334155;
}

#app-shell.dark-mode .siding-card.freight-disabled .siding-mid-lbl,
#app-shell.dark-mode .siding-card.freight-disabled .siding-mid-val {
  color: #94a3b8;
}
