:root {
  --bg: #0b0d10;
  --bg-2: #12151b;
  --card: #161a21;
  --card-2: #1c212a;
  --line: #262c36;
  --text: #e8edf5;
  --text-dim: #98a2b3;
  --text-faint: #67707f;
  --accent: #4f8cff;
  --accent-2: #22d3ee;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

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

/* 全局兜底：类选择器里的 display 会覆盖 [hidden]，这里强制生效 */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

button {
  font-family: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

a {
  color: var(--accent);
  text-decoration: none;
}

/* ============================ 连接页 ============================ */

.connect {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  overflow-y: auto;
}

.connect-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(60% 50% at 20% 0%, rgba(79, 140, 255, 0.18), transparent 70%),
    radial-gradient(50% 40% at 90% 10%, rgba(34, 211, 238, 0.12), transparent 70%),
    radial-gradient(60% 60% at 50% 110%, rgba(79, 140, 255, 0.08), transparent 70%);
  pointer-events: none;
}

.connect-card {
  position: relative;
  width: min(420px, 100%);
  padding: 28px 24px 22px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(28, 33, 42, 0.92), rgba(18, 21, 27, 0.96));
  border: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.brand-icon {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  box-shadow: 0 6px 20px rgba(79, 140, 255, 0.35);
}

.brand h1 {
  margin: 0;
  font-size: 21px;
  letter-spacing: 0.3px;
  font-weight: 650;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.pc-name {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 13px;
  margin-bottom: 16px;
  font-size: 14px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  color: var(--text-dim);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: 0 0 auto;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.dot[data-state='online'] {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.14);
}

.dot[data-state='connecting'] {
  background: var(--warn);
  box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.14);
  animation: pulse 1.2s infinite;
}

.dot[data-state='offline'] {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.14);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.field {
  display: block;
  margin-bottom: 12px;
}

.field-label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 7px;
  letter-spacing: 0.5px;
}

.pin-input {
  width: 100%;
  padding: 15px 16px;
  font-size: 24px;
  letter-spacing: 10px;
  text-align: center;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pin-input::placeholder {
  font-size: 15px;
  letter-spacing: 2px;
  color: var(--text-faint);
}

.pin-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.18);
}

.remember {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  margin: 4px 0 18px;
}

.remember.small {
  font-size: 12px;
  margin: 14px 0 0;
}

.remember input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 18px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
  border: 1px solid transparent;
  transition: transform 0.08s ease, filter 0.15s ease, background 0.15s ease;
}

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

.btn.primary {
  background: linear-gradient(135deg, #4f8cff, #3b74e8);
  color: #fff;
  box-shadow: 0 8px 24px rgba(79, 140, 255, 0.32);
}

.btn.primary:disabled {
  filter: grayscale(0.6) brightness(0.7);
  box-shadow: none;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line);
  color: var(--text);
}

.btn.small {
  width: auto;
  padding: 9px 14px;
  font-size: 13px;
  border-radius: 10px;
}

.hint {
  margin: 14px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-faint);
  text-align: center;
}

.connect-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.link {
  color: var(--text-dim);
}

.inline-toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(20, 24, 30, 0.96);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--text);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 30;
}

/* ============================ 远程页 ============================ */

.remote {
  position: absolute;
  inset: 0;
  background: #000;
  overflow: hidden;
  touch-action: none;
}

.viewport {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
  cursor: none;
}

#screen {
  display: block;
  transform-origin: center center;
  will-change: transform;
  image-rendering: auto;
  pointer-events: none;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-dim);
  font-size: 13px;
  background: #05070a;
  z-index: 2;
}

