:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev-2: #1f2632;
  --border: #2a323d;
  --text: #e6edf3;
  --text-dim: #8b97a4;
  --accent: #2f81f7;
  --accent-hover: #4493f8;
  --danger: #f85149;
  --success: #3fb950;
  --warn: #d29922;
  --radius: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
}

#app {
  height: 100%;
  width: 100%;
  position: relative;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen.hidden { display: none; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: min(420px, 92vw);
  text-align: center;
}

.card h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card h1 .subtitle {
  color: var(--text-dim);
  font-weight: 400;
}

.card .lead {
  margin: 0 0 24px;
  color: var(--text-dim);
  font-size: 14px;
}

#connect-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

#code-input {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 28px;
  text-align: center;
  letter-spacing: 0.4em;
  padding: 14px 12px;
  outline: none;
  transition: border-color 0.15s;
}

#code-input:focus { border-color: var(--accent); }
#code-input::placeholder { color: #4a5563; letter-spacing: 0.4em; }

button {
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  padding: 12px 16px;
  transition: background-color 0.15s;
}

button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.link-btn {
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 12px;
  padding: 6px 8px;
}

.link-btn:hover:not(:disabled) {
  background: transparent;
  color: var(--text);
}

.server-info {
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
}

.server-info code {
  background: var(--bg-elev-2);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
}

.server-info a {
  color: var(--accent);
  text-decoration: none;
  margin-left: 6px;
}

.server-info a:hover { text-decoration: underline; }

.spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto 16px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

#status-text {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
}

#screen-connected {
  background: #000;
}

#remote-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  cursor: none;
  outline: none;
}

#hud {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(22, 27, 34, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  z-index: 10;
  user-select: none;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot-green { background: var(--success); box-shadow: 0 0 8px var(--success); }
.dot-yellow { background: var(--warn); }
.dot-red { background: var(--danger); }

#hud-rtt {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-dim);
}

#hud button {
  background: var(--danger);
  font-size: 12px;
  padding: 6px 10px;
  margin-left: 4px;
}

#hud button:hover:not(:disabled) { background: #ff6b66; }

#toast-host {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: var(--shadow);
  min-width: 280px;
  max-width: 480px;
  pointer-events: auto;
}

.toast.toast-error { border-left-color: var(--danger); }
.toast.toast-warn  { border-left-color: var(--warn); }
.toast.toast-info  { border-left-color: var(--accent); }
