:root {
  --bg: #0b0f0c;
  --card: #111814;
  --text: #e9f0ea;
  --muted: #a5b3a9;
  --accent: #2ecc71;
  --border: rgba(255,255,255,0.08);
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  background: linear-gradient(180deg, #070a08, #0b0f0c);
  color: var(--text);
}

a { color: inherit; text-decoration: none; }
.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(7,10,8,0.7);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  gap: 12px;
}

.brand { display: inline-flex; align-items: baseline; gap: 10px; }
.brand-title { font-weight: 800; letter-spacing: 0.2px; }
.beta {
  font-size: 10px;
  font-weight: 900;
  color: #ff4d4d;
  border: 1px solid rgba(255,77,77,0.35);
  padding: 2px 6px;
  border-radius: 999px;
}

.header-actions { display: flex; gap: 10px; }

.btn {
  background: rgba(46,204,113,0.12);
  border: 1px solid rgba(46,204,113,0.25);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { border-color: rgba(46,204,113,0.5); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
}

.select {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}
.select option { color: #111; }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 10px;
  cursor: pointer;
}

.section { padding: 22px 0 30px; }

.h1 {
  font-size: clamp(22px, 2.6vw, 32px);
  margin: 0 0 14px;
  font-weight: 800;
}

.headline .h1 { margin-bottom: 6px; }
.accent { color: var(--accent); font-weight: 900; }

.muted { color: var(--muted); font-size: 14px; }
.sep { margin: 0 8px; opacity: 0.6; }

.loading, .empty {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.card {
  display: block;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  box-shadow: var(--shadow);
}

.thumb { position: relative; aspect-ratio: 1 / 1; overflow: hidden; }
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scale(1.01);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,0.15), rgba(0,0,0,0.35));
}

.overlay-top { opacity: 0.9; }
.tag {
  font-weight: 800;
  line-height: 1.1;
  text-shadow: 0 2px 12px rgba(0,0,0,0.6);
}
.tag.genus { font-size: 20px; }
.tag.specie { font-size: 16px; font-weight: 600; opacity: 0.95; }

.overlay-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.time {
  font-weight: 700;
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.18);
  padding: 6px 8px;
  border-radius: 999px;
  font-size: 13px;
}

.play {
  width: 38px; height: 38px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.18);
  font-weight: 900;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 18px 0 30px;
}

/* Fullscreen viewer */
.fullscreen .viewer {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  background: rgba(0,0,0,0.45);
}

.viewer-media {
  width: 100%;
  max-height: 80vh;
  object-fit: contain;
  display: block;
}

/* Modal buscador */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  padding: 16px;
}
.modal[aria-hidden="false"] { display: grid; place-items: center; }

