/* ==========================================================================
   Rastros de Wilde
   ========================================================================== */

:root {
  --color-bg: #f6f4ef;
  --color-surface: #ffffff;
  --color-text: #1f2328;
  --color-muted: #5a6067;
  --color-border: #e1dcd2;
  --color-accent: #1d5c63;
  --color-accent-strong: #154449;
  --color-accent-soft: #e4eff0;
  --color-highlight: #8c1c3a;
  --color-highlight-soft: #f7e9ed;
  --color-focus: #e0a526;

  --font-serif: Georgia, "Times New Roman", serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --radius: 10px;
  --radius-small: 6px;
  --shadow-card: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 14px rgb(0 0 0 / 0.06);
  --shadow-card-hover: 0 2px 6px rgb(0 0 0 / 0.08), 0 14px 30px rgb(0 0 0 / 0.12);
  --shadow-panel: 2px 0 18px rgb(0 0 0 / 0.14);

  --top-bar-height: 64px;
  --panel-width: 380px;
  --page-gutter: 24px;
}

/* ---------- Base ---------- */

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

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 1.125rem;
  line-height: 1.6;
}

h1,
h2,
h3 {
  font-family: var(--font-serif);
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
}

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

a {
  color: var(--color-accent);
}

a:hover {
  color: var(--color-accent-strong);
}

:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

/* Headings receive focus on navigation (for screen readers); no ring needed. */
[tabindex="-1"]:focus {
  outline: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.noscript-message {
  margin: 0;
  padding: 40vh var(--page-gutter) 0;
  text-align: center;
  color: var(--color-muted);
}

/* ---------- Buttons and links ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 42px;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: 1rem;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.button:hover {
  border-color: var(--color-accent);
  color: var(--color-accent-strong);
  background: var(--color-accent-soft);
}

.button[aria-expanded="true"] {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
  color: var(--color-accent-strong);
}

.button-primary {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
}

.button-primary:hover {
  background: var(--color-accent-strong);
  border-color: var(--color-accent-strong);
  color: #fff;
}

.button-ghost {
  border-color: transparent;
  background: transparent;
}

.button-icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

/* ---------- Top bar ---------- */

.top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--top-bar-height);
  padding: 0 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.top-bar-title {
  flex: 1;
  min-width: 0;
  font-size: 1.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-bar-actions {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

/* ---------- Cover ---------- */

.screen-cover {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 48px var(--page-gutter);
  background:
    radial-gradient(ellipse at top, rgb(29 92 99 / 0.07), transparent 60%),
    var(--color-bg);
}

.cover {
  width: 100%;
  max-width: 860px;
  text-align: center;
}

.cover-title {
  font-size: clamp(2.75rem, 8vw, 5rem);
  letter-spacing: 0.01em;
  color: var(--color-accent-strong);
}

.cover-subtitle {
  margin: 0.5rem 0 0;
  font-family: var(--font-serif);
  font-size: clamp(1.4rem, 3.5vw, 1.9rem);
  font-style: italic;
  color: var(--color-muted);
}

.cover-ornament {
  width: 96px;
  height: 1px;
  margin: 2rem auto 2.5rem;
  background: var(--color-highlight);
}

.cover-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 1.5rem;
}

.cover-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 2.25rem 1.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
  color: var(--color-text);
  text-decoration: none;
  transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
}

.cover-option:hover,
.cover-option:focus-visible {
  transform: translateY(-3px);
  border-color: var(--color-accent);
  box-shadow: var(--shadow-card-hover);
  color: var(--color-text);
}

.cover-option-icon {
  width: 52px;
  height: 52px;
  margin-bottom: 0.25rem;
  fill: none;
  stroke: var(--color-accent);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cover-option-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-accent-strong);
}

.cover-option-text {
  color: var(--color-muted);
  font-size: 1rem;
}

.cover-about-link {
  display: inline-block;
  margin-top: 2.5rem;
  color: var(--color-muted);
  font-size: 1rem;
}

