:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1c1b19;
  --muted: #6b6862;
  --line: #e4e1da;
  --chip: #ebe8e1;
  --accent: #2f5bd3;
  --accent-ink: #ffffff;
  --thumb: #e9e6df;
  --radius: 10px;
  /* Un color por tipo: solo un punto pequeño, para reconocerlo de un vistazo. */
  --t-pinceles: #e0701b;
  --t-texturas: #8a6a3d;
  --t-paletas: #0f9e8f;
  --t-plantillas: #8b4fd8;
  --t-imagenes: #2f80c8;
  --t-tutoriales: #2f9e4f;
  --t-m3d: #c13068;
  --t-tipografias: #b8860b;
  --t-otros: #8a8780;
  --t-consultas: #b3b0a8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413;
    --surface: #1d1d1b;
    --text: #ecebe7;
    --muted: #9c9a94;
    --line: #2e2d2a;
    --chip: #2a2927;
    --accent: #7b9cff;
    --accent-ink: #0d1530;
    --thumb: #262523;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141413;
  --surface: #1d1d1b;
  --text: #ecebe7;
  --muted: #9c9a94;
  --line: #2e2d2a;
  --chip: #2a2927;
  --accent: #7b9cff;
  --accent-ink: #0d1530;
  --thumb: #262523;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Cabecera fija: buscador + filtros siempre a mano */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
}
.bar, .chips, .tools, main, .foot { max-width: 1280px; margin: 0 auto; }
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
  height: 46px;
}
.search:focus-within { border-color: var(--accent); }
.search svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; flex: none; }
.search input {
  flex: 1; min-width: 0; height: 100%;
  border: 0; outline: 0; background: transparent;
  font-size: 17px; /* >=16px evita el zoom automático en iOS */
}
.search input::-webkit-search-cancel-button { cursor: pointer; }
.hint {
  font: 12px/1 ui-monospace, monospace; color: var(--muted);
  border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px;
}
@media (hover: none) { .hint { display: none; } }

.chips {
  display: flex; gap: 6px;
  overflow-x: auto; scrollbar-width: none;
  padding: 10px 0 0;
  margin-left: -2px; margin-right: -2px;
}
.chips::-webkit-scrollbar { display: none; }
.chips.subs { padding-top: 6px; }
.chip {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid transparent; border-radius: 999px;
  background: var(--chip);
  cursor: pointer; white-space: nowrap;
  font-size: 14px;
}
.subs .chip { height: 28px; font-size: 13px; background: transparent; border-color: var(--line); }
.chip .n { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.chip[aria-pressed="true"] .n { color: inherit; opacity: .7; }
.subs .chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--t-otros)); flex: none; }

.tools {
  display: flex; align-items: center; gap: 14px;
  padding-top: 8px;
  font-size: 13px; color: var(--muted);
}
.count { margin-right: auto; font-variant-numeric: tabular-nums; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.sort select {
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text);
  height: 30px; padding: 0 8px; font-size: 13px;
}
.reload {
  flex: none; width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 16px; line-height: 1;
}
.reload:disabled { opacity: .5; cursor: progress; }
.reload:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 420px) { .tools { gap: 8px; } }
.toast {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  margin: 0; max-width: min(92vw, 460px); padding: 10px 14px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: 14px; box-shadow: 0 4px 16px rgb(0 0 0 / .2);
}

main { padding: 14px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); }
.status { color: var(--muted); text-align: center; margin: 48px 0; }
.status:empty { display: none; }

/* Rejilla: 2 columnas en móvil, más según el ancho */
.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(164px, 1fr));
}
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 18px; } }

