* { box-sizing: border-box; }
[hidden] { display: none !important; }
:root {
  color-scheme: dark;
  --camera-width: min(100vw, 56.25vh);
  --read-size: 22px;
  --bg: #0b172b;
  --panel: #11223c;
  --stroke: #293e5d;
  --muted: #aec0d9;
  --accent: #87b7ff;
  --ink: #edf4ff;
}
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 70% 0%, #142b4d55, transparent 58%), var(--bg);
  color: var(--ink);
  font: 16px/1.45 Inter, system-ui, -apple-system, sans-serif;
}
/* The full-screen camera handles its own insets. Keep the other steps and
   their controls clear of display cutouts and the home indicator as well. */
body:not(.active) {
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
button, a.primary, textarea { font: inherit; }
button { cursor: pointer; color: inherit; background: none; border: 0; }
button:disabled { opacity: .56; cursor: default; }
button:focus-visible, a:focus-visible, textarea:focus-visible, #reader:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
header {
  height: 72px;
  border-bottom: 1px solid var(--stroke);
  padding: 0 max(5vw, calc((100vw - 1180px) / 2));
  display: flex;
  align-items: center;
  gap: 18px;
  background: #0d1b32;
}
.logo { width: 52px; height: auto; display: block; border-radius: 8px; }
.divider { height: 22px; border-left: 1px solid #314663; }
.product, .heading p, .result p { color: var(--muted); }
main { width: min(1180px, 90%); margin: clamp(28px, 6vh, 68px) auto; }
.heading { margin-bottom: 28px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(34px, 4.3vw, 62px); font-weight: 630; line-height: 1.12; letter-spacing: -.055em; }
.heading p { margin-top: 10px; font-size: 17px; }
.panel { border: 1px solid var(--stroke); background: var(--panel); border-radius: 19px; padding: 20px; }
.paneltitle, .paneltitle h2 { display: flex; align-items: center; }
.paneltitle { justify-content: space-between; min-height: 32px; margin-bottom: 15px; }
.paneltitle h2 { gap: 11px; }
.paneltitle > span { font-size: 14px; color: var(--muted); }
h2 { font-size: 19px; font-weight: 610; letter-spacing: -.035em; }
.texticon { color: var(--accent); font-family: Georgia, serif; }
.editor { display: flex; flex-direction: column; }
textarea { resize: vertical; min-height: 145px; flex: 1; width: 100%; border: 1px solid #344966; background: #0c1b30; color: var(--ink); border-radius: 11px; padding: 15px; line-height: 1.6; }
textarea::placeholder { color: #a3b5ce; }
.counter { color: var(--muted); font-size: 14px; display: flex; justify-content: space-between; align-items: center; min-height: 34px; }
.counter button { font-size: 14px; }
.example, .secondary { border: 1px solid #38547a; border-radius: 8px; padding: 8px 12px; }
.example { color: var(--accent); background: #192f50; font-size: 14px; }
.example:hover, .secondary:hover { background: #243d60; }
.bottom { margin-top: 15px; border-top: 1px solid var(--stroke); padding-top: 16px; }
.bottom p { font-size: 14px; color: var(--muted); margin: 5px 0 15px; }
.primary { border: 0; background: #245fb6; color: #fff; width: 100%; min-height: 49px; border-radius: 10px; display: flex; align-items: center; justify-content: center; gap: 10px; text-decoration: none; font-weight: 650; }
.primary:hover { background: #2d6bc6; }
.secondary { width: 100%; margin-top: 10px; }
.result { margin: 14px auto; max-width: 580px; }
.result p { margin: 7px 0 16px; }
/* Reserve the portrait canvas before Safari has read the video metadata. */
.result video {
  --player-height: min(54vh, 600px);
  display: block;
  margin: 0 auto 14px;
  width: calc(var(--player-height) * 9 / 16);
  height: var(--player-height);
  object-fit: contain;
  border-radius: 10px;
  background: #09090a;
}
.active header { display: none; }
@media (max-width: 730px) {
  header { height: 56px; padding: 0 16px; gap: 12px; }
  .logo { width: 42px; }
  .product { font-size: 14px; }
  main { width: calc(100% - 24px); margin: 23px auto; }
  .heading { margin: 0 3px 18px; }
  .heading p { font-size: 15px; }
  .panel { padding: 14px; border-radius: 14px; }
  .paneltitle { margin-bottom: 10px; }
  textarea { min-height: clamp(94px, 16vh, 136px); }
  .bottom { margin-top: 4px; }
}

/* Fill the visible camera screen; keep UI out of the encoded video. */
body.active { overflow: hidden; }
#capture {
  touch-action: manipulation;
  position: fixed;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #060d17;
  color: #fff;
  --lens-top: max(8px, calc(env(safe-area-inset-top, 0px) + 5px));
}
@supports (height: 100dvh) { :root { --camera-width: min(100vw, 56.25dvh); } }
#capture:fullscreen { width: 100%; height: 100%; }
#reopeningControls { inset: auto 0 0; }
#frame { touch-action: none; position: absolute; inset: 0; overflow: hidden; background: #000; }
#camera, #frame > canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; object-position: center; }
/* The stage owns tap/pinch. Keep inline video out of native Safari tap
   handling; the image and all interactive overlay controls remain visible. */
#camera, #frame > canvas { pointer-events: none; touch-action: none; }
#capture button { touch-action: manipulation; }
#frame:has(> canvas) #camera { opacity: 0; }
#zoomControls {
  position: absolute; z-index: 2; left: 50%; transform: translateX(-50%);
  bottom: calc(99px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; background: #071323dc;
  border: 1px solid #a7b9cb80; border-radius: 24px;
}
#zoomControls button {
  min-width: 44px; min-height: 44px; padding: 0 8px; border: 0;
  background: transparent; color: #fff; font-size: 20px;
}
#zoomControls #resetZoom { font: inherit; font-variant-numeric: tabular-nums; }
#zoomControls button:disabled { opacity: .45; }
#reader {
  position: absolute;
  top: max(2px, env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: min(19rem, 82vw, calc(var(--camera-width) - 12px));
  height: calc(2.55 * var(--read-size) + 10px);
  padding: 4px 10px 6px;
  overflow: hidden;
  overscroll-behavior: contain;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  cursor: grab;
  scrollbar-width: none;
  scrollbar-gutter: auto;
  background: linear-gradient(to bottom, #071528dd 40%, #071528b8);
  border-radius: 10px;
  color: #fff;
  font-size: var(--read-size);
  line-height: 1.28;
  font-weight: 580;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 3px #000c;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
/* The track moves underneath this stationary guide; gestures pass through it. */
#reader::after {
  content: '';
  position: absolute;
  inset: var(--guide-y, 50%) 0 0;
  pointer-events: none;
  z-index: 1;
  background: linear-gradient(to right, transparent, #a5cdff 8%, #a5cdff 92%, transparent)
    top center / calc(100% - 16px) 1px no-repeat, rgb(7 21 40 / 48%);
}
#reader::-webkit-scrollbar { display: none; }
#reader.dragging { cursor: grabbing; }
.capture-controls {
  position: absolute;
  z-index: 1;
  inset: auto 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  padding: 32px max(12px, env(safe-area-inset-right)) max(10px, calc(env(safe-area-inset-bottom) + 5px)) max(12px, env(safe-area-inset-left));
  background: linear-gradient(transparent, #061020ba 30%, #061020f5);
}

#takeStatus { color: #f1f6ff; font-size: 14px; line-height: 1.4; max-width: 430px; text-shadow: 0 1px 3px #000; }
#framingControls { padding-top: 8px; background: none; }
#toSettings {
  position: absolute; z-index: 1; top: var(--lens-top);
  left: max(12px, env(safe-area-inset-left)); background: #071323cf;
}
.shutter {
  display: inline-flex; padding: 4px; border-radius: 50%;
}
.shutter-ring {
  display: block; width: 72px; height: 72px; border-radius: 50%;
  border: 4px solid white; padding: 4px; background: #ff3b39 content-box;
  box-shadow: inset 0 0 0 4px #181818, 0 1px 5px #0008;
}
.shutter:active .shutter-ring { transform: scale(.96); }
.live-controls { padding-top: 10px; background: none; }
.live-row { display: flex; align-items: center; gap: 7px; }
.elapsed, #stop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 30px;
  color: #fff;
  background: #071323dc;
  border: 1px solid #a7b9cb80;
}
.elapsed { min-height: 36px; padding: 3px 12px; font-size: 14px; font-variant-numeric: tabular-nums; }
.elapsed i { width: 8px; height: 8px; border-radius: 50%; background: #ff6c73; }
#stop { min-height: 46px; padding: 5px 16px; font-size: 15px; font-weight: 640; }
.square { width: 13px; height: 13px; border-radius: 3px; background: #ff6c73; }
#takeStatus { padding: 3px 10px; border-radius: 8px; background: #071323df; }
#takeStatus:empty { display: none; }

@media (max-height: 510px) and (orientation: landscape) {
  #reader { --read-size: clamp(16px, 5.2vh, 22px); }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
#reader {
  -webkit-mask-image: linear-gradient(to bottom, transparent, black 3px, black calc(100% - 13px), transparent);
  mask-image: linear-gradient(to bottom, transparent, black 3px, black calc(100% - 13px), transparent);
}
@media (max-width: 730px) and (max-height: 690px) {
  main { margin-block: 16px; }
  .heading { margin-bottom: 12px; }
  .heading p { margin-top: 6px; }
  .bottom { padding-top: 10px; }
}

.example, .secondary, .back, #speed { min-height: 44px; }
.counter { min-height: 42px; }
.counter button { position: relative; }
.counter button::after { content: ''; position: absolute; inset: -12px 0; }
@media (max-width: 440px) and (max-height: 640px) {
  header { height: 48px; }
  .logo { width: 36px; }
  main { margin-block: 12px; }
  .heading h1 { font-size: 30px; }
  .heading p { margin-top: 4px; }
  .panel { padding: 12px; }
  .paneltitle { margin-bottom: 8px; }
  textarea { min-height: 82px; height: 82px; }
  .bottom { margin-top: 0; padding-top: 7px; }
  .bottom p { margin: 3px 0 10px; }
  .result video { --player-height: min(53vh, calc(100vh - 295px)); }
}

.speed-row { display: flex; align-items: center; gap: 10px; }
.speed-row button {
  flex: 0 0 44px;
  height: 44px;
  font: 500 22px/1 system-ui, sans-serif;
  color: #c8deff;
  border-radius: 8px;
}
.speed-row button:hover:not(:disabled) { background: #1c3454; }
.speed-row #speed { flex: 1; min-width: 0; }


#studio { max-width: 690px; }
.step-label { display: block; color: #aaccfc; font-size: 14px; font-weight: 600; margin-bottom: 7px; }
.editor textarea { min-height: clamp(132px, 25vh, 250px); }
.editor .bottom { padding-top: 12px; margin-top: 4px; }
#notice:empty, #exportHint:empty { display: none; }
.device-access {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  margin-top: 14px;
}
.device-access > span { display: inline-flex; align-items: center; gap: 7px; }
.access-mark {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #273a54;
  color: #c4cedc;
  font: 700 15px/1 system-ui, sans-serif;
}
.access-mark[data-state="granted"] { background: #174438; color: #82e4aa; }
.access-mark[data-state="off"] { background: #482b37; color: #ffadb0; }
.speed-label, .speed-ends, .setup-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.speed-label label { font-size: 18px; font-weight: 600; }
.speed-label output { font-size: 20px; color: #bad8ff; font-weight: 650; font-variant-numeric: tabular-nums; }
#speed { width: 100%; margin: 0; height: 44px; cursor: pointer; accent-color: #80b5ff; }
.speed-row { margin-block: 6px; }
.speed-ends { font-size: 14px; color: var(--muted); padding-inline: 54px; }
#readyStatus { min-height: 1.45em; margin-top: 12px; color: #e7ecf4; }
.setup-actions { margin-top: 24px; gap: 12px; }
.back { white-space: nowrap; border: 1px solid #546d90; border-radius: 10px; padding: 4px 14px; min-height: 48px; }
.setup-actions .primary { flex: 1; }
#countdown { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 15px; text-align: center; }
#countdown { pointer-events: none; }
#cancelCount {
  pointer-events: auto;
  color: white;
  width: 94px;
  height: 94px;
  border: 0;
  border-radius: 50%;
  font: 650 62px/1 system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 11px #000;
  background: #091422a6;
}
#cancelCount:focus:not(:focus-visible) { outline: none; }

/* Both stages use the same reader node, camera-width constraint and text metrics. */
.preview-box {
  margin: 19px 0 0;
  padding: 12px 0 14px;
  border-block: 1px solid var(--stroke);
}
#speedPreview { display: flex; justify-content: center; padding: 7px 0; }
#speedPreview #reader { position: relative; top: auto; left: auto; transform: none; flex: none; }
.result a.secondary { display: flex; align-items: center; justify-content: center; text-decoration: none; color: inherit; }
.result h2 { margin-bottom: 12px; }
.result #changeFolder { min-height: 44px; margin-bottom: 8px; }
#embeddedNotice p { margin: 8px 0 16px; color: var(--muted); }
@media (max-width: 730px) {
  .result-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .result-actions .secondary { flex: 1 1 40%; margin: 0; padding-inline: 6px; }
  @supports (height: 100svh) {
    .result video { --player-height: clamp(168px, min(52svh, calc(100svh - 340px)), 600px); }
    .result:has(#saveFolder:not([hidden])) video {
      --player-height: clamp(168px, min(52svh, calc(100svh - 398px)), 600px);
    }
  }
}
/* Keep a real, playing in-viewport video for mobile camera negotiation,
   without compositing a full-screen moving image beneath the settings. */
#capture.preflight {
  inset: 0 auto auto 0; width: 2px; height: 2px; z-index: -1;
  pointer-events: none; contain: strict;
}
@media (max-height: 640px) {
  .preview-box { margin-top: 9px; padding-block: 9px; }
  .setup-actions { margin-top: 12px; }
}

#mirrorCamera {
  position: absolute; z-index: 1; top: var(--lens-top);
  right: max(12px, env(safe-area-inset-right)); background: #071323e8;
}
#mirrorCamera[aria-pressed="true"] { background: #164786; border-color: #bad8ff; }
