/* ============================================================
   RESET & VARIABLES
   ============================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:           #f3f6fb;
  --surface:      #fff;
  --text:         #1a2233;
  --muted:        #58627a;
  --shadow:       0 12px 30px rgba(16, 35, 74, 0.12);
  --radius:       16px;
  /* Fix #1: was --color-border-tertiary which was never defined */
  --border-muted: rgba(88, 98, 122, 0.22);
}

/* ============================================================
   BASE
   ============================================================ */

body {
  min-height: 100vh;
  font-family: "Roboto", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 15%, rgba(47, 109, 246, 0.12), transparent 30%),
    radial-gradient(circle at 90% 10%, rgba(106, 69, 255, 0.09), transparent 28%),
    var(--bg);
}

a {
  text-decoration: none;
  color: inherit;
}

img {
  display: block;
  max-width: 100%;
}

/* ============================================================
   NOSCRIPT — Fix #15
   ============================================================ */

.noscript-msg {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  font-size: 1rem;
  line-height: 1.8;
  text-align: center;
  color: var(--muted);
}

/* ============================================================
   PAGE LAYOUT
   ============================================================ */

#app { display: block; }

.page {
  width: 70%;
  margin: 24px auto 32px;
}

.page--section { width: 65%; }
.page--object  { width: 60%; }

.page__header {
  margin-bottom: 20px;
}

.page__title {
  font-size: clamp(22px, 3.2vw, 42px);
  line-height: 1.15;
  text-align: center;
}

/* ============================================================
   LANGUAGE SWITCHER (globe dropdown)
   Fix #5: trigger is now a <button> with full keyboard support
   ============================================================ */

.lang-switcher {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 50;
  font-family: "Roboto", sans-serif;
}

.lang-switcher__trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-radius: 999px;
  background: rgba(26, 34, 51, 0.86);
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.25s, transform 0.25s;
  user-select: none;
  white-space: nowrap;
  -webkit-appearance: none;
  appearance: none;
}

.lang-switcher__trigger:hover,
.lang-switcher__trigger:focus-visible {
  background: rgba(26, 34, 51, 0.98);
  transform: translateY(-1px);
  outline: 2px solid rgba(255, 255, 255, 0.4);
  outline-offset: 2px;
}

.lang-switcher__globe  { flex-shrink: 0; color: #fff; }
.lang-switcher__label  { color: #fff; }
.lang-switcher__caret  {
  flex-shrink: 0;
  color: rgba(255, 255, 255, 0.7);
  transition: transform 0.25s;
}
.lang-switcher--open .lang-switcher__caret { transform: rotate(180deg); }

.lang-switcher__dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 148px;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: rgba(26, 34, 51, 0.97);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

.lang-switcher__dropdown--open { display: block; }

.lang-switcher__option {
  padding: 9px 16px;
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  outline: none;
}

.lang-switcher__option:hover,
.lang-switcher__option:focus {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.lang-switcher__option--active {
  color: #fff;
  font-weight: 600;
  cursor: default;
  background: rgba(255, 255, 255, 0.08);
}

@media (max-width: 600px) {
  .lang-switcher { top: 10px; right: 10px; }
}

/* ============================================================
   BACK BUTTON
   ============================================================ */

.back-button {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(26, 34, 51, 0.86);
  color: #fff;
  font-family: "Roboto", sans-serif;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  transition: background 0.25s, transform 0.25s;
}

.back-button[hidden] { display: none; }

.back-button:hover,
.back-button:focus-visible {
  background: rgba(26, 34, 51, 0.98);
  transform: translateY(-1px);
}

/* ============================================================
   CARD GRID
   ============================================================ */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.page--section .card-grid,
.page--list .card-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ============================================================
   CARD (image card with overlay)
   ============================================================ */

.card {
  position: relative;
  min-height: 260px;
  display: flex;
  align-items: flex-end;
  padding: 16px;
  border-radius: var(--radius);
  overflow: hidden;
  isolation: isolate;
  color: #fff;
  box-shadow: var(--shadow);
  transition: transform 0.3s, box-shadow 0.3s;
}

.card::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(
    to top,
    rgba(6, 10, 25, 0.82),
    rgba(6, 10, 25, 0.15) 55%,
    rgba(6, 10, 25, 0.03)
  );
}

.card:hover,
.card:focus-visible {
  transform: translateY(-4px);
  box-shadow: 0 20px 42px rgba(16, 35, 74, 0.24);
  outline: none;
}

.card__bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center;
  transition: transform 0.35s ease;
}

.card:hover .card__bg,
.card:focus-visible .card__bg { transform: scale(1.04); }

.card__title {
  position: relative;
  z-index: 2;
  font-size: clamp(18px, 2.1vw, 26px);
  font-weight: 700;
  text-shadow: 0 3px 14px rgba(0, 0, 0, 0.35);
}

/* ============================================================
   LIST ITEM
   ============================================================ */

.list-item {
  display: flex;
  align-items: center;
  gap: 18px;
  width: 100%;
  padding: 14px 18px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform 0.25s, box-shadow 0.25s;
}

.list-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 18px 40px rgba(16, 35, 74, 0.22);
}

