/* グローバルスタイル */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  height: -webkit-fill-available; /* iOSのツールバー対策 */
}

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: #000;
  color: #fff;
  overflow: hidden;
  height: 100vh;
  height: -webkit-fill-available; /* iOSのツールバー対策 */
}

/* アプリコンテナ */
#app-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 100%;
  height: -webkit-fill-available;
  background-color: #000;
  overflow: hidden;
}

/* 9:16アスペクト比のファインダー */
#viewfinder {
  position: relative;
  width: 100%;
  /* 画面の高さが足りない場合に上下のボタンエリアが押し出されないよう、最大高さを制限 */
  max-height: calc(100vh - 180px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  aspect-ratio: 9 / 16;
  background-color: #000;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-grow: 1; /* 高さに合わせて伸縮可能にする */
  flex-shrink: 1;
}

/* ビデオ表示領域（カメラのプレビュー） */
#camera-view {
  width: 100%;
  height: 100%;
  object-fit: cover; /* ファインダー内に比率を保って広げる */
  z-index: 1;
  transition: transform 0.1s ease; /* 反転時の僅かなアニメーション（任意） */
}

/* 前面カメラ（インカメラ）のプレビューを鏡像（左右反転）表示にする */
#camera-view.mirror {
  transform: scaleX(-1);
}

/* シャッター押下時のフラッシュエフェクト */
#flash-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #fff;
  opacity: 0;
  z-index: 5;
  pointer-events: none;
  transition: opacity 0.1s ease-out;
}

#flash-overlay.active {
  opacity: 1;
  transition: none; /* 一瞬で白くするためトランジションを無効化 */
}

/* 読み込み中スピナー */
#loading-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  background: rgba(0, 0, 0, 0.6);
  padding: 20px;
  border-radius: 12px;
  backdrop-filter: blur(8px);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-left-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ヘッダーパネル（上部コントロール - 完全な黒背景） */
#controls-top {
  position: relative;
  z-index: 3;
  width: 100%;
  padding-top: env(safe-area-inset-top); /* セーフエリア分のパディング */
  height: calc(50px + env(safe-area-inset-top)); /* セーフエリア込みの高さ */
  padding-left: 20px;
  padding-right: 20px;
  display: flex;
  justify-content: center; /* ブランド名を中央に配置 */
  align-items: center;
  background-color: #000;
  flex-shrink: 0; /* 絶対に縮まないようにする */
}

.brand {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: rgba(255, 255, 255, 0.9);
}

/* フッターパネル（下部コントロール - 完全な黒背景） */
#controls-bottom {
  position: relative;
  z-index: 3;
  width: 100%;
  padding-bottom: env(safe-area-inset-bottom); /* 下部インジケータ領域の余白 */
  height: calc(100px + env(safe-area-inset-bottom)); /* セーフエリア込みの高さ */
  padding-left: 30px;
  padding-right: 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #000;
  flex-shrink: 0; /* 絶対に縮まないようにする */
}

/* ボタンの共通スタイル */
.icon-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.icon-btn:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.3);
}

.control-placeholder {
  width: 46px; /* 両端のバランス調整用 */
}

/* シャッターボタン */
#shutter-btn {
  background: none;
  border: 5px solid #fff;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  padding: 4px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  transition: transform 0.1s ease;
}

#shutter-btn:active {
  transform: scale(0.92);
}

.shutter-inner {
  background-color: #fff;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: block;
  transition: transform 0.1s ease, border-radius 0.1s ease;
}

#shutter-btn:active .shutter-inner {
  transform: scale(0.9);
}

/* 撮影結果プレビューモーダル */
#preview-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #121212;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  animation: slideIn 0.3s cubic-bezier(0.1, 0.76, 0.55, 0.94);
}

@keyframes slideIn {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* プレビューヘッダー */
.preview-header {
  padding: calc(15px + env(safe-area-inset-top)) 20px 15px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: rgba(18, 18, 18, 0.9);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.preview-title {
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: 0.05em;
}

.text-btn {
  background: none;
  border: none;
  color: #aaa;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  padding: 8px 12px;
  transition: color 0.2s ease;
}

.text-btn:active {
  color: #fff;
}

.accent-btn {
  background: #fff;
  border: none;
  color: #000;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  transition: opacity 0.2s ease;
}

.accent-btn:active {
  opacity: 0.8;
}

/* プレビューボディ */
.preview-body {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #000;
  padding: 15px;
  overflow: hidden;
  position: relative;
}

.image-container {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

#preview-img {
  max-width: 100%;
  max-height: calc(100vh - 200px);
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.05);
  /* iOSでの画像長押し保存ポップアップを確実に有効化する設定 */
  -webkit-touch-callout: default !important;
  pointer-events: auto !important;
  user-select: auto !important;
  -webkit-user-select: auto !important;
}

/* ガイド用メッセージトースト */
.guide-toast {
  margin-top: 15px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 0.8rem;
  color: #ccc;
  text-align: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: pulse 2s infinite ease-in-out;
  pointer-events: none; /* タップ操作を透過させて画像を長押ししやすくする */
}

@keyframes pulse {
  0% { opacity: 0.8; }
  50% { opacity: 1; }
  100% { opacity: 0.8; }
}

/* ユーティリティ */
.hidden {
  display: none !important;
}

/* ==========================================
   スマートフォン横向き（Landscape）用のレイアウト調整
   ========================================== */
@media (orientation: landscape) {
  #app-container {
    flex-direction: row; /* 横並びにする */
    justify-content: space-between;
    align-items: center;
  }

  /* 横向き時のファインダー（16:9） */
  #viewfinder {
    aspect-ratio: 16 / 9;
    height: 100%;
    max-height: 100%;
    /* 左右の操作バーの幅を考慮して最大幅を制限（はみ出し防止） */
    max-width: calc(100vw - 220px - env(safe-area-inset-left) - env(safe-area-inset-right));
    width: auto;
    flex-grow: 1;
    flex-shrink: 1;
  }

  /* 左部コントロールバー（ブランド表記） */
  #controls-top {
    width: calc(60px + env(safe-area-inset-left));
    height: 100%;
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: env(safe-area-inset-left);
    padding-right: 10px;
    flex-direction: column;
    justify-content: center;
    flex-shrink: 0;
  }

  /* ブランド文字を縦書きにして美しく配置 */
  .brand {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 0.95rem;
  }

  /* 右部コントロールバー（操作ボタン） */
  #controls-bottom {
    width: calc(100px + env(safe-area-inset-right));
    height: 100%;
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: 10px;
    padding-right: env(safe-area-inset-right);
    flex-direction: column-reverse; /* ボタンの順序を横持ち用に最適化 */
    justify-content: space-around;
    flex-shrink: 0;
  }
  
  /* 切り替えボタンのサイズや余白調整 */
  .control-placeholder {
    display: none; /* 横向き時は不要なスペースを非表示 */
  }
  
  /* プレビュー画像が横向き時も画面に収まるように調整 */
  #preview-img {
    max-height: calc(100vh - 100px);
  }
}
