/* Maily Aufnahme — calm studio tool.
   One idea: the camera monitor is the dark centre of the screen; everything else is quiet, neutral controls. */

:root {
  --bg: #f3f3f1;
  --surface: #fff;
  --field: #fafaf8;
  --line: #e4e4df;
  --line-strong: #d2d3cc;
  --hover: #efefeb;
  --text: #1c1e1a;
  --text-2: #555a51;
  --text-3: #7d8278;
  --accent: #3e6b2d;
  --accent-hover: #345b26;
  --accent-soft: #e9f0e2;
  --rec: #d0392b;
  --danger-text: #962a1e;
  --danger-bg: #fcece9;
  --danger-line: #eeb8ae;
  --warn-text: #5a420c;
  --warn-bg: #fbf2da;
  --warn-line: #ead39a;
  --monitor: #191a18;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%237d8278' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, textarea, select { font: inherit; color: inherit; }
button, summary, select { cursor: pointer; }
button { transition: background-color .14s, border-color .14s, color .14s; }
button:disabled, select:disabled { cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible, .preview-prompter:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em; line-height: 1.2; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- Header ---------- */
header.studio-nav { height: 48px; display: flex; align-items: center; gap: 24px; padding: 0 20px; }
.app-name { font-size: 14px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
.app-name span { color: var(--text-3); font-weight: 450; margin-left: 2px; }
.studio-nav nav { display: flex; gap: 2px; }
.studio-nav nav button { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--text-2); font-size: 13px; font-weight: 500; }
.studio-nav nav button:hover { background: var(--hover); color: var(--text); }
.studio-nav nav button[aria-pressed=true] { background: #e5e5e0; color: var(--text); font-weight: 600; }
.count { min-width: 18px; padding: 1px 5px; border-radius: 9px; background: #dcdcd6; color: var(--text-2); font-size: 11px; font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
main { padding: 0 20px 20px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(345px, 1fr); gap: 20px; min-height: 0; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 28px; }

/* Left column: one quiet panel, sections divided by a single hairline. */
.setup { display: flex; flex-direction: column; gap: 20px; min-height: 0; padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.device-setup { display: grid; gap: 12px; }
.text-setup { display: flex; flex-direction: column; gap: 12px; min-height: 0; flex: 1; }

/* ---------- Controls ---------- */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 13px; font-weight: 500; white-space: nowrap; }
.button:hover:not(:disabled) { background: var(--hover); }
.button:disabled { color: #a3a69e; background: var(--field); border-color: var(--line); }

/* Connect: the primary action until devices are connected, then a quiet secondary. */
.connect { width: 100%; min-height: 40px; background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.connect:hover:not(:disabled) { background: var(--accent-hover); }
.connect span { display: none; }
.device-setup:has(#deviceStatus.ready) .connect { min-height: 36px; background: var(--surface); border-color: var(--line-strong); color: var(--text); font-weight: 500; }
.device-setup:has(#deviceStatus.ready) .connect:hover:not(:disabled) { background: var(--hover); }
.device-setup:has(#deviceStatus.ready) .connect span { display: inline; color: var(--text-3); }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); white-space: nowrap; }
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #b9bcb3; }
.badge.ready { color: var(--accent); font-weight: 500; }
.badge.ready::before { background: #4b8a34; }
.badge.lost { color: var(--rec); font-weight: 500; }
.badge.lost::before { background: var(--rec); }

label { display: block; min-width: 0; font-size: 12px; font-weight: 500; color: var(--text-2); }
select { display: block; width: 100%; min-width: 0; height: 36px; margin-top: 6px; padding: 0 30px 0 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface) var(--chevron) no-repeat right 11px center; color: var(--text); font-size: 13px; font-weight: 400; text-overflow: ellipsis; appearance: none; }
select:hover:not(:disabled) { border-color: #babcb4; }
select:disabled { color: var(--text-3); background-color: var(--field); }
.device-fields { display: grid; gap: 5px; }
.device-fields label { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 8px; }
.device-fields select { margin-top: 0; }

.sound { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; font-size: 12px; color: var(--text-3); }
.meter { height: 6px; border-radius: 3px; background: #e8e8e4; overflow: hidden; }
.meter > div { height: 100%; width: 0; background: #5f9a43; transition: width .08s; }
.meter > div.clip { background: var(--rec); }
#soundLabel { color: var(--text-2); font-weight: 500; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.hint { margin: 0; font-size: 12px; line-height: 1.45; color: var(--text-3); }
.subtle { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.hardware-help { position: relative; font-size: 12px; color: var(--text-3); }
.hardware-help summary { display: inline-flex; align-items: center; gap: 6px; list-style: none; border-radius: 4px; }
.hardware-help summary::-webkit-details-marker { display: none; }
.hardware-help summary::before { content: '?'; display: grid; place-items: center; width: 15px; height: 15px; border: 1px solid var(--line-strong); border-radius: 50%; font-size: 10px; font-weight: 600; }
.hardware-help summary:hover { color: var(--text); }
.hardware-help[open] summary { color: var(--text); }
.hardware-help > div { position: absolute; top: 26px; left: 0; right: 0; z-index: 10; max-height: 240px; overflow-y: auto; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(20, 22, 18, .14); color: var(--text-2); font-size: 13px; line-height: 1.5; }
.hardware-help p { margin: 0 0 8px; }
.hardware-help p:last-child { margin: 0; }

/* Text section */
.title-actions { display: flex; gap: 4px; margin-left: auto; }
.section-title h2 label { font: inherit; color: inherit; }
.file-button { height: 30px; padding: 0 10px; border: 1px solid #c6cbc1; border-radius: 7px; background: var(--field); color: var(--text-2); font-size: 12px; font-weight: 500; }
.file-button:hover { background: var(--hover); color: var(--text); }
textarea { flex: 1; width: 100%; min-height: 96px; padding: 12px 14px; resize: none; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--field); color: var(--text); font-size: 14px; line-height: 1.55; }
textarea:focus { background: var(--surface); }
textarea::placeholder { color: #58644f; }
#script:placeholder-shown { background: #f4f7ef; border: 1.5px dashed #87997b; }
#script:focus { border: 1.5px solid var(--accent); background: var(--surface); }
.device-fields select { border-color: #bfc6b8; background-color: var(--field); font-weight: 500; }
.device-fields select[data-missing="true"] { border-color: #b7a16b; background-color: #fbf8ef; }
#script.drop-active { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--accent-soft); }
.script-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: -4px; flex: none; }
#readTime { flex: none; white-space: nowrap; }

kbd { display: inline-block; padding: 0 5px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface); font: 500 11px/16px inherit; font-family: inherit; color: var(--text-2); }

.script-settings { display: grid; gap: 20px; }
.setting > label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.setting > label > span { color: var(--text-3); font-weight: 400; font-variant-numeric: tabular-nums; white-space: nowrap; }
.setting output { color: var(--text); font-weight: 500; }
.tempo-row { display: flex; align-items: center; gap: 8px; height: 30px; margin-top: 6px; }
.tempo-row button { flex: none; width: 28px; height: 28px; padding: 0; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--surface); color: var(--text); font-size: 16px; line-height: 1; }
.tempo-row button:hover { background: var(--hover); }
input[type=range] { flex: 1; min-width: 0; width: 100%; margin: 0; accent-color: var(--accent); }

.prompter-actions { display: flex; gap: 8px; flex: none; }
.text-play { flex: 1; min-width: 0; padding: 0 10px; overflow: hidden; text-overflow: ellipsis; background: #ececE8; border-color: transparent; font-weight: 600; }
.text-play:hover:not(:disabled) { background: #e2e2dd; }
.text-play.running { background: var(--accent-soft); border-color: #c5d7b7; color: var(--accent); }

.prompter-actions .reset { flex: none; width: 36px; padding: 0; font-size: 17px; }
#openPrompter { flex: none; padding: 0 12px; }
#popupFallback { font-size: 12px; color: var(--accent); }

/* ---------- Monitor (right) ---------- */
section.recording { container-type: inline-size; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 clamp(12px, 1.3vw, 20px) 16px; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.stage-toolbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; height: 44px; flex: none; }
.stage-state { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; letter-spacing: .05em; color: var(--text-2); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #b9bcb3; flex: none; }
.live-dot.ready { background: #4b8a34; }
.live-dot.is-recording { background: var(--rec); animation: pulse 1.2s ease-in-out infinite; }
.stage-state:has(.is-recording) { color: var(--rec); }
@keyframes pulse { 50% { opacity: .35; } }
/* Live sound next to the stage status: visible at a glance while recording. */
.stage-level { display: inline-flex; align-items: center; gap: 7px; margin-left: 6px; padding-left: 12px; border-left: 1px solid var(--line); font-weight: 500; letter-spacing: 0; color: var(--text-2); }
.stage-level[hidden] { display: none; }
.stage-state, .stage-level { white-space: nowrap; }
@media (max-width: 1180px) {
  /* The red dot and timer already say "recording"; keep the sound state on one line. */
  .stage-state:has(.stage-level:not([hidden])) #stageStatus { display: none; }
  .stage-level { margin-left: 0; padding-left: 0; border-left: 0; }
}
.stage-level .bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.stage-level i { width: 3px; border-radius: 1px; background: #d6d7d1; transition: background .08s; }
.stage-level i:nth-child(1) { height: 5px; } .stage-level i:nth-child(2) { height: 7px; } .stage-level i:nth-child(3) { height: 9px; } .stage-level i:nth-child(4) { height: 11px; } .stage-level i:nth-child(5) { height: 14px; }
.stage-level i.on { background: #4b8a34; }
.stage-level.clip i.on { background: var(--rec); }
.stage-level.silent #stageSound { color: var(--rec); font-weight: 600; }
.stage-state:has(.is-recording) .stage-level:not(.silent) #stageSound { color: var(--text-2); }

#rotateCamera { padding: 4px 9px; min-height: 30px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); white-space: nowrap; font-size: 12px; }
#rotateCamera:disabled { opacity: .5; }
#timer { justify-self: end; font: 500 15px/1 ui-monospace, 'SF Mono', Menlo, monospace; font-variant-numeric: tabular-nums; color: var(--text-2); }
.stage-toolbar:has(.is-recording) #timer { color: var(--rec); font-weight: 600; }

.stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--monitor); transition: box-shadow .2s; }
.recording:has(.record-button.is-recording) .stage { box-shadow: 0 0 0 3px var(--rec); }
.frame { position: relative; flex: none; overflow: hidden; background: #242424; }
.frame video { position: absolute; left: 50%; top: 50%; object-fit: cover; display: block; transform: translate(-50%, -50%) scaleX(var(--mirror, 1)) rotate(var(--rotation, 0deg)); }
.frame video.mirrored { --mirror: -1; }
#emptyStage { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 16px; text-align: center; color: #8f938b; font-size: 12px; line-height: 1.45; }
#emptyStage strong { color: #e4e5e1; font-size: 14px; font-weight: 500; }

/* Simulated Instagram UI, scaled with the 9:16 frame. */
.reels-guide { position: absolute; inset: 0; z-index: 2; container-type: inline-size; pointer-events: none; user-select: none; color: #fff; background: linear-gradient(transparent 70%, #0005); }
.reel-actions { position: absolute; right: 3%; bottom: 7%; display: grid; justify-items: center; gap: 2.8cqw; text-shadow: 0 1px 3px #0009; }
.reel-actions > div { display: grid; justify-items: center; gap: .5cqw; font-size: 2.9cqw; font-weight: 600; }
.reel-actions svg { width: 6.2cqw; height: 6.2cqw; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 1px 2px #0007); }
.reel-actions .reel-more { fill: currentColor; stroke: none; }
.reel-caption { position: absolute; left: 3.6%; right: 15%; bottom: 2.3%; display: grid; gap: 1.6cqw; text-shadow: 0 1px 3px #0008; font-size: 3.4cqw; }
.reel-profile { display: flex; align-items: center; gap: 2cqw; }
.reel-avatar { display: grid; place-items: center; width: 7cqw; height: 7cqw; border: 1px solid #fffa; border-radius: 50%; color: #262626; background: #fafafa; font-size: 2.8cqw; font-weight: 700; text-shadow: none; }
.reel-audio { font-size: 2.9cqw; }
.reel-cta { display: flex; justify-content: space-between; align-items: center; border-radius: 1.3cqw; padding: 1.5cqw 2.3cqw; background: #ffffffeb; color: #222; font-weight: 600; text-shadow: none; }

.preview-prompter { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; color: #fff; mask-image: linear-gradient(transparent, #000 7%, #000 88%, transparent); background: linear-gradient(#0006, transparent 70%); }
.preview-prompter > div { padding: 10% 14px 90%; font-size: clamp(15px, 2.3vh, 21px); font-weight: 600; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; text-shadow: 0 1px 4px #0009; }
.countdown { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; background: rgba(0, 0, 0, .45); color: #fff; font-size: 96px; font-weight: 600; font-variant-numeric: tabular-nums; }

input.switch { appearance: none; position: relative; flex: none; width: 32px; height: 18px; margin: 0; border: 0; border-radius: 9px; background: #cfd0c9; cursor: pointer; transition: background-color .14s; }
input.switch::before { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: transform .14s; }
input.switch:checked { background: var(--accent); }
input.switch:checked::before { transform: translateX(14px); }
input.switch:disabled { opacity: .5; cursor: not-allowed; }

/* Status + record */
.record-panel { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; flex: none; }
#micWarning, #senderReminder:not([hidden]) { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; padding: 9px 12px; border: 1px solid; border-radius: 8px; font-size: 13px; line-height: 1.4; }
#micWarning { border-color: var(--danger-line); background: var(--danger-bg); color: var(--danger-text); font-weight: 500; flex-wrap: nowrap; }
#micWarning::before { content: '!'; display: grid; place-items: center; flex: none; width: 18px; height: 18px; border-radius: 50%; background: var(--rec); color: #fff; font-size: 12px; font-weight: 700; }
#senderReminder { border-color: var(--warn-line); background: var(--warn-bg); color: var(--warn-text); }
#senderReminder strong { font-weight: 600; }
#senderReminder button { margin-left: auto; padding: 4px 2px; border: 0; background: transparent; color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
#senderReminder:not([hidden]) + .message:not(.error) { display: none; }
.message { min-height: 19px; margin: 0; font-size: 13px; line-height: 1.45; color: var(--text-2); }
.message.error { color: var(--danger-text); font-weight: 500; }

.record-actions { display: flex; align-items: stretch; gap: 12px; flex: none; }
.timer-setting { display: flex; align-items: center; gap: 8px; flex: none; font-size: 12px; }
.timer-setting select { width: 96px; height: 48px; margin: 0; }
.record-button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 48px; border: 0; border-radius: 10px; background: var(--text); color: #fff; font-size: 15px; font-weight: 600; }
.record-button:hover:not(:disabled) { background: #30332d; }
.record-button:disabled { background: #deded9; color: #8d9188; }
.record-button.is-recording { background: var(--rec); }
.record-button.is-recording:hover:not(:disabled) { background: #b93224; }
.record-icon { width: 12px; height: 12px; border-radius: 50%; background: #f0543f; flex: none; }
.record-button:disabled .record-icon { background: #b9bbb4; }
.is-recording .record-icon { border-radius: 2px; background: #fff; }

/* ---------- Takes ---------- */
.takes-section { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 1080px; min-height: 0; margin: 0 auto; padding-top: 8px; }
.takes-section > .section-title { flex-direction: column; align-items: flex-start; gap: 4px; }
.takes-section h2 { font-size: 20px; letter-spacing: -.015em; }
.takes-section > .hint { padding: 9px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-text); font-size: 13px; }
#libraryMessage:not(:empty) { font-size: 13px; color: var(--text-2); }
.sync-copy { padding: 2px 4px; border: 0; background: transparent; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.takes { min-height: 0; overflow-y: auto; overscroll-behavior: contain; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.takes-empty { padding: 48px 24px; text-align: center; color: var(--text-3); font-size: 13px; }
.take { display: flex; align-items: center; gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.take:last-child { border-bottom: 0; }
.take:hover { background: #fafaf8; }
.take-title { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.take-title strong { display: block; font-size: 14px; font-weight: 500; }
.take-title span { display: block; margin-top: 3px; font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.take button, .take a { height: 32px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--surface); color: var(--text); font-size: 13px; font-weight: 500; text-decoration: none; white-space: nowrap; }
.take button:hover:not(:disabled), .take a:hover { background: var(--hover); }
.take .delete { width: 32px; padding: 0; border-color: transparent; background: transparent; color: var(--text-3); font-size: 18px; line-height: 1; }
.take .delete:hover:not(:disabled) { background: var(--danger-bg); color: var(--danger-text); }
.take .delete:disabled { opacity: .35; }
.take .take-preview { position: relative; flex: none; width: 96px; height: 54px; padding: 0; overflow: hidden; border: 0; border-radius: 6px; background: var(--monitor) center / contain no-repeat; }
.take .take-preview:hover:not(:disabled) { background-color: var(--monitor); }
.take-preview span { position: absolute; inset: 0; display: grid; place-items: center; width: 26px; height: 26px; margin: auto; border-radius: 50%; background: rgba(0, 0, 0, .55); color: #fff; font-size: 11px; transition: background-color .14s; }
.take-preview:hover span { background: var(--accent); }

/* ---------- Dialogs ---------- */
dialog { max-width: 90vw; max-height: 90vh; padding: 20px; border: 0; border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: 0 24px 64px rgba(16, 18, 14, .28); }
dialog::backdrop { background: rgba(20, 21, 19, .55); }
dialog h2 { font-size: 16px; }
dialog p { margin: 8px 0 0; font-size: 14px; line-height: 1.5; color: var(--text-2); }
dialog button { height: 34px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); font-size: 13px; font-weight: 500; }
dialog button:hover:not(:disabled) { background: var(--hover); }
#decision { width: min(380px, 90vw); }
#decision form > div { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
#decisionAction { background: var(--text); border-color: var(--text); color: #fff; }
#decisionAction:hover { background: #30332d; }
#playback { padding: 16px; }
.playback-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
#playbackTitle { margin: 0; font-size: 14px; font-weight: 500; color: var(--text); }
#closePlayback { min-height: 32px; height: 32px; }
dialog video { display: block; max-width: 80vw; max-height: 70vh; margin-top: 12px; border-radius: 8px; background: #000; }
#rodeChoice { width: min(460px, 92vw); }
.rode-candidate { display: grid; gap: 6px; margin: 12px 0; }
.rode-candidate button { height: auto; min-height: 34px; padding: 6px 12px; text-align: left; }
.rode-candidate audio { width: 100%; height: 32px; }
.rode-choice-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
#rodeCancel { margin-left: auto; }

/* ---------- External teleprompter window ---------- */
.prompter-mode { overflow: hidden; background: #0b0c0b; color: #f2f2ef; }
#prompterView { height: 100dvh; }
#externalScroll { height: 100%; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; mask-image: linear-gradient(transparent, #000 14%, #000 80%, transparent); }
#externalScroll:focus-visible { outline: none; }
#externalText { max-width: 1100px; margin: auto; padding: 0 64px; font-size: 44px; font-weight: 600; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
#externalReset { position: fixed; right: 16px; bottom: 16px; width: 40px; height: 40px; border: 0; border-radius: 8px; background: #1b1d1a; color: #b8bcb3; font-size: 20px; }
#externalReset:hover, #externalReset:focus-visible { background: #2c2f2a; color: #fff; }

/* ---------- Responsive ---------- */
/* MacBook views from 1000 × 620: everything fits, no page scrolling. */
@media (min-width: 1000px) and (min-height: 620px) {
  main#studio, header.studio-nav { max-width: 1400px; margin-inline: auto; }
  body:not(.prompter-mode) { height: 100dvh; overflow: hidden; }
  main#studio { display: grid; grid-template-rows: minmax(0, 1fr); height: min(calc(100dvh - 48px), 775px); }
  #takeLibrary { height: 100%; }
}
@media (min-width: 1000px) and (max-height: 760px) {
  header.studio-nav { height: 44px; }
  main { padding: 0 16px 16px; }
  main#studio { height: calc(100dvh - 44px); }
  .workspace { gap: 16px; }
  .setup { padding: 16px; gap: 14px; }
  .device-setup, .text-setup { gap: 10px; }

  .connect { min-height: 36px; }
  .button { min-height: 34px; }
  select { height: 34px; }
  textarea { min-height: 64px; padding: 10px 12px; }
  .stage-toolbar { height: 38px; }
  .record-panel { gap: 6px; padding-top: 4px; }
  .record-button, .timer-setting select { min-height: 44px; height: 44px; }
}


/* Narrow or short windows: normal page scrolling. */
@media (max-width: 999px), (max-height: 619px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 320px; }
  section.recording { min-height: 600px; }
  textarea { min-height: 160px; }
  .takes { max-height: none; }
}
@media (max-width: 760px) {
  header.studio-nav { gap: 16px; padding: 0 16px; }
  main { padding: 0 16px 24px; }
  .workspace { display: flex; flex-direction: column; gap: 24px; }
  .setup { padding: 16px; }
  textarea { min-height: 140px; }
  section.recording { min-height: 0; }
  .stage { flex: none; height: min(64vh, 560px); }

  .button, select { min-height: 40px; height: auto; }
  select { height: 40px; }
  .tempo-row button { width: 36px; height: 36px; }
  .tempo-row { height: 36px; }
  .record-actions { gap: 8px; }
  .timer-setting { gap: 6px; }
  .timer-setting select { width: 88px; }
  .take { flex-wrap: wrap; gap: 8px 12px; padding: 12px; }
  .take-title { flex-basis: calc(100% - 148px); }
  .take > button:not(.take-preview):not(.delete) { flex: 1; }
  #externalText { padding: 0 32px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media (max-width: 420px) {
  .stage-toolbar { grid-template-columns: auto 1fr auto; gap: 4px; }
  .stage-level #stageSound { display: none; }
}

.device-fields .device-field { display: grid; grid-template-columns: 64px minmax(0,1fr); align-items: center; gap: 8px; }
.device-fields label { display: block; }
.device-select { position: relative; min-width: 0; }
.device-select select { position: absolute; width: 1px; height: 1px; padding: 0; clip-path: inset(50%); pointer-events: none; }
.device-trigger { width: 100%; height: 36px; border: 1px solid #bfc6b8; border-radius: 8px; background: var(--field) var(--chevron) no-repeat right 12px center; text-align: left; padding: 0 30px 0 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.device-trigger:disabled { color: var(--text-3); }
.device-trigger[aria-expanded=true] { border-color: var(--accent); }
.device-menu { position: absolute; inset: calc(100% + 4px) 0 auto; z-index: 10; max-height: 250px; overflow-y: auto; padding: 4px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); box-shadow: 0 5px 18px #0002; }
.device-group { padding: 6px 8px 3px; font-size: 11px; color: var(--text-2); }
.device-menu button { display: block; width: 100%; min-height: 32px; padding: 5px 25px 5px 8px; border: 0; border-radius: 5px; text-align: left; background: transparent; color: var(--text); }
.device-menu button:focus, .device-menu button:hover { background: var(--hover); }
.device-menu button[aria-selected=true] { position: relative; background: var(--accent-soft); }
.device-menu button[aria-selected=true]::after { content: '✓'; position: absolute; right: 8px; }
.device-menu button:disabled { color: var(--text-3); }
#resolutionInfo { margin-left: auto; color: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.take-check { width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.take:has(.take-check:checked) { background: var(--accent-soft); }
.take-title { cursor: pointer; user-select: none; }
#deleteSelection { align-self: flex-start; color: var(--danger-text); }

.take-tools { display:flex; align-items:center; flex-wrap:wrap; gap:4px 10px; font-size:12px; }
#testStatus { color:var(--text-2); }
.script-name { width:100%; min-height:30px; border:1px solid var(--line-strong); border-radius:6px; padding:4px 9px; background:var(--surface); color:var(--text); font:inherit; font-size:13px; }
#review p { margin:10px 0; font-size:14px; }

.quiet-button { padding: 4px 0; color: var(--accent); background: transparent; border: 0; font-size: 12px; font-weight: 550; }
.quiet-button:hover { text-decoration: underline; }
.settings-form { display: grid; gap: 20px; }

.name-field { display: grid; gap: 6px; }
.prompter-actions { border-top: 1px solid var(--line); padding-top: 10px; }
.text-play:not(:disabled):not(.running) { background: var(--accent-soft); color: var(--accent-hover); }
.record-panel { margin-top: 8px; border-top: 1px solid var(--line); }
.take-tools .file-button:disabled { opacity: .55; cursor: default; }
@media (min-width: 1600px) and (min-height: 850px) {
  header.studio-nav { height: 64px; }
  main#studio, header.studio-nav { max-width: clamp(1400px, 84vw, 1680px); }
  body:not(.prompter-mode) {
    --studio-height: min(82dvh, 880px);
    padding-top: clamp(0px, calc((100dvh - var(--studio-height) - 64px) / 2), 24px);
  }
  main#studio { height: var(--studio-height); }
  .workspace { grid-template-columns: minmax(0, 1.55fr) minmax(420px, 1fr); gap: 24px; }
}

/* Studio workspace */
header.studio-nav { gap: 24px; }
.app-name { font-size: 21px; letter-spacing: -.055em; }
.app-name span { margin-left: 4px; font-size: 14px; letter-spacing: -.015em; color: var(--text-2); }
#connectPreview { padding: 8px 12px; border-radius: 8px; font-weight: 550; }



.setup { background: transparent; padding: 0; border: 0; gap: 14px; min-width: 0; }
.text-setup, .device-setup { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.text-setup h2 { font-size: 19px; letter-spacing: -.025em; }
.device-setup { gap: 9px; }
.device-setup .connect { min-height: 32px; }
.device-setup .hardware-help > div { top: auto; bottom: 26px; }
section.recording { border-radius: 14px; padding: 0 14px 14px; }
.stage-toolbar { height: 54px; gap: 8px; grid-template-columns: minmax(0,1fr) auto auto; }
.framing-preset select { margin: 0; width: auto; height: 32px; font-weight: 500; }
#timer { min-width: 51px; text-align: right; }
.stage { background: #363636; }
#emptyStage { gap: 14px; }
#connectPreview { border: 1px solid #58665b; color: #ecf3e9; background: #354239; }
#connectPreview:hover { background: #425447; }
.record-panel { border: none; margin: 0; padding-top: 12px; gap: 9px; }
.record-actions { justify-content: space-between; align-items: center; }
.take-tools { gap: 8px; }
#testTake { height: 40px; padding-inline: 12px; }
.record-button { flex: 0 1 auto; min-width: 200px; padding: 0 20px; }
.prompter-actions { padding-top: 0; border: 0; }
@media (min-width: 761px) {
  .device-setup .device-menu { inset: auto 0 calc(100% + 4px); }
}
@media (min-width: 1000px) and (max-height: 760px) {
  .text-setup, .device-setup { padding: 12px 14px; }
  .device-setup { gap: 6px; }
  .stage-toolbar { height: 44px; }
}
@container (max-width: 565px) {
  .take-tools { align-items: start; flex-direction: column; gap: 2px; }
  #testStatus { font-size: 11px; }
  .stage-toolbar { grid-template-columns: minmax(0,1fr) auto; height: auto; padding: 8px 0; gap: 5px; }
  .stage-state { grid-column: 1; grid-row: 1; }
  .framing-preset { grid-column: 1 / -1; grid-row: 2; }
  #timer { grid-column: 2; grid-row: 1; }
  .record-button { min-width: 0; flex: 1; font-size: 13px; padding: 0 10px; }
}
@media (max-width: 760px) {
  header.studio-nav { gap: 5px; padding-inline: 10px; }

  .app-name { font-size: 17px; }
  .app-name span { display: none; }
  .studio-nav nav button { padding: 0 7px; }
  .workspace { gap: 14px; }
  .stage { height: min(49dvh, 420px); }
  .text-setup, .device-setup { padding: 14px; }
}

#message:empty { display: none; }
@media (min-width: 761px) { #connectPreview { display: none; } }

.camera-strip { display: flex; flex: none; align-items: center; min-height: 38px; padding: 0 12px; background: #292929; color: #eee; }
.camera-strip > label, .image-menu label, .script-overlay-option { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.camera-strip > label { min-height: 36px; color: inherit; }
.camera-strip > label input:not(:checked) { background: #707970; }
#imageOptions { position: relative; margin-left: auto; }
#imageOptions summary { padding: 8px 2px 8px 10px; font-size: 12px; }
.image-menu { position: absolute; right: 0; bottom: calc(100% + 3px); z-index: 5; display: grid; gap: 12px; width: max-content; padding: 14px; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 5px 18px #0002; }
.image-menu #resolutionInfo { margin: 0; }
.record-actions .timer-setting { margin-left: auto; gap: 6px; }
.record-actions .timer-setting select { height: 34px; min-height: 34px; width: 82px; padding-left: 8px; }
#folderSettings { font-size: 13px; color: var(--text-2); }
#folderSettings summary { width: fit-content; cursor: pointer; color: var(--accent); }
#folderSettings p { margin: 8px 0; }
#playbackNote:empty { display: none; }
#playbackTitle { overflow-wrap: anywhere; min-width: 0; }
#folderSettings > div { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
@container (max-width: 565px) {
  .record-actions .timer-setting { display: grid; gap: 2px; font-size: 11px; }
}
@container (max-width: 350px) {
  .record-actions { flex-wrap: wrap; }
  .record-actions .timer-setting { display: flex; }
  .record-button { flex-basis: 100%; }
}

/* Frequently used script controls stay within reach while reading. */
.text-setup .script-meta { gap: 10px; align-items: center; margin: 0; }
.script-meta .script-name { flex: 1; min-width: 0; }
.script-meta .subtle { white-space: nowrap; }
.text-setup .script-settings { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 16px; }
.text-setup .script-overlay-option { align-self: flex-start; }
@media (min-width: 761px) and (max-height: 760px) {
  .text-setup { gap: 5px; }
  .text-setup .tempo-row { margin-top: 2px; height: 24px; }
  .text-setup .tempo-row button { height: 24px; width: 24px; }
  .text-setup textarea { min-height: 50px; }
}
@media (max-width: 420px) {
  .text-setup .script-settings { gap: 10px; }
  .text-setup .tempo-row { gap: 4px; }
}

#preparation { min-height: 0; overflow-y: auto; }
.prep-layout { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(280px, 1fr); gap: 18px; max-width: 1160px; margin: 0 auto; align-items: start; }
.prep-card { padding: clamp(16px, 2vw, 28px); border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.prep-card h2 { font-size: 21px; letter-spacing: -.035em; }
.prep-card h3 { margin: 0; font-size: 15px; line-height: 1.35; }
.prep-card p { margin: 5px 0 0; font-size: 14px; line-height: 1.5; color: var(--text-2); }
.prep-steps { list-style: none; counter-reset: step; margin: 12px 0 0; padding: 0; }
.prep-steps li { display: grid; grid-template-columns: 24px minmax(0,1fr) 96px; gap: 12px; align-items: start; padding: 15px 0; border-bottom: 1px solid var(--line); counter-increment: step; }
.prep-steps li::before { content: counter(step); display: grid; place-items: center; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.prep-photo { display: block; width: 100%; height: 68px; padding: 0; background: var(--field); border: 0; border-radius: 6px; overflow: hidden; cursor: zoom-in; }
.prep-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.prep-detail { margin-top: 9px; }
.prep-detail summary, .prep-detail a { color: var(--accent); font-weight: 550; line-height: 1.5; }
.prep-lights { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; margin-top: 8px; }
.prep-lights figure { margin: 0; }
.prep-lights figcaption { margin-top: 4px; font-size: 12px; }
.prep-side { display: grid; gap: 12px; }
.prep-side .connect { margin: 16px 0 3px; }
.prep-side .prep-note { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; }
.prep-card .prep-status { color: var(--accent); font-size: 13px; }
.prep-status:empty { display: none; }
.prep-detail a { display: inline-block; margin-top: 10px; }
.prep-end { padding-block: 14px; }
.prep-end summary { font-weight: 600; }
.prep-test { display: flex; align-items: center; gap: 16px; padding-top: 18px; }
.prep-test .connect { width: auto; flex: none; }
#prepPhotoDialog { width: max-content; max-width: min(94vw, 760px); }
#prepPhotoDialog .section-title { margin-bottom: 12px; }
#prepPhotoLarge { display: block; margin: auto; max-height: 68dvh; max-width: 100%; object-fit: contain; }
#manualSkill { min-height: 76px; margin-top: 6px; }
@media (max-width: 760px) {
  .prep-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .prep-steps li { grid-template-columns: 20px minmax(0,1fr) 64px; gap: 8px; }
  .prep-steps li::before { height: 20px; }
  .prep-photo { height: 56px; }
  .prep-test { flex-wrap: wrap; }
  .prep-lights { grid-template-columns: 1fr; }
  .prep-lights figure { display: grid; grid-template-columns: 64px 1fr; gap: 6px; align-items: center; }
}

.prep-steps > li { align-items: center; grid-template-columns: 24px minmax(0, 1fr) clamp(100px, 11vw, 152px); }
.prep-card strong { color: var(--text); }
.prep-steps > li > .prep-photo { align-self: center; height: auto; aspect-ratio: 4 / 3; }
.prep-photo img { object-fit: contain; background: #f4f4f2; }
#prepPhotoDialog .prep-photo-credit { text-align: center; font-size: 12px; color: var(--text-2); }
#readerFullscreen { position: fixed; right: 16px; top: 16px; border: 1px solid #555; border-radius: 6px; padding: 7px 10px; background: #1b1b1b; color: #eee; }
@media (max-width: 760px) {
  .prep-steps > li { grid-template-columns: 20px minmax(0, 1fr) 72px; }
}
