:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --bg-elevated: rgba(255, 255, 255, 0.78);
  --surface: #f4f4f5;
  --grouped: #ffffff;
  --grouped-secondary: #f4f4f5;
  --label: #000000;
  --secondary: rgba(0, 0, 0, 0.48);
  --tertiary: rgba(0, 0, 0, 0.32);
  --separator: rgba(0, 0, 0, 0.08);
  --border: rgba(0, 0, 0, 0.09);
  --fill: rgba(0, 0, 0, 0.05);
  --fill-strong: rgba(0, 0, 0, 0.09);
  --tint: #111111;
  --tint-fill: rgba(0, 0, 0, 0.06);
  --on-tint: #ffffff;
  --capsule: rgba(255, 255, 255, 0.86);
  --capsule-border: rgba(0, 0, 0, 0.09);
  --capsule-shadow: 0 10px 40px rgba(0, 0, 0, 0.10);
  --danger: #111111;
  --hairline: 1px;
  --nav: 44px;
  --tab: 56px;
  --radius: 16px;
  --radius-l: 22px;
  --radius-xl: 28px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --browser-inset: 0px;
  --dock-bottom: calc(var(--browser-inset) + max(14px, var(--safe-bottom)));
  --font: -apple-system, system-ui, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elevated: rgba(0, 0, 0, 0.72);
    --surface: #0d0d0d;
    --grouped: #0d0d0d;
    --grouped-secondary: #111111;
    --label: #ffffff;
    --secondary: rgba(255, 255, 255, 0.48);
    --tertiary: rgba(255, 255, 255, 0.32);
    --separator: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.10);
    --fill: rgba(255, 255, 255, 0.06);
    --fill-strong: rgba(255, 255, 255, 0.10);
    --tint: #ffffff;
    --tint-fill: rgba(255, 255, 255, 0.08);
    --on-tint: #000000;
    --capsule: rgba(18, 18, 18, 0.86);
    --capsule-border: rgba(255, 255, 255, 0.10);
    --capsule-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
    --danger: #ffffff;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  }
}

html.browser {
  --browser-inset: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--label);
  font-family: var(--font); font-size: 17px; line-height: 1.3;
  -webkit-font-smoothing: antialiased;
}
body { min-height: 100dvh; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--label); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--tertiary); }
img { max-width: 100%; display: block; }
#app { min-height: 100dvh; }

.hit { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.hit svg, .nav-compact svg { width: 22px; height: 22px; color: var(--label); }

/* Login */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(28px + var(--safe-top)) 24px calc(28px + var(--safe-bottom));
  background: var(--bg);
}
.login-card { width: 100%; max-width: 400px; text-align: center; }
.login-card .mark {
  width: 84px; height: 84px; margin: 0 auto 22px;
  border-radius: 22px; overflow: hidden;
  border: 1px solid var(--border);
}
.login-card .mark img { width: 100%; height: 100%; object-fit: cover; }
.login-card h1 {
  font-size: 34px; font-weight: 700; letter-spacing: -0.04em; margin: 0 0 6px;
}
.login-card .lede { margin: 0 0 32px; color: var(--secondary); font-size: 17px; }
.login-card .field { text-align: left; margin: 0 0 14px; }
.login-card input[type="password"],
.login-card input[type="text"] {
  width: 100%; min-height: 48px; padding: 12px 16px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--label);
}
.segmented {
  display: flex; background: var(--fill); border-radius: 12px; padding: 3px; min-height: 36px;
  border: 1px solid var(--border);
}
.segmented button {
  flex: 1; min-height: 32px; border-radius: 10px; font-size: 14px; font-weight: 600;
  color: var(--secondary); padding: 4px 8px;
  transition: background 0.28s ease, color 0.28s ease, transform 0.35s cubic-bezier(0.22, 1.15, 0.36, 1);
}
.segmented button[aria-pressed="true"],
.segmented button[aria-selected="true"] {
  background: var(--grouped); color: var(--label);
  box-shadow: 0 0.5px 2px rgba(0,0,0,0.08);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 50px; padding: 12px 18px; border-radius: 14px;
  background: var(--label); color: var(--bg); font-weight: 600;
  letter-spacing: -0.01em;
  transition: transform 0.35s cubic-bezier(0.22, 1.15, 0.36, 1), opacity 0.2s ease;
}
.btn:active { transform: scale(0.98); }
.btn.block { width: 100%; }
.btn.ghost {
  background: transparent; color: var(--label);
  border: 1px solid var(--border);
}
.btn.danger { background: transparent; color: var(--label); border: 1px solid var(--border); }
.btn.passkey { margin-top: 12px; }
.or-row {
  display: flex; align-items: center; gap: 12px; margin: 18px 0 14px;
  color: var(--tertiary); font-size: 13px; font-weight: 500;
}
.or-row::before, .or-row::after { content: ""; flex: 1; height: 1px; background: var(--separator); }
.form-error { color: var(--secondary); font-size: 15px; min-height: 1.2em; margin: 8px 0; }

