:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e2430;
  --text: #e8edf7;
  --muted: #9aa6b2;
  --accent: #ff6b9d;
  --danger: #ff5d5d;
  --border: #2a3140;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: radial-gradient(1200px 600px at 10% -10%, #1a1030 0%, var(--bg) 45%);
  color: var(--text);
  min-height: 100%;
}

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
}

button:hover { border-color: #3d4b63; }
button.ghost { background: transparent; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.active-filter {
  background: #3a2f14;
  border-color: rgba(255, 209, 102, 0.45);
  color: #ffd166;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(10px);
  background: rgba(15, 17, 21, 0.88);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem 0.85rem;
  display: grid;
  gap: 0.65rem;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
}

.brand strong { letter-spacing: 0.02em; }
.muted { color: var(--muted); font-size: 0.92rem; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.65rem;
  align-items: center;
  justify-content: space-between;
}

.controls-main {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.65rem;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
}

.controls-end {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  margin-left: auto;
}

.controls input[type="search"] {
  min-width: min(280px, 70vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
}

.controls select {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.45rem 0.55rem;
}

.group {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  padding: 0.15rem;
}

button.btn-quiet {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.4rem 0.65rem;
  border-radius: 999px;
}

button.btn-quiet:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border-color: transparent;
}

main { padding: 1rem; }

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

.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 220px;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.card:hover { transform: translateY(-2px); border-color: #3d4b63; }
.card.is-starred { border-color: rgba(255, 209, 102, 0.35); }

.card a.thumb-link {
  display: block;
  aspect-ratio: 16 / 10;
  background: #0b0d12;
  color: inherit;
  text-decoration: none;
  overflow: hidden;
}

.card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  background: #0b0d12;
}

.card .placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.75rem;
  text-align: center;
}

.card .meta {
  padding: 0.55rem 0.65rem 0.7rem;
  display: grid;
  gap: 0.35rem;
}

.card .title {
  font-size: 0.86rem;
  line-height: 1.25;
  max-height: 2.5em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card .sub {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.75rem;
}

.card .star,
.card .remove {
  position: absolute;
  top: 0.45rem;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  z-index: 2;
}

.card .star { left: 0.45rem; }
.card .star.on {
  color: #ffd166;
  border-color: rgba(255, 209, 102, 0.45);
}
.card .star:hover,
.card .remove:hover { background: rgba(0, 0, 0, 0.9); }
.card .remove { right: 0.45rem; }
.card .remove:hover {
  background: var(--danger);
  border-color: transparent;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 4rem 1rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  background: #111827;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.65rem 1rem;
  box-shadow: var(--shadow);
  z-index: 50;
  max-width: min(90vw, 520px);
}

.lock {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.lock[hidden] {
  display: none !important;
}

.lock-card {
  width: min(360px, 92vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.25rem;
  display: grid;
  gap: 0.75rem;
}

.lock-card input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
}

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

@media (max-width: 720px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .controls input[type="search"] { min-width: 100%; }
  .controls-end { width: 100%; justify-content: flex-end; }
}
