:root {
  color-scheme: dark;
  --bg: #080b0f;
  --panel: rgba(16, 21, 28, 0.86);
  --line: rgba(255, 255, 255, 0.11);
  --muted: #9ba8b8;
  --white: #f8fbff;
  --red: #ef2424;
  --red-dark: #9f0909;
  --green: #20c765;
  --green-dark: #087331;
  --yellow: #ffbc27;
  --blue: #52a7ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body, #app { width: 100%; min-height: 100%; margin: 0; }

body {
  min-height: 100dvh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--white);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }

.boot-screen, .auth-screen {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  gap: 18px;
  padding: 28px;
  text-align: center;
  background: radial-gradient(circle at 50% 30%, #18212c 0, var(--bg) 55%);
}

.spinner {
  width: 38px;
  height: 38px;
  margin: auto;
  border: 3px solid rgba(255,255,255,.15);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.auth-card {
  width: min(420px, calc(100vw - 40px));
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 28px 80px rgba(0,0,0,.45);
}

.auth-card h1 { margin: 0 0 8px; font-size: 1.65rem; }
.auth-card p { color: var(--muted); line-height: 1.45; }
.auth-card input {
  width: 100%;
  margin-top: 12px;
  padding: 14px 16px;
  color: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #080c11;
}

.auth-card button {
  width: 100%;
  margin-top: 12px;
  padding: 14px;
  border: 0;
  border-radius: 12px;
  color: #05111c;
  font-weight: 800;
  background: var(--blue);
}

.selector-screen {
  position: relative;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  background: #05070a;
  isolation: isolate;
}

.selector-screen::before {
  position: absolute;
  inset: 0;
  z-index: -3;
  content: "";
  background:
    linear-gradient(rgba(255,255,255,.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.022) 1px, transparent 1px);
  background-size: 52px 52px;
  mask-image: linear-gradient(to bottom, black, transparent 88%);
}

.selector-glow {
  position: absolute;
  z-index: -2;
  width: min(75vw, 680px);
  aspect-ratio: 1;
  border-radius: 50%;
  filter: blur(90px);
  opacity: .16;
}
.selector-glow-one { top: -38%; left: -16%; background: #268cff; }
.selector-glow-two { right: -24%; bottom: -48%; background: #15d875; }

.selector-card {
  width: min(440px, 100%);
  padding: clamp(25px, 6vw, 38px);
  border: 1px solid rgba(255,255,255,.115);
  border-radius: 30px;
  background: linear-gradient(145deg, rgba(22,27,35,.9), rgba(9,12,16,.86));
  box-shadow: 0 30px 100px rgba(0,0,0,.55), inset 0 1px rgba(255,255,255,.04);
  backdrop-filter: blur(30px) saturate(125%);
}

.selector-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin-bottom: 27px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 15px;
  background: rgba(255,255,255,.05);
}
.selector-mark span { width: 16px; height: 16px; border: 5px solid #ff3b30; border-radius: 50%; box-shadow: 0 0 24px rgba(255,59,48,.55); }
.selector-card h1 { margin: 9px 0 0; font-size: clamp(2.25rem, 9vw, 3.2rem); line-height: 1; letter-spacing: -.055em; }
.selector-card > p { margin: 14px 0 27px; color: var(--muted); font-size: .96rem; }

.camera-number-field {
  height: 82px;
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 0 21px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 19px;
  background: rgba(0,0,0,.27);
  transition: border-color .2s, box-shadow .2s, transform .2s;
}
.camera-number-field:focus-within { border-color: rgba(82,167,255,.72); box-shadow: 0 0 0 4px rgba(82,167,255,.11); }
.camera-number-field.invalid { border-color: var(--red); animation: field-shake .32s ease; }
@keyframes field-shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.camera-number-field > span { color: #7f8b99; font-size: .78rem; font-weight: 900; letter-spacing: .16em; }
.camera-number-field input {
  min-width: 0;
  flex: 1;
  padding: 0;
  border: 0;
  outline: 0;
  color: var(--white);
  background: transparent;
  font-size: 2.7rem;
  font-weight: 850;
  letter-spacing: -.04em;
  appearance: textfield;
}
.camera-number-field input::-webkit-inner-spin-button { appearance: none; }

.selector-submit {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding: 16px 19px;
  border: 0;
  border-radius: 16px;
  color: #07101a;
  background: #f5f8fc;
  font-weight: 850;
  cursor: pointer;
  transition: transform .15s, background .15s;
}
.selector-submit:active { transform: scale(.985); background: #dfe8f2; }
.selector-submit span { font-size: 1.25rem; }
.quick-label { margin: 27px 0 10px; color: #778391; font-size: .67rem; font-weight: 850; letter-spacing: .14em; text-transform: uppercase; }
.quick-cameras { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.quick-cameras button {
  aspect-ratio: 1.25;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 14px;
  color: var(--white);
  background: rgba(255,255,255,.045);
  font-size: 1.05rem;
  font-weight: 850;
  cursor: pointer;
  transition: background .15s, transform .15s;
}
.quick-cameras button:active { transform: scale(.94); background: rgba(255,255,255,.12); }
.admin-link { display: flex; justify-content: space-between; margin-top: 27px; padding-top: 19px; border-top: 1px solid rgba(255,255,255,.085); color: #94a1b0; font-size: .8rem; font-weight: 750; text-decoration: none; }

.tally {
  position: relative;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  transition: none;
}

.tally::before {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  background: radial-gradient(circle at 50% 44%, rgba(255,255,255,.17), transparent 52%);
}

.tally.program { background: linear-gradient(145deg, var(--red), var(--red-dark)); }
.tally.preview { background: linear-gradient(145deg, var(--green), var(--green-dark)); }
.tally.idle { background: linear-gradient(145deg, #151c24, #05070a); }
.tally.offline {
  background-color: #17130b;
  background-image: repeating-linear-gradient(-45deg, rgba(255,188,39,.18) 0 20px, rgba(0,0,0,.18) 20px 40px);
}

.topbar, .bottombar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand, .source-pill, .metric-pill {
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  background: rgba(0,0,0,.22);
  backdrop-filter: blur(14px);
}

.brand { padding: 9px 13px; font-size: .72rem; font-weight: 900; letter-spacing: .16em; }
.source-pill { padding: 8px 12px; font-size: .73rem; font-weight: 800; }
.source-pill::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--yellow); }
.source-pill.local::before { background: #62ff9d; }
.source-pill.cloud::before { background: var(--blue); }
.source-pill.offline::before { background: var(--yellow); }

.tally-center {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  text-align: center;
  text-shadow: 0 4px 24px rgba(0,0,0,.3);
}

.camera-label {
  margin: 0;
  font-size: clamp(4.5rem, 25vw, 14rem);
  font-weight: 950;
  line-height: .82;
  letter-spacing: -.075em;
}

.state-label {
  margin-top: clamp(20px, 5vw, 42px);
  font-size: clamp(1.2rem, 5vw, 3.5rem);
  font-weight: 900;
  letter-spacing: .25em;
  transform: translateX(.125em);
}

.bottombar { align-items: flex-end; }
.metrics { display: flex; flex-wrap: wrap; gap: 8px; }
.metric-pill { padding: 7px 10px; font-size: .68rem; color: rgba(255,255,255,.82); }
.event-id { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, monospace; font-size: .62rem; opacity: .66; }

.admin {
  min-height: 100dvh;
  padding: 22px;
  background: radial-gradient(circle at 80% 0, #182838 0, var(--bg) 38%);
}

.admin-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin: 4px auto 22px; max-width: 1320px; }
.eyebrow { color: var(--blue); font-size: .74rem; font-weight: 900; letter-spacing: .18em; }
.admin h1 { margin: 5px 0 0; font-size: clamp(1.8rem, 4vw, 3rem); letter-spacing: -.04em; }
.admin-subtitle { margin: 7px 0 0; color: var(--muted); }
.admin-header-status { display: flex; align-items: center; gap: 8px; }
.client-count-pill { padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: rgba(0,0,0,.22); font-size: .68rem; font-weight: 850; letter-spacing: .07em; }
.atem-device-pill { max-width: min(42vw, 340px); overflow: hidden; padding: 8px 12px; border: 1px solid rgba(82,167,255,.24); border-radius: 999px; color: #a9d2ff; background: rgba(31,102,174,.13); font-size: .68rem; font-weight: 850; letter-spacing: .04em; text-overflow: ellipsis; white-space: nowrap; }

.admin-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; max-width: 1320px; margin: auto; }
.camera-card, .diagnostics-card {
  position: relative;
  min-height: 150px;
  overflow: hidden;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: 0 16px 45px rgba(0,0,0,.18);
}
.camera-card.program { background: linear-gradient(150deg, rgba(239,36,36,.96), rgba(107,7,7,.92)); }
.camera-card.preview { background: linear-gradient(150deg, rgba(32,199,101,.9), rgba(4,75,31,.92)); }
.camera-card.offline { border-color: rgba(255,188,39,.5); background: repeating-linear-gradient(-45deg, #2b2516 0 16px, #201b11 16px 32px); }
.camera-card .number { font-size: 3.4rem; line-height: 1; font-weight: 950; letter-spacing: -.06em; }
.camera-card .name { margin-top: 8px; color: rgba(255,255,255,.68); font-size: .72rem; font-weight: 800; letter-spacing: .12em; }
.camera-card .mode { position: absolute; right: 15px; bottom: 15px; font-size: .68rem; font-weight: 900; letter-spacing: .13em; }

.diagnostics { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; max-width: 1320px; margin: 12px auto 0; }
.diagnostics-card { min-height: 0; }
.diagnostics-card h2 { margin: 0 0 14px; font-size: .88rem; letter-spacing: .08em; }
.devices-card { grid-column: 1 / -1; }
.card-title-row { display: flex; justify-content: space-between; align-items: center; }
.card-title-row > span { color: #62ff9d; font-size: .68rem; font-weight: 850; letter-spacing: .1em; }
.device-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.device-row { min-width: 0; display: grid; grid-template-columns: 38px minmax(0, 1fr) auto 8px; align-items: center; gap: 11px; padding: 11px 12px; border: 1px solid rgba(255,255,255,.075); border-radius: 14px; background: rgba(0,0,0,.18); }
.device-camera { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; color: #08130d; background: #62ff9d; font-size: .82rem; font-weight: 950; }
.device-camera.admin-device { color: #07101a; background: var(--blue); }
.device-primary, .device-stats { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.device-primary strong, .device-stats strong { font-size: .77rem; }
.device-primary span, .device-stats span { overflow: hidden; color: var(--muted); font-size: .66rem; text-overflow: ellipsis; white-space: nowrap; }
.device-stats { align-items: flex-end; }
.online-dot { width: 7px; height: 7px; border-radius: 50%; background: #62ff9d; box-shadow: 0 0 12px rgba(98,255,157,.55); }
.empty-devices { padding: 24px; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); text-align: center; font-size: .78rem; }
.metric-table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.metric-table th, .metric-table td { padding: 8px 6px; border-top: 1px solid var(--line); text-align: left; }
.metric-table th { color: var(--muted); font-weight: 600; }
.log-line { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-top: 1px solid var(--line); font: .72rem ui-monospace, monospace; }
.log-line span:last-child { color: var(--muted); }

@media (max-width: 900px) {
  .admin-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .diagnostics { grid-template-columns: 1fr; }
  .device-list { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .admin { padding: 14px; }
  .admin-grid { gap: 8px; }
  .admin-header { align-items: stretch; flex-direction: column; }
  .admin-header-status { justify-content: space-between; }
  .atem-device-pill { order: 3; width: 100%; max-width: none; text-align: center; }
  .admin-header-status { flex-wrap: wrap; }
  .camera-card { min-height: 125px; border-radius: 16px; }
  .camera-card .number { font-size: 2.8rem; }
  .event-id { display: none; }
}

@media (orientation: landscape) and (max-height: 600px) {
  .camera-label { font-size: min(34vh, 9rem); }
  .state-label { margin-top: 12px; font-size: min(8vh, 2rem); }
}
