:root {
  --bg: #f3f5fb;
  --hero-grad-a: #dfe4fb;
  --hero-grad-b: #f4f2fc;
  --surface: #ffffff;
  --surface-hover: #f7f7fd;
  --border: #e5e7f2;
  --border-strong: #d2d5e6;
  --ink: #14162a;
  --ink-dim: #6c7086;
  --accent: #5b52e0;
  --accent-2: #17a398;
  --accent-soft: rgba(91, 82, 224, 0.1);
  --gold: #d99a2b;
  --danger: #d84a5a;
  --radius: 16px;
  --radius-lg: 22px;
  --font-display: "Space Grotesk", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;
  --shadow-lift: 0 18px 36px -20px rgba(30, 20, 90, 0.18);
}

[data-theme="dark"] {
  --bg: #0e0f18;
  --hero-grad-a: #1b1e35;
  --hero-grad-b: #12141f;
  --surface: #171a2a;
  --surface-hover: #1f2333;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.17);
  --ink: #eceaf7;
  --ink-dim: #8f92a8;
  --accent: #8178ff;
  --accent-2: #3ddbd1;
  --accent-soft: rgba(129, 120, 255, 0.18);
  --gold: #d9c15c;
  --shadow-lift: 0 20px 44px -22px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; transition: background-color 0.25s ease, color 0.25s ease; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px clamp(20px, 5vw, 64px);
  position: relative;
  z-index: 5;
}

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

.mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  box-shadow: 0 6px 16px -6px var(--accent-soft);
}

.brand-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.01em;
}

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

.edit-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 15px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.edit-toggle:hover { background: var(--surface-hover); transform: translateY(-1px); border-color: var(--border-strong); }
.edit-toggle.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(100deg, var(--accent), var(--accent-2));
}

.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 15px;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}
.theme-toggle:hover { background: var(--surface-hover); transform: translateY(-1px); border-color: var(--border-strong); }

/* ---------- Hero ---------- */

.hero-panel {
  background: linear-gradient(160deg, var(--hero-grad-a), var(--hero-grad-b));
  border-radius: 0 0 32px 32px;
  padding: 8px clamp(20px, 5vw, 64px) 44px;
}

.hero-inner {
  max-width: 720px;
  margin: 0 auto;
  text-align: center;
  padding-top: 28px;
}

.badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 22px;
  box-shadow: 0 8px 20px -14px rgba(30, 20, 90, 0.3);
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.hero-panel h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(34px, 6.6vw, 52px);
  line-height: 1.08;
  letter-spacing: -0.015em;
  margin: 0 0 16px;
}

.hero-panel h1 .accent {
  background: linear-gradient(100deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-sub {
  color: var(--ink-dim);
  font-size: 15.5px;
  margin: 0 0 28px;
}
.hero-sub strong { color: var(--accent); font-weight: 600; }

.command-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 10px 26px -18px rgba(30, 20, 90, 0.35);
}
.command-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.command-bar .search-icon { color: var(--ink-dim); font-size: 16px; }

.command-bar input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
}
.command-bar input::placeholder { color: var(--ink-dim); }

.command-bar .hint { font-family: var(--font-mono); font-size: 12px; color: var(--ink-dim); white-space: nowrap; }

.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 18px; }

.chip {
  font-size: 12.5px;
  font-weight: 500;
  padding: 8px 15px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-dim);
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover { color: var(--ink); border-color: var(--border-strong); }
.chip.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(100deg, var(--accent), var(--accent-2));
}

/* ---------- List ---------- */

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px clamp(20px, 5vw, 64px) 100px;
}

.list, .skeleton-list { display: flex; flex-direction: column; gap: 12px; }

.row-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  animation: rise 0.4s ease backwards;
}

.row-card:hover { transform: translateY(-2px); border-color: var(--border-strong); box-shadow: var(--shadow-lift); }
.row-card:hover .row-arrow { color: var(--accent); transform: translateX(2px); }

