:root {
  color-scheme: light;
  --sky: #00a9c8;
  --deep: #064b6b;
  --sun: #ffd24c;
  --orange: #ff7a1a;
  --leaf: #19a974;
  --ink: #14232e;
  --muted: #667987;
  --paper: #fffaf0;
  --line: rgba(6, 75, 107, 0.18);
  --shadow: 0 18px 46px rgba(6, 75, 107, 0.18);
  font-family: Poppins, Roboto, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(0, 169, 200, 0.15), rgba(255, 250, 240, 0.92) 42%),
    var(--paper);
}

button,
select,
input {
  font: inherit;
  max-width: 100%;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  min-height: 72px;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  background: rgba(255, 250, 240, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  flex: 0 1 auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--deep);
  font-weight: 800;
  text-decoration: none;
}

.brand img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.brand span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.stream-status {
  display: grid;
  grid-template-columns: auto minmax(0, auto) auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: min(42vw, 360px);
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--deep);
  background: rgba(255, 255, 255, 0.86);
}

.stream-status #statusText {
  min-width: 0;
  overflow: hidden;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stream-status #timer {
  justify-self: end;
}

.nav {
  display: flex;
  margin-left: auto;
  align-items: center;
  gap: 10px;
}

.nav form {
  margin: 0;
}

