:root {
  color-scheme: dark;
  --bg: #0e0e10;
  --surface: #131315;
  --raised: #1c1b1d;
  --raised-2: #201f22;
  --line: #353437;
  --line-strong: #444748;
  --text: #f4f2f4;
  --muted: #c4c7c8;
  --dim: #8e9192;
  --primary: #ffffff;
  --primary-text: #111113;
  --success: #7ddc9a;
  --warning: #f4c76b;
  --danger: #ff7b7b;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  font-family: Geist, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100svh;
  background: #09090a;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
}

button {
  border: 0;
  border-radius: 0;
  cursor: pointer;
}

.app-shell {
  display: flex;
  justify-content: center;
  min-height: 100svh;
  background:
    radial-gradient(circle at 50% 36%, rgba(255, 255, 255, 0.08), transparent 28%),
    #09090a;
}

.phone-app {
  display: grid;
  width: min(100vw, 430px);
  min-height: 100svh;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(env(safe-area-inset-top) + 18px) 20px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(14, 14, 16, 0.88);
  backdrop-filter: blur(20px);
}

.screen-login .topbar,
.screen-pair .topbar {
  position: relative;
  border-bottom: 0;
  background: transparent;
  backdrop-filter: none;
}

.screen-scan {
  grid-template-rows: auto 1fr auto;
  background: #09090a;
}

.brand-row,
.title-row,
.inline-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.brand {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0;
}

.screen-title {
  margin-top: 10px;
  min-width: 0;
  color: var(--text);
  font-size: 26px;
  font-weight: 800;
  line-height: 32px;
  letter-spacing: 0;
}

.screen-detail .screen-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.device-chip,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  max-width: 168px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 9px;
  background: var(--raised);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.device-chip span:last-child,
.badge {
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-chip.quiet {
  color: var(--dim);
}

.icon-text {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 10px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 760;
}

.icon-text:active,
.icon-text:focus-visible {
  border-color: var(--line);
  color: var(--text);
  background: var(--raised);
  outline: 0;
}

.dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--dim);
}

.dot.online,
.badge.success .dot {
  background: var(--success);
}

.dot.limited,
.dot.reconnecting,
.badge.warning .dot {
  background: var(--warning);
}

.dot.offline,
.badge.danger .dot {
  background: var(--danger);
}

.content {
  min-width: 0;
  padding: 18px 20px 24px;
  overflow-x: hidden;
}

.screen-login .content,
.screen-pair .content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-bottom: max(36px, env(safe-area-inset-bottom));
}

.bottom-tabs {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 8px 14px calc(env(safe-area-inset-bottom) + 8px);
  border-top: 1px solid var(--line);
  background: rgba(14, 14, 16, 0.92);
  backdrop-filter: blur(18px);
}

.tab {
  position: relative;
  min-height: 48px;
  border-radius: 8px;
  color: var(--dim);
  background: transparent;
  font-size: 12px;
  font-weight: 760;
}

.tab.active {
  color: var(--text);
  background: var(--raised-2);
}

.tab-badge {
  position: absolute;
  top: 5px;
  right: 22%;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  padding: 0 4px;
  background: var(--danger);
  color: #111113;
  font-size: 10px;
  font-weight: 850;
  line-height: 16px;
}

.section {
  margin-bottom: 18px;
}

.section-title {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.list {
  overflow: hidden;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.row-btn,
.row {
  width: 100%;
  display: block;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  padding: 15px 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.row-btn:last-child,
.row:last-child {
  border-bottom: 0;
}

.row-btn:active,
.row-btn:focus-visible {
  background: rgba(255, 255, 255, 0.04);
  outline: 2px solid rgba(255, 255, 255, 0.16);
  outline-offset: 8px;
}

.row-title {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 15px;
  font-weight: 780;
  line-height: 21px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-meta,
.row-preview,
.detail-meta {
  margin-top: 5px;
  color: var(--dim);
  font-size: 13px;
  line-height: 18px;
}

.row-preview {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.banner {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--raised);
  color: var(--muted);
  font-size: 13px;
  line-height: 18px;
}

.banner.warning {
  border-color: rgba(244, 199, 107, 0.34);
  color: var(--warning);
}

.banner.danger {
  border-color: rgba(255, 123, 123, 0.34);
  color: var(--danger);
}

.open-browser-tip {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  right: 12px;
  z-index: 80;
  width: min(280px, calc(100vw - 24px));
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  padding: 13px 40px 13px 14px;
  background: rgba(28, 27, 29, 0.98);
  color: var(--text);
  box-shadow: var(--shadow);
}

.open-browser-arrow {
  position: absolute;
  top: -8px;
  right: 24px;
  width: 14px;
  height: 14px;
  transform: rotate(45deg);
  border-left: 1px solid rgba(255, 255, 255, 0.18);
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(28, 27, 29, 0.98);
}

.open-browser-close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 28px;
  height: 28px;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.open-browser-title {
  font-size: 15px;
  font-weight: 820;
  line-height: 20px;
}

.open-browser-text {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 18px;
}

.empty {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--muted);
  background: var(--raised);
  font-size: 14px;
  line-height: 20px;
}

.intro-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: -12px 0 28px;
  text-align: center;
}

.intro-panel h1 {
  margin: 28px 0 10px;
  color: var(--text);
  font-size: 27px;
  font-weight: 820;
  line-height: 34px;
  letter-spacing: 0;
}

.intro-panel p {
  margin: 0;
  max-width: 315px;
  color: var(--muted);
  font-size: 15px;
  line-height: 23px;
}

.connect-rail {
  position: relative;
  display: grid;
  width: 132px;
  height: 132px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    var(--raised);
  background-size: 66px 66px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), var(--shadow);
}

.connect-rail::before {
  content: "";
  position: absolute;
  inset: 20px;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 18px;
}

.connect-node {
  position: absolute;
  display: block;
  border: 3px solid var(--primary);
  background: transparent;
}

.connect-node.desktop {
  width: 44px;
  height: 32px;
  border-radius: 5px;
}

.connect-node.desktop::before {
  content: "";
  position: absolute;
  left: 16px;
  bottom: -12px;
  width: 12px;
  height: 10px;
  border-left: 3px solid var(--primary);
  border-right: 3px solid var(--primary);
}

.connect-node.desktop::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -16px;
  height: 3px;
  border-radius: 999px;
  background: var(--primary);
}