.modal-card {
  width: min(720px, 100%);
  border: 1px solid var(--border);
  background: rgba(17,24,20,0.95);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.modal-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.modal-title { font-weight: 900; font-size: 18px; }

.search-input {
  width: 100%;
  padding: 12px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  outline: none;
  font-size: 15px;
}

.search-results {
  margin-top: 10px;
  max-height: 55vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.result {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.result:hover { background: rgba(255,255,255,0.04); }

.result .left { display: flex; flex-direction: column; gap: 2px; }
.result .title { font-weight: 900; }
.result .subtitle { color: var(--muted); font-size: 13px; }
.result .count { color: var(--muted); font-size: 13px; white-space: nowrap; }

.modal-foot { margin-top: 10px; }

/* -----------------------
   Responsive improvements
------------------------ */

/* Evitar que textos largos rompan cards */
.tag,
.time,
.brand-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Header: permitir wrap y que no se desborde */
.header-row {
  flex-wrap: wrap;
}

.header-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Botones y select: tamaños fluidos */
.btn, .btn-ghost, .select {
  padding: 8px 12px;
  border-radius: 10px;
}

/* Grid más flexible */
.grid {
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

/* Overlay: fuentes fluidas */
.tag.genus {
  font-size: clamp(16px, 2.2vw, 22px);
}
.tag.specie {
  font-size: clamp(13px, 1.8vw, 16px);
}

/* Breadcrumbs y títulos permiten wrap */
.headline .muted {
  line-height: 1.35;
  word-break: break-word;
}

.h1 {
  word-break: break-word;
}

/* Viewer: mejor en móvil */
.viewer-media {
  max-height: 80vh;
}

/* Modal en móvil/tablet: más usable */
.modal-card {
  width: min(720px, 100%);
}

/* -----------------------
   Breakpoints
------------------------ */

/* Tablets */
@media (max-width: 900px) {
  .container { padding: 0 14px; }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .btn, .btn-ghost, .select {
    padding: 8px 10px;
  }

  .viewer-media {
    max-height: 75vh;
  }
}

/* Móvil */
@media (max-width: 600px) {
  .container { padding: 0 12px; }

  .header-row {
    align-items: center;
  }

  .brand-title {
    font-size: 16px;
  }

  .beta {
    font-size: 9px;
    padding: 2px 6px;
  }

  .header-actions {
    width: 100%;
    gap: 8px;
  }

  /* Botones y select a tamaño cómodo */
  .btn, .btn-ghost, .select {
    font-size: 14px;
    padding: 9px 10px;
  }

  /* Grid: prioriza 2 columnas si caben */
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  /* Overlay: menos padding */
  .overlay {
    padding: 8px;
  }

  .time {
    font-size: 12px;
    padding: 5px 7px;
  }

  .play {
    width: 34px;
    height: 34px;
  }

  /* Modal: casi pantalla completa */
  .modal {
    padding: 10px;
  }

  .modal-card {
    border-radius: 14px;
    padding: 12px;
  }

  .search-results {
    max-height: 60vh;
  }

  /* Viewer: deja más espacio a controles */
  .viewer-media {
    max-height: 70vh;
  }
}

/* Móvil pequeño */
@media (max-width: 380px) {
  .grid {
    grid-template-columns: 1fr; 
  }

  .tag.genus { font-size: 16px; }
  .tag.specie { font-size: 13px; }
}

@media (max-width: 600px) {
  .header-row {
    flex-wrap: nowrap;        
    gap: 8px;
  }

  .brand {
    min-width: 0;               
    flex: 1 1 auto;             
  }

  .brand-title {
    font-size: 14px;
    max-width: 52vw;            
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .beta {
    display: none;             
  }

  .header-actions {
    flex-wrap: nowrap;          
    gap: 6px;
  }

  .btn {
    padding: 7px 10px;
    font-size: 13px;
    white-space: nowrap;
  }

  .select.select-lang {
    width: 56px;                
    padding: 7px 8px;
    font-size: 13px;
    text-align: center;
  }
}

.site-header {
  padding: 10px 0; /* ✅ padding vertical del header */
}

.header-actions {
  width: auto;           /* ✅ evita bajar a otra línea */
  flex: 0 0 auto;
}

@media (max-width: 600px) {
  .header-row {
    flex-wrap: nowrap;        /* ✅ una sola fila */
    align-items: center;
    gap: 8px;
    padding: 6px 0;           /* ✅ padding interno */
  }

  .brand {
    flex: 1 1 auto;           /* ✅ el título ocupa lo que pueda */
    min-width: 0;             /* ✅ permite ellipsis */
  }

  .brand-title {
    max-width: 52vw;          /* ✅ evita empujar a los botones */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
  }

  .beta {
    display: none;            /* opcional: ahorra espacio */
  }

  .header-actions {
    width: auto !important;   /* ✅ pisa tu regla anterior width:100% */
    flex-wrap: nowrap;        /* ✅ mantener en una fila */
    justify-content: flex-end;
    gap: 6px;
  }

  .btn {
    padding: 7px 10px;
    font-size: 13px;
    white-space: nowrap;
  }

  .select.select-lang {
    width: 56px;
    padding: 7px 8px;
    font-size: 13px;
    text-align: center;
  }
}

.fullscreen .headline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.fullscreen .headline .h1 {
  margin: 0;
  font-size: clamp(18px, 2.2vw, 26px);
}

/* Header padding real */
.site-header {
  padding: 10px 0;
}

/* Mantener una fila en general */
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* Brand no empuja raro */
.brand { min-width: 0; }
.brand-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Searchbar estilo input moderno (pero es botón) */
.searchbar {
  flex: 1 1 520px;              /* ✅ expandido en el centro */
  max-width: 720px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  cursor: pointer;
  user-select: none;
  text-align: left;
}

.searchbar:hover {
  border-color: rgba(46,204,113,0.35);
  background: rgba(255,255,255,0.06);
}

.searchbar:focus-visible {
  outline: 2px solid rgba(46,204,113,0.45);
  outline-offset: 2px;
}

.searchbar-icon {
  opacity: 0.9;
}

.searchbar-text {
  flex: 1 1 auto;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.searchbar-kbd {
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.2);
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  width: auto;
}

/* Móvil: 1 fila (titulo + search + idioma). Ocultamos tienda para que quepa. */
@media (max-width: 600px) {
  .header-row {
    flex-wrap: nowrap;          /* ✅ una fila */
    gap: 8px;
    padding: 6px 0;
  }

  .beta { display: none; }

  .brand { flex: 0 1 auto; }
  .brand-title { max-width: 34vw; font-size: 14px; }

  .searchbar {
    flex: 1 1 auto;
    padding: 9px 10px;
  }

  .searchbar-kbd { display: none; } /* ✅ ahorra espacio */
  .shop-btn { display: none; }      /* ✅ cumple: título + buscar + idioma */

  .select.select-lang {
    width: 54px;
    padding: 8px 8px;
    font-size: 13px;
    text-align: center;
  }
}

/* Header padding consistente */
.site-header {
  padding: 10px 0;
}

/* Desktop/tablet: barra centrada y expandida */
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand { min-width: 0; }
.brand-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Searchbar estilo input moderno */
.searchbar {
  flex: 1 1 520px;
  max-width: 720px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  cursor: pointer;
  user-select: none;
  text-align: left;
}

.searchbar:hover {
  border-color: rgba(46,204,113,0.35);
  background: rgba(255,255,255,0.06);
}

.searchbar:focus-visible {
  outline: 2px solid rgba(46,204,113,0.45);
  outline-offset: 2px;
}

.searchbar-text {
  flex: 1 1 auto;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.searchbar-kbd {
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.2);
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  width: auto;
}

/* ✅ Móvil: fila 1 (brand + actions) y debajo search */
@media (max-width: 600px) {
  .header-row {
    flex-wrap: wrap;             /* permite 2 filas */
    gap: 8px;
    padding: 6px 0;
  }

  .beta { display: none; }       /* opcional: ahorra espacio */

  .brand {
    flex: 1 1 auto;              /* fila 1 izquierda */
    min-width: 0;
  }

  .brand-title {
    font-size: 14px;
    max-width: 60vw;
  }

  .header-actions {
    flex: 0 0 auto;              /* fila 1 derecha */
    width: auto !important;      /* pisa width:100% si existiera */
    gap: 6px;
  }

  .select.select-lang {
    width: 54px;
    padding: 8px 8px;
    font-size: 13px;
    text-align: center;
  }

  /* Search ocupa toda la fila 2 */
  .searchbar {
    order: 3;
    flex: 1 0 100%;
    max-width: none;
    width: 100%;
    padding: 10px 12px;
  }

  .searchbar-kbd { display: none; } /* en móvil fuera */
}
