/* 撮影画面のスタイル（K4）。スマホの横向きで、車載時に離れて見ても読めることを優先する。 */

:root {
  --bg: #101418;
  --panel: #1b2229;
  --text: #f2f5f7;
  --muted: #a9b4be;
  --line: #36424d;
  --primary: #2f80ed;
  --danger: #e5484d;
  --warn-bg: #4a3a00;
  --warn-text: #ffd866;
  --error-bg: #4a1518;
  --error-text: #ffb3b5;
  --ok: #3ddc84;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

/* hidden 属性を、display を指定した要素でも必ず効かせる（録画中に他の操作を見せないため） */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.screen {
  max-width: 960px;
  margin: 0 auto;
}

h1 {
  margin: 0 0 8px;
  font-size: 1.4rem;
}

h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

p {
  margin: 0 0 12px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--muted);
}

.panel {
  margin: 0 0 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

fieldset.panel {
  min-width: 0;
}

legend {
  padding: 0 6px;
  color: var(--muted);
}

.conditions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.field label,
.login-form label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

select,
input[type="text"] {
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem; /* 16px 未満だと iOS が入力時に拡大する */
}

.login-form {
  display: grid;
  gap: 12px;
  max-width: 480px;
}

.button {
  min-height: 48px;
  padding: 10px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  touch-action: manipulation;
}

.button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.button.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.button.large {
  width: 100%;
  min-height: 72px;
  font-size: 1.5rem;
}

.button.small {
  min-height: 48px; /* 文字は小さくても、タップ領域は 48px を保つ */
  padding: 6px 12px;
  font-size: 0.9rem;
}

a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.button:disabled {
  opacity: 0.4;
}

.button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.message {
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--panel);
}

.message.warning {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.message.error {
  background: var(--error-bg);
  color: var(--error-text);
}

.page-url {
  padding: 8px 12px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  overflow-wrap: anywhere;
  user-select: all;
  -webkit-user-select: all;
}

/* プレビューと水平ガイド */
.preview {
  position: relative;
  padding: 0;
  overflow: hidden;
  background: #000;
}

.preview-video {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  background: #000;
}

.level {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.level-base,
.level-line {
  grid-area: 1 / 1;
  width: 70%;
  height: 0;
}

.level-base {
  border-top: 1px dashed rgba(255, 255, 255, 0.6);
}

.level-line {
  border-top: 3px solid var(--ok);
  transform-origin: center;
}

.level.is-warning .level-line {
  border-top-color: var(--danger);
}

.level-readout {
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
}

.permission-list,
.session-list {
  margin: 0 0 12px;
  padding-left: 1.2em;
}

.issue-list {
  margin: 0 0 12px;
  padding: 8px 12px 8px 2em;
}

.session-list {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.1rem;
  overflow-wrap: anywhere;
  user-select: all;
  -webkit-user-select: all;
}

/* 録画中 */

/*
 * 停止ボタンは画面の下端に固定する。警告がいくつ出ても、横向きの低い画面（高さ 320px 程度）でも、
 * スクロールなしで押せる位置にある。下の余白は、固定したボタンが内容に重ならないための分。
 */
.stop-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  padding: 8px max(16px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.stop-bar .button.large {
  min-height: 64px;
}

#app[data-phase="recording"] {
  padding-bottom: calc(64px + 16px + max(8px, env(safe-area-inset-bottom)) + 12px);
}

.rec-indicator {
  color: var(--danger);
  font-weight: 700;
}

[data-phase="stopping"] .rec-indicator {
  display: none;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin: 0 0 12px;
}

.stat {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.stat dt {
  color: var(--muted);
  font-size: 0.85rem;
}

.stat dd {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.relogin {
  margin-bottom: 12px;
}

/* 横向きでは、プレビューと操作を左右に並べる */
@media (orientation: landscape) and (min-width: 640px) {
  [data-phase="ready"] .screen-capture,
  [data-phase="recording"] .screen-capture,
  [data-phase="stopping"] .screen-capture {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    gap: 12px;
    align-items: start;
  }

  [data-phase="ready"] .app-header,
  [data-phase="ready"] .conditions {
    grid-column: 1 / -1;
  }

  .preview-video {
    max-height: 70vh;
  }
}
