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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: #1a1a1a;
}

body {
  display: flex;
  flex-direction: column;
  background: #f5f5f5;
}

/* ── Video ── */
.video-wrapper {
  position: relative;
  width: 100%;
  margin-top: 8px;
  background: #000;
}

#video {
  display: block;
  width: 100%;
}

/* コントロール: 動画の上に重ねて下部固定 */
.vc {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.75));
  padding: 24px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 20;
  pointer-events: none;
}

.video-wrapper:hover .vc {
  opacity: 1;
  pointer-events: auto;
}

.vc-seek {
  width: 100%;
  height: 4px;
  accent-color: #2563eb;
  cursor: pointer;
  display: block;
}

.vc-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.vc-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  color: #eee;
  font-size: 17px;
  cursor: pointer;
  padding: 0 3px;
  line-height: 1;
}

.vc-time {
  flex: 1;
  color: #aaa;
  font-size: 13px;
  white-space: nowrap;
}

.vc-vol {
  width: 73px;
  height: 4px;
  accent-color: #aaa;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Header ── */
#header {
  flex-shrink: 0;
  height: 82px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 30px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

#logo {
  width: 130px;
  height: 60px;
  object-fit: contain;
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
}

.header-right {
  display: flex;
  align-items: center;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #9e9e9e;
  background: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  color: #555;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.icon-btn:hover {
  background: #f0f0f0;
}

/* ── Main ── */
#main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Left pane ── */
#left-pane {
  width: 340px;
  margin-left: 30px;
  flex-shrink: 0;
  background: #f5f5f5;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.company-info {
  padding: 14px 16px 10px;
  border-bottom: 1px solid #e0e0e0;
}

.company-name {
  font-size: 12px;
  color: #666;
  margin-bottom: 3px;
}

.presentation-title {
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
  line-height: 1.4;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid #e0e0e0;
}

.ctrl-btn {
  flex: 1;
  height: 30px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}

.ctrl-btn:hover {
  background: #eee;
}

.play-row {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid #e0e0e0;
}

.play-btn {
  flex: 1;
  height: 32px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s;
}

.play-btn:hover {
  background: #eee;
}

.play-btn.primary {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

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

.play-btn.primary.playing {
  background: #dc2626;
  border-color: #dc2626;
}

/* ── TOC ── */
#toc {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.toc-section {
  margin-bottom: 2px;
}

.toc-section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #333;
  user-select: none;
  transition: background 0.1s;
}

.toc-section-header:hover {
  background: #ebebeb;
}

.toc-section.active > .toc-section-header {
  background: #dbeafe;
  color: #1d4ed8;
}

.toc-arrow {
  font-size: 10px;
  transition: transform 0.2s;
  flex-shrink: 0;
  /* 折りたたみ専用のボタン。見た目は変えずに押せる範囲だけ広げる */
  padding: 6px;
  margin: -6px;
}

.toc-section.collapsed .toc-arrow {
  transform: rotate(-90deg);
}

.toc-section.collapsed .toc-items {
  display: none;
}

.toc-items {
  list-style: none;
}

.toc-item {
  display: flex;
  align-items: center;
  padding: 6px 12px 6px 28px;
  cursor: pointer;
  font-size: 12px;
  color: #444;
  border-left: 3px solid transparent;
  transition: background 0.1s, border-color 0.1s;
  line-height: 1.4;
}

.toc-item:hover {
  background: #e8e8e8;
}

.toc-item.active {
  border-left-color: #2563eb;
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 500;
}

/* ── Right pane ── */
#right-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #f0f0f0;
  overflow: hidden;
}

#slide-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  padding: 0 30px;
}

#slide-canvas {
  display: block;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

#slide-loading {
  position: absolute;
  color: #aaa;
  font-size: 14px;
  display: none;
}

#slide-loading.visible {
  display: block;
}

/* ── Slide controls ── */
#slide-controls {
  flex-shrink: 0;
  height: 60px;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 30px;
  gap: 8px;
}

.page-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

#page-info {
  color: #555;
  font-size: 13px;
  min-width: 60px;
  text-align: center;
}

.slide-btn {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  position: relative;
  padding: 0 20px;
  height: 38px;
  text-align: center;
  font-size: 0.8rem;
  color: #fff;
  background: rgb(16, 45, 141);
  border: none;
  border-radius: 4px;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.3s;
}

.slide-btn:hover {
  background: rgb(10, 30, 100);
  color: #fff;
}

.slide-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.slide-btn.active {
  background: rgb(16, 45, 141);
  color: #fff;
}

/* ── Footer ── */
#footer {
  flex-shrink: 0;
  height: 52px;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 45px;
  font-size: 12px;
  color: #666;
}

/* コピーライトを中央、運営を右に置く（左列は空き） */
.footer-center {
  grid-column: 2;
  text-align: center;
  white-space: nowrap;
}
.footer-right {
  grid-column: 3;
  text-align: right;
}

/* ── Mobile menu button (hidden on desktop) ── */
#btn-menu { display: none; }

/* ── TOC backdrop ── */
#toc-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 399;
}

#toc-backdrop.visible { display: block; }

