/* ==============================
   MaDO — Base Styles
   ============================== */

/* --- カラー変数 --- */
:root {
  --color-gold:    #D4AF37;
  --color-navy:    #1B2A4A;
  --color-white:   #FFFFFF;
  --overlay-bg:    rgba(27, 42, 74, 0.75);
  --inactive:      rgba(255, 255, 255, 0.5);
  --font-main:     'Montserrat', sans-serif;
}

/* --- リセット --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--color-navy);
  font-family: var(--font-main);
  color: var(--color-white);
  -webkit-user-select: none;
  user-select: none;
}

/* --- 画面切り替え --- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

/* ==============================
   待機画面（Lobby）
   ============================== */
#screen-lobby {
  align-items: center;
  justify-content: center;
  background-color: var(--color-navy);
}

.lobby-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.lobby-logo {
  width: 120px;
  height: auto;
}

.lobby-tagline {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.15em;
  color: var(--color-white);
  opacity: 0.7;
  text-transform: uppercase;
}

/* ==============================
   映像通話画面（Call）
   ============================== */
#screen-call {
  background-color: #000;
}

/* --- メイン映像 --- */
.video-main-wrap {
  position: absolute;
  inset: 0;
}

.video-main-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* --- 小窓（共通） --- */
.pip {
  position: absolute;
  width: 100px;
  height: 178px;            /* 9:16比率 */
  border-radius: 12px;
  overflow: hidden;
  border: 1.5px solid var(--color-gold);
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.pip video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 自分映像：左下 */
.pip-local {
  left: 12px;
  bottom: 24px;
}

/* 相手B映像：右下 */
.pip-remote {
  right: 12px;
  bottom: 24px;
}

/* --- 接続状態ドット --- */
.connection-dot {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  z-index: 20;
}

.connection-dot.connected {
  background-color: var(--color-gold);
}

.connection-dot.disconnected {
  background-color: var(--color-white);
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.2; }
}

/* --- オーバーレイUI --- */
.overlay-ui {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: var(--overlay-bg);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* ==============================
   ステップ2 — Lobby UI
   ============================== */

/* --- 役割選択 --- */
.role-select {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 260px;
  margin-top: 32px;
}

/* --- ボタン共通 --- */
.btn {
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.05em;
  border: none;
  border-radius: 8px;
  padding: 14px 0;
  cursor: pointer;
  transition: opacity 0.2s, background-color 0.2s;
  width: 100%;
}

.btn:active {
  opacity: 0.8;
}

/* プライマリ（ゴールド背景） */
.btn-primary {
  background-color: var(--color-gold);
  color: var(--color-navy);
}

.btn-primary:disabled {
  opacity: 0.35;
  cursor: default;
}

/* アウトライン（枠線のみ） */
.btn-outline {
  background-color: transparent;
  color: var(--color-gold);
  border: 1.5px solid var(--color-gold);
}

/* テキストボタン（戻る等） */
.btn-text {
  background: none;
  color: var(--inactive);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 0;
}

/* --- セクション共通 --- */
.lobby-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 260px;
  margin-top: 32px;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--inactive);
}

.section-hint {
  font-size: 11px;
  color: var(--inactive);
  text-align: center;
  line-height: 1.6;
}

/* --- ルームキー表示（ホスト） --- */
.room-key-display {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: 0.3em;
  color: var(--color-gold);
  text-align: center;
  padding: 8px 0;
}

/* --- ルームキー入力（ゲスト） --- */
.key-input-wrap {
  width: 100%;
}

#room-key-input {
  width: 100%;
  padding: 14px 16px;
  font-family: var(--font-main);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.25em;
  text-align: center;
  text-transform: uppercase;
  color: var(--color-white);
  background-color: rgba(255, 255, 255, 0.08);
  border: 1.5px solid var(--color-gold);
  border-radius: 8px;
  outline: none;
  caret-color: var(--color-gold);
  transition: border-color 0.2s;
}

#room-key-input::placeholder {
  color: var(--inactive);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.1em;
}

#room-key-input:focus {
  border-color: var(--color-white);
}

