:root {
  color-scheme: dark;
  font-family: "Segoe UI", "Microsoft YaHei UI", system-ui, sans-serif;
  background: #05070b;
  color: #f4f7fb;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: #05070b;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 12% -10%, rgba(62, 122, 213, 0.19), transparent 34rem),
    radial-gradient(circle at 92% 12%, rgba(34, 197, 134, 0.1), transparent 30rem),
    #05070b;
}

button,
input,
select {
  font: inherit;
}

button,
input,
select,
video[tabindex] {
  outline: none;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
video[tabindex]:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(107, 172, 255, 0.92);
  outline-offset: 3px;
}

.app-shell {
  width: min(1240px, calc(100% - 40px));
  margin: 0 auto;
  padding: 36px 0 28px;
}

.app-header,
.panel-heading,
.session-topbar,
.form-actions,
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.app-header {
  align-items: flex-start;
  margin-bottom: 24px;
}

.eyebrow,
.step-label {
  margin: 0 0 7px;
  color: #72aefb;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 7px;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.12;
  letter-spacing: -0.035em;
}

h2 {
  margin-bottom: 0;
  font-size: 21px;
  letter-spacing: -0.015em;
}

.subtitle,
.privacy-note,
.control-help {
  color: #9ba7ba;
}

.subtitle {
  max-width: 700px;
  margin-bottom: 0;
}

.security-badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid #594b2b;
  border-radius: 999px;
  color: #f0cc76;
  background: rgba(69, 50, 17, 0.55);
  font-size: 13px;
}

.security-badge span {
  color: #f2b94b;
  font-size: 10px;
  text-shadow: 0 0 12px rgba(242, 185, 75, 0.8);
}

.panel,
.session-panel,
.global-status,
.diagnostics {
  border: 1px solid #242b38;
  border-radius: 16px;
  background: rgba(13, 17, 24, 0.94);
  box-shadow: 0 26px 75px rgba(0, 0, 0, 0.28);
}

.connection-panel {
  padding: 26px;
}

.panel-heading {
  align-items: flex-end;
  padding-bottom: 22px;
  border-bottom: 1px solid #252c38;
}

.privacy-note {
  margin: 0;
  font-size: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  padding-top: 22px;
}

.field {
  display: grid;
  gap: 8px;
  color: #dbe2ee;
  font-size: 14px;
  font-weight: 600;
}

.field-wide {
  grid-column: 1 / -1;
}

.field small {
  color: #7f8a9c;
  font-size: 12px;
  font-weight: 400;
}

input:not([type="checkbox"]) {
  min-height: 48px;
  width: 100%;
  border: 1px solid #364052;
  border-radius: 10px;
  padding: 11px 13px;
  color: #f8faff;
  background: #090d14;
}

input:not([type="checkbox"]):hover {
  border-color: #526078;
}

input:not([type="checkbox"]):focus {
  border-color: #6b9fe9;
  background: #0c111a;
}

input:not([type="checkbox"])[aria-invalid="true"] {
  border-color: #e46771;
}

.remember-token-option {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-top: 2px;
  color: #c5cedc;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
}

.remember-token-option input {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: #6b9fe9;
  cursor: pointer;
}

.remember-token-option input:focus-visible {
  outline: 2px solid #8bb8f5;
  outline-offset: 3px;
}

.remember-token-option input:disabled,
.remember-token-option input:disabled + span {
  cursor: not-allowed;
  opacity: 0.65;
}

.form-actions {
  align-items: flex-end;
  margin-top: 22px;
}

.form-error {
  margin: 0;
  color: #ffabb1;
  font-size: 14px;
}

.button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 17px;
  color: #edf3fb;
  background: #202735;
  font-weight: 650;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:disabled {
  color: #6f7888;
  background: #171c25;
  cursor: not-allowed;
}

.button-primary {
  min-width: 150px;
  border-color: #3d83dc;
  background: #2468bd;
}

.button-primary:hover:not(:disabled) {
  background: #2f78d2;
}

.button-secondary {
  border-color: #414b5e;
}

.button-secondary:hover:not(:disabled) {
  background: #2a3343;
}

.button-danger {
  border-color: #7b3941;
  color: #ffcdd1;
  background: #32181d;
}

.button-danger:hover:not(:disabled) {
  background: #492127;
}

.button-control {
  margin-right: auto;
  border-color: #3b536f;
  background: #19283a;
}

.button-control[aria-pressed="true"] {
  border-color: #25966a;
  color: #b8f5d9;
  background: #123428;
}

.session-panel {
  overflow: hidden;
}

.session-topbar {
  padding: 19px 22px;
  border-bottom: 1px solid #242b38;
}

#active-device-id,
.diagnostics dd {
  font-family: Consolas, "Cascadia Mono", monospace;
}

