/* ============================================================
   Allfishes — design system
   Tokens -> typography -> layout -> components -> details
   ============================================================ */

:root {
  /* Palette */
  --bg: #f5f8fa;
  --surface: #ffffff;
  --surface-2: #ecf2f6;
  --ink: #14232e;
  --muted: #5a6b78;
  --line: #dce4eb;
  --accent: #0891b2;
  --accent-strong: #0e7490;
  --accent-soft: #e3f4f9;
  --header-bg: rgb(255 255 255 / 82%);

  /* Radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-full: 999px;

  /* Elevation */
  --shadow-1: 0 1px 2px rgb(13 36 50 / 0.06);
  --shadow-2: 0 12px 32px -14px rgb(13 36 50 / 0.28);

  /* Spacing (4px grid) */
  --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px;
  --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;

  --font-body: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Lora", Georgia, "Times New Roman", serif;

  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0b1620;
  --surface: #11212e;
  --surface-2: #182c3c;
  --ink: #e6eef5;
  --muted: #94a8b6;
  --line: #22384a;
  --accent: #22b8d4;
  --accent-strong: #56cfe8;
  --accent-soft: #10303c;
  --header-bg: rgb(17 33 46 / 80%);

  --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-2: 0 12px 32px -14px rgb(0 0 0 / 0.6);

  color-scheme: dark;
}

/* ------------------------------------------------ base */

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent); color: #fff; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

h1, h2, h3 {
  font-family: var(--font-display);
  line-height: 1.18;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
h1 { font-size: clamp(1.9rem, 1.35rem + 2vw, 2.7rem); margin: 0.6em 0 0.45em; }
h2 {
  font-size: clamp(1.25rem, 1.05rem + 0.8vw, 1.55rem);
  margin: 2em 0 0.7em;
  padding-top: 0.35em;
}
h3 { font-size: 1.08rem; }

.muted { color: var(--muted); }
.count { color: var(--muted); font-size: 0.85em; font-variant-numeric: tabular-nums; }

.container { max-width: 1200px; margin: 0 auto; padding: 0 var(--sp-4); }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: #fff;
  padding: 10px 18px; border-radius: 0 0 var(--r-sm) 0; z-index: 100;
}
.skip-link:focus { left: 0; }

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

/* -------------------------------------------- header */

.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  display: flex; align-items: center; gap: var(--sp-5);
  min-height: 62px; flex-wrap: wrap;
}
.logo {
  font-family: var(--font-display);
  font-weight: 700; font-size: 1.3rem; color: var(--ink);
  letter-spacing: -0.02em;
  display: inline-flex; align-items: center; gap: 9px;
}
.logo-ico { border-radius: 8px; box-shadow: var(--shadow-1); }
.logo:hover { text-decoration: none; color: var(--accent); }

.main-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.main-nav > a, .nav-item > a {
  padding: 8px 12px; border-radius: var(--r-full);
  color: var(--ink); font-weight: 500; font-size: 0.95rem;
  display: inline-block; transition: background 150ms ease-out, color 150ms ease-out;
}
.main-nav > a:hover, .nav-item > a:hover {
  background: var(--surface-2); text-decoration: none;
}

.nav-item { position: relative; }
.submenu {
  display: none;
  position: absolute; top: calc(100% + 6px); left: 0;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  padding: var(--sp-3); gap: 2px 20px;
  max-height: min(70vh, 520px); overflow-y: auto;
  grid-template-columns: repeat(3, minmax(190px, 250px));
  z-index: 60;
}
.has-sub:hover .submenu,
.has-sub:focus-within .submenu { display: grid; }
.submenu a {
  padding: 7px 10px; border-radius: var(--r-sm);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 250px; color: var(--ink); font-size: 0.92rem;
  transition: background 120ms ease-out, color 120ms ease-out;
}
.submenu a:hover { background: var(--accent-soft); color: var(--accent-strong); text-decoration: none; }

.header-search { margin-left: auto; position: relative; }
.header-search input {
  border: 1px solid var(--line); border-radius: var(--r-full);
  padding: 9px 16px; width: 210px; font-size: 0.92rem;
  background: var(--surface); color: var(--ink);
  transition: border-color 150ms ease-out, box-shadow 150ms ease-out;
}
.header-search input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.theme-toggle {
  border: 1px solid var(--line); background: var(--surface);
  width: 40px; height: 40px; border-radius: var(--r-full);
  cursor: pointer; display: grid; place-items: center;
  font-size: 1rem; transition: background 150ms ease-out, transform 100ms ease-out;
}
.theme-toggle:hover { background: var(--surface-2); }
.theme-toggle:active { transform: scale(0.92); }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon,
:root:not([data-theme="dark"]) .icon-moon { display: none; }