/* ── Mobile layout ── */
@media (max-width: 768px) {
  body { padding: 0; }

  #header {
    height: 56px;
    padding: 0 16px;
  }

  #btn-menu {
    display: flex;
    width: 40px;
    height: 40px;
    font-size: 22px;
  }

  /* 並び順: スライド → 動画・操作ボタン → ページ送り（#right-pane の枠を外して並べ替える） */
  #main {
    flex-direction: column;
    overflow-y: auto;
    background: #fff;
  }
  #right-pane { display: contents; }
  #slide-container { order: 1; }
  #left-pane       { order: 2; }
  #slide-controls  { order: 3; }

  #left-pane {
    width: 100%;
    height: auto;
    margin: 12px 0 0;
    padding: 12px 16px;
    flex-shrink: 0;
    overflow: visible;
    border-right: none;
  }

  .company-info {
    padding: 0;
    border-bottom: none;
  }
  .video-wrapper { margin-top: 0; }

  #left-pane #toc { display: none; }

  /* 操作ボタン4つを1列に（-10秒 / 速度 / +10秒 / 最初から再生） */
  #left-pane:not(.open) {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px 6px;
  }
  #left-pane:not(.open) .company-info { width: 100%; }
  #left-pane:not(.open) .control-row,
  #left-pane:not(.open) .play-row { display: contents; }
  #left-pane.open .control-row,
  #left-pane.open .play-row { display: none; }

  #left-pane .ctrl-btn,
  #left-pane .play-btn {
    flex: 1;
    min-width: 0;
    height: 34px;
    padding: 0 4px;
    font-size: 13px;
    white-space: nowrap;
  }

  /* ドロワーが開いた状態 */
  #left-pane.open {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: auto;
    width: 85%;
    height: 100%;
    overflow-y: auto;
    z-index: 400;
    border-right: 1px solid #e0e0e0;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.2);
  }

  #left-pane.open .video-wrapper { display: none; }

  #left-pane.open #toc { display: block; }

  /* ダウンロード / ページ送り / 非同期モード */
  #slide-controls {
    height: auto;
    /* app.js の syncControlsPadding() が PC 用に上下0のインライン padding を入れるので上書きする */
    padding: 12px 8px !important;
    gap: 8px 4px;
    flex-wrap: wrap;  /* 収まらない狭い画面では2段にする */
  }
  #slide-controls .slide-btn {
    height: 30px;
    padding: 0 6px;
    font-size: 10px;
  }
  .page-nav { gap: 4px; }
  #page-info { min-width: 0; font-size: 12px; white-space: nowrap; }
  body.stage-mode #page-info { font-size: 10px; }  /* 「オープニング」表記は長いので小さく */

  /* 前後ページは小さい矢印ボタン（文言は隠して矢印だけ出す） */
  #slide-controls #btn-prev,
  #slide-controls #btn-next {
    width: 28px;
    height: 24px;
    padding: 0;
    justify-content: center;
    font-size: 0;
    color: #333;
    background: #fff;
    border: 1px solid #ccc;
  }
  #btn-prev::before { content: '◀'; font-size: 10px; }
  #btn-next::before { content: '▶'; font-size: 10px; }

  #footer {
    height: auto;
    padding: 8px 16px;
    font-size: 11px;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .footer-center { white-space: normal; }
  .footer-right { text-align: center; }

  /* スライド・OP/ED は横幅いっぱい。高さはスライドの比率（16:9）に合わせて余白を出さない */
  #slide-container {
    flex: none;
    aspect-ratio: 16 / 9;
    padding: 0;
  }
  #slide-container #stage { padding: 0; }  /* #stage の定義が後ろにあるため詳細度を上げる */
}

/* ── Start overlay ── */
.play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  cursor: pointer;
}

.start-play-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  padding-left: 5px;
  color: #fff;
  transition: transform 0.15s, background 0.15s, opacity 0.3s;
}

.play-overlay:hover .start-play-btn {
  transform: scale(1.12);
  background: rgba(29, 78, 216, 0.95);
}

.play-overlay.playing .start-play-btn {
  opacity: 0;
}

.play-overlay.playing:hover .start-play-btn {
  background: rgba(0, 0, 0, 0.3);
  opacity: 0.5;
}

/* ── OP / ED ステージ（スライド領域に動画を表示） ── */
#stage {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 8px 38px;
  z-index: 5;
}
body.stage-mode #stage {
  display: flex;
}
/* サイズは fitStage() で動画の縦横比に合わせて設定 */
#stage-frame {
  position: relative;
  background: #000;
}
#stage-video {
  display: block;
  width: 100%;
  height: 100%;
}
#stage-frame:hover .vc {
  opacity: 1;
  pointer-events: auto;
}

/* OP / ED 中は左上の動画枠にタイトルを表示 */
#title-card {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background: #fff;
  color: rgb(16, 45, 141);
  text-align: center;
  z-index: 30;
}
body.stage-mode #title-card {
  display: flex;
}
.title-card-label {
  font-size: 11px;
  letter-spacing: 0.1em;
  opacity: 0.75;
}
.title-card-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
}

/* ED は小さい枠で本編を流したまま、大きい枠にタイトルを出す（app.js の placeTitleCard） */
body.stage-ed #stage-frame { display: none; }
body.stage-ed #title-card {
  margin: auto;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}
body.stage-ed #slide-canvas { visibility: hidden; }
body.stage-ed .title-card-label { font-size: 14px; }
body.stage-ed .title-card-title { font-size: 28px; }
@media (max-width: 768px) {
  body.stage-ed .title-card-label { font-size: 11px; }
  body.stage-ed .title-card-title { font-size: 18px; }
}
