/* Screen Control - Viewer styles. Dark, modern, responsive. */

:root {
  --bg: #0b0f17;
  --bg-2: #0f1522;
  --panel: #141b2b;
  --panel-2: #1a2334;
  --border: #243049;
  --border-soft: #1c2639;
  --text: #e8edf6;
  --text-dim: #9aa6bd;
  --text-faint: #6b7890;
  --accent: #4c8dff;
  --accent-2: #3a74e0;
  --danger: #ff5a6a;
  --danger-2: #e23b4c;
  --ok: #37d19a;
  --warn: #ffb020;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(1100px 700px at 15% -10%, rgba(76, 141, 255, 0.12), transparent 60%),
    radial-gradient(900px 600px at 110% 10%, rgba(55, 209, 154, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

/* ---- Connect panel ---------------------------------------------------- */
.panel {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  gap: 18px;
}

.card {
  width: 100%;
  max-width: 440px;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 24px 22px;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.logo {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: var(--accent);
  background: rgba(76, 141, 255, 0.12);
  border: 1px solid rgba(76, 141, 255, 0.25);
}

.card-titles h1 {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: 0.2px;
}

.card-titles p {
  margin: 2px 0 0;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field > span {
  display: block;
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 6px;
  letter-spacing: 0.2px;
}

.field input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input::placeholder {
  color: var(--text-faint);
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(76, 141, 255, 0.2);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 600;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease, opacity 0.15s ease;
  user-select: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  width: 100%;
  margin-top: 4px;
  color: #fff;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
}

.btn.primary:hover {
  background: linear-gradient(180deg, #5c98ff, #3f7ae8);
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn.danger {
  color: #fff;
  background: linear-gradient(180deg, var(--danger), var(--danger-2));
}

.btn.danger:hover {
  background: linear-gradient(180deg, #ff6f7d, #d8333f);
}

.btn.small {
  font-size: 0.86rem;
  padding: 8px 14px;
}

.status {
  margin: 16px 0 4px;
  font-size: 0.9rem;
  color: var(--text-dim);
  min-height: 1.2em;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}

.status.error {
  color: #ffd7db;
  background: rgba(255, 90, 106, 0.12);
  border-color: rgba(255, 90, 106, 0.35);
}

/* ---- Saved hosts ------------------------------------------------------ */
.book {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border-soft);
}

.book-head h2 {
  margin: 0 0 10px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-faint);
  font-weight: 600;
}

.saved-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.saved-item {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.saved-pick {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  padding: 11px 13px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.saved-pick:hover {
  border-color: var(--accent);
  background: #1e2a40;
}

.saved-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.saved-id {
  font-size: 0.82rem;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}

.saved-remove {
  flex: 0 0 auto;
  padding: 0 12px;
  font-size: 0.8rem;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.saved-remove:hover {
  color: var(--danger);
  border-color: rgba(255, 90, 106, 0.4);
}

.saved-empty {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-faint);
}

.foot {
  font-size: 0.8rem;
  color: var(--text-faint);
  text-align: center;
  max-width: 440px;
}

/* ---- Session view ----------------------------------------------------- */
.session {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #000;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(20, 27, 43, 0.96), rgba(15, 21, 34, 0.96));
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(55, 209, 154, 0.6);
  animation: pulse 2s infinite;
  flex: 0 0 auto;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(55, 209, 154, 0.5);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(55, 209, 154, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(55, 209, 154, 0);
  }
}

.session-title {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.latency {
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  color: var(--text-dim);
  padding: 5px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}

.latency-unit {
  color: var(--text-faint);
  margin-left: 2px;
  font-size: 0.78rem;
}

.stage {
  flex: 1 1 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
}

.stage video {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.stage-hint {
  position: absolute;
  color: var(--text-dim);
  font-size: 0.95rem;
  padding: 14px 20px;
  background: rgba(20, 27, 43, 0.8);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* ---- Small screens ---------------------------------------------------- */
@media (max-width: 480px) {
  .card {
    padding: 22px 18px 18px;
  }

  .card-titles h1 {
    font-size: 1.18rem;
  }

  .topbar {
    padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top));
  }

  .session-title {
    font-size: 0.88rem;
  }

  .btn.small {
    padding: 8px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .live-dot {
    animation: none;
  }
}