/* -------------------------------------------- hero */

.hero {
  position: relative;
  background:
    radial-gradient(900px 380px at 15% -10%, rgb(34 211 238 / 28%), transparent 60%),
    radial-gradient(700px 320px at 90% 0%, rgb(14 116 144 / 38%), transparent 55%),
    linear-gradient(140deg, #0b3954 0%, #085e7d 55%, #0b7285 100%);
  border-radius: var(--r-lg);
  color: #f0fbff;
  margin-top: var(--sp-5);
  overflow: hidden;
  text-align: center;
  padding: clamp(44px, 6vw, 84px) var(--sp-6) clamp(58px, 7vw, 96px);
}
.hero h1 {
  margin: 0 0 10px;
  color: #fff;
  font-size: clamp(2.1rem, 1.4rem + 3vw, 3.4rem);
}
.hero p { opacity: 0.88; margin: 0 auto var(--sp-5); max-width: 52ch; font-size: 1.05rem; }
.hero-wave {
  position: absolute; left: 0; right: 0; bottom: -1px;
  width: 100%; height: clamp(30px, 5vw, 60px);
}
.hero-wave path { fill: var(--bg); }

.hero-search {
  display: flex; gap: var(--sp-2); justify-content: center; flex-wrap: wrap;
  position: relative; z-index: 1;
}
.hero-search input {
  padding: 13px 20px; border-radius: var(--r-full); border: none;
  min-width: min(360px, 80vw); font-size: 1rem; color: var(--ink);
  box-shadow: var(--shadow-2);
}
.hero-search input:focus-visible { outline-offset: 3px; }
.hero-search button {
  padding: 13px 26px; border-radius: var(--r-full); border: none; cursor: pointer;
  background: linear-gradient(135deg, #22d3ee, #0891b2);
  color: #04222c; font-weight: 600; font-size: 1rem;
  transition: transform 120ms ease-out, filter 120ms ease-out;
}
.hero-search button:hover { filter: brightness(1.07); }
.hero-search button:active { transform: scale(0.97); }

/* -------------------------------------------- group cards */

.group-cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-4); margin: var(--sp-6) 0;
}
.group-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-5) var(--sp-4);
  display: flex; flex-direction: column; gap: 4px;
  transition: transform 160ms ease-out, box-shadow 160ms ease-out, border-color 160ms ease-out;
}
.group-card:hover {
  transform: translateY(-3px); box-shadow: var(--shadow-2);
  border-color: var(--accent); text-decoration: none;
}
.group-name {
  font-weight: 600; font-size: 1.08rem; color: var(--ink);
  font-family: var(--font-display);
}
.group-card .count { color: var(--muted); }

/* -------------------------------------------- chips */

.chip-cloud { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-5); }
.chip {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-full);
  padding: 6px 14px; font-size: 0.88rem; color: var(--ink);
  transition: border-color 130ms ease-out, background 130ms ease-out, transform 130ms ease-out;
}
.chip span { color: var(--muted); font-size: 0.8em; }
.chip:hover {
  border-color: var(--accent); background: var(--accent-soft);
  text-decoration: none; transform: translateY(-1px);
}
.chip-more { color: var(--accent); font-weight: 600; }
.chip-cloud.small .chip { font-size: 0.78rem; padding: 3px 11px; }

/* -------------------------------------------- fish grid & cards */

.fish-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: var(--sp-4); margin: var(--sp-4) 0 var(--sp-6);
}
.fish-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  transition: transform 160ms ease-out, box-shadow 160ms ease-out, border-color 160ms ease-out;
}
.fish-card > a { color: inherit; display: block; height: 100%; }
.fish-card:hover {
  transform: translateY(-3px); box-shadow: var(--shadow-2);
  border-color: var(--line); text-decoration: none;
}
.fish-thumb {
  aspect-ratio: 4 / 3; overflow: hidden;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
}
.fish-thumb img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform 350ms ease-out;
}
.fish-card:hover .fish-thumb img { transform: scale(1.045); }
.noimg { font-size: 3rem; opacity: 0.35; }
.fish-card h3 { margin: var(--sp-3) 14px 2px; font-size: 1.02rem; font-family: var(--font-body); font-weight: 600; }
.fish-card .latin { margin: 0 14px; font-style: italic; color: var(--muted); font-size: 0.85rem; }
.fish-card .excerpt { margin: 6px 14px 14px; color: var(--muted); font-size: 0.85rem; }

.result-count { color: var(--muted); font-size: 0.9rem; }

/* -------------------------------------------- filters */

