/* =============================
   リセット・ベース
   ============================= */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  background: #1a1a2e;
  color: #eee;
  font-family: -apple-system, 'Helvetica Neue', sans-serif;
  /* iOSのスクロールバウンスを抑止 */
  overscroll-behavior: none;
  overflow: hidden;
  /* テキスト選択禁止（タッチ誤操作防止） */
  user-select: none;
  -webkit-user-select: none;
}

button {
  /* iOSの300msタップ遅延を解消 */
  touch-action: manipulation;
  cursor: pointer;
  border: none;
  outline: none;
  font-family: inherit;
}

/* =============================
   画面管理
   ============================= */
.screen {
  display: none;
  width: 100vw;
  height: 100vh;        /* フォールバック */
  height: 100dvh;       /* iOS Safari対応: ツールバーを除いた実際の高さ */
}
.screen.active {
  display: flex;
}

/* =============================
   画面1: エクササイズ選択
   ============================= */
#screen-select {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  /* iPhoneノッチ対応 */
  padding-left:  max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
  gap: 20px;
}

#screen-select h1 {
  font-size: clamp(22px, 5vw, 36px);
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
  color: #e0e0ff;
}

.subtitle {
  font-size: 14px;
  color: #888;
  text-align: center;
}

.exercise-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 360px;
}

.btn-exercise {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px 24px;
  background: #16213e;
  border: 1px solid #2a2a5a;
  border-radius: 14px;
  color: #eee;
  transition: background 0.15s, transform 0.1s;
  -webkit-appearance: none;
}
.btn-exercise:active {
  background: #0f3460;
  transform: scale(0.97);
}

.ex-icon {
  font-size: 28px;
}
.ex-name {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  line-height: 1.3;
}
.ex-angles {
  font-size: 12px;
  color: #00dcff;
  opacity: 0.8;
}

/* ランドスケープ時は横並び */
@media (orientation: landscape) and (min-width: 600px) {
  .exercise-buttons {
    flex-direction: row;
    max-width: 100%;
    justify-content: center;
  }
  .btn-exercise {
    flex: 1;
    max-width: 220px;
  }
}

/* =============================
   画面2: カメラ・録画
   ============================= */
#screen-camera {
  position: relative;
  background: #000;
}

/* カメラ映像（非表示）*/
#video {
  display: none;
}

/* 描画Canvas（JSでサイズ・位置を制御するためposition:absoluteのみ設定）*/
#canvas {
  position: absolute;
  /* 幅・高さ・left・top はapp.js内のfitCanvas()で設定 */
}

/* =============================
   UIオーバーレイ
   ============================= */
#ui-overlay {
  position: absolute;
  inset: 0;
  z-index: 10; /* Canvasより必ず前面に */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  /* iPhoneセーフエリア */
  padding-top:    max(16px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  padding-left:   max(16px, env(safe-area-inset-left));
  padding-right:  max(16px, env(safe-area-inset-right));
  pointer-events: none; /* Canvas操作を通過させる */
}

/* 上部バー */
#top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

#exercise-label {
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  backdrop-filter: blur(4px);
}

#model-status {
  background: rgba(0, 0, 0, 0.55);
  color: #aaa;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  backdrop-filter: blur(4px);
}

/* 録画タイマー（右上） */
#record-timer {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  background: rgba(220, 0, 0, 0.75);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 6px 12px;
  border-radius: 8px;
  letter-spacing: 1px;
}

/* 下部コントロール */
#controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: auto;
}

/* 戻るボタン */
#btn-back {
  background: rgba(0, 0, 0, 0.6);
  color: #ccc;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 10px;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.15);
}
#btn-back:active {
  background: rgba(255, 255, 255, 0.15);
}

/* RECボタン */
#btn-record {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #e74c3c;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  border: 4px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.5);
  transition: transform 0.1s;
}
#btn-record:active {
  transform: scale(0.93);
}
#btn-record:disabled,
#btn-record.loading {
  background: #444;
  border-color: rgba(255, 255, 255, 0.4);
  color: #ddd;
  font-size: 11px;
}
#btn-record.recording {
  background: #fff;
  color: #e74c3c;
  animation: recPulse 1.2s ease-in-out infinite;
}
@keyframes recPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.6); }
  50%       { box-shadow: 0 0 0 12px rgba(231, 76, 60, 0); }
}

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

/* 縦・横どちらでも使用可能 */
