:root {
  --bg: #f6f7f9; --card: #ffffff; --fg: #17202a; --muted: #66717d; --line: #e1e5ea;
  --hover: #f0f3f5; --accent: #0d8f7f; --accent-soft: #d9f1ed; --on-accent: #ffffff;
  --ok: #1f9d55; --warn: #c47a12; --danger: #d0393e;
  --bar: rgba(255, 255, 255, 0.92);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14191e; --card: #1b2229; --fg: #e7ecf0; --muted: #8c99a6; --line: #28313a;
    --hover: #212a32; --accent: #2fc2ad; --accent-soft: #16352f; --on-accent: #06201c;
    --ok: #3ccf7a; --warn: #e5a33a; --danger: #f0595d;
    --bar: rgba(27, 34, 41, 0.92);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.2em; margin: 10px 0 0; }

/* ---------- home */
#home {
  min-height: 100%; display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.card {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px 22px 20px; text-align: center;
}
.logo { width: 64px; height: 64px; border-radius: 14px; }
h1 { font-size: 22px; margin: 12px 0 2px; }
#host-detail { margin: 0 0 18px; }
.field { display: block; text-align: left; margin: 12px 0; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); outline: none; font-size: 17px;
}
.field input:focus { border-color: var(--accent); }
#pin { letter-spacing: 3px; text-align: center; font-size: 22px; font-variant-numeric: tabular-nums; }
details { text-align: left; margin: 10px 0 4px; color: var(--muted); font-size: 14px; }
details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details b { color: var(--fg); font-weight: 600; }
button.link { background: none; border: 0; color: var(--accent); padding: 4px 0; cursor: pointer; font-size: 14px; }
button.primary, .primary {
  width: 100%; margin-top: 14px; padding: 12px; border: 0; border-radius: 10px;
  background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: 16px; cursor: pointer;
}
button.primary:disabled { opacity: .5; cursor: default; }
button.secondary {
  width: 100%; margin-top: 10px; padding: 11px; border: 1px solid var(--accent); border-radius: 10px;
  background: none; color: var(--accent); font-weight: 600; font-size: 16px; cursor: pointer;
}
.hint { font-size: 13px; margin: 14px 0 0; }

/* ---------- session */
#session { position: fixed; inset: 0; background: #000; overflow: hidden; touch-action: none; }
#stage { position: absolute; inset: 0; overflow: hidden; }
#screen { position: absolute; left: 0; top: 0; image-rendering: auto; background: #000; }
#waiting { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#cursor {
  position: absolute; width: 18px; height: 18px; margin: -2px 0 0 -2px; pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath d='M2 2l5 14 2.2-5.8L15 8z' fill='white' stroke='black' stroke-width='1.3' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat;
}
#session.mouse #stage { cursor: none; }
#kbd { position: absolute; left: -1000px; top: 0; width: 10px; height: 10px; opacity: 0; font-size: 16px; }

#bar {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: max(10px, env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 2px;
  background: var(--bar); border: 1px solid var(--line); border-radius: 14px; padding: 4px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); box-shadow: 0 6px 24px rgba(0,0,0,.25);
  max-width: calc(100% - 20px); transition: opacity .2s;
}
@media (pointer: fine) {
  #bar { top: 10px; bottom: auto; opacity: .35; }
  #bar:hover, #bar.open { opacity: 1; }
}
#bar .peer { display: flex; align-items: center; gap: 6px; padding: 0 10px 0 8px; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
#bar .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
#bar button {
  width: 40px; height: 40px; border: 0; border-radius: 10px; background: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--fg); flex: none;
}
#bar button:hover, #bar button.on { background: var(--hover); }
#bar button.on { color: var(--accent); }
#bar button.danger { color: var(--danger); }
#bar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 420px) { #bar .peer { display: none; } }
@media (pointer: fine) { .touch-only { display: none !important; } }

#keys {
  position: absolute; left: 0; right: 0; bottom: calc(max(10px, env(safe-area-inset-bottom)) + 56px);
  padding: 0 8px; display: flex; flex-direction: column; align-items: center; gap: 6px;
}
@media (pointer: fine) { #keys { top: 62px; bottom: auto; } }
#keys .row {
  display: flex; gap: 4px; overflow-x: auto; background: var(--bar); border: 1px solid var(--line);
  border-radius: 12px; padding: 4px; max-width: 100%; scrollbar-width: none;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
#keys .row::-webkit-scrollbar { display: none; }
#keys button {
  min-width: 42px; height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); cursor: pointer; white-space: nowrap; font-size: 14px; flex: none;
}
#keys button.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

#sheet {
  position: absolute; inset: 0; background: rgba(0,0,0,.35); display: flex;
  align-items: flex-end; justify-content: center; touch-action: auto;
}
@media (pointer: fine) { #sheet { align-items: center; } }
.sheet-card {
  width: 100%; max-width: 440px; max-height: 80vh; overflow: auto; background: var(--card);
  border-radius: 16px 16px 0 0; padding: 14px 16px max(16px, env(safe-area-inset-bottom));
}
@media (pointer: fine) { .sheet-card { border-radius: 16px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head b { font-size: 17px; }
.close { border: 0; background: var(--hover); width: 32px; height: 32px; border-radius: 50%; cursor: pointer; }
.panel p { margin: 4px 0 10px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid button, .buttons button {
  padding: 12px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  cursor: pointer; font-weight: 500;
}
.grid button:hover, .buttons button:hover { background: var(--hover); }
.buttons { display: flex; gap: 8px; margin: 8px 0 12px; }
.buttons button { flex: 1; margin: 0; }
.buttons button.primary { border: 0; font-size: 15px; }
textarea {
  width: 100%; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  padding: 10px; resize: vertical; outline: none; font-size: 16px;
}
textarea:focus { border-color: var(--accent); }
.label { font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 0 6px !important; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  flex: 1 0 auto; padding: 9px 12px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg); cursor: pointer;
}
.seg button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.file-pick { display: block; text-align: center; }
#transfers { list-style: none; padding: 0; margin: 12px 0 0; }
#transfers li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
#transfers li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#transfers a { color: var(--accent); }

#toasts {
  position: absolute; left: 0; right: 0; top: max(12px, env(safe-area-inset-top));
  display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none;
}
@media (pointer: fine) { #toasts { top: 70px; } }
.toast {
  background: var(--bar); color: var(--fg); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 14px; font-size: 14px; max-width: 90%; pointer-events: auto;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast button { margin-left: 10px; border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; }

/* ---------- phone app: list of computers */
#computer-list { text-align: left; margin-bottom: 4px; }
#computer-list h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 14px 0 6px; }
.computer {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px; margin: 0 0 8px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg); cursor: pointer; text-align: left;
}
.computer .os { width: 36px; height: 36px; border-radius: 10px; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; flex: none; }
.computer .os svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.computer .text { flex: 1; min-width: 0; }
.computer b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.computer small { color: var(--muted); }
.computer .forget { border: 0; background: none; color: var(--muted); font-size: 18px; padding: 4px 6px; cursor: pointer; }
#back { margin-top: 10px; }

#qr-scan {
  position: fixed; inset: 0; z-index: 50; background: #000; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 16px;
}
#qr-scan[hidden] { display: none; }
#qr-scan video { width: 100%; max-width: 520px; max-height: 70vh; object-fit: cover; border-radius: 12px; background: #111; }
#qr-scan p { text-align: center; margin: 0; }
#qr-scan button { max-width: 520px; }