.filter-bar {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-4); margin: var(--sp-4) 0;
  box-shadow: var(--shadow-1);
}
.filter-row { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.filter-row.wrap { row-gap: var(--sp-2); }
.filter-bar select,
.filter-bar input[type="number"],
.filter-bar input[type="text"],
.filter-bar input[type="search"] {
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 8px 12px; font-size: 0.92rem; background: var(--surface);
  color: var(--ink); transition: border-color 140ms ease-out, box-shadow 140ms ease-out;
}
.filter-bar select:hover, .filter-bar input:hover { border-color: var(--accent); }
.filter-bar select:focus, .filter-bar input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.filter-bar label { color: var(--muted); font-size: 0.88rem; display: inline-flex; gap: 6px; align-items: center; }
.filter-bar input[type="number"] { width: 86px; }
.filter-bar details summary {
  cursor: pointer; margin-top: var(--sp-3);
  color: var(--accent); user-select: none; font-size: 0.92rem; font-weight: 500;
}
.filter-bar details[open] summary { margin-bottom: var(--sp-3); }

.btn {
  border: none; border-radius: var(--r-full); padding: 9px 20px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 0.92rem;
  transition: filter 130ms ease-out, transform 100ms ease-out;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:active { transform: scale(0.97); }
.btn-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--line);
}
.btn-ghost:hover { color: var(--ink); border-color: var(--muted); filter: none; }

.htmx-request#fish-grid-inner { opacity: 0.5; transition: opacity 150ms ease-out; }

/* -------------------------------------------- pagination */

.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: var(--sp-4); margin: var(--sp-6) 0;
  color: var(--muted); font-size: 0.95rem;
}
.pagination a {
  border: 1px solid var(--line); background: var(--surface);
  padding: 8px 18px; border-radius: var(--r-full); color: var(--ink);
  transition: border-color 130ms ease-out, background 130ms ease-out;
}
.pagination a:hover { border-color: var(--accent); background: var(--accent-soft); text-decoration: none; }

/* -------------------------------------------- breadcrumbs */

.breadcrumbs {
  color: var(--muted); font-size: 0.87rem;
  padding: var(--sp-4) 0 0;
}
.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--accent); }

/* -------------------------------------------- detail pages */

.fish-header h1 { margin-bottom: 6px; }
.latin-big { font-style: italic; color: var(--muted); font-weight: 400; font-size: 0.62em; }
.other-names { color: var(--muted); margin-top: 0; max-width: 75ch; }

.fish-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px;
  gap: var(--sp-6); align-items: start;
}
.fish-aside { position: sticky; top: 86px; }
@media (max-width: 900px) {
  .fish-layout { grid-template-columns: 1fr; }
  .fish-aside { position: static; }
}

.fish-photo {
  width: 100%; max-width: 500px; border-radius: var(--r-lg);
  display: block; margin-bottom: var(--sp-5);
  border: 1px solid var(--line); box-shadow: var(--shadow-1);
}

.prose { max-width: 72ch; }
.prose img { max-width: 100%; border-radius: var(--r-sm); }

.info-box {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-4); margin-bottom: var(--sp-4);
  box-shadow: var(--shadow-1);
}
.info-box h3 {
  margin: 0 0 10px; font-family: var(--font-body); font-weight: 600;
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted);
}
.info-box table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.info-box th {
  text-align: left; color: var(--muted); font-weight: 500;
  padding: 5px 10px 5px 0; vertical-align: top; white-space: nowrap;
}
.info-box td { padding: 5px 0; font-variant-numeric: tabular-nums; }

.gallery { margin-top: var(--sp-6); }
.gallery-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px;
}
.gallery-grid img {
  width: 100%; height: 132px; object-fit: cover;
  border-radius: var(--r-sm); border: 1px solid var(--line);
  transition: transform 200ms ease-out, border-color 200ms ease-out;
}
.gallery-grid a { display: block; overflow: hidden; border-radius: var(--r-sm); }
.gallery-grid a:hover img { transform: scale(1.05); border-color: var(--accent); }

.related { margin-top: var(--sp-7); }

/* -------------------------------------------- indexes */

.letter-index .letter-group { margin-bottom: var(--sp-3); }
.letter-index h2 {
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px; margin-bottom: 12px;
  font-size: 1.15rem;
}
.location-list { list-style: none; padding: 0; margin: 0; columns: 3; column-gap: var(--sp-6); }
.location-list li { break-inside: avoid; padding: 3px 0; }
.location-list .latin { color: var(--muted); font-size: 0.85em; }
@media (max-width: 800px) { .location-list { columns: 2; } }
@media (max-width: 520px) { .location-list { columns: 1; } }

.group-intro {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-5); margin-bottom: var(--sp-2);
  box-shadow: var(--shadow-1);
}
.group-intro p { margin: 0.6em 0; }

/* -------------------------------------------- articles */