.nav a,
.nav button,
.primary,
.secondary,
.danger {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.nav a,
.nav button {
  display: inline-flex;
  align-items: center;
  color: var(--deep);
  background: #ffffff;
  border: 1px solid var(--line);
  text-decoration: none;
}

.menu-button {
  display: none;
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.menu-button span {
  display: block;
  width: 22px;
  height: 2px;
  margin: 5px auto;
  background: var(--deep);
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 390px);
  gap: 18px;
  width: min(1380px, 100%);
  margin: 0 auto;
  padding: 18px max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow: hidden;
}

.preview-panel {
  position: relative;
  overflow: visible;
  min-width: 0;
  min-height: calc(100svh - 108px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #072b38;
  box-shadow: var(--shadow);
}

video,
.preview-empty {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

video {
  object-fit: contain;
  border-radius: 8px;
  background: #071e28;
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: rgba(7, 30, 40, 0.38);
  pointer-events: none;
}

.countdown-overlay[hidden] {
  display: none;
}

.countdown-overlay span {
  min-width: min(34svh, 180px);
  border-radius: 8px;
  padding: 10px 22px;
  text-align: center;
  font-size: clamp(4rem, 20svh, 10rem);
  font-weight: 900;
  line-height: 1;
  background: rgba(7, 30, 40, 0.62);
}

.camera-overlay {
  position: static;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px;
  align-items: stretch;
  gap: 12px;
  width: 100%;
  pointer-events: auto;
}

.camera-overlay[hidden] {
  display: none;
}

.zoom-control {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  color: var(--deep);
  pointer-events: auto;
}

.zoom-actions {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.zoom-head {
  display: grid;
  gap: 2px;
  min-width: 54px;
}

.zoom-head label,
.zoom-head output {
  color: var(--deep);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.zoom-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.zoom-buttons button {
  min-width: 0;
  min-height: 54px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--deep);
  font-size: 1.65rem;
  font-weight: 900;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.zoom-buttons button::before {
  display: block;
  pointer-events: none;
}

#zoomOutButton::before {
  content: "-";
}

#zoomInButton::before {
  content: "+";
}

.zoom-control select {
  min-height: 34px;
  padding: 0 6px;
  font-size: 0.72rem;
}

.focus-button {
  width: 100%;
  min-width: 0;
  min-height: 54px;
  border: 0;
  border-radius: 8px;
  color: #073143;
  background: var(--sun);
  font-size: 0.78rem;
  font-weight: 900;
  pointer-events: auto;
}

.focus-target {
  position: absolute;
  z-index: 6;
  width: 54px;
  height: 54px;
  border: 3px solid var(--sun);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(7, 30, 40, 0.45);
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: focus-pulse 760ms ease-out;
}

.focus-target[hidden] {
  display: none;
}

@keyframes focus-pulse {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.35);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.preview-empty {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: #ffffff;
  background:
    radial-gradient(circle at 50% 35%, rgba(0, 169, 200, 0.35), transparent 36%),
    #073143;
}

.preview-empty[hidden] {
  display: none;
}

.preview-empty img {
  width: min(34vw, 220px);
  max-width: 70%;
}

.preview-empty p {
  margin: 0;
  font-weight: 800;
}

#timer {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--sun);
}

.status-dot.warming {
  background: var(--sun);
  box-shadow: 0 0 0 6px rgba(252, 188, 38, 0.22);
}

.status-dot.live,
.status-dot.armed,
.status-dot.saved {
  background: #34d399;
  box-shadow: 0 0 0 6px rgba(52, 211, 153, 0.2);
}

.status-dot.processing {
  background: var(--orange);
  box-shadow: 0 0 0 6px rgba(255, 122, 26, 0.18);
}

.status-dot.error {
  background: #ef4444;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-self: start;
  min-height: calc(100svh - 108px);
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.control-top,
.grid-2 {
  display: grid;
  gap: 10px;
}

.control-top {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: start;
}

.grid-2 {
  grid-template-columns: 1fr 1fr;
}

.inline-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.primary {
  color: #ffffff;
  background: var(--orange);
}

.secondary {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--deep);
  background: #ffffff;
  font-weight: 800;
  cursor: pointer;
}

.danger {
  color: #ffffff;
  background: #cf2e2e;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.field {
  display: grid;
  gap: 7px;
}

label,
.range-label {
  color: var(--deep);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.range-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

select,
input[type="range"] {
  width: 100%;
}

select {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #ffffff;
  min-width: 0;
}

input[type="range"] {
  accent-color: var(--sky);
}

.toggles {
  display: grid;
  gap: 10px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  color: var(--ink);
  text-transform: none;
}

.toggle input {
  width: 20px;
  height: 20px;
  accent-color: var(--leaf);
}

body.camera-controls-off .camera-control,
body.camera-controls-off .camera-overlay {
  display: none;
}

.pipeline {
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(6, 75, 107, 0.06);
}

.location-status {
  padding: 8px 10px;
  background: rgba(0, 169, 200, 0.08);
}

.pipeline-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.pipeline-row span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #a8b7c1;
}

.pipeline-row strong {
  min-width: 0;
  overflow: hidden;
  color: var(--deep);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pipeline-row em {
  overflow: hidden;
  max-width: 130px;
  font-style: normal;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pipeline-row.ok span {
  background: #34d399;
}

.pipeline-row.warn span {
  background: var(--sun);
}

.pipeline-row.error span {
  background: #ef4444;
}

.audio-meter {
  overflow: hidden;
  width: 100%;
  height: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(6, 75, 107, 0.12);
}

.audio-meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--leaf), var(--sun), var(--orange));
  transition: width 80ms linear;
}

.message {
  min-height: 52px;
  margin: auto 0 0;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.rotate-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  place-items: center;
  align-content: center;
  gap: 12px;
  padding: 24px;
  color: #ffffff;
  text-align: center;
  background: #073143;
}

.rotate-gate img {
  width: min(38vw, 150px);
  max-width: 70%;
  height: auto;
}

.rotate-gate h1,
.rotate-gate p {
  margin: 0;
}

.rotate-gate h1 {
  font-size: clamp(1.8rem, 8vw, 3rem);
}

body.portrait-blocked {
  overflow: hidden;
}

body.portrait-blocked .rotate-gate {
  display: grid;
}

.login-body {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-shell {
  width: min(420px, 100%);
}

.login-panel {
  display: grid;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.login-panel img {
  width: 104px;
  height: auto;
  justify-self: center;
}

.login-panel h1 {
  margin: 0;
  color: var(--deep);
  text-align: center;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form input,
.settings-form input,
.settings-form textarea {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #ffffff;
}

.settings-form textarea {
  min-height: 96px;
  padding: 12px;
  resize: vertical;
}

.account-shell {
  width: min(860px, 100%);
  margin: 0 auto;
  padding: 18px max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.settings-panel {
  display: grid;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.settings-panel h1,
.settings-panel h2 {
  margin: 0;
  color: var(--deep);
}

.settings-form {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.settings-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.history-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.history-panel {
  display: grid;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.history-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.history-head h1,
.history-card h2,
.video-card h2 {
  margin: 0;
  color: var(--deep);
}

.history-head p,
.history-card p,
.video-card p {
  margin: 4px 0 0;
  color: var(--muted);
}

.history-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.history-tab {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--deep);
  background: #ffffff;
  font-weight: 800;
}

.history-tab.active {
  color: #ffffff;
  background: var(--deep);
}

.history-view {
  display: none;
}

.history-view.active {
  display: block;
}

.history-list,
.video-list {
  display: grid;
  gap: 12px;
}

.history-card,
.video-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
}

.history-card {
  grid-template-columns: minmax(0, 1fr) auto;
}

.history-card-main,
.video-copy {
  min-width: 0;
}

.history-card h2,
.video-card h2 {
  overflow-wrap: anywhere;
  font-size: 1rem;
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 6px;
}

.history-meta span {
  border-radius: 999px;
  padding: 5px 8px;
  color: var(--deep);
  background: rgba(0, 169, 200, 0.12);
  font-size: 0.76rem;
  font-weight: 800;
}

.history-card dl {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.history-card dl div {
  min-width: 0;
}

.history-card dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.history-card dd {
  margin: 2px 0 0;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-link {
  grid-column: 1 / -1;
  justify-self: start;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--deep);
  background: rgba(255, 210, 76, 0.28);
  font-weight: 800;
  text-decoration: none;
}

.video-card {
  grid-template-columns: minmax(220px, 320px) minmax(0, 1fr);
  align-items: start;
}

.video-card video {
  position: static;
  width: 100%;
  height: auto;
  max-height: 56vh;
  aspect-ratio: 16 / 9;
  object-fit: contain;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  background: rgba(6, 75, 107, 0.05);
}

@media (max-width: 860px) {
  .menu-button {
    display: block;
  }

  .nav {
    position: absolute;
    top: 72px;
    right: 16px;
    display: none;
    flex-direction: column;
    align-items: stretch;
    min-width: 178px;
    max-width: calc(100vw - 32px);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    background: #ffffff;
    box-shadow: var(--shadow);
  }

  .nav.open {
    display: flex;
  }

  .shell {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .preview-panel {
    min-height: min(62svh, 62vw);
    aspect-ratio: 16 / 9;
  }

  .controls {
    min-height: auto;
  }

  .history-card,
  .video-card {
    grid-template-columns: 1fr;
  }

  .history-meta {
    justify-content: start;
  }

  .history-card dl {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) and (orientation: landscape) {
  .brand span {
    max-width: 48vw;
  }

  .shell {
    padding-inline: 10px;
  }

  .controls {
    padding: 12px;
  }

  .grid-2,
  .inline-control {
    grid-template-columns: 1fr;
  }

  .control-top {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .history-head {
    display: grid;
  }

  .history-tabs {
    grid-template-columns: 1fr;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app-header {
    min-height: 58px;
    padding-block: 6px;
  }

  .brand img {
    width: 40px;
    height: 40px;
  }

  .shell {
    grid-template-columns: minmax(0, 1fr) clamp(272px, 38vw, 340px);
    gap: 10px;
    height: calc(100svh - 58px);
    padding-block: 10px;
    overflow: hidden;
  }

  .preview-panel,
  .controls {
    min-height: 0;
    height: 100%;
  }

  .controls {
    gap: 9px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 10px;
  }

  .nav a,
  .nav button,
  .primary,
  .secondary,
  .danger,
  select {
    min-height: 40px;
  }

  .field {
    gap: 5px;
  }

  .toggle {
    min-height: 34px;
  }

  .countdown-overlay span {
    min-width: min(34svh, 132px);
    font-size: clamp(3rem, 18svh, 7rem);
  }

  .camera-overlay {
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) 88px;
  }

  .zoom-control {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 6px;
  }

  .zoom-buttons button {
    min-height: 46px;
  }

  .focus-button {
    min-height: 46px;
  }

  .pipeline {
    padding: 8px;
  }

  .message {
    display: none;
  }

  .history-shell {
    height: calc(100svh - 58px);
    padding-block: 10px;
    overflow: hidden;
  }

  .history-panel {
    height: 100%;
    overflow-y: auto;
    padding: 12px;
  }

  .account-shell {
    height: calc(100svh - 58px);
    padding-block: 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .account-shell .settings-panel {
    min-height: min-content;
  }
}

@media (orientation: landscape) and (max-height: 430px) {
  .app-header {
    min-height: 50px;
  }

  .brand img {
    width: 34px;
    height: 34px;
  }

  .shell {
    height: calc(100svh - 50px);
    grid-template-columns: minmax(0, 1fr) clamp(250px, 36vw, 310px);
    padding: 6px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .account-shell {
    height: calc(100svh - 50px);
    padding-block: 6px;
  }

  .controls {
    gap: 7px;
  }

  .control-top {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 7px;
  }

  .camera-overlay {
    grid-template-columns: minmax(0, 1fr) 78px;
  }

  .zoom-control {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 5px;
  }

  .zoom-buttons {
    gap: 5px;
  }

  .zoom-buttons button {
    min-height: 40px;
    font-size: 1.35rem;
  }

  .zoom-control select {
    min-height: 30px;
    font-size: 0.68rem;
  }

  label,
  .range-label {
    font-size: 0.74rem;
  }
}