/* ==============================
   ステップ3 — カメラプレビュー & 通話画面
   ============================== */

/* --- 待機画面のカメラプレビュー --- */
.preview-wrap {
  width: 140px;
  height: 249px;           /* 9:16比率 */
  border-radius: 12px;
  overflow: hidden;
  border: 1.5px solid var(--color-gold);
  background-color: rgba(0, 0, 0, 0.3);
  margin-bottom: 16px;
}

.preview-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);  /* 鏡像表示 */
}

/* --- 通話画面：自分映像も鏡像 --- */
.pip-local video {
  transform: scaleX(-1);
}

/* --- カメラエラー表示 --- */
.camera-error {
  color: #FF6B6B;
  font-size: 12px;
  text-align: center;
  line-height: 1.5;
}

/* ==============================
   ステップ5 — 映像レイアウト & 切替
   ============================== */

/* --- メイン映像プレースホルダー --- */
.main-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background-color: var(--color-navy);
  z-index: 1;
  transition: opacity 0.4s;
}

.main-placeholder.fade-out {
  opacity: 0;
  pointer-events: none;
}

.placeholder-logo {
  width: 64px;
  height: auto;
  opacity: 0.5;
}

.placeholder-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--inactive);
  letter-spacing: 0.05em;
}

/* --- 小窓ラベル（タップで切替） --- */
.pip-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 4px 0;
  text-align: center;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--color-white);
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.3s;
}

.pip-remote:hover .pip-label,
.pip-remote:active .pip-label {
  opacity: 1;
}

/* --- 小窓タップ時のフィードバック --- */
.pip-remote {
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.pip-remote:active {
  transform: scale(0.95);
}

/* --- 接続状態ラップ --- */
.connection-status-wrap {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 20;
}

.connection-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-white);
  opacity: 0.8;
}

/* --- 既存 .connection-dot の position 上書き --- */
.connection-dot {
  position: static;
}

/* --- メイン映像のフェード切替 --- */
.video-main-wrap video {
  transition: opacity 0.3s;
}

/* --- 小窓の出現アニメーション --- */
.pip-remote {
  animation: pip-in 0.3s ease-out;
}

@keyframes pip-in {
  from {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ==============================
   ステップ6 — オーバーレイUI & 設定
   ============================== */

/* --- オーバーレイバー --- */
.overlay-ui {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transition: opacity 0.3s, transform 0.3s;
}

.overlay-ui.hidden {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  display: flex !important;
}

.overlay-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding: 16px 24px;
  background: var(--overlay-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* --- オーバーレイボタン --- */
.ov-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 12px;
  transition: background-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.ov-btn:active {
  background-color: rgba(255, 255, 255, 0.1);
}

.ov-icon {
  width: 26px;
  height: 26px;
  color: var(--inactive);
  transition: color 0.2s;
}

.ov-label {
  font-family: var(--font-main);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--inactive);
  transition: color 0.2s;
}

/* アクティブ状態（ON） */
.ov-btn.active .ov-icon {
  color: var(--color-gold);
}

.ov-btn.active .ov-label {
  color: var(--color-gold);
}

/* ミュート時の打ち消し線 */
.ov-btn.muted {
  position: relative;
}

.ov-btn.muted::after {
  content: '';
  position: absolute;
  top: 10px;
  left: 50%;
  width: 30px;
  height: 2px;
  background-color: #FF6B6B;
  transform: translateX(-50%) rotate(-45deg);
  pointer-events: none;
}

/* --- 設定パネル --- */
.settings-panel {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  transition: opacity 0.3s;
}

.settings-panel.hidden {
  opacity: 0;
  pointer-events: none;
  display: flex !important;
}

.settings-inner {
  width: 100%;
  max-width: 400px;
  background: var(--color-navy);
  border-radius: 20px 20px 0 0;
  padding: 24px 24px calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateY(0);
  transition: transform 0.3s;
}

.settings-panel.hidden .settings-inner {
  transform: translateY(100%);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.settings-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-white);
}

.settings-close {
  background: none;
  border: none;
  color: var(--inactive);
  font-size: 28px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.settings-group {
  margin-bottom: 20px;
}

.settings-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--inactive);
  margin-bottom: 8px;
}

