* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: #111418; color: #e8eaed;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden; overscroll-behavior: none;
}
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }
button, select, input {
  font: inherit; color: inherit; background: #2a2f37; border: 1px solid #3b424d;
  border-radius: 8px; padding: 6px 10px;
}
button { cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
button:active { background: #3b424d; }
button.on { background: #1a73e8; border-color: #1a73e8; }
button.danger { background: #8b1e1e; border-color: #a33; }
.muted { color: #9aa0a6; }
.small { font-size: 13px; }
.error { color: #ff6b6b; min-height: 1.4em; }

/* вход */
#login { align-items: center; justify-content: center; padding: 16px; }
.card { width: 100%; max-width: 340px; background: #1b1f25; padding: 24px; border-radius: 14px;
        display: flex; flex-direction: column; gap: 12px; }
.card h1 { margin: 0; font-size: 22px; }
.card input { padding: 12px; font-size: 16px; }
.card button { padding: 12px; background: #1a73e8; border-color: #1a73e8; font-weight: 600; }

/* панель инструментов */
#toolbar {
  display: flex; gap: 6px; align-items: center; padding: 6px; padding-top: max(6px, env(safe-area-inset-top));
  background: #1b1f25; border-bottom: 1px solid #2a2f37; overflow-x: auto; flex: 0 0 auto;
  scrollbar-width: none;
}
#toolbar button { min-width: 40px; padding: 6px 8px; }
#status { margin-left: auto; white-space: nowrap; font-size: 13px; color: #9aa0a6; padding: 0 6px; }
#status.ok { color: #7bd88f; }
#status.bad { color: #ff9f6b; }

/* картинка удалённого экрана */
#viewport {
  position: relative; flex: 1 1 auto; overflow: hidden; background: #000;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
#screen { display: block; image-rendering: auto; pointer-events: none;
          -webkit-user-drag: none; user-select: none; }
#viewport.pan { cursor: grab; }
#message {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
  background: rgba(20, 22, 26, .92); padding: 14px 18px; border-radius: 10px; text-align: center;
  max-width: 90%;
}

/* выдвижные панели */
.panel {
  flex: 0 0 auto; background: #1b1f25; border-top: 1px solid #2a2f37; padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom)); max-height: 45vh; overflow-y: auto;
}
.panel .row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; align-items: center; }
.panel .row button { min-width: 44px; }
.panel .hint { font-size: 12px; color: #9aa0a6; }
#send-text { flex: 1 1 160px; min-width: 0; }
#settings-panel label { display: flex; gap: 8px; align-items: center; justify-content: space-between;
                        margin-bottom: 8px; }
#settings-panel input[type=range] { flex: 1; max-width: 260px; }

/* скрытое поле ввода: должно быть "видимым" для браузера, чтобы открылась клавиатура */
#kbd-input {
  position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0;
  font-size: 16px; /* меньше 16px - iPhone начнёт увеличивать страницу */
  border: 0; padding: 0; resize: none; background: transparent; color: transparent;
}

/* узкие экраны (телефон) */
@media (max-width: 600px) {
  #toolbar { gap: 4px; padding: 4px; }
  #toolbar button { min-width: 36px; padding: 6px 6px; }
  #status { font-size: 11px; }
}

details { margin: 8px 0; }
details .row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
details input { flex: 1 1 140px; min-width: 0; }

/* страница настройки */
body.setup { overflow: auto; }
.setup-wrap { max-width: 560px; margin: 0 auto; padding: 20px 16px 60px; }
.setup-wrap label { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.setup-wrap label:has(input[type=radio]) { flex-direction: row; align-items: center; }
.setup-wrap input, .setup-wrap textarea { padding: 10px; font-size: 16px; color: inherit; background: #2a2f37;
  border: 1px solid #3b424d; border-radius: 8px; resize: none; word-break: break-all; }
.setup-wrap button { padding: 12px 20px; background: #1a73e8; border-color: #1a73e8; font-weight: 600; margin-top: 10px; }
.setup-wrap a { color: #8ab4f8; }
.checks { list-style: none; padding: 0; }
.checks .ok, p.ok { color: #7bd88f; }
.checks .bad { color: #ff6b6b; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px !important; }
