:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --primary: #2f81f7;
  --primary-hover: #388bfd;
  --danger: #da3633;
  --success: #2ea043;
  --warning: #d29922;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* 버튼 공통 (모바일 44px 이상 터치 타깃) */
.btn {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-secondary {
  background: var(--surface-2);
}

.btn-danger {
  background: rgba(218, 54, 51, 0.16);
  border-color: rgba(218, 54, 51, 0.5);
  color: #ff7b72;
}

.btn-ghost {
  background: transparent;
}

.btn-icon {
  min-width: 44px;
  padding: 0;
  font-size: 16px;
}

.btn-compact {
  min-height: 40px;
  padding: 0 10px;
  font-size: 13px;
}

.btn.active-toggle {
  background: rgba(210, 153, 34, 0.25);
  border-color: var(--warning);
  color: #f0c05a;
}

.version-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(47, 129, 247, 0.18);
  border: 1px solid rgba(47, 129, 247, 0.45);
  color: #79c0ff;
  white-space: nowrap;
}

/* 로그인 화면 */
.login-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.login-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
}

.login-desc {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

input, select {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

input:focus, select:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.login-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(218, 54, 51, 0.16);
  border: 1px solid rgba(218, 54, 51, 0.5);
  color: #ff7b72;
  font-size: 13px;
}

/* 메인 앱 레이아웃 */
.app-screen {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.top-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.url-form {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 6px;
}

.url-form input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  font-size: 14px;
}

.shortcut-row {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
}

.chip {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.control-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 6px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.tab-controls, .view-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tab-controls select {
  max-width: 170px;
  min-height: 40px;
  font-size: 13px;
}

.view-controls select {
  min-height: 40px;
  font-size: 13px;
}

.conn-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.conn-badge.online {
  background: rgba(46, 160, 67, 0.18);
  border-color: rgba(46, 160, 67, 0.5);
  color: #56d364;
}

.conn-badge.offline {
  background: rgba(210, 153, 34, 0.18);
  border-color: rgba(210, 153, 34, 0.5);
  color: #e3b341;
}

/* 실시간 뷰포트 영역 */
.viewport-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #010409;
  padding: 6px;
  overflow: hidden;
}

.stage {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
}

#screen-img {
  display: block;
  max-width: 100%;
  max-height: calc(100dvh - 265px);
  width: auto;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #ffffff;
  touch-action: none;
}

.empty-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 17, 23, 0.85);
  color: var(--muted);
  font-size: 14px;
  padding: 16px;
  border-radius: 8px;
}

.tap-ripple {
  position: absolute;
  width: 28px;
  height: 28px;
  margin-left: -14px;
  margin-top: -14px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  background: rgba(47, 129, 247, 0.35);
  pointer-events: none;
  animation: ripple 0.35s ease-out forwards;
}

@keyframes ripple {
  from {
    transform: scale(0.5);
    opacity: 1;
  }
  to {
    transform: scale(1.6);
    opacity: 0;
  }
}

/* 하단 모바일 입력 도크 */
.input-dock {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.text-form {
  display: flex;
  align-items: center;
  gap: 6px;
}

.text-form input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
}

.key-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.btn-key {
  min-height: 38px;
  padding: 0 11px;
  font-size: 12px;
  background: var(--bg);
}

@media (max-width: 640px) {
  .top-bar {
    padding: 6px 8px;
  }
  .btn-icon {
    min-width: 38px;
    min-height: 38px;
  }
  .control-bar {
    padding: 5px 8px;
  }
  .tab-controls select {
    max-width: 135px;
  }
}
