:root {
  color-scheme: light dark;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  font-synthesis: none;
  --page: #f5f5f7;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --surface-raised: rgba(255, 255, 255, 0.94);
  --text: #1d1d1f;
  --secondary: #6e6e73;
  --tertiary: #86868b;
  --separator: rgba(60, 60, 67, 0.15);
  --separator-strong: rgba(60, 60, 67, 0.22);
  --control: rgba(118, 118, 128, 0.10);
  --control-hover: rgba(118, 118, 128, 0.16);
  --accent: #0071e3;
  --accent-pressed: #0066cc;
  --danger: #d70015;
  --warning: #9a6700;
  --success: #248a3d;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #1c1c1e;
    --surface: rgba(44, 44, 46, 0.78);
    --surface-solid: #2c2c2e;
    --surface-raised: rgba(58, 58, 60, 0.94);
    --text: #f5f5f7;
    --secondary: #aeaeb2;
    --tertiary: #8e8e93;
    --separator: rgba(235, 235, 245, 0.12);
    --separator-strong: rgba(235, 235, 245, 0.20);
    --control: rgba(118, 118, 128, 0.24);
    --control-hover: rgba(118, 118, 128, 0.32);
    --accent: #0a84ff;
    --accent-pressed: #409cff;
    --danger: #ff453a;
    --warning: #ffd60a;
    --success: #30d158;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--page); }
body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button, input, select { accent-color: var(--accent); }
input::placeholder { color: var(--tertiary); opacity: 1; }

.shell {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 44px 28px 64px;
}

.masthead,
.row,
.card-heading,
.session-footer,
.preflight-footer {
  display: flex;
  align-items: center;
}
.masthead {
  justify-content: space-between;
  gap: 24px;
  margin: 0 2px 26px;
}
h1 {
  margin: 0;
  font-size: clamp(29px, 4vw, 36px);
  line-height: 1.08;
  letter-spacing: -0.035em;
  font-weight: 650;
}
.masthead p {
  margin: 5px 0 0;
  color: var(--secondary);
  font-size: 14px;
}
h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: -0.015em;
  font-weight: 620;
}

.card {
  margin: 14px 0;
  padding: 24px;
  border: 1px solid var(--separator);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.02), 0 10px 36px rgba(0, 0, 0, 0.045);
  backdrop-filter: blur(24px) saturate(125%);
  -webkit-backdrop-filter: blur(24px) saturate(125%);
}
.card-heading {
  min-height: 30px;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 18px;
}
.field {
  display: grid;
  gap: 7px;
  min-width: 0;
  margin: 0;
}
.field-wide { grid-column: 1 / -1; }
.field > span {
  color: var(--secondary);
  font-size: 12px;
  font-weight: 520;
}
input,
select {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--separator-strong);
  border-radius: 10px;
  outline: none;
  background: var(--surface-raised);
  color: var(--text);
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}
input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.level-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: 'copy button' 'meter button';
  gap: 10px 18px;
  align-items: center;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--separator);
}
.level-copy {
  grid-area: copy;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}
.codec {
  color: var(--tertiary);
  font-size: 12px;
  text-align: right;
}
.meter {
  grid-area: meter;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--control);
}
.meter i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 60ms linear;
}

button {
  min-height: 38px;
  padding: 0 15px;
  border: 1px solid var(--separator-strong);
  border-radius: 10px;
  background: var(--surface-raised);
  color: var(--text);
  cursor: pointer;
  font-weight: 520;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease, opacity 120ms ease;
}
button:hover:not(:disabled) { background: var(--control-hover); }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 28%, transparent); outline-offset: 2px; }
button:disabled { cursor: default; opacity: 0.44; }
.primary {
  min-width: 138px;
  border-color: transparent;
  background: var(--accent);
  color: #fff;
  font-weight: 620;
}
.primary:hover:not(:disabled) { background: var(--accent-pressed); }
.secondary-button { min-width: 118px; }
.level-panel > button { grid-area: button; min-width: 142px; }

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--control);
  color: var(--secondary);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}
.connection-pill { max-width: 44vw; }
.pill.rec { background: var(--danger); color: #fff; font-weight: 650; }
.pill.warn {
  background: color-mix(in srgb, var(--warning) 16%, transparent);
  color: var(--warning);
  font-weight: 620;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}
.checks li {
  padding: 5px 9px;
  border: 1px solid var(--separator);
  border-radius: 999px;
  color: var(--secondary);
  font-size: 12px;
}
.checks li::before { content: '✓ '; color: var(--success); }
.preflight-footer {
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 7px 16px;
  margin-top: 14px;
}
.hint,
.quality,
.session-message {
  margin: 0;
  color: var(--secondary);
  font-size: 13px;
  line-height: 1.45;
}
.quality[data-quality='good'] { color: var(--success); }
.quality[data-quality='unstable'] { color: var(--warning); }
.quality[data-quality='poor'] { color: var(--danger); }

.session-heading { margin-bottom: 14px; }
.status-row { gap: 9px; flex-wrap: wrap; justify-content: flex-end; }
.timecode {
  color: var(--secondary);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.reference-frame {
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  background: #09090a;
}
video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #09090a;
}
.takes {
  display: grid;
  gap: 5px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}
.takes li {
  padding: 7px 10px;
  border-radius: 9px;
  background: var(--control);
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.session-footer {
  justify-content: space-between;
  gap: 16px 24px;
  margin-top: 16px;
}
.session-actions { gap: 9px; flex-wrap: wrap; }
.session-message { max-width: 48%; text-align: right; }

body[data-session-state='connected'] .session-card {
  border-color: color-mix(in srgb, var(--accent) 24%, var(--separator));
}

@media (max-width: 700px) {
  .shell { padding: 28px 16px 44px; }
  .card { padding: 20px; border-radius: 18px; }
  .settings-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .session-heading { align-items: flex-start; flex-direction: column; }
  .status-row { justify-content: flex-start; }
  .session-footer { align-items: flex-start; flex-direction: column; }
  .session-message { max-width: none; text-align: left; }
}

@media (max-width: 520px) {
  .shell { padding-inline: 12px; }
  .masthead { margin-inline: 4px; }
  .connection-pill { max-width: 50vw; overflow: hidden; text-overflow: ellipsis; }
  .level-panel {
    grid-template-columns: 1fr;
    grid-template-areas: 'copy' 'meter' 'button';
  }
  .level-copy { align-items: flex-start; flex-direction: column; gap: 4px; }
  .codec { text-align: left; }
  .level-panel > button { width: 100%; }
  .session-actions { width: 100%; }
  .session-actions button { flex: 1 1 120px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}