.status-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-chip {
  padding: 6px 10px;
  border: 1px solid #3b4556;
  border-radius: 999px;
  color: #a9b3c2;
  background: #151b25;
  font-size: 12px;
}

.status-chip[data-state="ready"] {
  border-color: #247a59;
  color: #83dfb7;
  background: #10291f;
}

.status-chip[data-state="error"] {
  border-color: #873e46;
  color: #ff9da6;
  background: #32171b;
}

.status-chip[data-state="active"] {
  border-color: #2b9a6d;
  color: #c0f8df;
  background: #12402f;
  box-shadow: 0 0 20px rgba(38, 171, 115, 0.12);
}

.remote-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 360px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-bottom: 1px solid #242b38;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.018) 25%, transparent 25%) 0 0 / 22px 22px,
    linear-gradient(-45deg, rgba(255, 255, 255, 0.018) 25%, transparent 25%) 0 0 / 22px 22px,
    #020305;
}

.remote-stage:fullscreen,
.remote-stage[data-fullscreen="true"] {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  min-width: 0;
  min-height: 0;
  aspect-ratio: auto;
  border: 0;
  z-index: 9999;
}

.remote-stage video {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: block;
  object-fit: contain;
  object-position: center;
  background: #000;
}

.remote-stage[data-control-active="true"] video {
  cursor: crosshair;
}

.video-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 30px;
  text-align: center;
  color: #c8d1df;
  background: rgba(3, 5, 8, 0.82);
  pointer-events: none;
}

.video-overlay strong {
  margin-top: 8px;
  color: #f3f6fb;
  font-size: 18px;
}

.video-overlay span {
  max-width: 600px;
  color: #8e9aab;
  font-size: 14px;
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid #2b3545;
  border-top-color: #65a7f4;
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

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

.control-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 13px;
  border: 1px solid rgba(59, 213, 148, 0.55);
  border-radius: 999px;
  color: #c5f8e1;
  background: rgba(13, 61, 43, 0.92);
  font-size: 13px;
  pointer-events: none;
}

.special-key-toolbar {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 4;
  display: flex;
  max-width: calc(100% - 24px);
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.special-keys-toggle {
  min-height: 44px;
  padding: 10px 14px;
  border-color: rgba(101, 167, 244, 0.58);
  background: rgba(14, 24, 38, 0.94);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.34);
}

.special-keys-panel {
  width: min(430px, calc(100vw - 24px));
  padding: 12px;
  border: 1px solid #344258;
  border-radius: 12px;
  background: rgba(8, 12, 19, 0.96);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.46);
  backdrop-filter: blur(10px);
}

.special-keys-panel[hidden] {
  display: none;
}

.special-keys-label {
  display: block;
  margin: 0 0 9px;
  color: #aab5c5;
  font-size: 12px;
}

.special-keys-hint {
  display: block;
  margin: -3px 0 9px;
  color: #91a2b8;
  font-size: 11px;
  line-height: 1.35;
}

.special-keys-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.special-key-button {
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid #3b4b63;
  border-radius: 8px;
  color: #e7edf6;
  background: #172131;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.special-key-button:hover:not(:disabled),
.special-key-button:focus-visible {
  border-color: #65a7f4;
  background: #20324a;
  outline: 3px solid #9bc7ff;
  outline-offset: 2px;
}

.special-key-button small {
  display: block;
  margin-top: 2px;
  color: #e9aab0;
  font-size: 10px;
  font-weight: 500;
}

.special-key-button-danger {
  border-color: #7c4248;
  color: #ffd8dc;
  background: #3a1d22;
}

.special-key-button-danger:hover:not(:disabled),
.special-key-button-danger:focus-visible {
  border-color: #e47983;
  background: #54252c;
}

.special-key-button:disabled,
.special-keys-toggle:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.session-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid #242b38;
}

.session-meta > div {
  min-width: 0;
  padding: 17px 20px;
}

.session-meta > div + div {
  border-left: 1px solid #242b38;
}

.session-meta span,
.session-meta strong,
.session-meta small {
  display: block;
}

.session-meta span {
  margin-bottom: 5px;
  color: #7f8a9c;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.session-meta strong {
  overflow: hidden;
  margin-bottom: 4px;
  color: #eef3f9;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-meta small {
  overflow: hidden;
  color: #8792a3;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  justify-content: flex-end;
  padding: 12px 20px;
  border-bottom: 1px solid #242b38;
  background: #111720;
}

.video-quality-control {
  display: grid;
  min-width: 250px;
  gap: 3px;
  color: #9ca8ba;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.video-quality-home {
  min-width: 250px;
}

.fullscreen-quality-toggle {
  min-height: 44px;
  padding: 10px 14px;
  border-color: rgba(101, 167, 244, 0.58);
  background: rgba(14, 24, 38, 0.94);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.34);
}