/* ---------- Content pages (characters, about) ---------- */

.page {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 32px var(--page-gutter) 64px;
}

.page-narrow {
  max-width: 780px;
}

.empty-message {
  color: var(--color-muted);
}

.search-input {
  display: block;
  width: 100%;
  max-width: 420px;
  margin-bottom: 1.25rem;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: 1rem;
}

.search-input:focus {
  border-color: var(--color-accent);
}

/* ---------- Photos and placeholders ---------- */

.photo-placeholder {
  display: grid;
  place-items: center;
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-family: var(--font-serif);
  font-weight: 700;
  letter-spacing: 0.04em;
  user-select: none;
}

.photo-figure {
  margin: 0;
}

.photo-credit {
  margin-top: 0.4rem;
  color: var(--color-muted);
  font-size: 0.875rem;
  line-height: 1.4;
}

/* ---------- Character album (main area of the Characters screen) ---------- */

.album {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow-y: auto;
  padding: 24px var(--page-gutter) 48px;
  background: var(--color-bg);
}

/* Leaves room for the minimized-panel button. */
.is-panel-collapsed .album {
  padding-top: 72px;
}

/* Cards start beside the open panel, as the map frames its pins beside it. */
.split-body:not(.is-panel-collapsed) .album {
  padding-left: calc(min(var(--panel-width), 100% - 48px) + var(--page-gutter));
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr));
  gap: 1.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.character-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
  color: var(--color-text);
  text-decoration: none;
  transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
}

.character-card:hover,
.character-card:focus-visible,
.character-card.is-hovered {
  transform: translateY(-3px);
  border-color: var(--color-accent);
  box-shadow: var(--shadow-card-hover);
  color: var(--color-text);
}

.character-card.is-selected {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent), var(--shadow-card-hover);
}

.character-card-photo {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  object-position: center top;
}

.character-card-photo.photo-placeholder {
  font-size: 3rem;
}

.character-card-name {
  padding: 0.85rem 1rem 1rem;
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
}

/* ---------- Detail (inside the panel) ---------- */

.panel-detail .photo-figure {
  margin-bottom: 1.25rem;
}

.detail-title {
  font-size: 1.75rem;
  margin-bottom: 1rem;
}

.detail-text {
  margin: 0 0 1.5rem;
  white-space: pre-line;
}

.detail-section {
  margin-top: 1.75rem;
}

.detail-section-title {
  margin-bottom: 0.75rem;
  font-size: 1.5rem;
}

.link-list {
  margin: 0;
  padding-left: 1.25rem;
}

.link-list li + li {
  margin-top: 0.35rem;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0 0 1.25rem;
  padding: 0;
  list-style: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1rem;
  text-decoration: none;
  transition: border-color 0.15s, background-color 0.15s;
}

.chip::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50% 50% 50% 0;
  background: var(--color-highlight);
  transform: rotate(-45deg);
}

.chip:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
  color: var(--color-text);
}

/* ---------- Split screens (Places and Characters) ---------- */

.screen-split {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.split-body {
  position: relative;
  overflow: hidden;
}

.map {
  position: absolute;
  inset: 0;
  z-index: 0; /* keeps Leaflet's internal z-indexes below the panel */
  background: #e6e3dc;
}

.map-unavailable {
  display: grid;
  place-content: center;
  height: 100%;
  padding: var(--page-gutter);
  padding-left: calc(var(--panel-width) + var(--page-gutter));
  text-align: center;
  color: var(--color-muted);
}

.map-unavailable p {
  margin: 0.25rem 0;
}

/* ---------- Side panel ---------- */

.side-panel {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  width: min(var(--panel-width), calc(100% - 48px));
  background: var(--color-surface);
  box-shadow: var(--shadow-panel);
  transition: transform 0.25s ease, visibility 0s linear 0s;
}

.side-panel-content {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px;
}

.is-panel-collapsed .side-panel {
  transform: translateX(calc(-100% - 24px));
  visibility: hidden;
  transition: transform 0.25s ease, visibility 0s linear 0.25s;
}

/* Stays in the panel corner while its content scrolls. */
.panel-minimize {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1;
  width: 38px;
  height: 38px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-muted);
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.panel-minimize:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
  color: var(--color-accent-strong);
}

