:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #0b0d12;
  --panel: #141821;
  --panel-2: #1b202c;
  --line: #2a3140;
  --muted: #919bad;
  --text: #f6f7fb;
  --accent: #7c9cff;
  --accent-2: #a6b9ff;
  --danger: #ff747d;
  --ok: #4cdb9b;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

button, input, textarea, select { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

.install-tip {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  left: max(14px, env(safe-area-inset-left));
  z-index: 20;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 28px;
  gap: 11px;
  max-width: 520px;
  margin: 0 auto;
  padding: 13px;
  border: 1px solid rgba(166,185,255,.3);
  border-radius: 16px;
  background: rgba(20,24,33,.97);
  box-shadow: 0 18px 55px rgba(0,0,0,.48);
  backdrop-filter: blur(16px);
}

.install-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 11px;
  background: var(--accent);
  color: #0b1020;
  font-size: 22px;
  font-weight: 800;
}

.install-tip strong { display: block; margin: 1px 0 4px; font-size: 14px; }
.install-tip p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.install-tip > button { padding: 0; border: 0; background: none; color: var(--muted); font-size: 25px; line-height: 1; }

.login-view {
  display: grid;
  min-height: 100%;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 10%, rgba(86, 119, 255, .2), transparent 35%),
    radial-gradient(circle at 86% 80%, rgba(108, 65, 206, .18), transparent 38%),
    var(--bg);
}

.login-card {
  width: min(100%, 420px);
  padding: 34px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 24px;
  background: rgba(20, 24, 33, .9);
  box-shadow: 0 28px 80px rgba(0,0,0,.42);
  backdrop-filter: blur(18px);
}

.logo {
  display: grid;
  grid-template-columns: repeat(2, 13px);
  gap: 4px;
  width: max-content;
  margin-bottom: 28px;
  padding: 11px;
  border-radius: 12px;
  background: linear-gradient(145deg, #91a9ff, #5e74da);
  box-shadow: 0 10px 28px rgba(94, 116, 218, .35);
}

.logo span { width: 13px; height: 13px; border-radius: 3px; background: #0f1424; }
.eyebrow { margin: 0 0 8px; color: var(--accent-2); font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(32px, 9vw, 46px); letter-spacing: -.04em; }
.intro { margin: 12px 0 28px; color: var(--muted); line-height: 1.5; }
label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 650; }

#accessCode {
  width: 100%;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: #0f1219;
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: normal;
  text-align: left;
}

.password-toggle { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; color: var(--muted); font-weight: 400; }
.password-toggle input { accent-color: var(--accent); }

#accessCode:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 156, 255, .16); }
.form-error { min-height: 20px; margin: 8px 0; color: var(--danger); font-size: 13px; }

.primary-button, .send-button {
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #0b1020;
  font-weight: 750;
  cursor: pointer;
}

.primary-button { width: 100%; padding: 14px 18px; }
.primary-button:disabled { cursor: wait; opacity: .65; }
.network-note { margin: 24px 0 0; color: #737d8f; font-size: 12px; line-height: 1.45; text-align: center; }

.remote-view {
  display: grid;
  width: 100%;
  height: 100dvh;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  background: #050608;
}

.topbar {
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 18, 25, .97);
}

.connection { display: flex; min-width: 0; flex: 1; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
#statusText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #e7b25d; box-shadow: 0 0 0 4px rgba(231,178,93,.1); }
.status-dot.online { background: var(--ok); box-shadow: 0 0 0 4px rgba(76,219,155,.1); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 4px rgba(255,116,125,.1); }

#monitorSelect {
  max-width: 148px;
  min-width: 0;
  height: 36px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-2);
}

.icon-button svg { width: 19px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
#gameModeButton.active { border-color: rgba(76,219,155,.65); background: rgba(76,219,155,.15); color: var(--ok); }

.viewer {
  position: relative;
  display: flex;
  min-height: 0;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #030405;
  touch-action: none;
  user-select: none;
}

.viewer:focus { outline: none; }
.pointer-locked .viewer { cursor: none; }

.screen {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
  -webkit-user-drag: none;
}

.zoom-controls {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 4;
  display: grid;
  grid-template-columns: 40px 62px 40px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 11px;
  background: rgba(15,18,25,.92);
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
  backdrop-filter: blur(12px);
}

.gaming-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 4;
  max-width: calc(100% - 20px);
  padding: 7px 10px;
  border: 1px solid rgba(76,219,155,.35);
  border-radius: 9px;
  background: rgba(8,20,16,.9);
  color: #87efbd;
  font-size: 11px;
  font-weight: 700;
  pointer-events: none;
}