.video-quality-panel {
  width: min(320px, calc(100vw - 24px));
  padding: 10px;
  border: 1px solid #3a475d;
  border-radius: 12px;
  background: rgba(12, 19, 29, 0.97);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.42);
}

.video-quality-panel .video-quality-control {
  width: 100%;
  min-width: 0;
}

.video-quality-control select {
  min-height: 44px;
  width: 100%;
  border: 1px solid #414b5e;
  border-radius: 10px;
  padding: 8px 34px 8px 11px;
  color: #edf3fb;
  background: #171e29;
  cursor: pointer;
}

.video-quality-control select:hover:not(:disabled) {
  border-color: #5b6a83;
  background: #1d2634;
}

.video-quality-control select:disabled {
  color: #6f7888;
  cursor: not-allowed;
  opacity: 0.72;
}

#video-quality-status {
  min-height: 15px;
  color: #7f8b9e;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0;
}

#video-quality-status[data-state="applied"] {
  color: #77d9ad;
}

#video-quality-status[data-state="partial"] {
  color: #f2c66e;
}

#video-quality-status[data-state="error"] {
  color: #ff9da6;
}

.control-help {
  margin: 0;
  padding: 15px 20px 18px;
  font-size: 13px;
}

.global-status {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding: 13px 16px;
  box-shadow: none;
}

#global-status-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #718096;
}

.global-status[data-kind="working"] #global-status-dot {
  background: #5ba5fa;
  box-shadow: 0 0 13px rgba(91, 165, 250, 0.8);
}

.global-status[data-kind="success"] #global-status-dot {
  background: #42d494;
  box-shadow: 0 0 13px rgba(66, 212, 148, 0.75);
}

.global-status[data-kind="error"] #global-status-dot {
  background: #f16b75;
  box-shadow: 0 0 13px rgba(241, 107, 117, 0.7);
}

.global-status strong,
.global-status span {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.global-status strong {
  margin-bottom: 2px;
  font-size: 14px;
}

.global-status span {
  color: #929daf;
  font-size: 13px;
}

.diagnostics {
  margin-top: 14px;
  padding: 0 16px;
  color: #a3adbc;
  box-shadow: none;
}

.diagnostics summary {
  min-height: 44px;
  padding: 12px 0;
  cursor: pointer;
  font-size: 13px;
}

.diagnostics dl {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0 0 14px;
}

.diagnostics dl div {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 12px;
}

.diagnostics dt {
  color: #6f7b8e;
}

.diagnostics dd {
  overflow-wrap: anywhere;
  margin: 0;
  color: #b7c1cf;
  font-size: 12px;
}

#diagnostic-route {
  width: fit-content;
  padding: 2px 8px;
  border: 1px solid #455165;
  border-radius: 999px;
}

#diagnostic-route[data-route="p2p"] {
  border-color: #247a59;
  color: #83dfb7;
  background: #10291f;
}

#diagnostic-route[data-route="relay"] {
  border-color: #8a6428;
  color: #f2c66e;
  background: #30240f;
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 24px, 680px);
    padding-top: 22px;
  }

  .app-header,
  .panel-heading,
  .session-topbar,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .security-badge {
    align-self: flex-start;
  }

  .form-grid,
  .session-meta {
    grid-template-columns: 1fr;
  }

  .field-wide {
    grid-column: auto;
  }

  .form-actions .button,
  .toolbar .button {
    width: 100%;
  }

  .status-chips {
    justify-content: flex-start;
  }

  .remote-stage {
    min-height: 240px;
  }

  .session-meta > div + div {
    border-top: 1px solid #242b38;
    border-left: 0;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .video-quality-control {
    width: 100%;
    min-width: 0;
  }

  .video-quality-home {
    width: 100%;
    min-width: 0;
  }

  .button-control {
    margin-right: 0;
  }

  .special-key-toolbar {
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    max-width: calc(100% - 16px);
  }

  .special-keys-panel {
    width: min(400px, calc(100vw - 16px));
  }

  .diagnostics dl div {
    grid-template-columns: 1fr;
    gap: 3px;
  }
}

@media (max-height: 420px) {
  .special-key-toolbar {
    display: grid;
    width: min(400px, calc(100% - 16px));
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
  }

  .fullscreen-quality-toggle {
    grid-column: 1;
    grid-row: 2;
  }

  .special-keys-toggle {
    grid-column: 2;
    grid-row: 2;
  }

  .video-quality-panel,
  .special-keys-panel {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .special-keys-panel {
    padding: 8px;
  }

  .special-keys-label {
    margin-bottom: 6px;
  }

  .special-keys-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .special-key-button {
    padding: 6px 7px;
    font-size: 12px;
  }
}

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