/* The minimized panel: names what is open in it, over the map or the album. */
.panel-restore {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: calc(100% - 96px);
  min-height: 44px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  box-shadow: var(--shadow-card-hover);
  color: var(--color-text);
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.panel-restore:hover {
  border-color: var(--color-accent);
  color: var(--color-accent-strong);
}

.panel-restore-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.split-body:not(.is-panel-collapsed) .panel-restore {
  display: none;
}

.panel-title {
  margin-bottom: 0.75rem;
  font-size: 1.5rem;
}

.panel-title-count {
  color: var(--color-muted);
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 400;
}

.highlight-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--color-highlight);
  border-radius: var(--radius-small);
  background: var(--color-highlight-soft);
  font-size: 1rem;
}

.highlight-banner p {
  margin: 0;
}

.highlight-banner a {
  color: var(--color-highlight);
  font-weight: 700;
}

/* ---------- Panel list ---------- */

.item-list {
  display: grid;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.list-item {
  display: grid;
  grid-template-columns: 60px 1fr;
  align-items: center;
  gap: 0.85rem;
  padding: 0.5rem;
  border-radius: 8px;
  color: var(--color-text);
  text-decoration: none;
  transition: background-color 0.15s, opacity 0.15s;
}

.list-item:hover,
.list-item:focus-visible {
  background: var(--color-accent-soft);
  color: var(--color-text);
}

.list-item.is-highlighted {
  box-shadow: inset 4px 0 0 var(--color-highlight);
}

.list-item.is-dimmed {
  opacity: 0.5;
}

.list-item.is-dimmed:hover,
.list-item.is-dimmed:focus-visible {
  opacity: 1;
}

.list-item-photo {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-small);
  object-fit: cover;
}

.list-item-photo.photo-placeholder {
  font-size: 1.15rem;
}

.list-item-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.list-item-name {
  font-weight: 600;
  line-height: 1.3;
}

.list-item-meta {
  overflow: hidden;
  color: var(--color-muted);
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.character-detail-photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-small);
  object-fit: cover;
  object-position: center top;
}

.character-detail-photo.photo-placeholder {
  font-size: 4rem;
}

.location-detail-photo {
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius-small);
  object-fit: cover;
}

.location-detail-photo.photo-placeholder {
  aspect-ratio: 16 / 7;
  font-size: 2.5rem;
}

.excerpt {
  margin: 0 0 1.5rem;
  padding: 0.25rem 0 0.25rem 1rem;
  border-left: 3px solid var(--color-accent);
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-style: italic;
  white-space: pre-line;
}

.person-list {
  display: grid;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.person-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem;
  border-radius: 8px;
  color: var(--color-text);
  font-weight: 600;
  text-decoration: none;
}

.person-link:hover,
.person-link:focus-visible {
  background: var(--color-accent-soft);
  color: var(--color-text);
}

.person-link-photo {
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
}

.person-link-photo.photo-placeholder {
  font-size: 1rem;
}

/* ---------- Map pins (L.divIcon) ---------- */

.map-pin {
  border-radius: 4px;
}

.map-pin-shape {
  position: absolute;
  left: 15px;
  top: 8px;
  width: 26px;
  height: 26px;
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  background: var(--color-accent);
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.35);
  /* Rotates around the sharp corner, so the tip stays on the coordinate. */
  transform-origin: 0 100%;
  transform: rotate(-45deg);
  transition: transform 0.15s, background-color 0.15s, opacity 0.15s, filter 0.15s;
}

.map-pin-shape::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  transform: translate(-50%, -50%);
}

.map-pin:hover .map-pin-shape,
.map-pin:focus-visible .map-pin-shape,
.map-pin.is-hovered .map-pin-shape {
  transform: rotate(-45deg) scale(1.2);
}