.settings-select {
  width: 100%;
  padding: 12px 14px;
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 500;
  color: var(--color-white);
  background-color: rgba(255, 255, 255, 0.08);
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23ffffff' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  cursor: pointer;
}

.settings-select:focus {
  border-color: var(--color-gold);
}

.settings-select option {
  background-color: var(--color-navy);
  color: var(--color-white);
}

/* ==============================
   ステップ7 — 退席 & 再接続
   ============================== */

/* --- 退席ボタン --- */
.ov-btn-leave .ov-icon {
  color: #FF6B6B;
}

.ov-btn-leave .ov-label {
  color: #FF6B6B;
}

.ov-btn-leave:active {
  background-color: rgba(255, 107, 107, 0.15);
}

/* --- 再接続オーバーレイ --- */
.reconnect-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(27, 42, 74, 0.92);
  transition: opacity 0.3s;
}

.reconnect-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  display: flex !important;
}

.reconnect-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px;
  max-width: 280px;
  text-align: center;
}

/* --- スピナー --- */
.reconnect-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(212, 175, 55, 0.2);
  border-top-color: var(--color-gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.reconnect-spinner.stopped {
  animation: none;
  border-color: rgba(255, 255, 255, 0.2);
  border-top-color: rgba(255, 255, 255, 0.2);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- メッセージ --- */
.reconnect-message {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-white);
}

.reconnect-sub {
  font-size: 12px;
  color: var(--inactive);
  line-height: 1.5;
}

.reconnect-btn {
  max-width: 200px;
}

/* --- 退席確認ダイアログ --- */
.confirm-overlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  transition: opacity 0.3s;
}

.confirm-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  display: flex !important;
}

.confirm-box {
  background: var(--color-navy);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 260px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.confirm-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-white);
}

.confirm-text {
  font-size: 13px;
  color: var(--inactive);
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.confirm-actions .btn {
  flex: 1;
  padding: 12px 0;
}

.btn-danger {
  background-color: #FF6B6B;
  color: var(--color-white);
}

/* ==============================
   ステップ8 — 最終調整
   ============================== */

/* --- PWA / フルスクリーン対応 --- */
html {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
}

/* --- セーフエリア対応 --- */
@supports (padding-top: env(safe-area-inset-top)) {
  .connection-status-wrap {
    top: calc(16px + env(safe-area-inset-top));
  }

  .overlay-bar {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .pip-local {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }

  .pip-remote {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

/* --- バージョンラベル --- */
.version-label {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.2);
  letter-spacing: 0.05em;
}

/* --- 横向き警告（CSS のみ） --- */
@media (orientation: landscape) and (max-height: 500px) {
  body::after {
    content: '縦向きにしてご利用ください';
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--color-navy);
    color: var(--color-white);
    font-family: var(--font-main);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.1em;
  }
}

/* --- ビデオ要素の黒帯防止 --- */
video {
  background-color: #000;
}

/* --- タッチハイライト無効化 --- */
* {
  -webkit-tap-highlight-color: transparent;
}

/* --- スクロール完全防止 --- */
html, body {
  touch-action: none;
}

/* ==============================
   iOS Safari 対応
   ============================== */

/* --- メイン映像をタップ領域として使用 --- */
.video-main-wrap {
  z-index: 1;
  cursor: pointer;
}

/* --- 小窓ラベル（hover 廃止 → JSで制御） --- */
.pip-label {
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.pip-remote.show-label .pip-label {
  opacity: 1;
}

/* --- オーバーレイ・パネル類のタッチ操作改善 --- */
.overlay-bar {
  -webkit-user-select: none;
  user-select: none;
}

.ov-btn {
  touch-action: manipulation;
}

.settings-panel {
  touch-action: auto;
}

.settings-select {
  touch-action: manipulation;
}

.confirm-overlay {
  touch-action: manipulation;
}

.reconnect-overlay {
  touch-action: manipulation;
}

/* --- iOS Safari で button 内の SVG がタップを吸収する問題 --- */
.ov-btn svg,
.ov-btn span {
  pointer-events: none;
}