.list-item__image {
  width: 84px;
  height: 84px;
  flex-shrink: 0;
  border-radius: 50%;
  object-fit: cover;
}

.list-item__body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.list-item__title {
  font-size: 1.1rem;
  font-weight: 700;
}

.list-item__desc {
  font-size: 0.9rem;
  color: var(--muted);
}

/* ============================================================
   OBJECT CARD
   ============================================================ */

.object-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.object-card__image {
  width: 100%;
  height: auto;
  border-radius: 14px;
  object-fit: cover;
}

.object-card__audio-wrap { width: 100%; margin-top: 4px; }
.object-card__audio-player { width: 100%; }

.object-card__text {
  font-size: clamp(15px, 1.6vw, 19px);
  margin-top: 4px;
}

.object-card__text p { margin-bottom: 12px; }

.object-card__meta {
  color: var(--muted);
  text-align: center;
}

/* ============================================================
   STATES
   ============================================================ */

.status {
  width: min(700px, 100%);
  margin: 20px auto;
  padding: 16px 18px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
  color: var(--muted);
}

.status--error {
  border: 1px solid rgba(224, 78, 78, 0.35);
  color: #8f2323;
}

.status--empty {
  /* Fix #1: was var(--color-border-tertiary) which was undefined */
  border: 1px solid var(--border-muted);
  color: var(--muted);
}

.status a {
  color: var(--text);
  text-decoration: underline;
}

/* ============================================================
   MAP
   ============================================================ */

.map-section {
  width: 70%;
  height: 420px;
  margin: 0 auto 24px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.map-section--section { width: 65%; }

.map-popup {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 160px;
}

.map-popup__img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  border-radius: 8px;
}

.map-popup__title {
  font-family: "Roboto", sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: #1a2233;
  text-decoration: none;
  line-height: 1.3;
}

.map-popup__title:hover { text-decoration: underline; }

.map-popup-wrap .leaflet-popup-content-wrapper {
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
}

.map-popup-wrap .leaflet-popup-content { margin: 0; padding: 12px; }

.map-popup-wrap .leaflet-popup-close-button {
  top: 8px !important;
  right: 8px !important;
  width: 24px !important;
  height: 24px !important;
  line-height: 24px !important;
  font-size: 18px !important;
  background: rgba(255, 255, 255, 0.85) !important;
  border-radius: 50% !important;
  color: #1a2233 !important;
  z-index: 10;
}

/* ============================================================
   RESPONSIVE — tablet (≤ 1024px)
   ============================================================ */

@media (max-width: 1024px) {
  .page          { width: 82%; }
  .page--section { width: 82%; }
  .page--object  { width: 82%; }

  .map-section          { width: 82%; }
  .map-section--section { width: 82%; }
}

/* ============================================================
   RESPONSIVE — small tablet / large mobile (≤ 800px)
   ============================================================ */

@media (max-width: 800px) {
  .page,
  .page--section,
  .page--object {
    width: 92%;
    margin: 16px auto 24px;
  }

  .map-section,
  .map-section--section {
    width: 92%;
    height: 360px;
  }

  .card { min-height: 200px; }

  .card-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   RESPONSIVE — mobile (≤ 600px)
   Fix #14: use body.has-back class instead of :has() for old Firefox
   ============================================================ */

@media (max-width: 600px) {
  .page,
  .page--section,
  .page--object {
    width: 100%;
    margin: 12px auto 20px;
    padding: 0 14px;
  }

  .map-section,
  .map-section--section {
    width: 100%;
    height: 280px;
    border-radius: 0;
    margin-bottom: 16px;
  }

  body.has-back,
  body:has(.back-button:not([hidden])) { padding-top: 56px; }
  body.no-has.has-back                  { padding-top: 56px; }

  .back-button {
    top: 10px;
    left: 10px;
    padding: 8px 12px;
    font-size: 0.82rem;
  }

  .card { min-height: 160px; }

  .card__title { font-size: 1.1rem; }

  .list-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
  }

  .list-item__image {
    width: 56px;
    height: 56px;
  }

  .list-item__title { font-size: 1rem; }

  .object-card {
    padding: 14px;
    border-radius: 12px;
  }

  .object-card__image { border-radius: 10px; }

  .status {
    font-size: 0.9rem;
    padding: 12px 14px;
  }
}
