@font-face {
  font-family: "jf-openhuninn";
  src: url("/fonts/jf-openhuninn-2.1.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/fonts/jetbrains-mono-latin.woff2") format("woff2");
  font-weight: 500 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --ease-ui: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --font-sans: "jf-openhuninn", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei UI", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
::view-transition-old(root) { z-index: 1; }
::view-transition-new(root) { z-index: 9999; }

html[data-theme="dark"] {
  --canvas-bg:
    radial-gradient(ellipse 68% 58% at 14% 12%, rgba(56, 189, 248, 0.20), transparent 62%),
    radial-gradient(ellipse 62% 56% at 86% 88%, rgba(57, 197, 187, 0.17), transparent 60%),
    linear-gradient(148deg, #090c11 0%, #0e141c 48%, #0a0f15 100%);
  --grid-line: rgba(255, 255, 255, 0.028);
  --win-bg: rgba(16, 20, 27, 0.76);
  --topbar-bg: rgba(10, 13, 18, 0.68);
  --win-border: rgba(255, 255, 255, 0.12);
  --win-inset: rgba(255, 255, 255, 0.09);
  --card-bg: rgba(255, 255, 255, 0.048);
  --card-hover: rgba(255, 255, 255, 0.09);
  --card-inset: rgba(255, 255, 255, 0.07);
  --surface-subtle: rgba(255, 255, 255, 0.055);
  --surface-hover: rgba(255, 255, 255, 0.11);
  --divider: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);
  --input-bg: rgba(7, 10, 14, 0.62);
  --text-primary: #f2f5f8;
  --text-secondary: #c5cdd8;
  --text-muted: #94a3b8;
  --cta-bg: #39c5bb;
  --cta-text: #061414;
  --cta-hover: #4fd4ca;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.15);
  --mint: #39c5bb;
  --mint-soft: rgba(57, 197, 187, 0.15);
  --green: #34d399;
  --amber: #fbbf24;
  --red: #fb7185;
  --danger-soft: rgba(251, 113, 133, 0.15);
  --danger-border: rgba(251, 113, 133, 0.36);
  --ring-track: rgba(255, 255, 255, 0.12);
  --modal-bg: rgba(16, 21, 29, 0.94);
  --backdrop-scrim: rgba(4, 6, 10, 0.64);
  --toast-bg: rgba(17, 23, 32, 0.96);
  --toast-text: #f2f5f8;
  --copied-bg: rgba(52, 211, 153, 0.15);
  --copied-border: rgba(52, 211, 153, 0.42);
}

html[data-theme="light"] {
  --canvas-bg:
    radial-gradient(ellipse 68% 58% at 16% 12%, rgba(255, 255, 255, 0.88), transparent 62%),
    radial-gradient(ellipse 64% 58% at 86% 86%, rgba(57, 197, 187, 0.24), transparent 60%),
    linear-gradient(150deg, #cfd8e3 0%, #e1e7ef 50%, #c8d3e0 100%);
  --grid-line: rgba(15, 23, 42, 0.036);
  --win-bg: rgba(255, 255, 255, 0.74);
  --topbar-bg: rgba(244, 248, 252, 0.76);
  --win-border: rgba(15, 23, 42, 0.11);
  --win-inset: rgba(255, 255, 255, 0.95);
  --card-bg: rgba(255, 255, 255, 0.72);
  --card-hover: rgba(255, 255, 255, 0.94);
  --card-inset: rgba(255, 255, 255, 0.95);
  --surface-subtle: rgba(15, 23, 42, 0.05);
  --surface-hover: rgba(15, 23, 42, 0.095);
  --divider: rgba(15, 23, 42, 0.095);
  --border-strong: rgba(15, 23, 42, 0.18);
  --input-bg: rgba(255, 255, 255, 0.86);
  --text-primary: #11161d;
  --text-secondary: #2a3340;
  --text-muted: #526072;
  --cta-bg: #0f172a;
  --cta-text: #ffffff;
  --cta-hover: #1e293b;
  --accent: #0369a1;
  --accent-soft: rgba(3, 105, 161, 0.12);
  --mint: #0d9488;
  --mint-soft: rgba(13, 148, 136, 0.12);
  --green: #047857;
  --amber: #b45309;
  --red: #be123c;
  --danger-soft: rgba(190, 18, 60, 0.10);
  --danger-border: rgba(190, 18, 60, 0.30);
  --ring-track: rgba(15, 23, 42, 0.11);
  --modal-bg: rgba(250, 252, 255, 0.96);
  --backdrop-scrim: rgba(15, 23, 42, 0.42);
  --toast-bg: rgba(17, 22, 29, 0.94);
  --toast-text: #ffffff;
  --copied-bg: rgba(4, 120, 87, 0.12);
  --copied-border: rgba(4, 120, 87, 0.38);
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--canvas-bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: 32px 32px;
  z-index: 0;
}

.app-root {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* ---- Centered Auth / Unlock / Setup Shell ---- */
.auth-shell {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
}

.glass-panel {
  width: 100%;
  max-width: 440px;
  background: var(--win-bg);
  border: 1px solid var(--win-border);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.32), inset 0 1px 0 var(--win-inset);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border-radius: 24px;
  padding: 28px 24px 24px;
  animation: fadeSlideUp 0.28s var(--ease-out);
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.brand-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

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

.brand-logo {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.e2ee-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--mint);
  background: var(--mint-soft);
  border: 1px solid rgba(57, 197, 187, 0.28);
  white-space: nowrap;
}

.banner-info {
  background: var(--mint-soft);
  border: 1px solid rgba(57, 197, 187, 0.32);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--text-primary);
}

.banner-warn {
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.34);
  border-radius: 14px;
  padding: 11px 14px;
  margin-bottom: 16px;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 0.83rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.input-field {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--input-bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.96rem;
  outline: none;
  transition: border-color 0.16s var(--ease-ui), box-shadow 0.16s var(--ease-ui);
}

.input-field.mono {
  font-family: var(--font-mono);
  font-size: 0.88rem;
}

.input-field:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 3px var(--mint-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  padding: 11px 16px;
  font-family: var(--font-sans);
  font-size: 0.94rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s var(--ease-ui), background 0.16s var(--ease-ui), opacity 0.16s;
}

.btn:active { transform: scale(0.975); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary {
  width: 100%;
  background: var(--cta-bg);
  color: var(--cta-text);
  padding: 13px 18px;
}
.btn-primary:hover:not(:disabled) { background: var(--cta-hover); }

.btn-ghost {
  background: var(--surface-subtle);
  color: var(--text-primary);
  border: 1px solid var(--divider);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); }

.btn-danger {
  background: var(--danger-soft);
  color: var(--red);
  border: 1px solid var(--danger-border);
}
.btn-danger:hover:not(:disabled) { background: rgba(251, 113, 133, 0.24); }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: 1px solid var(--divider);
  background: var(--surface-subtle);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.12s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-hover); }
