:root {
  --bg: #0d0f12;
  --panel: #171a1f;
  --panel-2: #1f242b;
  --line: #2b3138;
  --text: #e6e9ee;
  --muted: #8b949e;
  --accent: #4c8dff;
  --danger: #ff5c5c;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute is how we switch screens, and the UA rule that
   implements it loses to any id selector that sets `display`. */
[hidden] {
  display: none !important;
}

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

.screen {
  height: 100%;
}

.muted {
  color: var(--muted);
}

.error {
  color: var(--danger);
  margin: 0;
}

/* ------------------------------------------------------------- login */

#login {
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

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

.card p {
  margin: 0;
}

input[type="password"] {
  padding: 11px 13px;
  font-size: 15px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
}

input[type="password"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

button {
  padding: 9px 13px;
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

#login-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #08101f;
  font-weight: 600;
}

button.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ----------------------------------------------------------- session */

#session {
  display: flex;
  flex-direction: column;
}

#stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  background: #000;
  position: relative;
}

#screen {
  display: block;
  cursor: crosshair;
  /* Sized in JS so the aspect ratio stays exact and pointer coordinates
     map 1:1 onto the remote screen. Zoom and pan are applied as a CSS
     transform, which getBoundingClientRect() already accounts for — so the
     coordinate maths keeps working untouched. */
  transform-origin: 0 0;
  /* Without this, Safari eats every gesture for its own scroll and zoom. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#screen:focus {
  outline: none;
}

#overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.72);
  font-size: 15px;
  color: var(--muted);
}

/* The capture has no cursor in it, so on touch we show where the last
   command actually landed. */
#cursor {
  position: absolute;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.7), 0 0 10px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  transition: opacity 0.4s;
}

#hint {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100% - 24px));
  padding: 12px 16px;
  background: rgba(23, 26, 31, 0.97);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.6;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

#hint b {
  color: var(--accent);
  font-weight: 600;
}

/* Modifier and special-key row, for phones where the on-screen keyboard has
   no ctrl, alt, esc or arrows. */
#keys {
  display: flex;
  gap: 6px;
  padding: 7px 9px;
  overflow-x: auto;
  background: var(--panel-2);
  border-top: 1px solid var(--line);
  scrollbar-width: none;
}

#keys::-webkit-scrollbar {
  display: none;
}

#keys button {
  padding: 9px 13px;
  font-size: 13px;
  flex: 0 0 auto;
}

/* A latched modifier stays held until tapped again, so two-key shortcuts are
   possible with one finger. */
#keys button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #08101f;
  font-weight: 600;
}

/* Focusable so the phone raises its keyboard, but never visible. */
#kbd {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
}

#toast {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(560px, calc(100% - 32px));
  padding: 10px 15px;
  background: rgba(23, 26, 31, 0.96);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  font-size: 13px;
}

/* --------------------------------------------------------------- bar */

#bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

#bar select {
  padding: 8px 10px;
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.field,
.toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  white-space: nowrap;
}

.field input[type="range"] {
  width: 96px;
  accent-color: var(--accent);
}

.toggle input {
  accent-color: var(--accent);
}

#stats {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

/* ------------------------------------------------------------- files */

#files {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  z-index: 10;
}

#files header,
#files footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

#files footer {
  border-bottom: none;
  border-top: 1px solid var(--line);
}

#files-path {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

#files-list {
  flex: 1;
  overflow-y: auto;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

.row:hover {
  background: var(--panel-2);
}

.row .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row .size {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.upload {
  padding: 8px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}

.upload:hover {
  border-color: var(--accent);
}

#files.dragging {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
}

@media (max-width: 720px) {
  #bar {
    gap: 7px;
    padding: 7px 9px;
    font-size: 13px;
  }
  #bar button {
    padding: 9px 11px;
  }
  .field input[type="range"] {
    width: 58px;
  }
  /* On a phone the screen itself is the scarce resource: drop the controls
     that are rarely touched rather than stacking the bar three rows high. */
  .toggle,
  #stats,
  #btn-fullscreen {
    display: none;
  }
}