.map-pin.is-highlighted .map-pin-shape {
  background: var(--color-highlight);
  transform: rotate(-45deg) scale(1.2);
}

.map-pin.is-highlighted:hover .map-pin-shape,
.map-pin.is-highlighted:focus-visible .map-pin-shape,
.map-pin.is-highlighted.is-hovered .map-pin-shape {
  transform: rotate(-45deg) scale(1.35);
}

.map-pin.is-dimmed .map-pin-shape {
  opacity: 0.4;
  filter: grayscale(1);
}

.map-pin.is-dimmed:hover .map-pin-shape,
.map-pin.is-dimmed:focus-visible .map-pin-shape,
.map-pin.is-dimmed.is-hovered .map-pin-shape {
  opacity: 1;
  filter: none;
}

.map-pin.is-selected .map-pin-shape {
  box-shadow: 0 0 0 3px rgb(255 255 255 / 0.9), 0 0 0 6px currentColor, 0 2px 8px rgb(0 0 0 / 0.4);
  transform: rotate(-45deg) scale(1.35);
}

.map-pin.is-selected {
  color: var(--color-accent);
}

.map-pin.is-selected.is-highlighted {
  color: var(--color-highlight);
}

/* ---------- Leaflet overrides ---------- */

.leaflet-container {
  font-family: var(--font-sans);
  font-size: 1rem;
}

.leaflet-control-layers-expanded {
  padding: 0.6rem 0.9rem;
  font-size: 1rem;
  line-height: 1.8;
}

.map-popup .leaflet-popup-content-wrapper {
  border-radius: var(--radius);
}

.map-popup .leaflet-popup-content {
  margin: 12px;
  font-size: 1rem;
  line-height: 1.4;
}

.map-popup-photo {
  width: 100%;
  height: 120px;
  border-radius: var(--radius-small);
  object-fit: cover;
}

.map-popup-photo.photo-placeholder {
  font-size: 1.75rem;
}

.map-popup-name {
  margin: 0.6rem 0 0.35rem !important;
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 700;
}

.leaflet-container a.map-popup-link {
  color: var(--color-accent);
  font-weight: 600;
}

/* ---------- About ---------- */

.about-section + .about-section {
  margin-top: 2.25rem;
}

.about-section h2 {
  margin-bottom: 0.75rem;
  font-size: 1.6rem;
}

.about-section p {
  margin: 0 0 0.75rem;
}

.credit-list {
  margin: 0;
  padding-left: 1.25rem;
}

.credit-list li + li {
  margin-top: 0.4rem;
}

/* ---------- Error screen ---------- */

.screen-error {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--page-gutter);
}

.message-card {
  max-width: 560px;
  padding: 2rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
}

.message-card-title {
  margin-bottom: 1rem;
  font-size: 1.75rem;
  color: var(--color-highlight);
}

.message-card-detail {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-small);
  background: var(--color-bg);
  color: var(--color-muted);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.875rem;
  overflow-wrap: anywhere;
}

.message-card-detail:empty {
  display: none;
}

/* ---------- Responsive ---------- */

@media (max-width: 600px) {
  :root {
    --page-gutter: 16px;
    --top-bar-height: 58px;
  }

  .top-bar {
    gap: 0.5rem;
    padding: 0 10px;
  }

  /* Top-bar buttons keep their icon; the text stays available to screen readers. */
  .top-bar .button-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .top-bar .button {
    padding: 0.45rem 0.65rem;
  }

  .character-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
  }

  .character-card-name {
    padding: 0.65rem 0.75rem 0.75rem;
    font-size: 1.1rem;
  }

  .map-unavailable {
    padding-left: var(--page-gutter);
  }

  /* The open panel covers the album here, as it covers the map. */
  .split-body:not(.is-panel-collapsed) .album {
    padding-left: var(--page-gutter);
  }
}

@media (max-width: 400px) {
  .screen-split .top-bar-title {
    font-size: 1.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0s !important;
    transition-delay: 0s !important;
  }
}