/* Shell */
.shell { height: 100dvh; min-height: 100dvh; display: flex; flex-direction: column; background: var(--bg); overflow: hidden; }
.nav-bar {
  position: sticky; top: 0; z-index: 20;
  padding: var(--safe-top) 0 0;
  background: var(--bg-elevated);
  -webkit-backdrop-filter: saturate(140%) blur(24px);
  backdrop-filter: saturate(140%) blur(24px);
}
.nav-compact {
  height: var(--nav);
  display: grid;
  grid-template-columns: 44px 44px 1fr 44px;
  align-items: center;
  padding: 0 10px;
  gap: 2px;
}
.nav-compact.with-add { grid-template-columns: 44px 44px 1fr 44px 44px; }
.nav-title-small {
  text-align: center; font-size: 17px; font-weight: 600; letter-spacing: -0.02em;
  opacity: 0; transform: translateY(6px);
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: none;
}
.shell.compact .nav-title-small { opacity: 1; transform: none; }
.large-title-wrap { padding: 2px 20px 10px; }
.large-title {
  margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -0.045em;
  line-height: 1.1;
  transition: opacity 160ms ease, transform 160ms ease;
}
.shell.compact .large-title { opacity: 0; transform: scale(0.7) translateY(-8px); height: 0; margin: 0; overflow: hidden; }
.nav-search { padding: 0 20px 12px; }
.search-field {
  display: flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 8px 14px; border-radius: 14px;
  background: var(--fill); border: 1px solid var(--border);
}
.search-field svg { flex: none; width: 18px; height: 18px; color: var(--secondary); }
.search-field input {
  flex: 1; border: 0; background: transparent; outline: none; min-height: 24px;
  font-size: 17px; color: var(--label);
}
.search-field input::placeholder { color: var(--secondary); }
.nav-filters { padding: 0 20px 12px; }
.buyer-filter { margin-top: 8px; }

