:root {
  --ink: #0E0E0E;
  --ink-soft: #4B4B4B;
  --paper: #FEFFEE;
  --tile: #EFF0D8;
  --blue: #00AED6;
  --green: #00AA69;
  --red: #F45344;
  --line: rgba(14, 14, 14, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter Tight", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
}

/* ---------- header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 24px;
  background: var(--paper);
  border-bottom: 1.5px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { display: flex; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: -0.02em; }

.search-wrap { flex: 1; max-width: 460px; }
#search {
  width: 100%;
  padding: 9px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  outline: none;
}
#search:focus { border-color: var(--blue); }

.icon-btn {
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink-soft); }

/* ---------- controls ---------- */
.controls {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 14px 24px 4px;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--ink-soft);
  background: transparent;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.chip i { width: 11px; height: 11px; border-radius: 50%; border: 1px solid var(--line); }
.chip.active { color: var(--ink); background: #fff; border-color: var(--ink); }
.chips.small .chip { padding: 4px 10px; font-size: 12px; }

.text-btn {
  margin-left: auto;
  padding: 6px 12px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--ink-soft);
  background: transparent;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.text-btn:hover { color: var(--ink); border-color: var(--ink-soft); }

/* ---------- grid ---------- */
main { padding: 16px 24px 40px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 14px;
}
/* recents strip: exactly one row at any window width — extra items land in
 * zero-height implicit rows and are clipped */
.grid.one-row {
  grid-template-rows: auto;
  grid-auto-rows: 0;
  row-gap: 0;
  overflow: hidden;
  margin-bottom: 6px;
}
.section-label {
  margin: 4px 0 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}
.cell {
  border: none;
  padding: 0;
  background: transparent;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
}
.cell .tile {
  aspect-ratio: 1;
  border-radius: 14px;
  background: var(--tile);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.08s ease;
}
.cell:hover .tile { transform: scale(1.045); }
.cell .tile img { width: 72%; height: 72%; }
.cell .name {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--ink-soft);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.empty { color: var(--ink-soft); padding: 40px 0; text-align: center; }
.hidden { display: none !important; }

/* ---------- footer ---------- */
.foot {
  padding: 14px 24px 22px;
  font-size: 11.5px;
  color: var(--ink-soft);
  border-top: 1.5px solid var(--line);
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(14, 14, 14, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal {
  position: relative;
  background: var(--paper);
  border-radius: 18px;
  padding: 26px;
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 18px 60px rgba(14, 14, 14, 0.3);
}
.modal.narrow { max-width: 460px; }
.modal h2 { margin: 12px 0 8px; font-size: 17px; text-transform: capitalize; }
.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 30px; height: 30px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 15px;
  cursor: pointer;
}
.modal-close:hover { background: var(--tile); color: var(--ink); }
.modal-body { display: flex; gap: 26px; }
.modal-preview-col { flex: 0 0 220px; }
.modal-preview {
  width: 220px; height: 220px;
  border-radius: 16px;
  background: var(--tile);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-preview.dark { background: var(--ink); }
.modal-preview img { width: 74%; height: 74%; }
.modal-actions { flex: 1; min-width: 0; }
.group-label {
  margin: 14px 0 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}
.group-label:first-child { margin-top: 2px; }
.hint { font-size: 11.5px; color: var(--ink-soft); font-weight: 400; text-transform: none; letter-spacing: 0; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.dl-btn {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.dl-btn:hover { border-color: var(--ink); }
.dl-btn:active { transform: translateY(1px); }
.dl-btn.busy { opacity: 0.5; pointer-events: none; }
#update-url {
  flex: 1;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  outline: none;
}
#update-url:focus { border-color: var(--blue); }

/* ---------- toasts ---------- */
.toasts {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.toast {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--paper);
  background: var(--ink);
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(14, 14, 14, 0.35);
  animation: toast-in 0.18s ease;
}
.toast.err { background: var(--red); color: #fff; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 620px) {
  .modal-body { flex-direction: column; }
  .modal-preview-col { flex: none; }
  .modal-preview { width: 100%; height: auto; aspect-ratio: 1; }
}
