/* ==========================================================================
   反転フラップ式案内表示機（パタパタ発車標）スタイルシート
   ========================================================================== */

:root {
  --bg-dark: #12151b;
  --chassis-dark: #1c202a;
  --chassis-border: #2e3444;
  --chassis-metal: #282d3b;
  --chassis-inner: #0d0f14;
  --flap-bg: #11141a;
  --flap-text: #f0f3f8;
  --flap-border: #06070a;
  --flap-shadow: rgba(0, 0, 0, 0.7);
  --accent-gold: #f59e0b;
  --lamp-green: #10b981;
  --lamp-red: #ef4444;
  --screw-color: #586178;

  /* 鉄道種別カラー */
  --type-tokkyu-bg: #dc2626;      /* 特急: 赤 */
  --type-tokkyu-text: #ffffff;
  --type-kaitoku-bg: #991b1b;     /* 快特: 深紅 */
  --type-kaitoku-text: #ffffff;
  --type-shinkaisoku-bg: #2563eb; /* 新快速: 青 */
  --type-shinkaisoku-text: #ffffff;
  --type-kyuko-bg: #ea580c;        /* 急行: 橙 */
  --type-kyuko-text: #ffffff;
  --type-kaisoku-bg: #0284c7;      /* 快速: 水色/青 */
  --type-kaisoku-text: #ffffff;
  --type-junkyu-bg: #16a34a;      /* 準急: 緑 */
  --type-junkyu-text: #ffffff;
  --type-futsu-bg: #1e2430;       /* 各停/普通: 黒紺 */
  --type-futsu-text: #f1f5f9;
  --type-kaisou-bg: #ffffff;      /* 回送: 白地に赤文字 */
  --type-kaisou-text: #dc2626;
  --type-rinji-bg: #7c3aed;       /* 臨時: 紫 */
  --type-rinji-text: #ffffff;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'M PLUS 1p', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(ellipse at 50% 0%, #1e2638 0%, transparent 70%),
    linear-gradient(to bottom, #12151b 0%, #0a0c10 100%);
  color: #e2e8f0;
  min-height: 100vh;
  padding: 1.5rem 1rem 4rem;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  width: 100%;
  max-width: 1200px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* --------------------------------------------------------------------------
   ヘッダー
   -------------------------------------------------------------------------- */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.5rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.2s ease;
}

.back-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateX(-2px);
}

.title-group {
  text-align: center;
}

.badge-railway {
  display: inline-block;
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-gold);
  border: 1px solid rgba(245, 158, 11, 0.35);
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 4px;
}

.page-title {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #f8fafc;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.4rem;
}

.page-title span {
  font-size: 1rem;
  color: #94a3b8;
  font-weight: 500;
}

.header-clock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  background: #090c12;
  padding: 0.35rem 0.85rem;
  border-radius: 6px;
  border: 1px solid #1e293b;
}

.clock-label {
  font-size: 0.65rem;
  color: #64748b;
  letter-spacing: 0.05em;
}

.clock-val {
  font-family: 'Share Tech Mono', monospace;
  font-size: 1.15rem;
  font-weight: 700;
  color: #38bdf8;
  letter-spacing: 0.05em;
}

/* --------------------------------------------------------------------------
   発車標 筐体 (Chassis) デザイン
   -------------------------------------------------------------------------- */
.display-chassis-outer {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 10px;
}

/* 吊り下げステー */
.hanger-mounts {
  width: 75%;
  height: 24px;
  display: flex;
  justify-content: space-around;
  position: relative;
}

.hanger-pole {
  width: 18px;
  height: 100%;
  background: linear-gradient(90deg, #475569 0%, #94a3b8 40%, #334155 100%);
  border-radius: 2px 2px 0 0;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5), 0 2px 4px rgba(0,0,0,0.4);
}

.display-board {
  width: 100%;
  background: linear-gradient(180deg, #242a38 0%, #151821 100%);
  border: 4px solid #333d4e;
  border-radius: 12px;
  box-shadow: 
    0 15px 35px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(0, 0, 0, 0.8),
    inset 0 2px 1px rgba(255, 255, 255, 0.12),
    inset 0 -2px 4px rgba(0, 0, 0, 0.6);
  padding: 14px;
  position: relative;
  overflow-x: auto;
}

/* 筐体上部看板 */
.board-top-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(90deg, #090b10 0%, #121620 50%, #090b10 100%);
  border: 1px solid #2a3346;
  border-radius: 6px;
  padding: 8px 16px;
  margin-bottom: 10px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.8);
}