.remote-view.gaming-active .toolbar,
.remote-view.gaming-active .keyboard-panel,
.remote-view.gaming-active .zoom-controls,
.remote-view.gaming-active .game-key { display: none !important; }

.remote-view.gaming-active .screen {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: contain;
}

.zoom-controls button {
  height: 38px;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-weight: 700;
}

.zoom-controls button:last-child { border-right: 0; }
.zoom-controls button:active { background: #252c3a; }
.zoom-controls button:disabled { color: #596172; }
#zoomLabel { color: var(--accent-2); font-size: 12px; }

.game-key {
  position: absolute;
  bottom: 10px;
  left: 10px;
  z-index: 4;
  display: flex;
  width: 76px;
  height: 76px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1px;
  padding: 0;
  border: 2px solid rgba(166,185,255,.58);
  border-radius: 50%;
  background: rgba(20,24,33,.94);
  box-shadow: 0 10px 32px rgba(0,0,0,.42), inset 0 0 0 3px rgba(124,156,255,.08);
  color: var(--accent-2);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform 80ms ease, background 80ms ease, box-shadow 80ms ease;
}

.game-key strong { font-size: 31px; line-height: 1; }
.game-key span { color: var(--muted); font-size: 9px; font-weight: 650; }
.game-key.pressed {
  transform: scale(.9);
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 4px 18px rgba(124,156,255,.4);
  color: #0b1020;
}
.game-key.pressed span { color: #263154; }

.waiting-message, .viewer-message {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  background: rgba(20,24,33,.92);
  color: var(--muted);
  font-size: 13px;
}

.viewer-message { max-width: 85%; color: var(--danger); text-align: center; }
.spinner { width: 16px; height: 16px; border: 2px solid #343b4a; border-top-color: var(--accent); border-radius: 50%; animation: spin .85s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.keyboard-panel {
  padding: 12px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.keyboard-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; color: var(--muted); font-size: 12px; }
#closeKeyboard { padding: 0 5px; border: 0; background: none; color: var(--muted); font-size: 25px; line-height: 1; }
.text-row { display: flex; gap: 8px; }
#textInput { min-width: 0; flex: 1; resize: none; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; outline: none; background: #0f1219; color: var(--text); font-size: 16px; }
#textInput:focus { border-color: var(--accent); }
.send-button { padding: 0 14px; }

.key-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.key-grid button { padding: 8px 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); font-size: 12px; }
.key-grid .danger-key { grid-column: span 2; border-color: rgba(255,116,125,.45); background: rgba(255,116,125,.1); color: #ffadb3; }
.key-grid button:active, .icon-button:active, .tool:active { transform: translateY(1px); background: #252c3a; }

.toolbar {
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  padding: 6px max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: rgba(15, 18, 25, .98);
}

.tool {
  display: flex;
  min-width: 0;
  align-items: center;
  flex-direction: column;
  gap: 3px;
  padding: 7px 2px 5px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
}

.tool svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.tool[data-mode="pointer"] svg { fill: currentColor; stroke: none; }
.tool.active { background: rgba(124,156,255,.13); color: var(--accent-2); }

@media (orientation: landscape) and (max-height: 520px) {
  .topbar { position: absolute; top: 8px; right: 8px; left: 8px; min-height: 44px; padding: 5px; border: 1px solid var(--line); border-radius: 12px; opacity: .9; }
  .remote-view { grid-template-rows: minmax(0, 1fr) auto auto; }
  .viewer { grid-row: 1; }
  .toolbar { grid-row: 3; }
  .keyboard-panel { grid-row: 2; }
  .tool { flex-direction: row; justify-content: center; }
  .game-key { width: 66px; height: 66px; }
  .game-key strong { font-size: 27px; }
}

@media (max-width: 370px) {
  .tool span { display: none; }
  #monitorSelect { max-width: 112px; }
  .login-card { padding: 26px 22px; }
}
