:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  background: #080b10;
  color: #f3f5f7;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; overflow: hidden; }
main { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 0.75rem; }

.panel {
  width: min(30rem, 100%);
  background: #141925;
  border: 1px solid #2a3345;
  border-radius: 1rem;
  padding: 1.5rem;
}

h1 { margin: 0; }
form { display: grid; gap: 0.85rem; margin-top: 1rem; }
label { display: grid; gap: 0.35rem; color: #c9d2e3; font-size: 0.9rem; }

input, button {
  min-height: 2.75rem;
  border-radius: 0.6rem;
  border: 1px solid #38445c;
  font: inherit;
}

input { padding: 0 0.9rem; background: #0d111a; color: inherit; }
button { padding: 0 0.9rem; background: #263147; color: white; cursor: pointer; }
button:hover, button.selected { background: #3978f6; }
button.danger { background: #792d38; }
.error { color: #ff8b8b; min-height: 1.5rem; }
.hint { color: #94a1b8; font-size: 0.85rem; }
.hidden { display: none !important; }

#control-panel {
  width: 100%;
  height: calc(100dvh - 1.5rem);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0.55rem;
}

header, nav {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
}

nav {
  overflow-x: auto;
  padding-bottom: env(safe-area-inset-bottom);
  scrollbar-width: none;
}
nav::-webkit-scrollbar { display: none; }
#monitor-buttons { display: flex; gap: 0.4rem; }

#viewer {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: auto;
  background: #000;
  border-radius: 0.65rem;
  outline: none;
  touch-action: none;
  user-select: none;
}

#remote-screen {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#remote-screen.native {
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
}

#paused {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(0 0 0 / 68%);
  font-size: clamp(1rem, 4vw, 1.5rem);
}

#phone-keyboard {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0.01;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: -1;
}

body.immersive main {
  padding: 0;
}

body.immersive #control-panel {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  gap: 0;
  z-index: 100;
  background: #000;
}

body.immersive #viewer {
  border-radius: 0;
}

body.immersive header {
  position: absolute;
  top: max(0.4rem, env(safe-area-inset-top));
  left: max(0.5rem, env(safe-area-inset-left));
  z-index: 4;
  gap: 0.65rem;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  background: rgb(8 11 16 / 78%);
  backdrop-filter: blur(8px);
}

body.immersive nav {
  position: absolute;
  right: max(0.45rem, env(safe-area-inset-right));
  bottom: max(0.45rem, env(safe-area-inset-bottom));
  left: max(0.45rem, env(safe-area-inset-left));
  z-index: 4;
  justify-content: flex-start;
  padding: 0.45rem;
  border: 1px solid rgb(255 255 255 / 12%);
  border-radius: 0.8rem;
  background: rgb(8 11 16 / 82%);
  backdrop-filter: blur(10px);
}

@media (max-width: 650px) {
  main { padding: 0; }
  #control-panel {
    height: 100vh;
    height: 100dvh;
    gap: 0;
    grid-template-rows: 2.55rem minmax(0, 1fr) auto;
  }
  header {
    padding: 0.45rem 0.65rem;
    font-size: 0.8rem;
    background: #101622;
  }
  #viewer { border-radius: 0; }
  nav {
    justify-content: flex-start;
    gap: 0.35rem;
    padding: 0.4rem max(0.4rem, env(safe-area-inset-right))
      max(0.4rem, env(safe-area-inset-bottom))
      max(0.4rem, env(safe-area-inset-left));
    background: #101622;
  }
  nav button {
    flex: 0 0 auto;
    min-height: 2.65rem;
    padding-inline: 0.8rem;
    white-space: nowrap;
  }
  #monitor-buttons { display: contents; }
  body.immersive #control-panel {
    grid-template-rows: minmax(0, 1fr);
  }
  body.immersive header strong { display: none; }
}
