:root {
  --bg: #0f1720;
  --surface: #17212c;
  --surface-2: #1f2b38;
  --line: #2a3846;
  --text: #e8eef4;
  --muted: #93a3b3;
  --accent: #4dabf7;
  --accent-ink: #0b1a28;
  --danger: #ff6b6b;
  --warn-bg: #3a2e12;
  --warn-ink: #ffd8a8;
  --ok: #69db7c;
  --radius: 14px;
  --mono: ui-monospace, "Roboto Mono", "SFMono-Regular", Menlo, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f8; --surface: #ffffff; --surface-2: #eef1f5; --line: #d9dfe6;
    --text: #15202b; --muted: #5d6b79; --accent: #1c7ed6; --accent-ink: #ffffff;
    --danger: #e03131; --warn-bg: #fff4e6; --warn-ink: #8a4b08; --ok: #2b8a3e;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}
body.privacy main { visibility: hidden; }
main { max-width: 640px; margin: 0 auto; }
h1 { font-size: 1.2rem; margin: 0; font-weight: 650; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 28px 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); letter-spacing: .04em; }
.center-text { text-align: center; padding: 32px 0; }

/* ---------- controls ---------- */
input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }
label { font-size: .85rem; color: var(--muted); font-weight: 600; margin-top: 6px; }

.btn {
  font: inherit; font-weight: 600;
  border-radius: 12px; padding: 12px 16px;
  border: 1px solid transparent; cursor: pointer;
  width: 100%;
}
.btn.small { padding: 8px 10px; font-size: .85rem; width: auto; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn:active { transform: scale(.98); }

.icon-btn {
  background: none; border: 0; color: var(--text);
  font-size: 1.25rem; width: 44px; height: 44px; border-radius: 50%;
  cursor: pointer; display: inline-grid; place-items: center; flex: none;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.small { width: 32px; height: 32px; font-size: .9rem; }
.icon-btn.accent { color: var(--accent); font-size: 1.5rem; }

.pass { position: relative; }
.pass input { padding-right: 48px; }
.pass .icon-btn { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); font-size: 1rem; opacity: .7; }

.stack { display: flex; flex-direction: column; gap: 10px; }
.warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 10px 12px; font-size: .88rem; }
.meter { font-size: .85rem; margin: -4px 0 0; min-height: 1.2em; }
.meter.weak { color: var(--danger); }
.meter.ok { color: var(--warn-ink); }
.meter.good { color: var(--ok); }

