:root {
  --bg: #0c0c0e;
  --bg-2: #141417;
  --panel: #18181b;
  --line: #27272a;
  --line-strong: #3f3f46;
  --text: #ededef;
  --muted: #8b8b94;
  --accent: #3fcf8e;
  --radius: 8px;
  --gap: 5px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --font: "Geist", system-ui, sans-serif;
  --mono: "Geist Mono", ui-monospace, monospace;
  --edge: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f7f7f8;
    --bg-2: #ffffff;
    --panel: #ffffff;
    --line: #e4e4e7;
    --line-strong: #d4d4d8;
    --text: #18181b;
    --muted: #71717a;
    --accent: #139a5e;
    --edge: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100dvh;
  padding: 32px clamp(16px, 3vw, 48px) 40px;
  -webkit-font-smoothing: antialiased;
}

/* Grano fijo: no se repinta con el scroll. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Cabecera: título a la izquierda, herramientas a la derecha ---------- */
.top {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  align-items: end;
  gap: 24px;
  max-width: 1600px;
  margin: 0 auto 20px;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 3.2vw, 42px);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.035em;
}
h1 span { color: var(--muted); font-weight: 500; }

.sub { margin: 10px 0 0; color: var(--muted); font: 13px var(--mono); }
.sub strong { color: var(--text); font-weight: 500; }

.tools { display: flex; justify-content: flex-end; gap: 16px; align-items: end; flex-wrap: wrap; }

.search { display: grid; gap: 6px; font: 11px var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.search input {
  width: min(300px, 100%);
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-2);
  box-shadow: var(--edge);
  color: var(--text);
  font: 14px var(--font);
  text-transform: none;
  letter-spacing: 0;
  outline: none;
  transition: border-color 0.2s var(--ease);
}
.search input:focus { border-color: var(--accent); }

.known { font: 13px var(--mono); color: var(--muted); min-width: 150px; }
.known strong { color: var(--text); font-weight: 500; }
.known .bar { height: 2px; background: var(--line); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.known .bar i { display: block; height: 100%; width: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; transition: transform 0.5s var(--ease); }

/* ---------- Leyenda ---------- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 1600px;
  margin: 0 auto 20px;
}

.chip {
  --c: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 11px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: 500 12px var(--font);
  cursor: pointer;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 2px; background: var(--c); }
.chip:hover { color: var(--text); border-color: var(--line-strong); }
.chip[aria-pressed="true"] { color: var(--text); border-color: var(--c); background: color-mix(in srgb, var(--c) 8%, transparent); }
.chip:active { transform: scale(0.98); }
.legend.filtering .chip[aria-pressed="false"] { opacity: 0.5; }

/* ---------- Tabla ---------- */
main { max-width: 1600px; margin: 0 auto; }

.table {
  display: grid;
  grid-template-columns: repeat(18, minmax(0, 1fr));
  grid-template-rows: repeat(7, auto) 16px repeat(2, auto);
  gap: var(--gap);
}

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

@keyframes breathe {
  50% { opacity: 0.35; transform: scale(0.8); }
}

.el {
  --c: var(--muted);
  position: relative;
  aspect-ratio: 1 / 1.12;
  min-width: 0;
  padding: 6px 7px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-2);
  box-shadow: inset 0 2px 0 var(--c), var(--edge);
  color: var(--text);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  animation: rise 0.6s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 5ms);
  transition: transform 0.3s var(--ease), opacity 0.3s var(--ease), border-color 0.2s var(--ease), box-shadow 0.3s var(--ease), filter 0.3s var(--ease);
}

.el:hover, .el:focus-visible, .el.active {
  transform: translateY(-3px);
  z-index: 1;
  outline: none;
  border-color: color-mix(in srgb, var(--c) 55%, var(--line));
  box-shadow: inset 0 2px 0 var(--c), var(--edge), 0 14px 24px -14px color-mix(in srgb, var(--c) 45%, transparent);
}
.el:active { transform: translateY(-1px) scale(0.98); }

.el .num { font: 500 clamp(8px, 0.62vw, 11px) var(--mono); color: var(--muted); }
.el .sym { font: 600 clamp(14px, 1.65vw, 29px)/1 var(--font); color: var(--c); letter-spacing: -0.03em; }
.el .name {
  font-size: clamp(7px, 0.6vw, 11px);
  line-height: 1.15;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.el .new {
  position: absolute; top: 8px; right: 8px;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent);
  animation: breathe 2.8s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * -90ms);
}
.el.known::after {
  content: "";
  position: absolute; bottom: 9px; right: 8px;
  width: 7px; height: 4px;
  border-left: 1.5px solid var(--accent);
  border-bottom: 1.5px solid var(--accent);
  transform: rotate(-45deg);
}

