/*
  デザイン方針:
  色は「意味を持つ場所」だけに使う。
  赤 = LIVE(撮影中)、アンバー = VAR REPLAY(再生中)。それ以外は白黒のグレースケールで統一する。
*/
:root {
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --hairline: rgba(255,255,255,0.12);
  --glass: rgba(255,255,255,0.08);
  --glass-strong: rgba(255,255,255,0.16);
  --text: #ffffff;
  --text-dim: #8e8e93;
  --accent-live: #ff3b30;
  --accent-replay: #ff9f0a;
  --radius-lg: 16px;
  --radius-md: 12px;
  --gap: 10px;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
body {
  font-family: "Meiryo", "Kosugi", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  text-align: center;
  margin: 0;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  min-height: 100vh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin: 10px 0 20px 0;
  color: var(--text);
}
.card {
  background: var(--surface);
  padding: 16px;
  border-radius: 20px;
  margin: 0 auto;
  max-width: 480px;
  border: 1px solid var(--hairline);
}
input, button {
  padding: 12px 14px;
  font-size: 0.95rem;
  border-radius: var(--radius-md);
  margin: 3px;
  font-weight: 600;
  font-family: inherit;
  touch-action: manipulation;
  transition: background-color 0.2s var(--ease), opacity 0.15s var(--ease), transform 0.15s var(--ease);
}
input {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--hairline);
}
button {
  background: var(--glass);
  color: var(--text);
  border: 1px solid var(--hairline);
  cursor: pointer;
}
button:active { opacity: 0.6; transform: scale(0.97); }

/* 意味のある2色だけ: LIVE(赤) / REPLAY(アンバー) */
.btn-live { background: var(--accent-live); border-color: var(--accent-live); }
.btn-replay { background: var(--accent-replay); border-color: var(--accent-replay); color: #1a1200; }
.btn-hero { background: var(--text); color: #000; border-color: var(--text); }
.btn-active { background: var(--text) !important; color: #000 !important; border-color: var(--text) !important; }

canvas {
  width: 100%;
  height: auto;
  background: #000;
  border-radius: var(--radius-md);
  display: block;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-bottom: 10px;
  background: var(--glass);
  border: 1px solid var(--hairline);
}
.badge.bg-live { color: var(--accent-live); }
.badge.bg-replay { color: var(--accent-replay); }
.badge.bg-paused { color: var(--text-dim); }
.status-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.status-row .icon-btn {
  width: 34px;
  height: 34px;
  margin-bottom: 10px;
}
.status-row .icon-btn svg { width: 15px; height: 15px; }
.rec-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
.badge.bg-live .rec-dot { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

#cameraArea, #monitorArea { display: none; }
.controls-row {
  display: flex;
  justify-content: center;
  gap: var(--gap);
  margin-top: 6px;
  flex-wrap: wrap;
}
.cam-selector {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.cam-selector button {
  flex: 1 1 auto;
  min-width: 72px;
  padding: 10px 4px;
  font-size: 0.82rem;
}
.cam-selector button.cam-offline {
  opacity: 0.4;
}

/* --- 再生コントロール（プレイヤーツールバー） --- */
.time-readout {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.3px;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s var(--ease);
}
.time-readout.is-replay { color: var(--accent-replay); }

.primary-actions { margin-top: 10px; }
.action-btn {
  flex: 1;
  padding: 15px;
  font-size: 0.98rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.action-btn svg { width: 18px; height: 18px; }

.player-toolbar {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
}
.player-toolbar.show {
  display: flex;
}
.save-row {
  display: none;
  margin-top: 10px;
}
.save-row.show {
  display: flex;
}
.save-btn {
  width: 100%;
}
.icon-btn {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  background: var(--glass);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn-primary {
  width: 60px;
  height: 60px;
  background: var(--text);
  color: #000;
}
.icon-btn-primary svg { width: 24px; height: 24px; }
.speed-btn {
  width: auto;
  min-width: 56px;
  height: 40px;
  border-radius: 20px;
  font-size: 0.9rem;
  padding: 0 14px;
  background: var(--glass);
  align-self: center;
}
.step-btn {
  min-width: 0;
  padding: 0 10px;
  font-size: 0.8rem;
  white-space: nowrap;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  padding: 0;
  margin: 10px 0 0 0;
  background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--glass-strong);
  border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  margin-top: -6px;
  border: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--glass-strong);
  border-radius: 2px;
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  border: none;
}
input[type="range"]:disabled::-webkit-slider-thumb { background: var(--text-dim); }
input[type="range"]:disabled::-moz-range-thumb { background: var(--text-dim); }

/* --- トースト通知(alert()の代わり) --- */
.toast {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%) translateY(-16px);
  max-width: 86vw;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--text);
  text-align: center;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- 初心者向けの補足説明 --- */
.help-text {
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.5;
  margin: 4px 4px 0 4px;
  text-align: left;
}

/* --- 使い方ヘルプ(FAB + ボトムシート) --- */
.help-fab {
  position: fixed;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--glass-strong);
  font-size: 1.2rem;
  font-weight: 700;
  z-index: 60;
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
}
.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 55;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease);
}
.help-overlay.open { opacity: 1; pointer-events: auto; }
.help-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 65vh;
  overflow-y: auto;
  background: var(--surface);
  border-top: 1px solid var(--hairline);
  border-radius: 20px 20px 0 0;
  padding: 10px 20px max(20px, env(safe-area-inset-bottom));
  z-index: 58;
  text-align: left;
  transform: translateY(100%);
  transition: transform 0.28s var(--ease);
  box-shadow: 0 -4px 24px rgba(0,0,0,0.5);
}
.help-sheet.open { transform: translateY(0); }
.help-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--hairline);
  border-radius: 2px;
  margin: 4px auto 14px;
}
.help-sheet h3 { margin: 0 0 12px 0; font-size: 1.05rem; }
.help-sheet h4 { margin: 16px 0 4px 0; font-size: 0.92rem; }
.help-sheet h4:first-of-type { margin-top: 0; }
.help-sheet p { margin: 0; font-size: 0.85rem; color: var(--text-dim); line-height: 1.65; }

/* 外部リンク(公式LINEなど)を通常のボタンと同じ見た目で出す */
.link-btn {
  display: block;
  margin: 10px 3px 0;
  padding: 12px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  color: var(--text);
  background: var(--glass);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  transition: opacity 0.15s var(--ease), transform 0.15s var(--ease);
}
.link-btn:active { opacity: 0.6; transform: scale(0.97); }
