* {
  box-sizing: border-box;
  user-select: none;
}

body {
  margin: 0;
  padding: 0;
  background-color: #121214;
  color: #e0e0e0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;   
  box-sizing: border-box;
  padding: 12px 20px;
  background-color: #1e1e1e;
  border-bottom: 1px solid #333;
}

.notice-banner {
  background-color: #2a2d32;
  border-left: 4px solid #00d2ff;
  padding: 8px 14px;
  border-radius: 4px;
  max-width: 550px;
  
  margin-left: auto;       
  text-align: left;      
}

.notice-title {
  font-size: 13px;
  font-weight: bold;
  color: #00d2ff;
  margin-bottom: 2px;
}

.notice-text {
  font-size: 12px;
  color: #ccc;
  margin: 0;
  line-height: 1.4;
}

.notice-text span {
  font-size: 11px;
  color: #aaa;
}

header h1 {
  font-size: 16px;
  margin: 0;
  color: #00d2ff;
}

.app-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top-panel {
  flex: 1;
  display: flex;
  background-color: #18181c;
  min-height: 250px;
}

.preview-section {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background-color: #0d0d0f;
  position: relative;
}

.canvas-container {
  position: relative;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
  border-radius: 4px;
  overflow: hidden;
  background: #000;
}

canvas {
  display: block;
  max-width: 100%;
  max-height: 380px;
  object-fit: contain;
  cursor: move;
}

.tools-section {
  width: 340px;
  background-color: #1e1e24;
  border-left: 1px solid #2d2d32;
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
  overflow-y: auto;
}

.panel-title {
  font-size: 12px;
  font-weight: bold;
  color: #aaa;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.tool-card {
  background: #26262e;
  border-radius: 6px;
  padding: 10px;
  border: 1px solid #33333d;
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}

.slider-group label {
  font-size: 11px;
  color: #bbb;
}

input[type="range"] {
  width: 100%;
  accent-color: #0088ff;
  cursor: pointer;
}

.btn-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

button {
  background-color: #32323d;
  color: #fff;
  border: 1px solid #444452;
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

button:hover {
  background-color: #3d3d4a;
  border-color: #555566;
}

button.primary {
  background-color: #0088ff;
  border-color: #0077ee;
}

button.danger {
  background-color: #e74c3c;
  border-color: #c0392b;
}

input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 6px 8px;
  background-color: #121215;
  border: 1px solid #333340;
  border-radius: 4px;
  color: #fff;
  font-size: 12px;
  margin-bottom: 6px;
}

.form-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.timeline-section {
  height: 260px;
  background-color: #16161a;
  border-top: 1px solid #2d2d32;
  display: flex;
  flex-direction: column;
}

.timeline-toolbar {
  height: 38px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #1e1e24;
  border-bottom: 1px solid #2a2a30;
}

.time-display {
  font-family: monospace;
  font-size: 13px;
  color: #00d2ff;
  background: #121215;
  padding: 3px 6px;
  border-radius: 3px;
}

.timeline-container {
  flex: 1;
  position: relative;
  overflow-x: auto;
  overflow-y: auto;
}

.timeline-tracks {
  position: relative;
  min-width: 1200px;
  padding: 8px 0;
}

.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background-color: #ff3b30;
  z-index: 100;
  pointer-events: none;
}

.playhead-head {
  position: absolute;
  top: 0;
  left: -6px;
  width: 14px;
  height: 14px;
  background-color: #ff3b30;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.timeline-ruler {
  height: 24px;
  background-color: #18181d;
  border-bottom: 1px solid #2d2d32;
  position: sticky; /* 画面スクロール時も上部に固定 */
  top: 0;
  z-index: 30; /* トラックより前面に表示 */
  min-width: 1200px;
  cursor: pointer;
}

/* 左側に固定表示する操作案内の見出し */
.ruler-label {
  position: sticky;
  left: 0;
  width: 90px;
  height: 100%;
  background-color: #22222a;
  border-right: 1px solid #333340;
  font-size: 10px;
  color: #00d2ff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 35;
  font-weight: bold;
  float: left;
  pointer-events: none;
}

.track {
  height: 40px;
  background-color: #1a1a20;
  border-bottom: 1px solid #26262e;
  position: relative;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
}

.track-label {
  position: sticky;
  left: 0;
  width: 90px;
  height: 100%;
  background-color: #22222a;
  border-right: 1px solid #333340;
  font-size: 11px;
  color: #888;
  display: flex;
  align-items: center;
  padding-left: 8px;
  z-index: 20;
  font-weight: bold;
}

.track-content {
  position: relative;
  flex: 1;
  height: 100%;
}

