:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --card: #fff;
  --text: #203044;
  --muted: #526174;
  --line: #d9e1e8;
  --accent: #237685;
  --danger: #b3261e;
  --ok: #1b6e3a;
  --warn: #8a5a00;
  font-family: system-ui, "Microsoft JhengHei", sans-serif;
  line-height: 1.6;
}
* { box-sizing: border-box; }
/* 作者樣式的 display 會蓋過 hidden 屬性（小米實測曾因此擋住按鈕） */
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left));
}
h1 { font-size: 1.5rem; margin: .4em 0; }
h2 { font-size: 1.1rem; margin: 1.4em 0 .4em; border-bottom: 1px solid var(--line); padding-bottom: .3em; }
.note { background: #edf5f7; border-left: 4px solid var(--accent); padding: 8px 12px; margin: 0; }
.hint { color: var(--muted); font-size: .9rem; margin: .3em 0; }
.hint.error { color: var(--danger); }
.fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
label { display: grid; gap: 4px; font-weight: 600; }
label.block { margin: 8px 0; }
select, button, textarea { font: inherit; min-height: 44px; }
textarea {
  width: 100%;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-weight: 400;
  line-height: 1.6;
  resize: vertical;
}
textarea.invalid { border-color: var(--danger); }
input[type="range"] { width: 100%; min-width: 0; height: 44px; margin: 0; accent-color: var(--accent); }
output { font-variant-numeric: tabular-nums; }
.hint.warn { color: var(--warn); }
select { width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
select.attention { border-color: var(--warn); box-shadow: 0 0 0 3px #f3d9a4; }
.buttons { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 0; }
button {
  min-width: 44px;
  padding: 8px 16px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: var(--card);
  color: var(--accent);
  font-weight: 700;
}
button.primary { background: var(--accent); color: #fff; }
button:disabled { opacity: .4; }
button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible { outline: 3px solid #df8b13; outline-offset: 2px; }
.status { font-weight: 700; min-height: 1.6em; }
.status.error { color: var(--danger); }
.status.busy::before { content: "⏳ "; }

/* 取景框：固定 9:16，就是成片的範圍；其他控制放在框外 */
.stage {
  position: relative;
  aspect-ratio: 9 / 16;
  height: min(60vh, 640px);
  max-width: 100%;
  margin: 0 auto;
  background: #000;
  border: 2px solid #000;
}
.stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transform: scaleX(-1); /* 只鏡像顯示層，錄製的串流不受影響 */
}
.stage-wrap { position: relative; }
/* 提詞：疊在取景框上緣，半透明深底白字，只在顯示層，不進串流 */
.prompter {
  position: absolute;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  right: 0;
  padding: 8px 12px;
  background: rgba(0, 0, 0, .62);
  color: #fff;
  font-size: var(--prompter-font-size, 28px);
  line-height: var(--prompter-line-height, 42px);
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .8);
}
.prompter-viewport { overflow: hidden; }
.prompter-scroller { position: relative; will-change: transform; }
.prompter-scroller p {
  margin: 0 0 calc(var(--prompter-line-height, 42px) / 2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.prompter-scroller p:last-child { margin-bottom: 0; }
.control-group { display: inline-flex; gap: 6px; }
button.danger { border-color: var(--danger); background: var(--danger); color: #fff; }
.timer { font-variant-numeric: tabular-nums; font-size: 1.4rem; font-weight: 700; min-width: 4.5ch; }
#playback { width: 100%; max-height: 60vh; background: #000; }

/* 倒數：蓋在取景框上，數字大、可取消；只在 DOM，不進串流 */
.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 16px;
  background: rgba(0, 0, 0, .35);
  color: #fff;
  text-align: center;
}
.countdown-number { font-size: 96px; line-height: 1; margin: 0; font-weight: 700; text-shadow: 0 2px 8px #000; }
.countdown button { background: #fff; color: var(--text); border-color: #fff; }
.warn-banner, .rec-indicator {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}
.warn-banner { bottom: 16px; background: var(--warn); }
.rec-indicator { top: 50%; right: 8px; left: auto; transform: none; background: rgba(179, 38, 30, .85); font-size: .85rem; }

/* 錄影畫面：取景框與提詞占滿螢幕、控制列釘在底部；不用全螢幕 API（Spec 8） */
body.recording { overflow: hidden; }
body.recording .stage-wrap {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: #000;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-bottom: 72px;
}
body.recording .stage {
  width: min(100vw, calc((100dvh - 72px) * 9 / 16));
  height: auto;
  border: 0;
}
body.recording .prompter { top: max(8px, env(safe-area-inset-top, 0px)); }
body.recording .prompter-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 11;
  margin: 0;
  padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, .85);
  justify-content: center;
}
body.recording .prompter-controls button { background: #222; color: #fff; border-color: #666; }
body.recording .prompter-controls button.danger { background: var(--danger); border-color: var(--danger); }
body.recording .prompter-controls .timer { color: #fff; }
.stage-overlay {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  color: #ddd;
  text-align: center;
  padding: 16px;
  pointer-events: none;
}
.info { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 8px 0; }
.info:empty { display: none; }
.info dt { font-weight: 700; }
.info dd { margin: 0; overflow-wrap: anywhere; }
.checks { list-style: none; padding: 0; margin: 0; }
.checks li { padding: 2px 0; }
.checks .ok::before { content: "✔ "; color: var(--ok); font-weight: 700; }
.checks .bad::before { content: "✘ "; color: var(--danger); font-weight: 700; }