.table.dim .el:not(.match) { opacity: 0.12; filter: grayscale(1); }

.series-label {
  grid-column: 1 / span 2;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 10px;
  font: 500 clamp(9px, 0.68vw, 12px)/1.25 var(--mono);
  color: var(--muted);
  text-align: right;
}

/* ---------- Ficha (hueco central, como la leyenda de la tabla real) ---------- */
.preview {
  --c: var(--muted);
  grid-column: 3 / span 10;
  grid-row: 1 / span 3;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: clamp(14px, 1.8vw, 28px);
  align-items: center;
  padding: clamp(12px, 1.4vw, 22px) clamp(14px, 1.8vw, 28px);
  border-radius: 12px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  box-shadow: var(--edge);
  min-height: 0;
}

.big {
  --c: var(--muted);
  width: clamp(92px, 8.5vw, 140px);
  aspect-ratio: 1 / 1.12;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--c) 45%, var(--line));
  background: var(--bg-2);
  box-shadow: inset 0 3px 0 var(--c), var(--edge);
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 10px 12px;
  animation: rise 0.45s var(--ease) both;
}
.big .num { font: 500 13px var(--mono); color: var(--muted); }
.big .sym { font: 600 clamp(36px, 3.8vw, 60px)/1 var(--font); color: var(--c); letter-spacing: -0.04em; }
.big .yr { font: 12px var(--mono); color: var(--muted); }

.info { min-width: 0; animation: rise 0.45s var(--ease) both; animation-delay: 40ms; }
.info .cat { display: flex; align-items: center; gap: 8px; font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.info .cat::before { content: ""; width: 6px; height: 6px; border-radius: 2px; background: var(--c); }
.info .cat .tag { color: var(--accent); }
.info h2 { margin: 6px 0; font-size: clamp(18px, 1.7vw, 28px); font-weight: 600; line-height: 1.1; letter-spacing: -0.03em; }
.info p { margin: 0; color: var(--muted); font-size: clamp(12px, 0.92vw, 15px); line-height: 1.55; max-width: 65ch; }
.info .meta { font: 12px var(--mono); color: var(--muted); margin-bottom: 4px; }
.info .latest { margin-top: 10px; font: 12px var(--mono); color: var(--muted); }
.info .latest b { color: var(--text); font-weight: 500; }
.info .actions { margin-top: 12px; display: flex; gap: 12px; align-items: center; }
.btn {
  font: 500 12px var(--font);
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  box-shadow: var(--edge);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s var(--ease), color 0.2s var(--ease);
}
.btn:hover { border-color: var(--line-strong); }
.btn:active { transform: scale(0.98); }
.btn.on { border-color: var(--accent); color: var(--accent); }
.hint { font: 11px var(--mono); color: var(--muted); }
.close { display: none; }

.empty .big { border-style: dashed; box-shadow: none; }
.empty .big .sym { color: var(--line-strong); }

/* ---------- Pie ---------- */
.foot {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 24px;
  max-width: 1600px;
  margin: 28px auto 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.foot p { margin: 0; }
.foot p:last-child { text-align: right; }
.foot a { color: var(--text); text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.foot a:hover { text-decoration-color: var(--accent); }
kbd { font: 11px var(--mono); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; margin: 0 1px; }
.dot-key { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); vertical-align: middle; margin-right: 4px; }

/* Modo claro: los tonos de familia pierden contraste sobre blanco, se oscurecen. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .el .sym,
  :root:not([data-theme="dark"]) .big .sym { color: color-mix(in srgb, var(--c) 60%, #18181b); }
}

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

/* ---------- Móvil: fichas agrupadas + ficha inferior ---------- */
@media (max-width: 900px) {
  body { padding: 20px 16px 28px; }
  .top, .foot { grid-template-columns: 1fr; }
  .tools { justify-content: flex-start; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .foot p:last-child { text-align: left; }
  .table {
    grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
    grid-template-rows: none;
  }
  .el { grid-row: auto !important; grid-column: auto !important; }
  .el .sym { font-size: 22px; }
  .el .name { font-size: 9px; }
  .el .num { font-size: 9px; }
  .series-label { display: none; }
  .preview {
    position: fixed;
    left: 8px; right: 8px; bottom: 8px;
    z-index: 10;
    background: var(--panel);
    box-shadow: var(--edge), 0 -12px 32px -12px rgba(0, 0, 0, 0.45);
    transform: translateY(calc(100% + 16px));
    transition: transform 0.35s var(--ease);
  }
  .preview.open { transform: none; }
  .big { width: 84px; }
  .big .sym { font-size: 34px; }
  .close {
    display: block;
    position: absolute; top: 6px; right: 10px;
    border: 0; background: none; color: var(--muted); font-size: 22px; cursor: pointer;
  }
  .hint { display: none; }
}