.clip {
  position: absolute;
  top: 3px;
  height: 34px;
  background-color: #0078d4;
  border-radius: 4px;
  color: #fff;
  font-size: 11px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  cursor: grab;
  border: 1px solid rgba(255,255,255,0.2);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  box-sizing: border-box;
}

.clip.selected {
  border: 2px solid #00d2ff;
  box-shadow: 0 0 8px rgba(0,210,255,0.5);
}

.clip.audio-clip { background-color: #2e7d32; }
.clip.se-clip { background-color: #e65100; }
.clip.text-clip { background-color: #6a1b9a; }

.handle-left, .handle-right {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  background-color: rgba(255, 255, 255, 0.4);
  cursor: ew-resize;
  display: none;
}

.handle-left { left: 0; }
.handle-right { right: 0; }

.clip:hover .handle-left, .clip:hover .handle-right,
.clip.selected .handle-left, .clip.selected .handle-right {
  display: block;
}

#playhead {
  cursor: grab;
  user-select: none;
}

/* ドラッグ中のカーソル（掴んでいる状態） */
#playhead:active {
  cursor: grabbing;
}

#timelineRuler {
  cursor: pointer;
}


/* ==========================================
   スマホ（画面幅 768px 以下）専用設定
   ========================================== */
@media (max-width: 768px) {
  /* ヘッダーは高さを固定し、縮ませない */
  header {
    padding: 6px 10px !important;
    gap: 8px;
    flex-shrink: 0 !important;
  }
  
  html, body {
    height: 100dvh !important;
    margin: 0;
    padding: 0;
    overflow: hidden !important;
  }

  header h1 {
    font-size: 13px !important;
    white-space: nowrap;
  }

  .notice-banner {
    padding: 4px 8px !important;
    max-width: none !important;
  }

  .notice-title {
    font-size: 11px !important;
    margin-bottom: 0 !important;
  }

  .notice-text {
    font-size: 10px !important;
    line-height: 1.2 !important;
  }

  .notice-text span {
    font-size: 9px !important;
  }

  /* ① コンテナ：calcを使わず header の「残り高さ全て」を確実に埋める */
  .app-body {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  .top-panel {
    display: contents !important;
  }

  .timeline-toolbar {
    height: auto !important;
    padding: 6px 8px !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 6px !important;
  }

  .timeline-toolbar > div,
  .timeline-toolbar .btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    width: 100%;
  }

  .timeline-toolbar button {
    font-size: 10px !important;
    padding: 4px 6px !important;
    flex: 1 1 auto;
    white-space: nowrap;
  }

  .time-display {
    align-self: flex-end;
    font-size: 11px !important;
  }

  .timeline-section,
  .timeline-container {
    -webkit-overflow-scrolling: touch; /* iOSでのスクロールを滑らかにする設定 */
  }

  /* クリップのドラッグ操作や再生バー、キャンバス操作の誤スクロール防止のみ制御を残す */
  .clip,
  .timeline-ruler,
  canvas {
    touch-action: none !important;
  }

  /* プレビューエリア（高さ固定） */
  .preview-section {
    order: 1 !important;
    width: 100% !important;
    height: 220px !important; 
    flex-shrink: 0 !important; 
    flex-grow: 0 !important;
    max-height: none !important;
    min-height: 220px !important;
    padding: 0 !important;
    background-color: #0d0d0f;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden !important;
  }

  .preview-section .canvas-container {
    width: 100% !important;
    height: 100% !important;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .preview-section canvas {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain; 
  }

  /* 素材ツールエリア（高さ固定） */
  .tools-section {
    order: 2 !important;
    width: 100%;
    height: 130px !important;
    padding: 6px;
    background-color: #1a1a20;
    border-left: none;
    border-bottom: 1px solid #2d2d32;
    display: flex;
    flex-direction: column !important;
    gap: 6px;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    flex-shrink: 0 !important;
  }

  /* タイムラインエリア：180pxの固定を解除し、画面の「残りの高さ」を最下部まで全て埋める */
  .timeline-section {
    order: 3 !important;
    width: 100%;
    height: auto !important;           /* 固定高さを解除 */
    flex: 1 1 auto !important;         /* 画面下までの空白をすべて自動で占有 */
    min-height: 0 !important;          /* スクロールと伸縮を正しく動かす必須指定 */
    background-color: #16161a;
    border-top: 1px solid #2d2d32;
    display: flex;
    flex-direction: column;
  }

  /* ② 最下部パネル：余った高さを最下部まで伸ばしきる */
  .edit-panel-section,
  .terminal-section {
    order: 4 !important;
    flex: 1 1 auto !important; /* 画面下までの残りの高さを全て自動占有 */
    min-height: 0 !important;   /* flex:1 を正常動作させる必須プロパティ */
    height: auto !important;
    width: 100%;
    background-color: #1e1e24;
    padding: 10px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto !important;
  }
}