.icon-btn:active { transform: scale(0.94); }

.error-msg {
  color: var(--red);
  font-size: 0.84rem;
  margin-top: 8px;
  min-height: 1.2em;
}

.strength-bar {
  height: 5px;
  border-radius: 999px;
  background: var(--surface-subtle);
  overflow: hidden;
  margin-top: 8px;
}
.strength-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  transition: width 0.22s var(--ease-ui), background 0.22s;
}
.strength-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.auth-footer {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
}
.link-btn:hover { background: var(--accent-soft); }

/* ---- Unlocked Vault Main Layout ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--win-border);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
}

.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: auto;
}

.topbar-logo {
  width: 30px;
  height: 30px;
}

.topbar-name {
  font-size: 1.05rem;
  font-weight: 700;
}

.search-wrap {
  position: relative;
  flex: 1 1 220px;
  max-width: 360px;
}

.search-input {
  width: 100%;
  padding: 9px 14px 9px 36px;
  border-radius: 12px;
  border: 1px solid var(--divider);
  background: var(--input-bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  outline: none;
}
.search-input:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 3px var(--mint-soft);
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-add {
  background: var(--cta-bg);
  color: var(--cta-text);
  padding: 9px 14px;
  font-size: 0.88rem;
  border-radius: 11px;
}
.btn-add:hover { background: var(--cta-hover); }

.vault-main {
  flex: 1;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px 16px calc(36px + var(--safe-bottom));
}

.vault-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  font-size: 0.82rem;
  color: var(--text-muted);
  gap: 10px;
  flex-wrap: wrap;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(272px, 1fr));
  gap: 14px;
}

.totp-card {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--win-border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14), inset 0 1px 0 var(--card-inset);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border-radius: 18px;
  padding: 16px 18px 15px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.16s var(--ease-ui), background 0.18s var(--ease-ui), border-color 0.18s;
}

.totp-card:hover {
  background: var(--card-hover);
  transform: translateY(-2px);
}

.totp-card:active {
  transform: scale(0.985);
}

.totp-card.copied {
  background: var(--copied-bg);
  border-color: var(--copied-border);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.card-title-wrap {
  min-width: 0;
  flex: 1;
}

.card-name {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0.72;
  transition: opacity 0.15s;
}
.totp-card:hover .card-actions { opacity: 1; }

.card-action-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: none;
  background: var(--surface-subtle);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.card-action-btn:hover { background: var(--surface-hover); color: var(--text-primary); }
.card-action-btn.del:hover { background: var(--danger-soft); color: var(--red); }

.card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.totp-code {
  font-family: var(--font-mono);
  font-size: 1.92rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.totp-card.warn .totp-code { color: var(--amber); }
.totp-card.urgent .totp-code { color: var(--red); }

.ring-wrap {
  position: relative;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
}

.ring-svg {
  width: 38px;
  height: 38px;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: var(--ring-track);
  stroke-width: 3.2;
}

.ring-progress {
  fill: none;
  stroke: var(--mint);
  stroke-width: 3.2;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.35s linear, stroke 0.2s;
}

.totp-card.warn .ring-progress { stroke: var(--amber); }
.totp-card.urgent .ring-progress { stroke: var(--red); }

.ring-sec {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.empty-state {
  text-align: center;
  padding: 56px 20px;
  color: var(--text-muted);
  background: var(--card-bg);
  border: 1px dashed var(--border-strong);
  border-radius: 20px;
}

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--backdrop-scrim);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--modal-bg);
  border: 1px solid var(--win-border);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.42), inset 0 1px 0 var(--win-inset);
  border-radius: 22px;
  padding: 22px;
  animation: fadeSlideUp 0.2s var(--ease-out);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 1.08rem;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}
.modal-actions .btn { flex: 1; }

.settings-section {
  padding: 12px 0;
  border-bottom: 1px solid var(--divider);
}
.settings-section:last-of-type { border-bottom: none; }

.settings-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.settings-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 10px;
}

.kv-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  font-size: 0.8rem;
}
.kv-k { color: var(--text-muted); }
.kv-v { color: var(--text-primary); font-family: var(--font-mono); text-align: right; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + var(--safe-bottom));
  transform: translateX(-50%) translateY(18px);
  background: var(--toast-bg);
  color: var(--toast-text);
  border: 1px solid var(--win-border);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  z-index: 100;
  transition: opacity 0.2s, transform 0.22s var(--ease-out);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- Spinner ---- */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--surface-hover);
  border-top-color: var(--mint);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .topbar-inner { gap: 8px; }
  .search-wrap { order: 3; flex: 1 1 100%; max-width: none; }
  .cards-grid { grid-template-columns: 1fr; gap: 11px; }
  .totp-code { font-size: 1.82rem; }
  .glass-panel { padding: 22px 18px 20px; border-radius: 20px; }
  .card-actions { opacity: 0.95; }
}
