:root {
  --bg: #eef1f8;
  --fg: #1c1e26;
  --fg-muted: #5b5f70;
  --glass-bg: rgba(255, 255, 255, 0.55);
  --glass-border: rgba(255, 255, 255, 0.65);
  --glass-shadow: 0 8px 32px rgba(31, 38, 68, 0.12);
  --accent: #5b6cff;
  --accent-2: #ff6ba8;
  --accent-3: #35d0c0;
  --danger: #e6486b;
  --input-bg: rgba(255, 255, 255, 0.6);
  --input-border: rgba(28, 30, 38, 0.14);
  --radius-lg: 24px;
  --radius-md: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1220;
    --fg: #eef0fb;
    --fg-muted: #a3a8c2;
    --glass-bg: rgba(32, 35, 58, 0.55);
    --glass-border: rgba(255, 255, 255, 0.10);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
    --input-bg: rgba(255, 255, 255, 0.06);
    --input-border: rgba(255, 255, 255, 0.14);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}

/* ---------- animated gradient background ---------- */
.bg-blobs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  filter: blur(60px);
}

.blob {
  position: absolute;
  width: 45vmax;
  height: 45vmax;
  border-radius: 50%;
  opacity: 0.45;
  animation: drift 26s ease-in-out infinite alternate;
}

.blob-a { background: var(--accent); top: -15%; left: -10%; }
.blob-b { background: var(--accent-2); bottom: -20%; right: -10%; animation-duration: 32s; animation-delay: -6s; }
.blob-c { background: var(--accent-3); top: 30%; left: 55%; animation-duration: 38s; animation-delay: -14s; opacity: 0.3; }

@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(6%, 8%) scale(1.12); }
}

@media (prefers-reduced-motion: reduce) {
  .blob { animation: none; }
}

/* ---------- glass card primitive ---------- */
.glass-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
}

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 36px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-card h1 { margin: 0; font-size: 1.6rem; }
.login-card .subtitle { margin: -8px 0 8px; color: var(--fg-muted); }

.error, .form-error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0;
}

label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--fg-muted); }

input, select {
  font: inherit;
  color: var(--fg);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; }

.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; }
.btn-ghost { background: transparent; color: var(--fg); border: 1px solid var(--input-border); }
.btn-danger { background: var(--danger); color: white; }
.btn:hover { opacity: 0.9; }

/* ---------- dashboard layout ---------- */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.topbar {
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar h1 { margin: 0; font-size: 1.4rem; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 6px;
  align-self: flex-start;
}

.tab {
  font: inherit;
  font-weight: 600;
  color: var(--fg-muted);
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 8px 20px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab.active {
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 28px 16px 20px;
  text-decoration: none;
  color: var(--fg);
  min-height: 140px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.tile:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 40px rgba(31, 38, 68, 0.18);
}

.tile-icon { font-size: 2rem; line-height: 1; }
.tile-title { font-weight: 600; text-align: center; }
.tile-url { font-size: 0.75rem; color: var(--fg-muted); text-align: center; word-break: break-all; }

.tile-edit {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: transparent;
  color: var(--fg-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 999px;
  line-height: 1;
}
.tile-edit:hover { background: rgba(0, 0, 0, 0.08); color: var(--fg); }

.empty-hint { text-align: center; color: var(--fg-muted); }

/* ---------- modal ---------- */
dialog#tile-modal {
  border: none;
  padding: 28px;
  width: 100%;
  max-width: 380px;
  color: var(--fg);
}

dialog#tile-modal::backdrop {
  background: rgba(10, 12, 20, 0.45);
  backdrop-filter: blur(4px);
}

#tile-form { display: flex; flex-direction: column; gap: 14px; }
#tile-form h2 { margin: 0; font-size: 1.2rem; }

.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.modal-actions .spacer { flex: 1; }

@media (max-width: 480px) {
  .page { padding: 16px; }
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar-actions { justify-content: space-between; }
}
