:root {
  --bg: #0b0d12;
  --card: #151922;
  --border: #262c3a;
  --text: #e8ebf2;
  --muted: #8b93a7;
  --accent: #3b82f6;
  --danger: #ef4444;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body.in-session {
  overflow: hidden;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

/* ---------- màn hình kết nối ---------- */

#connect {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  display: grid;
  gap: 14px;
}

.card h1 { margin: 0; font-size: 24px; }
.card .sub { margin: -8px 0 4px; color: var(--muted); }

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px; /* >=16px để iPhone không tự phóng to khi focus */
}

input:focus { outline: 2px solid var(--accent); border-color: transparent; }

details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details label { margin-top: 8px; }

button {
  font: inherit;
  color: var(--text);
  background: #232a39;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 12px;
  cursor: pointer;
  touch-action: manipulation;
}

#btn-connect {
  background: var(--accent);
  border-color: var(--accent);
  padding: 12px;
  font-weight: 600;
}

#btn-connect:disabled { opacity: 0.6; cursor: default; }

#status { margin: 0; min-height: 1.4em; color: var(--muted); font-size: 14px; }
#status.error { color: var(--danger); }

/* ---------- phiên điều khiển ---------- */

#session {
  position: fixed;
  inset: 0;
  background: #000;
}

#stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#layer {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  will-change: transform;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  background: #000;
}

#cursor {
  position: absolute;
  left: 0;
  top: 0;
  display: none;
  pointer-events: none;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  will-change: transform;
}

#toolbar {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(15, 18, 26, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0.55;
  transition: opacity 0.15s;
  max-width: calc(100% - 16px);
  overflow-x: auto;
}

#toolbar:hover, #toolbar:focus-within { opacity: 1; }
#toolbar button { padding: 6px 10px; background: transparent; border-color: transparent; white-space: nowrap; }
#toolbar button:hover { background: rgba(255, 255, 255, 0.08); }
#toolbar .danger { color: var(--danger); }

#stats {
  position: absolute;
  left: calc(8px + env(safe-area-inset-left));
  top: calc(56px + env(safe-area-inset-top));
  margin: 0;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.65);
  border-radius: 8px;
  font: 12px/1.5 ui-monospace, Consolas, monospace;
  color: #b9f6ca;
  pointer-events: none;
}

#transfer-status {
  position: absolute;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 3;
  display: grid;
  gap: 6px;
  max-width: calc(100% - 24px);
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(15, 18, 26, 0.94);
  color: var(--text);
  text-align: center;
  overflow-wrap: anywhere;
}

#transfer-status a {
  color: #93c5fd;
  text-decoration: underline;
}

#transfer-message.error { color: var(--danger); }

#keys {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 6px;
  padding: 8px calc(8px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
  overflow-x: auto;
  background: rgba(15, 18, 26, 0.92);
  border-top: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

#keys button { flex: 0 0 auto; min-width: 44px; padding: 9px 10px; }
#keys button.on { background: var(--accent); border-color: var(--accent); }

#kbd-input {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  resize: none;
  font-size: 16px;
  caret-color: transparent;
}