.card {
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  min-width: 0;
}
.open {
  display: block; width: 100%; padding: 0; border: 0; background: none;
  text-align: left; cursor: pointer;
}
.thumb {
  aspect-ratio: 4 / 3;
  background: var(--thumb);
  overflow: hidden;
  display: grid; place-items: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .none { color: var(--muted); font-size: 12px; }
.swatch { display: flex; width: 100%; height: 100%; }
.swatch i { flex: 1; }
.d-swatch { height: 44px; border-radius: 8px; overflow: hidden; margin: 10px 0 4px; }
.new { font-size: 11px; font-weight: 600; color: var(--accent-ink); background: var(--accent); border-radius: 4px; padding: 0 5px; margin-left: 2px; }
.info { display: block; padding: 9px 11px 4px; }
.type {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.type b { color: var(--text); font-weight: 600; }
.title {
  margin: 4px 0 3px;
  font-size: 14.5px; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats { font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 5px; padding: 8px 9px 10px; margin-top: auto; }
.btn {
  flex: 1; min-width: 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  height: 32px; padding: 0 6px;
  border-radius: 8px; border: 1px solid var(--line);
  text-decoration: none; font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.actions .btn:not(.primary) { flex: none; padding: 0 10px; }
.btn.src .ar { display: none; }
/* En móvil el nombre de la fuente no cabe junto a "Descargar": queda la flecha (el nombre sigue para lectores de pantalla). */
@media (max-width: 420px) { .btn.src .nm { display: none; } .btn.src .ar { display: inline; } }
.btn:focus-visible, .chip:focus-visible, .open:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (hover: hover) {
  .chip:hover { border-color: var(--muted); }
  .btn:hover { border-color: var(--muted); }
  .btn.primary:hover { filter: brightness(1.08); }
  .open:hover .title { text-decoration: underline; text-underline-offset: 2px; }
}
.more { height: 1px; }

.foot {
  padding: 8px 16px max(24px, env(safe-area-inset-bottom));
  font-size: 12px; color: var(--muted); text-align: center;
}

/* Ficha de detalle */
dialog {
  width: min(680px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--text);
  overflow: auto;
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
.close-row { position: sticky; top: 0; height: 0; display: flex; justify-content: flex-end; z-index: 1; }
.close {
  margin: 8px; width: 34px; height: 34px; border-radius: 50%;
  border: 0; background: rgb(0 0 0 / .55); color: #fff; font-size: 22px; line-height: 1; cursor: pointer;
}
.d-img { background: var(--thumb); max-height: 60dvh; display: grid; place-items: center; }
.d-img img { max-width: 100%; max-height: 60dvh; display: block; }
.d-pad { padding: 16px 18px 20px; }
.d-pad h2 { margin: 6px 0 4px; font-size: 20px; line-height: 1.25; overflow-wrap: anywhere; }
.d-desc { margin: 12px 0; color: var(--text); white-space: pre-line; overflow-wrap: anywhere; }
.d-thumbs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 18px 0; }
.d-thumbs button { flex: none; width: 64px; height: 48px; padding: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--thumb); cursor: pointer; }
.d-thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.d-links { display: grid; gap: 8px; margin: 14px 0 0; }
.d-links .btn { flex: none; height: 40px; justify-content: space-between; padding: 0 14px; }
.d-links .btn span:last-child { opacity: .75; font-weight: 400; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); }
.note { font-size: 12px; color: var(--muted); margin-top: 14px; }

/* Resultados en vivo de museos (Openverse) y enlaces a otras webs */
.ext { margin: 4px 0 18px; }
.ext h2 { font-size: 14px; margin: 0 0 8px; }
.ext h2 span { font-weight: 400; color: var(--muted); font-size: 12px; }
.ov { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x proximity; min-height: 40px; align-items: center; }
.ov a { flex: none; scroll-snap-align: start; }
.ov img { height: 120px; width: auto; max-width: 220px; object-fit: cover; border-radius: 8px; display: block; background: var(--line, #ddd); }
.ov .ov-more { padding: 0 12px; font-size: 13px; white-space: nowrap; }
.ov-msg, .ext-links { color: var(--muted); font-size: 13px; }
.ext-links a { white-space: nowrap; }
.none.font { font-size: 20px; font-weight: 600; color: var(--text); padding: 0 12px; text-align: center; }

/* Botón y página de enlaces */
.links-btn { font-size: 14px; color: var(--accent); text-decoration: none; white-space: nowrap; }
.links-btn:hover { text-decoration: underline; }
.links-page { max-width: 1100px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px 48px; }
.links-page h1 { margin: 8px 0 4px; }
.links-page .lead { color: var(--muted); margin: 0 0 8px; }
.links-page h2 { font-size: 16px; margin: 28px 0 10px; }
.back { color: var(--accent); text-decoration: none; }
.links { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.links a { display: flex; flex-direction: column; gap: 4px; height: 100%; box-sizing: border-box; padding: 14px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface); color: var(--text); text-decoration: none; }
.links a:hover, .links a:focus-visible { border-color: var(--accent); }
.links b::after { content: " ↗"; color: var(--muted); font-weight: 400; }
.links span { color: var(--muted); font-size: 14px; line-height: 1.4; }
