:root {
  color-scheme: dark;
  --bg: #0b0b0c;
  --panel: #18181b;
  --btn: #27272c;
  --line: #303036;
  --text: #ececf0;
  --muted: #9a9aa3;
  --accent: #4c8dff;
  --ok: #3ccf7a;
  --bad: #ff6b5e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--btn);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  cursor: pointer;
  touch-action: manipulation;
}
button:active { filter: brightness(1.3); }
button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: #ffb3ab; }
button:disabled { opacity: .6; }
[hidden] { display: none !important; }

/* ---------- sign-in page */
body.login { display: grid; place-items: center; padding: 24px; }
body.login form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 10px; }
body.login h1 { margin: 6px 0 0; font-size: 22px; }
body.login .sub { margin: 0 0 10px; color: var(--muted); }
body.login label { font-size: 13px; color: var(--muted); }
body.login input {
  font: inherit; font-size: 17px; color: var(--text);
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; outline: none;
}
body.login input:focus { border-color: var(--accent); }
body.login button[type=submit] {
  height: 48px; background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}
#err { min-height: 1.4em; margin: 0; color: var(--bad); }

/* ---------- remote screen */
body.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #000;
  touch-action: none;
}

#stage {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

#screen { display: block; }

#cursor {
  position: absolute;
  width: 18px;
  height: 24px;
  margin: -1px 0 0 -1px;
  pointer-events: none;
  transform-origin: 1px 1px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 24'%3E%3Cpath d='M1 1v18l4.6-4.4 3.3 7.6 3-1.3-3.3-7.4H16z' fill='white' stroke='black' stroke-width='1.3' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat;
}

#status {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: 92vw;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(18, 18, 20, .78);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
#status.ok::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--ok);
  vertical-align: 1px;
}
#status.bad { color: #ffd6d1; background: rgba(110, 24, 18, .88); }

#dock { position: relative; flex: none; }

#bar {
  display: flex;
  gap: 5px;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  padding-left: max(6px, env(safe-area-inset-left));
  padding-right: max(6px, env(safe-area-inset-right));
  background: var(--panel);
  border-top: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
#bar button { flex: 1 0 auto; min-width: 46px; height: 40px; font-size: 14px; }
#kb, #menuBtn { font-size: 20px !important; }

.panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  max-height: 58vh;
  overflow-y: auto;
  padding: 8px 10px 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
  gap: 6px;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, .4);
}
.panel h3 {
  grid-column: 1 / -1;
  margin: 6px 0 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
}
.panel button { height: 40px; padding: 0 6px; font-size: 14px; }
.panel.text { display: block; user-select: text; -webkit-user-select: text; }
.panel.text h3 { margin-top: 12px; }
.panel.text p { margin: 6px 0; color: #d6d6dc; }

/* Off-screen box that receives the phone keyboard's typing. */
#kbd {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 2px;
  height: 2px;
  padding: 0;
  border: 0;
  opacity: 0;
  resize: none;
  font-size: 16px; /* stops iPhone zooming the page when it opens */
  pointer-events: none;
}