.connect-node.phone {
  right: 35px;
  bottom: 36px;
  width: 18px;
  height: 31px;
  border-radius: 5px;
  background: var(--raised);
}

.connect-line {
  display: none;
}

.link-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 11px;
  background: var(--raised);
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.button-row {
  display: flex;
  gap: 9px;
  margin-top: 12px;
}

.login-actions {
  display: grid;
  gap: 14px;
}

.login-actions .button-row {
  display: grid;
  gap: 10px;
  margin-top: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 6px;
  padding: 0 16px;
  color: var(--primary-text);
  background: var(--primary);
  font-size: 15px;
  font-weight: 780;
  transition: transform 120ms ease, background 120ms ease, opacity 120ms ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.44;
}

.btn.secondary {
  border: 1px solid var(--line-strong);
  color: var(--text);
  background: var(--raised);
}

.btn.danger {
  color: #111113;
  background: var(--danger);
}

.btn.full {
  width: 100%;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.field input,
.field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 12px;
  color: var(--text);
  background: var(--raised);
  font-size: 14px;
  line-height: 20px;
}

.field input:focus,
.field textarea:focus {
  border-color: rgba(255, 255, 255, 0.72);
  outline: 3px solid rgba(255, 255, 255, 0.12);
}

.field textarea::placeholder,
.field input::placeholder {
  color: var(--dim);
}

.composer {
  position: sticky;
  bottom: calc(64px + env(safe-area-inset-bottom));
  margin: 16px -20px -24px;
  padding: 12px 20px calc(env(safe-area-inset-bottom) + 12px);
  border-top: 1px solid var(--line);
  background: rgba(19, 19, 21, 0.96);
  backdrop-filter: blur(18px);
}

.composer textarea {
  max-height: 124px;
  min-height: 48px;
  resize: none;
}

.message-stream {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.message {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  background: var(--raised);
  color: var(--text);
  font-size: 14px;
  line-height: 21px;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  align-items: end;
  background: rgba(0, 0, 0, 0.56);
}

.sheet {
  max-height: calc(100svh - 64px);
  overflow: auto;
  border-radius: 14px 14px 0 0;
  border: 1px solid var(--line);
  border-bottom: 0;
  padding: 18px 18px calc(env(safe-area-inset-bottom) + 18px);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sheet h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.code-box {
  overflow: auto;
  max-height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #0a0a0b;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 17px;
  white-space: pre-wrap;
}

.debug-panel {
  margin: 6px 0 14px;
  color: var(--dim);
  font-size: 12px;
  font-weight: 760;
}

.debug-panel summary {
  display: flex;
  min-height: 42px;
  align-items: center;
  cursor: pointer;
}

.debug-panel[open] {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px 12px;
  background: var(--raised);
}

.scanner-topbar {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 18px) 20px 12px;
}

.scanner-title {
  color: var(--text);
  font-size: 22px;
  font-weight: 820;
  line-height: 28px;
  text-align: center;
}

.scanner-icon {
  display: inline-flex;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--raised);
  color: var(--text);
  font-size: 34px;
  font-weight: 300;
  line-height: 1;
}

.scanner-icon.placeholder {
  border-color: transparent;
  background: transparent;
}

.scanner-content {
  display: grid;
  align-content: center;
  gap: 20px;
  min-width: 0;
  padding: 20px;
}

.scanner-view {
  position: relative;
  overflow: hidden;
  width: 100%;
  max-height: min(62svh, 560px);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.12), transparent 34%),
    #000;
  aspect-ratio: 3 / 4;
  box-shadow: var(--shadow);
}

.scanner-view video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-frame {
  position: absolute;
  inset: 22% 12%;
  border: 3px solid rgba(255, 255, 255, 0.94);
  border-radius: 18px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.38), 0 0 30px rgba(255, 255, 255, 0.18);
}

.scanner-hint {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 22px;
  text-align: center;
}

.scanner-footer {
  padding: 12px 20px calc(env(safe-area-inset-bottom) + 20px);
}

@media (min-width: 700px) {
  .app-shell {
    padding: 20px 0;
  }

  .phone-app {
    min-height: calc(100svh - 40px);
    border: 1px solid var(--line);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: var(--shadow);
  }
}