.video-placeholder[hidden] {
  display: none;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.topbar {
  position: absolute;
  top: calc(10px + var(--safe-top));
  left: calc(10px + var(--safe-left));
  right: calc(10px + var(--safe-right));
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
  pointer-events: none;
}

.topbar > * {
  pointer-events: auto;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  font-size: 12px;
  color: var(--text-dim);
  background: rgba(12, 15, 19, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  backdrop-filter: blur(10px);
  white-space: nowrap;
}

.pill.stats {
  margin-left: auto;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}

.pill.stats b {
  color: var(--text);
  font-weight: 600;
}

.pill.stats.slow {
  border-color: rgba(251, 191, 36, 0.5);
  color: #f2d38a;
}

.pill.stats.slow b {
  color: #fbbf24;
}

.pill .sep {
  width: 1px;
  height: 10px;
  background: rgba(255, 255, 255, 0.12);
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 14px;
  color: var(--text-dim);
  background: rgba(12, 15, 19, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
}

.toolbar {
  position: absolute;
  left: 50%;
  bottom: calc(14px + var(--safe-bottom));
  transform: translateX(-50%) translateY(0);
  display: flex;
  gap: 2px;
  padding: 6px;
  background: rgba(14, 17, 22, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 18px;
  backdrop-filter: blur(16px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  z-index: 12;
  transition: transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1), opacity 0.22s ease;
}

.toolbar.hide {
  transform: translateX(-50%) translateY(120%);
  opacity: 0;
  pointer-events: none;
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 52px;
  padding: 7px 8px 6px;
  border-radius: 13px;
  color: var(--text-dim);
  transition: background 0.15s ease, color 0.15s ease;
}

.tool:active,
.tool.active {
  background: rgba(79, 140, 255, 0.16);
  color: #cfe0ff;
}

.tool.danger:active {
  background: rgba(248, 113, 113, 0.16);
  color: #ffd0d0;
}

.tool-ico {
  font-size: 16px;
  line-height: 1.1;
}

.tool-txt {
  font-size: 10px;
  letter-spacing: 0.3px;
}

.toolbar-handle {
  position: absolute;
  right: calc(10px + var(--safe-right));
  bottom: calc(16px + var(--safe-bottom));
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 18px;
  color: var(--text-dim);
  background: rgba(14, 17, 22, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.09);
  backdrop-filter: blur(12px);
  z-index: 11;
  opacity: 0.55;
}

.toolbar-handle:active {
  opacity: 1;
}

/* 面板 */
.panel {
  position: absolute;
  left: 50%;
  bottom: calc(72px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(520px, calc(100% - 20px));
  max-height: min(70vh, 560px);
  overflow-y: auto;
  padding: 16px;
  background: rgba(20, 24, 30, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(20px);
  z-index: 14;
  -webkit-overflow-scrolling: touch;
}

.panel[hidden] {
  display: none;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.panel-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
}

.panel-sub {
  margin-top: 16px;
}

.panel-sub h4 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.panel-hint {
  margin: 10px 0 0;
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.5;
}

.text-input {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  resize: vertical;
  -webkit-user-select: text;
  user-select: text;
}

.text-input:focus {
  border-color: var(--accent);
}

.text-input.monospace {
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-size: 13px;
}

.keyboard-mods,
.keyboard-grid,
.combo-grid {
  display: grid;
  gap: 7px;
}

.keyboard-mods {
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 10px;
}

.keyboard-grid {
  grid-template-columns: repeat(6, 1fr);
}

.combo-grid {
  grid-template-columns: repeat(2, 1fr);
}

.key {
  padding: 11px 6px;
  font-size: 13px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: var(--text);
}

.key:active {
  background: rgba(79, 140, 255, 0.2);
}

.key.mod.active {
  background: rgba(79, 140, 255, 0.28);
  border-color: var(--accent);
  color: #dbe8ff;
}

.key.combo {
  font-size: 12px;
  text-align: left;
  padding-left: 10px;
}

.setting-row .btn {
  white-space: nowrap;
  flex: 0 0 auto;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 14px;
}

.setting-row:last-of-type {
  border-bottom: 0;
}

.seg {
  display: inline-flex;
  padding: 3px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 10px;
  border: 1px solid var(--line);
}

.seg button {
  padding: 7px 12px;
  font-size: 12px;
  border-radius: 8px;
  color: var(--text-dim);
  white-space: nowrap;
}

.seg button.active {
  background: rgba(79, 140, 255, 0.22);
  color: #cfe0ff;
}

.setting-row input[type='range'] {
  width: 140px;
  accent-color: var(--accent);
}

.setting-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6, 8, 11, 0.86);
  backdrop-filter: blur(6px);
  z-index: 20;
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 28px 26px;
  min-width: 260px;
  text-align: center;
  border-radius: 18px;
  background: var(--card);
  border: 1px solid var(--line);
}

.overlay-card h3 {
  margin: 0;
  font-size: 16px;
}

.overlay-card p {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
}

.overlay-card .btn {
  width: auto;
  padding: 10px 18px;
  font-size: 13px;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(84px + var(--safe-bottom));
  transform: translateX(-50%);
  padding: 10px 16px;
  font-size: 13px;
  border-radius: 10px;
  background: rgba(20, 24, 30, 0.96);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 18;
  pointer-events: none;
  max-width: calc(100% - 32px);
  text-align: center;
}

.toast[hidden] {
  display: none;
}

/* 手势说明抽屉 */
.sheet {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.55);
}

.sheet[hidden] {
  display: none;
}

.sheet-card {
  width: 100%;
  max-height: 80%;
  overflow-y: auto;
  padding: 18px 20px calc(24px + var(--safe-bottom));
  background: var(--bg-2);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line);
  animation: slideUp 0.24s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0.4; }
  to { transform: translateY(0); opacity: 1; }
}

.help-list {
  margin: 0;
  font-size: 13px;
  line-height: 1.7;
}

.help-list dt {
  margin-top: 12px;
  font-weight: 600;
  color: var(--accent-2);
}

.help-list dd {
  margin: 3px 0 0;
  color: var(--text-dim);
}

/* ---------------- 外网访问面板 ---------------- */
.badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  font-size: 10px;
  border-radius: 999px;
  color: #0b0d10;
  background: var(--ok);
  vertical-align: 1px;
}

.wan-block {
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.wan-block:last-of-type {
  border-bottom: 0;
}

.wan-block h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: #cfe0ff;
  font-weight: 600;
}

.url-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  margin: 6px 0;
  background: rgba(0, 0, 0, 0.38);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.url-row code {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-size: 12.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  -webkit-user-select: text;
  user-select: text;
}

.btn.tiny {
  width: auto;
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 8px;
  flex: 0 0 auto;
}

.qr-wrap {
  display: flex;
  justify-content: center;
  padding: 12px 0 4px;
}

.qr-wrap[hidden] {
  display: none;
}

.qr {
  width: 168px;
  height: 168px;
  border-radius: 10px;
  background: #fff;
  padding: 0;
  image-rendering: pixelated;
}

.panel-hint b {
  color: var(--text);
}

.warn-tip {
  color: #e3c07a;
}

@media (max-height: 460px) and (orientation: landscape) {
  .qr {
    width: 120px;
    height: 120px;
  }
}

/* 横屏时收紧工具栏 */
@media (max-height: 460px) and (orientation: landscape) {
  .toolbar {
    bottom: calc(8px + var(--safe-bottom));
    padding: 4px;
  }
  .tool {
    min-width: 46px;
    padding: 5px 6px 4px;
  }
  .tool-txt {
    display: none;
  }
  .panel {
    bottom: calc(56px + var(--safe-bottom));
    max-height: 78vh;
  }
}

@media (pointer: fine) {
  .viewport {
    cursor: default;
  }
}