.article-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--sp-4);
}
.article-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--sp-5) var(--sp-4); color: inherit;
  display: flex; flex-direction: column; gap: 6px;
  transition: transform 160ms ease-out, box-shadow 160ms ease-out, border-color 160ms ease-out;
}
.article-card:hover {
  transform: translateY(-3px); box-shadow: var(--shadow-2);
  border-color: var(--accent); text-decoration: none;
}
.article-card h3 { margin: 0; font-size: 1.05rem; }
.article-card p { margin: 0; color: var(--muted); font-size: 0.9rem; flex: 1; }
.card-more { color: var(--accent); font-size: 0.88rem; font-weight: 600; }

.article-row { border-bottom: 1px solid var(--line); padding: var(--sp-4) 0; }
.article-row time { color: var(--muted); font-size: 0.85rem; }
.article-full { max-width: 76ch; }
.article-full time { color: var(--muted); font-size: 0.9rem; }
.article-full img { border-radius: var(--r-md); max-width: 100%; }
.lead { font-size: 1.1rem; color: var(--muted); }

/* -------------------------------------------- footer */

.site-footer {
  background: var(--surface); color: var(--muted);
  border-top: 1px solid var(--line);
  margin-top: var(--sp-8);
}
.footer-cols {
  display: grid; grid-template-columns: 2fr repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--sp-6); padding-top: var(--sp-7); padding-bottom: var(--sp-4);
}
.site-footer h4 {
  color: var(--ink); margin: 0 0 10px;
  font-family: var(--font-body); font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 0.07em;
}
.site-footer a { display: block; color: var(--muted); padding: 3px 0; transition: color 130ms ease-out; }
.site-footer a:hover { color: var(--accent); text-decoration: none; }
.footer-logo { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; color: var(--ink); margin: 0 0 8px; }
.footer-tag { margin: 0; font-size: 0.92rem; max-width: 34ch; }
.copyright {
  color: var(--muted); font-size: 0.85rem;
  padding-bottom: var(--sp-5); border-top: 1px solid var(--line);
  padding-top: var(--sp-4); margin-top: var(--sp-4);
}

/* -------------------------------------------- not found */

.notfound { text-align: center; padding: var(--sp-8) 0; }
.notfound-code {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(4rem, 3rem + 6vw, 7rem);
  color: var(--accent-soft); margin: 0;
  -webkit-text-stroke: 2px var(--accent);
  line-height: 1;
}
.notfound h1 { margin: 10px 0 6px; }

/* -------------------------------------------- lightbox */

.lightbox {
  position: fixed; inset: 0; z-index: 200;
  background: rgb(6 18 26 / 90%);
  display: flex; align-items: center; justify-content: center;
  animation: lb-fade 180ms ease-out;
}
.lightbox[hidden] { display: none; }
@keyframes lb-fade { from { opacity: 0; } to { opacity: 1; } }

.lb-figure { margin: 0; text-align: center; max-width: min(92vw, 1100px); }
.lb-img {
  display: block;
  max-width: min(92vw, 1100px);
  max-height: 82vh;
  border-radius: var(--r-sm);
  box-shadow: 0 24px 80px rgb(0 0 0 / 0.55);
  transition: opacity 160ms ease-out;
}
.lb-loading { opacity: 0.35; }
.lb-counter {
  margin-top: var(--sp-3); color: #cfe4ee; font-size: 0.9rem;
  font-variant-numeric: tabular-nums; letter-spacing: 0.05em;
}

.lb-btn {
  position: fixed;
  border: none; cursor: pointer;
  background: rgb(255 255 255 / 10%); color: #fff;
  transition: background 140ms ease-out, transform 100ms ease-out;
}
.lb-btn:hover { background: rgb(255 255 255 / 22%); }
.lb-btn:active { transform: scale(0.94); }

.lb-close {
  top: 16px; right: 16px;
  width: 44px; height: 44px; border-radius: var(--r-full);
  font-size: 1.5rem; line-height: 1;
}
.lb-nav {
  top: 50%; transform: translateY(-50%);
  width: 52px; height: 72px; border-radius: var(--r-md);
  font-size: 2.2rem; line-height: 1;
}
.lb-nav:active { transform: translateY(-50%) scale(0.94); }
.lb-prev { left: 14px; }
.lb-next { right: 14px; }

@media (max-width: 640px) {
  .lb-nav { width: 42px; height: 60px; font-size: 1.7rem; }
}

@media (prefers-reduced-motion: reduce) {
  .lightbox, .lb-img { animation: none; transition: none; }
}

@media (max-width: 640px) {
  .header-inner { gap: var(--sp-2); }
  .header-search { order: 10; width: 100%; margin-left: 0; }
  .header-search input { width: 100%; }
  .submenu { grid-template-columns: 1fr; }
}
