:root {
  --bar-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #0b0d12;
  --panel: rgba(18, 22, 31, 0.94);
  --line: rgba(255,255,255,.12);
  --text: #f6f7fb;
  --muted: #aab1c3;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button { appearance: none; border: 1px solid var(--line); background: rgba(255,255,255,.08); color: var(--text); border-radius: 12px; padding: 10px 12px; font-weight: 700; font-size: 14px; touch-action: manipulation; }
button:active { transform: translateY(1px); background: rgba(255,255,255,.18); }
button.danger { background: rgba(202, 54, 54, .42); }
.app-shell { position: fixed; inset: 0; display: grid; grid-template-rows: calc(var(--bar-h) + var(--safe-top)) 1fr calc(var(--bar-h) + var(--safe-bottom)); }
.topbar { padding: var(--safe-top) 10px 0; min-height: calc(var(--bar-h) + var(--safe-top)); display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; flex-direction: column; min-width: 160px; }
.brand strong { font-size: 17px; line-height: 1.1; }
.brand span { color: var(--muted); font-size: 12px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions, .bottombar { display: flex; gap: 8px; align-items: center; overflow-x: auto; scrollbar-width: none; }
.actions::-webkit-scrollbar, .bottombar::-webkit-scrollbar { display: none; }
.screen-wrap { position: relative; min-height: 0; background: #000; }
#vncFrame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #000; image-rendering: pixelated; }
.bottombar { min-height: calc(var(--bar-h) + var(--safe-bottom)); padding: 8px 10px var(--safe-bottom); background: var(--panel); border-top: 1px solid var(--line); }
.touch-pad { pointer-events: none; position: absolute; inset: 0; z-index: 5; }
.touch-pad button { pointer-events: auto; min-width: 58px; min-height: 52px; background: rgba(20, 28, 40, .58); backdrop-filter: blur(8px); }
.pad-left { position: absolute; left: 18px; bottom: 22px; width: 184px; height: 166px; }
.dpad { position: absolute; }
.dpad.up { left: 64px; top: 0; }
.dpad.left { left: 0; top: 56px; }
.dpad.right { right: 0; top: 56px; }
.dpad.down { left: 64px; bottom: 0; }
.pad-right { position: absolute; right: 18px; bottom: 22px; display: grid; grid-template-columns: repeat(2, minmax(72px, 1fr)); gap: 10px; }
.mainkey.ok { background: rgba(57, 122, 74, .58); }
.mainkey.cancel { background: rgba(158, 64, 64, .58); }
.hidden { display: none !important; }
.panel { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(0,0,0,.48); padding: 18px; }
.panel-card { width: min(760px, 100%); max-height: min(80vh, 720px); overflow: hidden; background: #151a24; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 12px 34px rgba(0,0,0,.5); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
#panelBody { margin: 0; padding: 16px; overflow: auto; max-height: 60vh; color: #dbe2f5; white-space: pre-wrap; font-size: 13px; line-height: 1.5; }
body.focus-mode .app-shell { grid-template-rows: 0 1fr 0; }
body.focus-mode .topbar, body.focus-mode .bottombar { display: none; }
body.focus-mode .touch-pad { display: block; }
@media (max-width: 720px) {
  :root { --bar-h: 52px; }
  button { font-size: 13px; padding: 9px 10px; }
  .brand strong { font-size: 15px; }
  .brand { min-width: 128px; }
  .pad-left { transform: scale(.9); transform-origin: bottom left; }
  .pad-right { transform: scale(.9); transform-origin: bottom right; }
}
@media (orientation: portrait) and (max-width: 720px) {
  .topbar { align-items: stretch; }
  .actions { flex: 1; justify-content: flex-end; }
}