.station-mark {
  font-size: 0.8rem;
  font-weight: 700;
  color: #94a3b8;
  letter-spacing: 0.1em;
  background: #1e2638;
  padding: 3px 8px;
  border-radius: 3px;
  border: 1px solid #334155;
}

.board-caption {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.main-caption {
  font-size: 1.35rem;
  font-weight: 900;
  color: #f8fafc;
  letter-spacing: 0.35em;
  text-indent: 0.35em;
  text-shadow: 0 0 10px rgba(255,255,255,0.3);
}

.en-caption {
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.7rem;
  font-weight: 700;
  color: #94a3b8;
  letter-spacing: 0.25em;
}

.board-status-lamp {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #0d1117;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid #222b3d;
}

.lamp-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #334155;
  transition: all 0.3s ease;
}

.lamp-dot.active {
  background: var(--lamp-green);
  box-shadow: 0 0 10px var(--lamp-green);
}

.lamp-dot.flapping {
  background: var(--accent-gold);
  box-shadow: 0 0 10px var(--accent-gold);
  animation: pulse-lamp 0.3s infinite alternate;
}

@keyframes pulse-lamp {
  from { opacity: 0.6; }
  to { opacity: 1; }
}

.lamp-text {
  font-size: 0.7rem;
  font-weight: 700;
  color: #94a3b8;
  letter-spacing: 0.05em;
}

/* カラム見出し */
.board-columns-header {
  display: grid;
  grid-template-columns: 70px 145px 125px 230px 90px 1fr;
  gap: 8px;
  background: #171d27;
  padding: 6px 10px;
  border-radius: 4px;
  margin-bottom: 8px;
  border: 1px solid #252e3e;
}

.col-head {
  color: #cbd5e1;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.15;
}

.col-head small {
  display: block;
  font-size: 0.65rem;
  font-weight: 500;
  color: #64748b;
  font-family: 'Share Tech Mono', sans-serif;
}

/* --------------------------------------------------------------------------
   発車標の各行 (Row)
   -------------------------------------------------------------------------- */
.board-rows-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #090c12;
  padding: 10px;
  border-radius: 6px;
  border: 2px solid #1a2230;
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.9);
}

.board-row {
  display: grid;
  grid-template-columns: 70px 145px 125px 230px 90px 1fr;
  gap: 8px;
  align-items: center;
  background: #131720;
  padding: 7px 8px;
  border-radius: 5px;
  border: 1px solid #1f2737;
  min-width: 880px;
}

/* 順序タグ */
.cell-order {
  display: flex;
  justify-content: center;
  align-items: center;
}

.order-tag {
  font-size: 0.9rem;
  font-weight: 800;
  padding: 6px 10px;
  border-radius: 4px;
  letter-spacing: 0.05em;
  text-align: center;
  width: 100%;
}

.tag-first {
  background: linear-gradient(135deg, #f59e0b 0%, #b45309 100%);
  color: #000;
  font-weight: 900;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
}

.tag-second {
  background: #334155;
  color: #f1f5f9;
  border: 1px solid #475569;
}

.tag-third {
  background: #1e293b;
  color: #94a3b8;
  border: 1px solid #334155;
}

/* --------------------------------------------------------------------------
   フラップセル共通 (3D Split Flap Mechanics)
   -------------------------------------------------------------------------- */
.flap-cell {
  position: relative;
  height: 58px;
  background: var(--flap-bg);
  border-radius: 5px;
  border: 2px solid #050608;
  perspective: 700px; /* 3D回転パースペクティブ */
  user-select: none;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.6);
}

/* 上下プレート共通スタイル */
.flap-card {
  position: absolute;
  left: 0;
  width: 100%;
  height: 50%;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #131722;
  box-shadow: inset 0 0 3px rgba(0,0,0,0.8);
}

/* 上段カード */
.flap-card.card-top {
  top: 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.95);
  border-radius: 4px 4px 0 0;
  align-items: flex-start;
}

/* 下段カード */
.flap-card.card-bottom {
  bottom: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0 0 4px 4px;
  align-items: flex-start;
}

