: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%;
}

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;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  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;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--deep);
  font-weight: 800;
  text-decoration: none;
}

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

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

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

.nav form {
  margin: 0;
}

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

.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));
}

.preview-panel {
  position: relative;
  overflow: hidden;
  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;
  background: #071e28;
}

.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;
}

.hud {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  border-radius: 8px;
  padding: 8px 12px;
  color: #ffffff;
  background: rgba(7, 30, 40, 0.72);
}

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

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

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

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

.controls {
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-self: start;
  min-height: calc(100svh - 108px);
  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;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

.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;
}

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);
}

.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;
}

.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: 104px;
  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;
}

@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;
    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;
  }

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

  .controls {
    min-height: auto;
  }
}

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

  .shell {
    padding-inline: 10px;
  }

  .controls {
    padding: 12px;
  }

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

@media (orientation: landscape) and (max-height: 560px) {
  .app-header {
    min-height: 58px;
    padding-block: 6px;
  }

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

  .shell {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
    gap: 10px;
    padding-block: 10px;
  }

  .preview-panel,
  .controls {
    min-height: calc(100svh - 78px);
  }

  .controls {
    gap: 9px;
    overflow: auto;
  }

  .message {
    display: none;
  }
}
