/* RemoteView viewer.
 *
 * Deliberately dark and low-contrast around the edges: the interesting thing on
 * this page is someone else's screen, and a bright frame around it makes the
 * remote desktop harder to read. Everything here is chrome that should recede.
 */

:root {
  --bg: #12151a;
  --panel: #1b202a;
  --line: #2a3140;
  --text: #e6eaf0;
  --muted: #8e99ab;
  --accent: #2f7de1;
  --good: #35c07a;
  --warn: #e0a72f;
  --bad: #e05a4f;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.panel { height: 100%; }
[hidden] { display: none !important; }

/* ---- connect ------------------------------------------------------------ */

#connect {
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
}

.card h1 {
  margin: 0 0 4px;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.lede { margin: 0 0 24px; color: var(--muted); font-size: 14px; }

label {
  display: block;
  margin: 16px 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.hint { font-weight: 400; opacity: 0.7; }

input[type="text"], input:not([type]) {
  width: 100%;
}

#connect-form input {
  width: 100%;
  padding: 11px 13px;
  background: #0f1319;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

#connect-form input:focus {
  outline: none;
  border-color: var(--accent);
}

#session-id, #password { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

#connect-btn {
  width: 100%;
  margin-top: 24px;
  padding: 12px;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

#connect-btn:disabled { opacity: 0.5; cursor: default; }
#connect-btn:not(:disabled):hover { background: #3a8bef; }

.status {
  min-height: 1.5em;
  margin: 16px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* ---- session ------------------------------------------------------------ */

#session {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

#bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.grow { flex: 1; }
.sep { width: 1px; height: 18px; background: var(--line); }
.muted { color: var(--muted); font-variant-numeric: tabular-nums; }
.muted.good { color: var(--good); }
.muted.warn { color: var(--warn); }

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.dot.good { background: var(--good); }
.dot.warn { background: var(--warn); }
.dot.bad  { background: var(--bad); }
.dot.waiting { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.3; } }

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}
.toggle input { accent-color: var(--accent); }

#bar button {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
}
#bar button:hover { background: #232a36; }
#bar .danger { border-color: #5a2b28; color: #f0918a; }
#bar .danger:hover { background: #3a1e1c; }

/* ---- stage -------------------------------------------------------------- */

#stage {
  position: relative;
  overflow: auto;
  background: #000;
  display: grid;
  place-items: center;
  min-height: 0;
}

#screen {
  max-width: 100%;
  max-height: 100%;
  /* `contain` keeps the remote screen's aspect ratio. The letterbox bars this
   * creates are accounted for in input-map.js - without that the cursor lands
   * in the wrong place. */
  object-fit: contain;
  outline: none;
  cursor: crosshair;
}

/* Actual size: one remote pixel to one local pixel, scroll to see the rest.
 * Needed when reading small text on a 4K remote screen shrunk into a window. */
#stage.actual-size { place-items: start; }
#stage.actual-size #screen { max-width: none; max-height: none; }

/* The on-screen keyboard catcher.
 *
 * Off-screen rather than display:none or visibility:hidden - either of those
 * makes it unfocusable, and being focusable is its entire job. It must also
 * stay a real, non-readonly textarea, because that is what phones look for
 * before raising a keyboard. */
#keyboard-trap {
  position: absolute;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  resize: none;
}

#bar button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  padding: 40px;
  text-align: center;
  background: rgba(18, 21, 26, 0.92);
  color: var(--muted);
}

.overlay p { max-width: 46ch; margin: 0; }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#hint-bar {
  padding: 7px 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

kbd {
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #0f1319;
  font: 11px ui-monospace, Consolas, monospace;
}

#stage:fullscreen { place-items: center; }
