:root {
  --bg: #111315;
  --surface: #181B1F;
  --surface-raised: #1F2329;
  --surface-pressed: #14171A;
  --border: #2A2F38;
  --border-strong: #3A414D;
  --text: #F5F5F2;
  --text-muted: #939AA6;
  --accent: #FF5A1F;
  --accent-dim: rgba(255, 90, 31, 0.16);
  --ok: #2FD07A;
  --warn: #F5A623;
  --err: #EF4444;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  overflow-x: hidden;
}

::selection {
  background: var(--accent-dim);
  color: var(--text);
}

.hidden {
  display: none !important;
}

/* ── Custom Wallpaper Layer ── */
.wallpaper-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-color: var(--bg);
  background-size: cover;
  background-position: center;
  pointer-events: none;
  transition: background-color 0.25s ease;
}

.wallpaper-dim {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: rgba(12, 14, 16, var(--wp-dim, 0.45));
  pointer-events: none;
}

/* ── Desktop / Setup Hub View ── */
.hub-view {
  position: relative;
  z-index: 5;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(56px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-x: hidden;
}

.hub-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}

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

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 13px;
  color: var(--text-muted);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.btn:active, .tab-btn:active, .copy-btn:active {
  transform: scale(0.97);
}

@media (hover: hover) and (pointer: fine) {
  .btn:hover {
    border-color: var(--text-muted);
  }
  .btn-accent:hover {
    opacity: 0.92;
  }
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #111315;
}

.hero-intro {
  margin-bottom: 26px;
  max-width: 68ch;
}

.hero-intro h2 {
  margin: 0 0 8px;
  font-size: clamp(24px, 4vw, 34px);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.hero-intro p {
  margin: 0;
  color: var(--text-muted);
  font-size: 15px;
}

.hub-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

@media (max-width: 780px) {
  .hub-grid { grid-template-columns: minmax(0, 1fr); }
}

.panel {
  min-width: 0;
  max-width: 100%;
  background: rgba(24, 27, 31, 0.92);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
}

.panel h3 {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.plain-explain {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 14px;
  overflow-wrap: anywhere;
}

.cmd-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  max-width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  margin-bottom: 12px;
}

.cmd-box code {
  min-width: 0;
  flex: 1;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.copy-btn {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.os-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
}

.tab-btn {
  padding: 7px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.connect-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.text-input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
}

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

@media (pointer: coarse) {
  .text-input {
    font-size: 16px;
  }
}

.qr-box {
  background: #F5F5F2;
  border-radius: 12px;
  padding: 12px;
  display: inline-grid;
  place-items: center;
  margin: 10px 0;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
}

.dot.connected { background: var(--ok); }
.dot.error { background: var(--err); }

/* ── Phone Mouse Surface View ── */
.mouse-view {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

.surface-grid {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.055) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
}

.top-bar {
  position: relative;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(14px, env(safe-area-inset-top)) 68px 8px 14px;
  pointer-events: none;
}

.top-bar > * {
  pointer-events: auto;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 11px;
  border-radius: 999px;
  background: rgba(24, 27, 31, 0.88);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.pill-btn.active {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-dim);
}

.latency-text {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.corner-settings-btn {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: 12px;
  z-index: 25;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(24, 27, 31, 0.9);
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  touch-action: none;
}

.hold-ring {
  position: absolute;
  inset: 0;
  width: 44px;
  height: 44px;
  transform: rotate(-90deg);
}

.hold-ring-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 2;
}

.hold-ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 119.38;
  stroke-dashoffset: 119.38;
}

.surface-center-info {
  position: relative;
  z-index: 8;
  margin: auto;
  text-align: center;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
}

.mode-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  color: rgba(245, 245, 242, 0.35);
  font-weight: 600;
}

.connect-card {
  pointer-events: auto;
  width: 100%;
  max-width: 340px;
  background: rgba(24, 27, 31, 0.94);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 16px;
  text-align: left;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.connect-card h3 {
  margin: 0 0 6px;
  font-size: 15px;
}

.connect-card p {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.desk-actions {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.calibrate-btn {
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.calibrate-btn.calibrating {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Ergonomic Center Button Cluster ── */
.button-cluster {
  position: relative;
  z-index: 15;
  width: calc(100% - 24px);
  max-width: 520px;
  height: var(--btn-height, 42dvh);
  margin: 0 auto calc(var(--btn-offset, 20px) + env(safe-area-inset-bottom));
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 8px;
  border-radius: 22px;
  background: rgba(24, 27, 31, 0.88);
  border: 1px solid var(--border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  touch-action: none;
}

.mouse-btn {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: rgba(31, 35, 41, 0.9);
  color: var(--text-muted);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  cursor: pointer;
  touch-action: none;
  transition: background 0.08s, transform 0.08s, border-color 0.08s;
}

.mouse-btn.pressed {
  background: var(--surface-pressed);
  border-color: var(--accent);
  color: var(--text);
  transform: scale(0.985);
}

.scroll-wheel {
  width: var(--scroll-width, 18%);
  min-width: 48px;
  border-radius: 15px;
  background: rgba(19, 21, 24, 0.92);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wheel-track {
  position: absolute;
  inset: -40px 0;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 10px,
    rgba(255, 255, 255, 0.09) 10px,
    rgba(255, 255, 255, 0.09) 12px
  );
  transform: translateY(var(--wheel-offset, 0px));
  pointer-events: none;
}

.wheel-indicator {
  width: 6px;
  height: 28px;
  border-radius: 999px;
  background: var(--accent);
  opacity: 0.85;
  pointer-events: none;
}

/* ── Settings Drawer ── */
.settings-sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  touch-action: pan-y;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.sheet-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.sheet-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  -webkit-overflow-scrolling: touch;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 500;
}

.val {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.seg-btn {
  padding: 9px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-raised);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  cursor: pointer;
}

.toggle-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toggle-title {
  font-size: 14px;
  font-weight: 500;
}

.toggle-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.switch {
  -webkit-appearance: none;
  appearance: none;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.15s, background 0.15s;
}

.switch:checked {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.switch:checked::after {
  transform: translateX(18px);
  background: var(--accent);
}

.divider {
  height: 1px;
  background: var(--border);
}

/* Wallpaper Swatches */
.swatch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.swatch {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 2px solid var(--border-strong);
  cursor: pointer;
  padding: 0;
}

.swatch.active {
  border-color: var(--accent);
}
