:root {
  --bg: #0f172a;
  --card: #1e293b;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --danger: #ef4444;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
  overscroll-behavior: none;
}

button, input, textarea { font: inherit; color: inherit; }

/* ---------- 접속 화면 ---------- */
#connect-view {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px 16px;
}

.card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
}

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

label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }

.card input {
  width: 100%;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 18px;
  outline: none;
}
.card input:focus { border-color: var(--accent); }
#host-id { letter-spacing: 2px; font-variant-numeric: tabular-nums; }

.card button {
  margin-top: 16px;
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 10px;
  background: var(--line);
  font-size: 16px;
  cursor: pointer;
}
.card button.primary { background: var(--accent); font-weight: 600; }
.card button:disabled { opacity: .6; }

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

#recent { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; }
#recent button {
  width: auto;
  margin: 0;
  padding: 8px 12px;
  font-size: 14px;
  background: transparent;
  border: 1px solid var(--line);
}

details { margin-top: 20px; font-size: 14px; color: var(--muted); }
summary { cursor: pointer; }

/* ---------- 원격 화면 ---------- */
#remote-view { position: fixed; inset: 0; background: #000; }

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

#screen {
  position: absolute;
  transform-origin: 0 0;
}

#video {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#cursor {
  position: absolute;
  width: 20px;
  height: 20px;
  margin: 0;
  pointer-events: none;
  transform-origin: 0 0;
  background: no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M2 1l0 16 4-4 3 6 3-1.5-3-6h6z' fill='white' stroke='black' stroke-width='1.2' stroke-linejoin='round'/%3E%3C/svg%3E");
}

#overlay-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
  color: var(--text);
  background: rgba(0, 0, 0, .6);
  font-size: 16px;
}

#toolbar {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 4px;
  max-width: calc(100% - 16px);
  overflow-x: auto;
  background: rgba(15, 23, 42, .88);
  border-radius: 12px;
  backdrop-filter: blur(6px);
}

#toolbar button, #btn-show {
  flex: none;
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 15px;
  white-space: nowrap;
}
#toolbar button:active, #toolbar button.on { background: var(--line); }
#toolbar button.danger { color: #fca5a5; }

#btn-show {
  position: absolute;
  top: max(4px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, .7);
  height: 28px;
}

#keys-panel {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: max(8px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
  padding: 8px;
  max-height: 45%;
  overflow-y: auto;
  background: rgba(15, 23, 42, .92);
  border-radius: 12px;
}
#keys-panel button {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-size: 14px;
}
#keys-panel button:active { background: var(--accent); }

/* 화면 밖에 두되 포커스는 가능해야 소프트 키보드가 뜬다 */
#kb-input {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  resize: none;
}

[hidden] { display: none !important; }
