:root {
  --bg: #faf9ff;
  --card: #ffffff;
  --text: #1b1830;
  --muted: #5c5876;
  --border: #e9e6f5;
  --primary: #6d5efc;
  --primary-hover: #5b4fd6;
  --danger: #ef4444;
  --radius: 16px;
  --grad: linear-gradient(135deg, #7c6cf5 0%, #6d5efc 50%, #5b8def 100%);
  --shadow: 0 4px 20px -6px rgba(76, 61, 168, 0.18);
  --shadow-lg: 0 18px 50px -12px rgba(76, 61, 168, 0.35);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0a12;
    --card: #15131f;
    --text: #f4f2fb;
    --muted: #a7a2c4;
    --border: #262233;
    --primary: #8b7cff;
    --primary-hover: #7a6bf0;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background:
    radial-gradient(50% 40% at 50% 0%, rgba(124, 108, 245, 0.14), transparent 70%),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: 40px 20px calc(120px + env(safe-area-inset-bottom));
}

/* Header / brand */
header { margin-bottom: 28px; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  border-radius: 12px;
  box-shadow: var(--shadow);
  flex: none;
}
h1 {
  margin: 0 0 2px;
  font-size: 30px;
  letter-spacing: -0.02em;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  display: inline-block;
}
.sub { color: var(--muted); font-size: 14px; }

/* Toolbar */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 20px; }
.toolbar input { flex: 1; }
.count { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* Inputs */
input, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(109, 94, 252, 0.18);
}
textarea { resize: vertical; min-height: 44px; }

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: filter 0.15s, background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background-image: var(--grad); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: rgba(127, 122, 160, 0.14); color: var(--text); }

/* Card grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }

/* Gradient banner — hue set inline per record */
.tile .banner {
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  color: #fff;
}
.tile .avatar {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.35);
}
.tile .open {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: #fff;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.35);
  transition: background 0.15s, transform 0.1s;
}
.tile .open:hover { background: rgba(255, 255, 255, 0.38); }
.tile .open:active { transform: scale(0.94); }
.tile .open.disabled { opacity: 0.4; pointer-events: none; }

.tile .body { padding: 14px 16px 12px; flex: 1; }
.tile h3 {
  margin: 0 0 4px;
  font-size: 16px;
  letter-spacing: -0.01em;
  word-break: break-word;
}
.tile .desc {
  color: var(--muted);
  font-size: 13.5px;
  margin: 0 0 8px;
  white-space: pre-wrap;
  word-break: break-word;
}
.tile a.link {
  color: var(--primary);
  font-size: 12.5px;
  text-decoration: none;
  word-break: break-all;
}
.tile a.link:hover { text-decoration: underline; }

.tile .actions {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

/* Floating action button */
.fab {
  position: fixed;
  right: calc(24px + env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background-image: var(--grad);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-lg);
  transition: transform 0.15s ease, filter 0.15s;
  z-index: 30;
}
.fab:hover { filter: brightness(1.08); transform: translateY(-2px) rotate(90deg); }
.fab:active { transform: scale(0.94); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 16, 40, 0.5);
  backdrop-filter: blur(4px);
  animation: fade 0.18s ease;
}
.modal {
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-lg);
  animation: pop 0.2s ease;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-head h2 { margin: 0; font-size: 20px; letter-spacing: -0.02em; }
form.add { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Misc */
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.hidden { display: none !important; }

.sync { font-size: 12.5px; color: var(--muted); }
.sync.ok { color: #10b981; }
.sync.busy { color: var(--primary); }
.sync.warn { color: #f59e0b; }