/* ---------- layout ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 96px 1fr 96px; align-items: center;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.bar h1 { text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-side { display: flex; }
.bar-side.right { justify-content: flex-end; }

.center { padding: 48px 20px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; }
.center .stack { width: 100%; max-width: 380px; text-align: left; margin-top: 18px; }
.logo img { width: 84px; height: 84px; border-radius: 22px; }

.list, .detail, .editor, .settings { padding: 14px 16px 110px; }
.list > input[type=search] { margin-bottom: 10px; }

.banner {
  width: 100%; text-align: left; font: inherit; font-size: .9rem;
  background: var(--warn-bg); color: var(--warn-ink);
  border: 0; border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; cursor: pointer;
}

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.chip {
  flex: none; font: inherit; font-size: .85rem;
  border-radius: 99px; padding: 6px 14px;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); cursor: pointer;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 560px) { .grid { grid-template-columns: 1fr 1fr; } }
.tile { padding: 0; border: 0; background: none; cursor: pointer; text-align: left; color: inherit; font: inherit; }

/* ---------- card face ---------- */
.face {
  aspect-ratio: 1.586;
  border-radius: var(--radius);
  padding: 16px 18px;
  color: #fff;
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(255,255,255,.22), transparent 55%),
    linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 55%, #000));
  box-shadow: 0 6px 18px rgba(0,0,0,.28);
  display: grid; grid-template-rows: auto 1fr auto auto; gap: 4px;
  overflow: hidden;
}
.face-top { display: flex; justify-content: space-between; font-size: .78rem; opacity: .9; }
.face-title { font-size: 1.2rem; font-weight: 700; align-self: start; margin-top: 4px; overflow-wrap: anywhere; }
.face-num { font-family: var(--mono); font-size: 1.1rem; letter-spacing: .12em; }
.face-bottom { display: flex; justify-content: space-between; align-items: end; gap: 8px; font-size: .85rem; text-transform: uppercase; opacity: .95; min-height: 1.3em; }
.face.big { margin-bottom: 14px; }
.badge { font-size: .7rem; padding: 3px 8px; border-radius: 99px; text-transform: none; font-weight: 700; flex: none; }
.badge.soon { background: #ffd43b; color: #3d2c00; }
.badge.expired { background: #fff; color: #c92a2a; }

.empty { text-align: center; padding: 60px 20px; }

.fab {
  position: fixed; right: max(20px, calc(50vw - 300px)); bottom: calc(24px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  font-size: 2rem; line-height: 1; cursor: pointer;
  box-shadow: 0 8px 22px rgba(0,0,0,.35);
}

/* ---------- detail ---------- */
.images { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.images:empty { display: none; }
figure { margin: 0; cursor: zoom-in; }
figure img { width: 100%; aspect-ratio: 1.586; object-fit: cover; border-radius: 10px; display: block; background: var(--surface); }
figcaption { font-size: .75rem; color: var(--muted); margin-top: 4px; text-align: center; }
.rows { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 4px; padding: 10px 6px 10px 14px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lbl { font-size: .75rem; color: var(--muted); }
.val { overflow-wrap: anywhere; }
.notes { margin-top: 14px; background: var(--surface); border-radius: var(--radius); padding: 12px 14px; border: 1px solid var(--line); white-space: pre-wrap; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }

/* ---------- editor ---------- */
.slots { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.slot { display: flex; flex-direction: column; gap: 6px; }
.slot-img {
  aspect-ratio: 1.586; border-radius: 10px; border: 1.5px dashed var(--line);
  display: grid; place-items: center; overflow: hidden; background: var(--surface);
}
.slot-img img { width: 100%; height: 100%; object-fit: cover; }
.slot-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.slot-btns .btn { flex: 1 1 auto; }
.ocr-out summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.ocr-out textarea { margin-top: 6px; font-family: var(--mono); font-size: .8rem; }

.field { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px 8px 8px; }
.field-head { display: flex; align-items: center; gap: 6px; }
.field .field-label { border: 0; background: none; padding: 4px 4px; font-size: .8rem; color: var(--muted); font-weight: 600; flex: 1; }
.field > input { background: var(--surface-2); }
.secret-toggle { display: flex; align-items: center; gap: 4px; margin: 0; font-weight: 500; font-size: .78rem; white-space: nowrap; }
.secret-toggle input { width: auto; }

.colors { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; background: var(--c); cursor: pointer; }
.swatch.on { border-color: var(--text); }

/* ---------- settings ---------- */
.settings .btn { margin-bottom: 8px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.set-row select { width: auto; min-width: 130px; padding: 8px 10px; }

/* ---------- overlays ---------- */
dialog.modal {
  width: min(92vw, 420px); border: 1px solid var(--line); border-radius: 18px;
  background: var(--surface); color: var(--text); padding: 20px;
}
dialog.modal::backdrop { background: rgba(0,0,0,.55); }
dialog.modal form { display: flex; flex-direction: column; gap: 10px; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.type-btn {
  font: inherit; font-size: .9rem; text-align: left; cursor: pointer;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; display: flex; align-items: center; gap: 8px;
}
.type-btn .ti { font-size: 1.3rem; }

.busy {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: #fff; padding: 24px; text-align: center;
}
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid rgba(255,255,255,.25); border-top-color: #fff; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 60;
  font-size: .9rem; max-width: 90vw; box-shadow: 0 6px 16px rgba(0,0,0,.3);
}
#viewer { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: 12px; }
#viewer[hidden] { display: none; }
#viewer img { max-width: 100%; max-height: 100%; border-radius: 8px; }

@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* ---------- sync button ---------- */
#syncBtn { position: relative; }
#syncBtn.spin { animation: spin 1s linear infinite; }
#syncBtn.dot::after {
  content: ''; position: absolute; top: 9px; right: 9px;
  width: 9px; height: 9px; border-radius: 50%; background: #ff922b;
}
.tight { padding: 4px 0 0; }
