/* ============================================================
   coffee ターミナル サイドバー＋単一表示レイアウト
   ============================================================ */
.coffee-layout {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* --- 左サイドバー（画面リスト） --- */
.coffee-sidebar {
  flex: 0 0 var(--coffee-sidebar-width, 200px);
  width: var(--coffee-sidebar-width, 200px);
  display: flex;
  flex-direction: column;
  background: #181825;
  border-right: 1px solid #313244;
  min-height: 0;
}

/* サイドバー幅調整ハンドル（PC専用・ドラッグで幅変更） */
.coffee-sidebar-resizer {
  flex: 0 0 4px;
  cursor: col-resize;
  background: #313244;
  transition: background 0.15s;
}
.coffee-sidebar-resizer:hover,
.coffee-sidebar-resizer.dragging {
  background: #6272a4;
}

.coffee-sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid #313244;
  flex-shrink: 0;
}

.coffee-sidebar-title {
  flex: 1;
  color: #6c7086;
  font-size: 0.78rem;
  font-family: 'Consolas', 'Monaco', monospace;
}

.coffee-sidebar-add {
  background: #313244;
  border: none;
  color: #a6e3a1;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.coffee-sidebar-add:hover { background: #45475a; }
.coffee-sidebar-add:active { background: #585b70; }

.coffee-screen-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px;
}

.coffee-screen-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: #cdd6f4;
  font-size: 0.85rem;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.coffee-screen-item:hover { background: #1e1e2e; }
.coffee-screen-item.active {
  background: #313244;
  box-shadow: inset 2px 0 0 #f9e2af;
}

.coffee-screen-item .terminal-status {
  flex-shrink: 0;
}

/* 名前とカレントディレクトリを縦に積む枠。
   min-width:0 が無いと長いパスが列を押し広げ、削除ボタン等がはみ出す。 */
.coffee-screen-label {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

/* 操作ボタン（✎ 📁 ×）は通常時は透明なのに幅だけ占有しており、
   名前とパスの表示幅が 66px しか残らなかった。
   浮かせて重ね、表示するときだけラベル側に余白を空ける。 */
.coffee-screen-item { position: relative; }
.coffee-screen-item .coffee-screen-edit,
.coffee-screen-item .coffee-screen-files,
.coffee-screen-item .coffee-screen-delete {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
}
.coffee-screen-item .coffee-screen-delete { right: 8px; }
.coffee-screen-item .coffee-screen-files  { right: 32px; }
.coffee-screen-item .coffee-screen-edit   { right: 60px; }

.coffee-screen-item:hover .coffee-screen-label,
.coffee-screen-item.active .coffee-screen-label {
  padding-right: 82px;
}

.coffee-screen-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* カレントディレクトリ（名前の下に小さく）。
   長いパスの短縮は JS 側で行う（direction:rtl は "~/git/k428" が
   "git/k428/~" と並び替わってしまうため使わない）。 */
.coffee-screen-cwd {
  font-size: 0.68rem;
  color: #7f849c;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.coffee-screen-cwd:empty { display: none; }
.coffee-screen-item.active .coffee-screen-cwd { color: #a6adc8; }

.coffee-screen-delete {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: #6c7086;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s, background 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.coffee-screen-item:hover .coffee-screen-delete,
.coffee-screen-item.active .coffee-screen-delete,
.coffee-screen-item:hover .coffee-screen-edit,
.coffee-screen-item.active .coffee-screen-edit {
  opacity: 1;
}
.coffee-screen-delete:hover { color: #ff5555; background: #1e1e2e; }

/* 画面名 編集ボタン（鉛筆） */
.coffee-screen-edit {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: #6c7086;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s, background 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.coffee-screen-edit:hover { color: #89b4fa; background: #1e1e2e; }

/* 画面ごとの ファイル閲覧ボタン（フォルダ） */
.coffee-screen-files {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: #6c7086;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s, background 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.coffee-screen-item:hover .coffee-screen-files,
.coffee-screen-item.active .coffee-screen-files { opacity: 1; }
.coffee-screen-files:hover { color: #f9e2af; background: #1e1e2e; }

/* 画面名 インライン編集の input */
.coffee-screen-rename {
  flex: 1;
  min-width: 0;
  background: #11111b;
  border: 1px solid #585b70;
  border-radius: 4px;
  color: #cdd6f4;
  font-size: 0.85rem;
  font-family: inherit;
  padding: 2px 6px;
  outline: none;
}

/* --- 右ペイン領域（アクティブ画面のみ表示） --- */
.coffee-panes {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: #000000;
}

.coffee-panes .terminal-pane {
  position: absolute;
  inset: 0;
}

.coffee-panes .terminal-pane:not(.active-screen) {
  display: none;
}

.coffee-panes .terminal-pane-header {
  display: none;
}

.coffee-panes .terminal-pane-body {
  background: #000000;
  height: 100%;
}

/* --- モバイル専用要素（PCでは非表示） --- */
.coffee-mobile-topbar { display: none; }
.coffee-sidebar-overlay { display: none; }
/* 動画プレイヤーはモバイル専用。PC では .open が付いていても出さない
   （PC は横に余裕があるのでファイルペイン内で再生する） */
.coffee-video { display: none; }

@media (max-width: 768px) {
  /* 動画プレイヤー（レイアウトの上側・通常フロー）。
     高さは動画の縦横比ぶんだけ取り、上限を % で抑える。固定 % にすると
     16:9 の動画で黒帯に 80px 以上取られ、その分ターミナルの行数が減る。
     上限に vh を使わないのは、vh がレイアウトビューポート基準で OSK が
     出ても縮まず、プレイヤーがキーボードの裏へ回り込むため。#coffee-view の
     高さは #app に追従するので、% ならターミナルと一緒に縮む。 */
  .coffee-video.open {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    max-height: 46%;
    min-height: 0;
    background: #000;
    border-bottom: 1px solid #313244;
  }

  /* スライダーを動画の下端に重ねるための包み。縮む鎖（.coffee-video →
     ここ → video）を切らないよう、flex の指定は video と同じにしておく */
  .coffee-video-stage {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 0 1 auto;
    min-height: 0;
  }

  /* aspect-ratio は loadedmetadata で実寸に差し替える（既定は暫定値）。
     縦長動画では max-height に当たって潰れるので、縮められるように
     flex-shrink を残し、はみ出しは object-fit: contain に任せる。 */
  .coffee-video-el {
    flex: 0 1 auto;
    min-height: 0;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    object-fit: contain;
    display: block;
  }

  /* 音声には映像が無いので、16/9 の黒枠は取らずに帯だけにする。
     取ってもターミナルの行数が減るだけで、見えるものは何も無い。
     スライダー（下端 18px）の上に、タップで再生/一時停止できる余白を残す。 */
  .coffee-video.audio .coffee-video-el {
    flex: 0 0 auto;
    aspect-ratio: auto;
    height: 48px;
  }
  /* 音声だと画面が真っ黒になるので、何が載っているかを示す */
  .coffee-video.audio .coffee-video-stage::before {
    content: '🎵';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    pointer-events: none;
  }

  /* 再生位置スライダー。見た目は 2px だが、指で掴めるよう帯は 18px 取り、
     線は帯の下端に寄せる。touch-action: none がないと横ドラッグが
     ページのスクロール／ビューのスワイプに持っていかれる */
  .coffee-video-seek {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 18px;
    touch-action: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .cv-seek-track,
  .cv-seek-buffered,
  .cv-seek-played {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 2px;
    transition: height 0.12s;
  }

  .cv-seek-track { right: 0; background: rgba(205, 214, 244, 0.25); }
  .cv-seek-buffered { width: 0; background: rgba(205, 214, 244, 0.45); }
  .cv-seek-played { width: 0; background: #89b4fa; }

  /* 掴んでいる間は線を太くする（2px では指の下に隠れて見えない） */
  .coffee-video-seek.dragging .cv-seek-track,
  .coffee-video-seek.dragging .cv-seek-buffered,
  .coffee-video-seek.dragging .cv-seek-played {
    height: 6px;
  }

  /* 何も読み込んでいないときは線ごと出さない */
  .coffee-video-seek.empty { display: none; }

  .coffee-video-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    height: 30px;
    padding: 0 4px 0 10px;
    background: #181825;
  }

  .coffee-video-name {
    flex: 1;
    min-width: 0;
    color: #cdd6f4;
    font-size: 0.78rem;
    font-family: 'Consolas', 'Monaco', monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .coffee-video-close,
  .coffee-video-pick {
    background: transparent;
    border: none;
    color: #cdd6f4;
    font-size: 1.2rem;
    line-height: 1;
    padding: 4px 10px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
  }

  .coffee-video-pick {
    font-size: 1rem;
    padding: 4px 6px 4px 0;
  }

  /* トップバーは左レールに統合（縦スペース確保のため常時非表示） */
  .coffee-mobile-topbar {
    display: none !important;
    align-items: center;
    gap: 10px;
    height: 40px;
    flex-shrink: 0;
    padding: 0 12px;
    background: #181825;
    border-bottom: 1px solid #313244;
  }

  .coffee-drawer-toggle {
    background: transparent;
    border: none;
    color: #cdd6f4;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
    -webkit-tap-highlight-color: transparent;
  }

  .coffee-mobile-active-name {
    color: #cdd6f4;
    font-size: 0.9rem;
    font-family: 'Consolas', 'Monaco', monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* サイドバーをオフキャンバスのドロワー化（左レールの右から出現）。
     閉状態は translateX(-100%) でちょうど左レールの真上に重なるため、
     visibility: hidden でヒットテストから外す（外さないとレールがタップ不能になる）。
     visibility はスライドアウト完了後に遅延で切り替え、アニメーションを保つ。 */
  .coffee-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: var(--mobile-rail-width, 0);
    width: calc(75% - var(--mobile-rail-width, 0px));
    max-width: 300px;
    z-index: 610;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }
  .coffee-sidebar.open {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.2s ease;
  }

  .coffee-sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 605;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .coffee-sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto;
  }

  /* 編集・削除ボタンはモバイルでは常時表示（hover が無いため） */
  .coffee-screen-delete,
  .coffee-screen-files,
  .coffee-screen-edit { opacity: 1; }

  /* 幅調整ハンドルは PC 専用 */
  .coffee-sidebar-resizer { display: none; }
}

/* ============================================================
   モバイル専用ステータスバー（画面下端）

   #app の中（.app-main の最後）に置く。position: fixed にすると
   レイアウトビューポート基準になり、OSK が出たときキーボードの裏に
   隠れてしまう。通常フローに置けば #app の高さ追従にそのまま乗る。
   各セルは等幅（flex: 1 1 0）にして、幅が変わっても崩れないようにする。
   ============================================================ */
@media (max-width: 768px) {
  .mobile-statusbar {
    display: flex;
    align-items: stretch;
    gap: 7px;
    flex-shrink: 0;
    height: 26px;
    padding: 0 8px;
    background: #181825;
    border-top: 1px solid #313244;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.58rem;
    line-height: 1;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
  }

  .mstat {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
  }
  .mstat-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 3px;
    overflow: hidden;
  }
  .mstat-label {
    color: #6c7086;
    white-space: nowrap;
  }
  .mstat-value {
    color: #a6adc8;
    white-space: nowrap;
  }
  .mstat-value.warn { color: #f9e2af; }
  .mstat-value.danger { color: #f38ba8; }

  .mstat-bar {
    height: 2px;
    background: #313244;
    border-radius: 1px;
    overflow: hidden;
  }
  .mstat-bar i {
    display: block;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    transition: width 0.6s ease, background 0.6s ease;
  }
  .mstat-bar i.warn { background: #f9e2af; }
  .mstat-bar i.danger { background: #f38ba8; }

  /* 利用枠と coffee の区切り */
  .mstat-sep {
    flex: 0 0 1px;
    width: 1px;
    background: #313244;
    margin: 5px 1px;
  }
}

/* ============================================================
   モバイル専用ショートカットキーバー
   ============================================================ */
.mobile-shortcut-bar {
  display: none;
}

@media (max-width: 768px) {
  .mobile-shortcut-bar {
    display: flex;
    align-items: stretch;
    background: #181825;
    border-top: 1px solid #313244;
    flex-shrink: 0;
    height: 42px;
  }

  #coffee-shortcut-bar {
    height: 84px;
    flex-direction: column;
    flex-shrink: 0;
  }

  .shortcut-row {
    display: flex;
    align-items: stretch;
    flex: 1;
    border-top: 1px solid #313244;
  }

  .shortcut-row:first-child {
    border-top: none;
  }

  .shortcut-key {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-right: 1px solid #313244;
    color: #cdd6f4;
    font-size: 0.82rem;
    font-family: 'Consolas', 'Monaco', monospace;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  .shortcut-row .shortcut-key:first-child,
  .shortcut-row .shortcut-key:last-child {
    flex: 1.1;
  }

  .shortcut-row .shortcut-key:last-child {
    border-right: none;
  }

  .shortcut-key:active {
    background: #313244;
  }

  /* 横向き: 縦領域が貴重なので coffee バーを1段に統合（全キーを1列に並べる） */
  @media (orientation: landscape) {
    #coffee-shortcut-bar {
      height: 42px;
      flex-direction: row;
    }
    /* row の箱を消して全キーをバー直下のフレックスアイテムにする */
    #coffee-shortcut-bar .shortcut-row {
      display: contents;
    }
    /* 1段化で行末でなくなったキー（↩︎）の右罫線を復活させる */
    #coffee-shortcut-bar .shortcut-row:first-child .shortcut-key:last-child {
      border-right: 1px solid #313244;
    }
  }

  .shortcut-key.com-key {
    color: #89b4fa;
  }

  .shortcut-key.com-key:active {
    background: #1e2030;
  }

  .shortcut-key.font-key {
    color: #a6e3a1;
    flex: 0.8;
    font-size: 0.75rem;
  }
}

/* コマンドピッカーモーダル */
.com-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 600;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.com-modal {
  background: #1e1e2e;
  border: 1px solid #313244;
  border-radius: 14px 14px 0 0;
  padding: 20px 16px 32px;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.com-modal-title {
  font-size: 0.85rem;
  color: #6c7086;
  text-align: center;
  margin-bottom: 4px;
  font-family: 'Consolas', 'Monaco', monospace;
}

.com-modal-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.com-modal-item {
  width: 100%;
  padding: 14px 16px;
  background: #313244;
  border: 1px solid #45475a;
  border-radius: 8px;
  color: #cdd6f4;
  font-size: 0.95rem;
  font-family: 'Consolas', 'Monaco', monospace;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;   /* 2度押しの2回目をダブルタップズームに取られないように */
}

.com-modal-item:active {
  background: #45475a;
}

/* 2度押しで実行する項目（coffee の /clear・/exit）。普段から赤字にして危険な操作だと
   分かるようにし、1回目を押した後（armed）は枠も赤くして「もう一度押すと…」に変える */
.com-modal-item.danger {
  color: #f38ba8;
}

.com-modal-item.danger.armed {
  background: rgba(243, 139, 168, 0.15);
  border-color: #f38ba8;
}

.com-modal-cancel {
  width: 100%;
  padding: 14px;
  background: transparent;
  border: 1px solid #45475a;
  border-radius: 8px;
  color: #6c7086;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  margin-top: 4px;
  -webkit-tap-highlight-color: transparent;
}

.com-modal-cancel:active {
  background: #313244;
}