/* Content */
.content {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 20px calc(var(--tab) + var(--dock-bottom) + 18px);
  -webkit-overflow-scrolling: touch;
}
.banner {
  margin: 0 0 18px; padding: 13px 16px; border-radius: var(--radius-l);
  background: var(--fill); color: var(--secondary); font-size: 15px; font-weight: 500;
  border: 1px solid var(--border);
}
.group {
  background: var(--grouped); border-radius: var(--radius-l);
  overflow: hidden; margin: 0 0 24px;
  border: 1px solid var(--border);
}
.group-label {
  margin: 0 8px 8px; font-size: 12px; font-weight: 500; color: var(--secondary);
  letter-spacing: 0.04em; text-transform: uppercase;
}
.row {
  position: relative;
  display: flex; align-items: stretch;
  min-height: 64px; overflow: hidden;
  background: transparent;
}
.row + .row { box-shadow: inset 0 var(--hairline) 0 var(--separator); }
.row-front {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 14px;
  width: 100%; min-height: 76px; padding: 12px 16px;
  background: var(--grouped);
  transition: transform 220ms cubic-bezier(0.22, 1.15, 0.36, 1);
  touch-action: pan-y;
}
.row.swiped .row-front { transform: translateX(-148px); }
.row-actions {
  position: absolute; inset: 0 0 0 auto; width: 148px;
  display: flex;
}
.row-actions button {
  flex: 1; color: var(--label); font-size: 13px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: var(--surface);
}
.row-actions .act-buy { background: var(--fill-strong); }
.row-actions .act-archive { background: var(--fill); }
.thumb {
  width: 52px; height: 52px; border-radius: 14px; overflow: hidden; flex: none;
  background: var(--fill); display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: var(--secondary); border: 1px solid var(--border);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.row-body { flex: 1; min-width: 0; }
.row-body h2 { margin: 0 0 2px; font-size: 17px; font-weight: 600; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-body .meta { margin: 0; font-size: 15px; color: var(--secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-trailing { text-align: right; flex: none; color: var(--secondary); font-size: 15px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.row-trailing svg, .chev { width: 14px; height: 14px; opacity: 0.35; }
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.01em;
  background: var(--fill); color: var(--secondary); border: 1px solid var(--border);
}
.badge.needs_review, .badge.pending, .badge.purchased,
.badge.bought, .badge.bought_similar, .badge.passed { background: var(--fill); color: var(--secondary); }
.row.completed .row-body h2 { color: var(--secondary); }
.empty { padding: 40px 20px; text-align: center; }
.empty h2 { margin: 0 0 6px; font-size: 20px; font-weight: 600; letter-spacing: -0.03em; }
.empty p { margin: 0; color: var(--secondary); font-size: 15px; }

/* Floating capsule tab bar */
.tab-dock {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: var(--dock-bottom);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
  height: 58px;
  padding: 4px;
  border-radius: 999px;
  background: var(--capsule);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  backdrop-filter: blur(28px) saturate(160%);
  border: 1px solid var(--capsule-border);
  box-shadow: var(--capsule-shadow);
}
.tab-dock button {
  flex: 1;
  min-height: 50px;
  min-width: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  color: var(--secondary);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.01em;
  border-radius: 999px;
  transition: color 0.25s ease, background 0.3s ease, transform 0.4s cubic-bezier(0.22, 1.2, 0.36, 1);
}
.tab-dock button svg { width: 24px; height: 24px; }
.tab-dock button[aria-selected="true"] {
  color: var(--label);
  background: var(--fill-strong);
  transform: scale(1.03);
}
.tab-dock button:active { transform: scale(0.96); }

/* Sheets */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,0.46);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 560px; max-height: min(92dvh, 860px);
  overflow: auto;
  background: var(--grouped-secondary);
  border-radius: 28px 28px 0 0;
  padding: 6px 16px calc(16px + var(--safe-bottom));
  border: 1px solid var(--border);
  border-bottom: 0;
  box-shadow: var(--shadow);
}
.grab {
  width: 36px; height: 5px; border-radius: 100px; background: var(--fill-strong);
  margin: 6px auto 12px;
}
.sheet h2 { margin: 0 16px 14px; font-size: 22px; font-weight: 700; letter-spacing: -0.03em; }
.sheet-group {
  background: var(--grouped); border-radius: var(--radius-l);
  overflow: hidden; margin: 0 0 18px; border: 1px solid var(--border);
}
.field { padding: 0; }
.sheet-group .field + .field { box-shadow: inset 0 var(--hairline) 0 var(--separator); }
.field label { display: block; padding: 6px 16px 0; font-size: 12px; color: var(--secondary); letter-spacing: 0.02em; }
.field input, .field select, .field textarea {
  width: 100%; border: 0; background: transparent; outline: none;
  min-height: 44px; padding: 6px 16px 12px; color: var(--label);
}
.field textarea { min-height: 88px; resize: vertical; padding-top: 8px; }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn { flex: 1; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; }
.account-note { margin: 0 4px 18px; color: var(--secondary); font-size: 15px; }

.passkey-list { list-style: none; margin: 0 0 16px; padding: 0; }
.passkey-row {
  display: flex; align-items: center; gap: 12px;
  min-height: 60px; padding: 10px 4px;
  border-bottom: 1px solid var(--separator);
}
.passkey-row:last-child { border-bottom: 0; }
.passkey-row .meta { flex: 1; min-width: 0; }
.passkey-row h3 { margin: 0 0 2px; font-size: 16px; font-weight: 600; letter-spacing: -0.02em; }
.passkey-row p { margin: 0; font-size: 13px; color: var(--secondary); }
.passkey-row .hit { color: var(--secondary); font-size: 13px; font-weight: 500; min-width: auto; padding: 0 8px; }

.action-sheet { padding-bottom: calc(10px + var(--safe-bottom)); }
.action-group { background: var(--grouped); border-radius: 18px; overflow: hidden; margin: 0 0 10px; border: 1px solid var(--border); }
.action-group button, .action-cancel {
  width: 100%; min-height: 56px; font-size: 19px; color: var(--label);
  display: flex; align-items: center; justify-content: center;
}
.action-group button + button { box-shadow: inset 0 var(--hairline) 0 var(--separator); }
.action-group button.destructive { color: var(--secondary); }
.action-cancel {
  background: var(--grouped); border-radius: 18px; font-weight: 600; min-height: 56px;
  width: 100%; color: var(--label); border: 1px solid var(--border);
}

.flash {
  position: fixed; left: 50%; bottom: calc(var(--tab) + var(--dock-bottom) + 16px);
  transform: translateX(-50%);
  z-index: 50; padding: 10px 16px; border-radius: 16px;
  background: var(--label); color: var(--bg); font-size: 15px; font-weight: 500;
  pointer-events: none; max-width: calc(100% - 40px);
}

@media (min-width: 720px) {
  body { background: var(--bg); }
  .shell { max-width: 560px; margin: 0 auto; }
  .tab-dock { left: calc(50% - 264px); right: auto; width: 528px; }
}
