:root {
  --bg: #0b0f14;
  --fg: #e7edf3;
  --muted: #8b98a5;
  --accent: #3b82f6;
  --panel: rgba(18, 24, 32, 0.88);
  --border: #232c37;
}

* { box-sizing: border-box; }

/* the `hidden` attribute must ALWAYS win (our panels set display:flex) */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#stage {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

#screen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  cursor: crosshair;
}

/* status bar */
#statusbar {
  position: absolute;
  top: env(safe-area-inset-top, 0);
  left: 0;
  right: 0;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  pointer-events: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
}
#role.operator { color: #6ee7a0; border-color: #2f5b44; }
#role.viewer { color: #f2b65c; }
#mode.ctrl { color: #6ee7a0; border-color: #2f5b44; }
#mode.local { color: #f2b65c; border-color: #4a3d22; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #f2b65c; }
#conn.ok .dot { background: #6ee7a0; }
#conn.err .dot { background: #f26d6d; }

#takeover {
  pointer-events: auto;
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
}

#dragHandle {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--muted);
  pointer-events: none;
}

/* toolbar */
#toolbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0));
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: linear-gradient(transparent, rgba(0,0,0,0.55));
  z-index: 10;
}

#typerow {
  display: flex;
  gap: 8px;
  align-items: center;
}
#typebox {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg);
  padding: 10px 12px;
  font-size: 16px;
  outline: none;
}
#btns {
  display: flex;
  gap: 8px;
  justify-content: center;
}
#btns button, #sendbtn, #typeclose, #typerow button {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  min-height: 40px;
}
#btns button.active { background: var(--accent); color: #fff; }
#sendbtn { color: #fff; background: var(--accent); }
button.ghost { color: var(--muted); }

#hintbox {
  position: absolute;
  left: 50%;
  top: 54px;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
  max-width: 90vw;
}

/* side panels (custom keys / files) */
.panel {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  width: min(360px, 92vw);
  background: var(--bg);
  border-left: 1px solid var(--border);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 20;
  overflow-y: auto;
}
.panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 15px;
}

/* custom keys grid */
#keygrid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.keybtn {
  min-height: 52px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg);
  font-size: 13px;
  padding: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  touch-action: manipulation;
}
.keybtn:active { background: var(--accent); color: #fff; }

/* file panel */
.filelist { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.filerow {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}
.fname { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fsize { color: var(--muted); font-size: 12px; }
#filebtns { display: flex; gap: 8px; }
#filebtns button { flex: 1; }
#progress { color: var(--muted); font-size: 12px; text-align: center; }
.note { color: var(--muted); font-size: 12px; text-align: center; }