/* めくれる動的リーフ (葉 / flap-leaf) */
.flap-leaf {
  position: absolute;
  left: 0;
  width: 100%;
  height: 50%;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  z-index: 5;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* 上から倒れ落ちるリーフ（手前下向きに回転） */
.flap-leaf.leaf-front {
  top: 0;
  transform-origin: bottom center;
  border-bottom: 1px solid rgba(0, 0, 0, 0.95);
  border-radius: 4px 4px 0 0;
}

/* 下で受け止めるリーフ（裏面から倒れてくる） */
.flap-leaf.leaf-back {
  bottom: 0;
  transform-origin: top center;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0 0 4px 4px;
  transform: rotateX(180deg);
}

/* 中央のスリットバー（機械的スリット） */
.flap-cell::after {
  content: "";
  position: absolute;
  top: calc(50% - 1px);
  left: 0;
  width: 100%;
  height: 2px;
  background: #020305;
  box-shadow: 0 1px 1px rgba(255, 255, 255, 0.08);
  z-index: 10;
  pointer-events: none;
}

/* 左右の軸受ヒンジ金具 */
.flap-cell::before {
  content: "";
  position: absolute;
  top: calc(50% - 5px);
  left: 0;
  right: 0;
  height: 10px;
  background: 
    radial-gradient(circle at 4px center, #475569 2px, transparent 3px),
    radial-gradient(circle at calc(100% - 4px) center, #475569 2px, transparent 3px);
  z-index: 12;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   フラップ内のコンテンツ表現（文字・デザイン）
   -------------------------------------------------------------------------- */
.flap-content {
  width: 100%;
  height: 58px; /* フラップ全体の高さと完全一致 */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  box-sizing: border-box;
  flex-shrink: 0;
}

/* 上カード・上リーフ内の位置調整（上半分をそのままクリップ） */
.card-top .flap-content,
.leaf-front .flap-content {
  transform: translateY(0);
}

/* 下カード・下リーフ内の位置調整（29px持ち上げて下半分を表示） */
.card-bottom .flap-content,
.leaf-back .flap-content {
  transform: translateY(-29px);
}

/* 種別プレートスタイル */
.type-badge {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-weight: 900;
  letter-spacing: 0.15em;
  padding: 0 4px;
}

.type-main {
  font-size: 1.25rem;
  line-height: 1.1;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.type-en {
  font-family: 'Share Tech Mono', sans-serif;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  opacity: 0.9;
}

/* 種別カラークラス */
.type-tokkyu { background: var(--type-tokkyu-bg); color: var(--type-tokkyu-text); }
.type-kaitoku { background: var(--type-kaitoku-bg); color: var(--type-kaitoku-text); }
.type-shinkaisoku { background: var(--type-shinkaisoku-bg); color: var(--type-shinkaisoku-text); }
.type-kyuko { background: var(--type-kyuko-bg); color: var(--type-kyuko-text); }
.type-kaisoku { background: var(--type-kaisoku-bg); color: var(--type-kaisoku-text); }
.type-junkyu { background: var(--type-junkyu-bg); color: var(--type-junkyu-text); }
.type-futsu { background: var(--type-futsu-bg); color: var(--type-futsu-text); }
.type-kaisou { background: var(--type-kaisou-bg); color: var(--type-kaisou-text); }
.type-rinji { background: var(--type-rinji-bg); color: var(--type-rinji-text); }

/* 時刻表示（デジタル/フリップ時計風） */
.time-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  gap: 2px;
}

.time-num-cell {
  width: 48px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Teko', 'Share Tech Mono', sans-serif;
  font-size: 2.2rem;
  font-weight: 700;
  color: #fffae8;
  letter-spacing: 0.04em;
  background: #10141d;
}

.time-colon {
  font-family: 'Teko', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent-gold);
  margin-top: -4px;
}

/* 行先表示 */
.dest-box {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #0f131a;
  padding: 0 8px;
}

.dest-main {
  font-size: 1.35rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: 0.18em;
  line-height: 1.1;
  text-shadow: 0 2px 4px rgba(0,0,0,0.6);
}

.dest-en {
  font-family: 'Share Tech Mono', sans-serif;
  font-size: 0.65rem;
  color: #94a3b8;
  letter-spacing: 0.08em;
  font-weight: 600;
}

/* のりば番号 */
.track-box {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: #0d1017;
}

.track-num {
  font-family: 'Teko', 'Share Tech Mono', sans-serif;
  font-size: 2.2rem;
  font-weight: 700;
  color: #38bdf8;
  line-height: 1;
}

.track-kanji {
  font-size: 0.8rem;
  font-weight: 700;
  color: #94a3b8;
  margin-top: 6px;
}

/* 記事・停車駅 */
.stops-box {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 12px;
  background: #0e121a;
  font-size: 0.88rem;
  font-weight: 600;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stops-cars-badge {
  background: #2563eb;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  margin-right: 8px;
  letter-spacing: 0.05em;
}

/* 筐体下部 */
.board-bottom-rim {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px 2px;
  border-top: 1px solid #232b3a;
  margin-top: 10px;
}

.screw-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle, #94a3b8 20%, #475569 80%);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.9), 0 1px 1px rgba(255,255,255,0.1);
  position: relative;
}

.screw-dot::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 1px;
  right: 1px;
  height: 1.5px;
  background: #1e293b;
}

.spec-label {
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.65rem;
  color: #475569;
  letter-spacing: 0.15em;
}

/* --------------------------------------------------------------------------
   コントロールパネル
   -------------------------------------------------------------------------- */
.control-panel {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  background: #151a24;
  border: 1px solid #283144;
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: #cbd5e1;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid #242c3e;
}

.section-title.clickable {
  cursor: pointer;
  user-select: none;
}

.section-title.clickable:hover {
  color: #fff;
}

.sec-icon {
  font-size: 1.1rem;
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.ctrl-btn {
  background: #1e2637;
  color: #cbd5e1;
  border: 1px solid #334155;
  padding: 0.55rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.ctrl-btn:hover {
  background: #2b354c;
  color: #fff;
  border-color: #475569;
}

.ctrl-btn.active {
  background: #0284c7;
  color: #fff;
  border-color: #38bdf8;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.35);
}

.action-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-top: 0.4rem;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: inherit;
}

.action-btn:active {
  transform: scale(0.98);
}

.btn-depart {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #000;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.btn-depart:hover {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.45);
}

.btn-shuffle {
  background: #334155;
  color: #f1f5f9;
  border: 1px solid #475569;
}

.btn-shuffle:hover {
  background: #475569;
}

.btn-autodemo {
  background: #1e293b;
  color: #94a3b8;
  border: 1px solid #334155;
}

.btn-autodemo.running {
  background: #15803d;
  color: #fff;
  border-color: #22c55e;
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.35);
}

/* 設定グリッド */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.setting-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #94a3b8;
}

.sound-ctrl-box {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.sound-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #1e293b;
  border: 1px solid #334155;
  color: #94a3b8;
  padding: 0.45rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
}

.sound-toggle.active {
  background: #0284c7;
  color: #fff;
  border-color: #38bdf8;
}

.volume-slider-box {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
}

.vol-label {
  font-size: 0.75rem;
  color: #64748b;
}

input[type="range"] {
  flex: 1;
  accent-color: #38bdf8;
  cursor: pointer;
}

.ctrl-select {
  background: #0f131a;
  border: 1px solid #2a3447;
  color: #e2e8f0;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  outline: none;
  font-family: inherit;
  cursor: pointer;
}

.ctrl-select:focus {
  border-color: #38bdf8;
}

/* カスタム編集アコーディオン */
.custom-editor {
  background: #11151f;
  border-radius: 6px;
  padding: 0.75rem;
  border: 1px solid #222a3a;
}

.editor-body {
  padding-top: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.editor-note {
  font-size: 0.8rem;
  color: #94a3b8;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.6rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.form-group label {
  font-size: 0.75rem;
  color: #94a3b8;
}

.form-submit {
  margin-top: 0.4rem;
}

.btn-primary {
  background: #2563eb;
  color: #fff;
  border-color: #3b82f6;
  width: 100%;
  padding: 0.65rem;
}

.btn-primary:hover {
  background: #1d4ed8;
}

/* レスポンシブ対応 */
@media (max-width: 920px) {
  .app-header {
    flex-wrap: wrap;
    gap: 0.8rem;
  }
  .display-board {
    padding: 8px;
  }
}
