:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-hover: #232733;
  --border: #2a2f3a;
  --text: #e6e8ed;
  --text-dim: #9aa1ad;
  --accent: #4f8cff;
  --error: #ff6b6b;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---- Lock screen ---- */
.lock {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 30%, #1a1d24, #0f1115);
  padding: 1rem;
}

.unlock-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: min(360px, 100%);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.unlock-box h1 { margin: 0 0 0.5rem; font-size: 1.5rem; }
.hint { color: var(--text-dim); margin: 0 0 1.5rem; font-size: 0.9rem; }

.unlock-box input {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 1rem;
}
.unlock-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.unlock-box button {
  width: 100%;
  padding: 0.75rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.unlock-box button:disabled { opacity: 0.6; cursor: default; }

.error { color: var(--error); font-size: 0.85rem; margin: 1rem 0 0; }

/* ---- App ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.topbar h1 { margin: 0; font-size: 1.25rem; }

.search {
  flex: 1;
  min-width: 200px;
  max-width: 400px;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}
.search:focus { outline: none; border-color: var(--accent); }

.grid { padding: 1.5rem; }

.category { margin-bottom: 2rem; }
.category-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 0 0 0.75rem;
}

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

.card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s, transform 0.15s, border-color 0.15s;
}
.card:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
}

.card-icon {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: contain;
  flex-shrink: 0;
}

/* Local letter-tile fallback (no network request). */
.monogram {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1;
  text-transform: uppercase;
}

.card-body { display: flex; flex-direction: column; min-width: 0; }
.card-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-desc {
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.no-results {
  text-align: center;
  color: var(--text-dim);
  padding: 3rem;
}

[hidden] { display: none !important; }

.attribution {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.75rem;
  padding: 2rem 1rem 3rem;
}
.attribution a { color: var(--accent); text-decoration: none; }
.attribution a:hover { text-decoration: underline; }

/* ---- Device password ---- */
.dpw-hint { color: var(--accent); }

.topbar-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ghost-btn {
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}
.ghost-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--accent);
}

.primary-btn {
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.dpw-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 20;
  padding: 1rem;
}

.dpw-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: min(380px, 100%);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.dpw-box h2 { margin: 0 0 0.5rem; font-size: 1.15rem; }
.dpw-box .hint { margin: 0 0 1rem; }
.dpw-box input {
  width: 100%;
  padding: 0.7rem 1rem;
  margin-bottom: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.dpw-box input:focus { outline: none; border-color: var(--accent); }

.dpw-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

/* ---- Edit mode + change queue ---- */
.ghost-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.badge {
  display: inline-block;
  min-width: 1.2em;
  margin-left: 0.4em;
  padding: 0 0.35em;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.4;
}

/* Card edit controls: hidden unless body is in edit mode. */
.card { position: relative; }
.card-controls {
  display: none;
  position: absolute;
  top: 6px;
  right: 6px;
  gap: 4px;
}
body.edit-mode .card-controls { display: flex; }
body.edit-mode .card { cursor: default; }

.card-ctl {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.card-ctl:hover { border-color: var(--accent); }
.card-ctl.remove:hover { border-color: var(--error); color: var(--error); }

/* Staged-state markers. */
.card.pending-remove {
  opacity: 0.45;
  border-color: var(--error);
}
.card.pending-remove .card-name { text-decoration: line-through; }
.card.pending-edit {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.review-box { width: min(640px, 100%); }
.review-text {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 0.75rem;
  resize: vertical;
  margin-bottom: 0.75rem;
}
.review-text:focus { outline: none; border-color: var(--accent); }
