:root {
  --bg: #0c0a16;
  --surface: #17142a;
  --surface-2: #211c3a;
  --line: rgba(196, 181, 253, 0.14);
  --text: #f4f1ff;
  --muted: #a8a0c8;
  --accent: #a78bfa;
  --grad: linear-gradient(135deg, #7c3aed 0%, #a855f7 55%, #d946ef 100%);
  --danger: #fb7185;
  --ok: #4ade80;
  --warn: #fbbf24;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top, 0px) 16px calc(112px + var(--safe-b));
  max-width: 640px;
  margin: 0 auto;
  -webkit-tap-highlight-color: transparent;
}
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.glow {
  position: fixed; inset: -20vh -20vw auto; height: 60vh; z-index: -1; pointer-events: none;
  background: radial-gradient(60% 60% at 30% 30%, rgba(124, 58, 237, 0.38), transparent 70%),
              radial-gradient(50% 50% at 80% 20%, rgba(217, 70, 239, 0.22), transparent 70%);
}

/* Header */
.top { display: flex; align-items: flex-start; justify-content: space-between; padding: 24px 0 16px; }
h1 { margin: 0; font-size: 32px; line-height: 1.1; letter-spacing: -0.02em; }
.status {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 8px; padding: 0;
  background: none; border: 0; color: var(--muted); font-size: 14px;
}
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status[data-s="ok"]::before { background: var(--ok); }
.status[data-s="syncing"]::before { background: var(--accent); animation: pulse 1s infinite alternate; }
.status[data-s="pending"]::before, .status[data-s="offline"]::before { background: var(--warn); }
.status[data-s="error"]::before { background: var(--danger); }
@keyframes pulse { to { opacity: 0.3; } }

.icon-btn {
  width: 48px; height: 48px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; color: var(--muted);
}

/* Install banner */
.install {
  display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px; margin-bottom: 16px;
  border-radius: 14px; background: linear-gradient(135deg, rgba(124, 58, 237, 0.28), rgba(217, 70, 239, 0.18));
  border: 1px solid rgba(196, 181, 253, 0.3); font-size: 14px;
}
.install[hidden] { display: none; }
.install span { flex: 1; }
.install button { height: 40px; border: 0; border-radius: 10px; padding: 0 16px; background: var(--grad); color: #fff; font-weight: 600; }
.install .install-x { width: 40px; padding: 0; background: none; color: var(--muted); font-size: 22px; }

/* Search */
.search {
  display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 16px; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; height: 100%; background: none; border: 0; outline: 0; color: var(--text); font: inherit; }
.search input::placeholder { color: var(--muted); }

/* List */
.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.card {
  display: flex; align-items: center; gap: 16px; width: 100%; padding: 16px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  transition: transform 0.12s ease, background 0.12s ease;
}
.card:active { transform: scale(0.98); background: var(--surface-2); }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--grad); color: #fff; font-weight: 700; font-size: 17px;
}
.card .info { min-width: 0; flex: 1; }
.card .name { font-weight: 600; font-size: 17px; }
.card .sub, .card .remark { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .remark { color: #cfc6f2; }
.pending-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }

.count { color: var(--muted); font-size: 14px; margin: 8px 4px; }
.empty { text-align: center; padding: 64px 24px; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 8px; }

/* FAB */
.fab {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; height: 56px; padding: 0 24px;
  border: 0; border-radius: 28px; background: var(--grad); color: #fff; font-weight: 600; font-size: 17px;
  box-shadow: 0 12px 32px rgba(124, 58, 237, 0.45), 0 2px 6px rgba(0, 0, 0, 0.4);
}
.fab:active { transform: translateX(-50%) scale(0.96); }

/* Sheets */
.sheet {
  width: 100%; max-width: 640px; max-height: 100dvh; height: 100dvh; margin: 0 auto; padding: 0 16px calc(24px + var(--safe-b));
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--bg); color: var(--text); border: 0; overflow-y: auto;
}
.sheet[open] { animation: up 0.24s cubic-bezier(0.2, 0.8, 0.2, 1); }
.sheet::backdrop { background: rgba(0, 0, 0, 0.6); }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
@media (min-width: 700px) {
  .sheet { height: auto; max-height: 90dvh; margin-top: 5dvh; border-radius: 24px; border: 1px solid var(--line); background: #110e20; }
}
.sheet-head { display: flex; align-items: center; height: 64px; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 17px; flex: 2; text-align: center; }
.sheet-head .text-btn, .sheet-head .spacer { flex: 1; }
.sheet-head > :last-child { text-align: right; }
.text-btn { background: none; border: 0; padding: 12px 0; color: var(--accent); font-size: 16px; text-align: left; }
.text-btn.strong { font-weight: 600; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin: 0 0 8px 4px; }
.field input, .field textarea {
  width: 100%; padding: 14px 16px; min-height: 52px; font: inherit; font-size: 17px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; outline: 0; resize: vertical;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(167, 139, 250, 0.18); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.err { display: block; font-style: normal; color: var(--danger); font-size: 14px; margin: 8px 4px 0; }
.err:empty { display: none; }

.primary, .secondary, .danger {
  width: 100%; height: 56px; border-radius: 16px; font-weight: 600; font-size: 17px;
}
.primary { border: 0; background: var(--grad); color: #fff; margin-top: 8px; box-shadow: 0 8px 24px rgba(124, 58, 237, 0.35); }
.primary:disabled { opacity: 0.6; }
.secondary { border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.danger { border: 1px solid rgba(251, 113, 133, 0.3); background: rgba(251, 113, 133, 0.08); color: var(--danger); margin-top: 24px; }

/* Detail */
.d-hero { text-align: center; padding: 8px 0 24px; }
.d-hero .avatar { width: 80px; height: 80px; font-size: 28px; margin: 0 auto 16px; }
.d-hero h3 { margin: 0; font-size: 24px; letter-spacing: -0.01em; }
.d-hero p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 24px; }
.actions a, .actions span {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); text-decoration: none; font-size: 14px;
}
.actions a svg { color: var(--accent); }
.actions span { color: var(--muted); opacity: 0.5; }
.rows { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.row { padding: 16px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row dt { font-size: 14px; color: var(--muted); }
.row dd { margin: 4px 0 0; word-break: break-word; white-space: pre-wrap; }
.row dd.none { color: var(--muted); }

/* Settings */
.sheet-link {
  display: flex; align-items: center; justify-content: center; gap: 8px; height: 56px; margin-bottom: 24px;
  border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text); text-decoration: none; font-weight: 600;
}
.sheet-link svg { color: var(--ok); }
.settings-msg { min-height: 20px; font-size: 14px; color: var(--muted); text-align: center; }
.settings-msg[data-s="error"] { color: var(--danger); }
.settings-msg[data-s="ok"] { color: var(--ok); }
.setup { margin-top: 16px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.setup summary { font-weight: 600; cursor: pointer; }
.setup ol { padding-left: 20px; color: #d8d1f5; }
.setup li { margin-bottom: 8px; }
.setup code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }

/* PIN */
.pin-sheet .pin-hero { text-align: center; padding: 15dvh 0 32px; }
.pin-sheet .avatar { width: 72px; height: 72px; margin: 0 auto 16px; }
.pin-sheet .avatar svg { width: 30px; height: 30px; }
.pin-sheet h2 { margin: 0; font-size: 24px; }
.pin-sheet p { margin: 8px 0 0; color: var(--muted); }
.pin-sheet input { text-align: center; font-size: 24px; letter-spacing: 0.4em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translate(-50%, 16px);
  padding: 12px 20px; border-radius: 14px; background: #2a2350; color: var(--text); font-size: 15px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); opacity: 0; pointer-events: none; transition: 0.2s ease; z-index: 10;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, .sheet[open] { animation: none !important; transition: none !important; }
}