.row-link { position: absolute; inset: 0; z-index: 1; border-radius: inherit; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.row-icon {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 22px;
  overflow: hidden;
  box-shadow: 0 6px 14px -8px rgba(20, 15, 40, 0.35);
}
.row-icon img { width: 100%; height: 100%; object-fit: cover; }

.row-icon-label {
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  text-align: center;
  line-height: 1.1;
  padding: 0 2px;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
  overflow-wrap: anywhere;
  hyphens: auto;
}

.row-content { flex: 1; min-width: 0; position: relative; }

.row-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }

.row-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16.5px;
  margin: 4px 0 6px;
}

.row-actions { display: flex; align-items: center; gap: 8px; flex: none; position: relative; z-index: 2; }

.row-arrow { color: var(--ink-dim); font-size: 17px; transition: all 0.18s ease; }

.row-edit,
.row-delete {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-dim);
  font-size: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.row-edit:hover { color: var(--accent); border-color: var(--accent); }
.row-delete:hover { color: var(--danger); border-color: var(--danger); }

.row-desc {
  font-size: 13.5px;
  color: var(--ink-dim);
  line-height: 1.5;
  margin: 0 0 12px;
}

.row-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.row-domain {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-dim);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
}

.row-category {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

/* Skeletons */
.skeleton-row {
  height: 96px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: linear-gradient(100deg, var(--surface) 25%, var(--surface-hover) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.empty-state {
  text-align: center;
  color: var(--ink-dim);
  padding: 60px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}
#emptyTitle { font-family: var(--font-display); font-weight: 700; font-size: 18px; color: var(--ink); margin: 0 0 8px; }
.empty-sub { font-size: 13.5px; margin: 0; }
.empty-state strong { color: var(--accent); }
.empty-state button {
  margin-top: 14px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}

.load-error { text-align: center; color: var(--danger); font-size: 13.5px; margin-top: 30px; }
.load-error button { background: none; border: none; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; }

/* ---------- FAB ---------- */

.fab {
  position: fixed;
  right: 26px;
  bottom: 26px;
  width: 58px;
  height: 58px;
  border-radius: 18px;
  border: none;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 16px 32px -12px var(--accent-soft), 0 6px 14px -8px rgba(0,0,0,0.2);
  z-index: 30;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.fab:hover { transform: translateY(-3px) scale(1.04); }
.fab:active { transform: translateY(0) scale(0.97); }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(20, 18, 40, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 26px;
  box-shadow: 0 30px 60px -20px rgba(20, 15, 40, 0.35);
  animation: pop 0.2s ease;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h2 { font-family: var(--font-display); font-size: 19px; margin: 0; }

.modal-close {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: none;
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 13px;
}
.modal-close:hover { color: var(--ink); border-color: var(--border-strong); }

.tool-form { display: flex; flex-direction: column; gap: 14px; }
.tool-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--ink-dim); font-weight: 500; }
.tool-form label em { color: var(--accent); font-style: normal; }

.tool-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.tool-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.form-error {
  color: var(--danger);
  font-size: 12.5px;
  background: rgba(216, 74, 90, 0.08);
  border: 1px solid rgba(216, 74, 90, 0.25);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 0;
}

.form-actions { margin-top: 4px; }

.btn-primary {
  width: 100%;
  padding: 12px;
  border-radius: 11px;
  border: none;
  background: linear-gradient(100deg, var(--accent), var(--accent-2));
  color: #fff;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

footer {
  text-align: center;
  padding: 10px 20px 50px;
  color: var(--ink-dim);
  font-size: 12.5px;
  font-family: var(--font-mono);
}
footer code {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 5px;
}

/* Elements toggled with the `hidden` attribute must always hide, even when
   another rule on the same selector sets `display` (author rules otherwise
   beat the default [hidden] rule regardless of specificity). */
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 480px) {
  .form-row { grid-template-columns: 1fr; }
  .row-card { padding: 14px; gap: 12px; }
  .row-icon { width: 44px; height: 44px; font-size: 19px; }
}
