* { box-sizing: border-box; }

:root {
  /* Light theme (default) */
  --c-bg:         #f7f5f0;
  --c-panel:      #fdfcf9;
  --c-panel-alt:  #f2eee3;
  --c-graph:      #f2eee3;
  --c-text:       #2a2a2a;
  --c-text-soft:  #4a4639;
  --c-muted:      #6b6458;
  --c-faint:      #a39d92;
  --c-border:     #e5e0d5;
  --c-border-soft: #d6cfc0;
  --c-tag-bg:     #e5e0d5;
  --c-note-bg:    #f7f5f0;
  --c-header-bg:  #1c1917;
  --c-header-text:#f7f5f0;
  --c-graph-dot:  rgba(0, 0, 0, 0.04);
  --c-shadow:     rgba(0, 0, 0, 0.15);
}

body.dark-mode {
  --c-bg:         #141210;
  --c-panel:      #1a1917;
  --c-panel-alt:  #2a2620;
  --c-graph:      #0b0a09;
  --c-text:       #e5e0d5;
  --c-text-soft:  #c9c1b0;
  --c-muted:      #a39d92;
  --c-faint:      #6b6458;
  --c-border:     #3a342d;
  --c-border-soft:#4a4639;
  --c-tag-bg:     #2a2620;
  --c-note-bg:    #1a1917;
  --c-graph-dot:  rgba(255, 255, 255, 0.05);
  --c-shadow:     rgba(0, 0, 0, 0.5);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Georgia', 'Times New Roman', serif;
  background: var(--c-bg);
  color: var(--c-text);
}

header {
  padding: 0.7rem 1.4rem;
  background: #1c1917;
  color: var(--c-header-text);
  display: flex;
  align-items: center;
  gap: 1rem;
  border-bottom: 3px solid #b8860b;
}

.hamburger {
  display: none;
  background: transparent;
  border: 1px solid var(--c-muted);
  color: var(--c-header-text);
  font-family: sans-serif;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.35rem 0.65rem;
  margin: 0;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.hamburger:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: #b8860b;
}

.theme-toggle,
.help-toggle {
  background: transparent;
  border: 1px solid var(--c-muted);
  color: var(--c-header-text);
  font-size: 1rem;
  line-height: 1;
  padding: 0.35rem 0.55rem;
  margin: 0;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  font-family: inherit;
}

.help-toggle {
  width: 2rem;
  font-weight: bold;
  font-family: sans-serif;
}
.theme-toggle:hover,
.help-toggle:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: #b8860b;
}
body.dark-mode .theme-toggle {
  background: #b8860b;
  color: #1c1917;
  border-color: #b8860b;
}

.panel-backdrop {
  display: none;
  position: fixed;
  inset: 52px 0 0 0;
  background: rgba(14, 13, 12, 0.55);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}

.panel-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: normal;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

header .subtitle {
  font-size: 0.85rem;
  opacity: 0.65;
  font-style: italic;
}

header .stats {
  margin-left: auto;
  font-size: 0.8rem;
  opacity: 0.7;
}

.layout {
  display: grid;
  grid-template-columns: 230px 1fr 440px;
  height: calc(100vh - 52px);
}

.panel {
  padding: 1rem 1.2rem;
  overflow-y: auto;
  background: var(--c-panel);
}

.controls { border-right: 1px solid var(--c-border); }
.detail   { border-left: 1px solid var(--c-border); }

/* Medium screens: tighten columns */
@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 200px 1fr 380px;
  }
}

/* Small screens (tablets portrait, phones): graph full width, panels become drawers */
@media (max-width: 900px) {
  .hamburger { display: inline-block; }
  .panel-backdrop { display: block; }

  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  header .subtitle,
  header .stats {
    font-size: 0.72rem;
  }

  header .stats { display: none; }

  .controls {
    position: fixed;
    top: 52px;
    left: 0;
    bottom: 0;
    z-index: 50;
    width: min(320px, 88vw);
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
  }

  .controls.panel-open {
    transform: translateX(0);
  }

  .detail {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    max-height: 70vh;
    z-index: 50;
    transform: translateY(100%);
    transition: transform 0.28s ease;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.18);
    border-left: none;
    border-top: 1px solid var(--c-border);
  }

  .detail.panel-open {
    transform: translateY(0);
  }

  /* Fullscreen modal: stack vertically on small screens */
  #fullscreen {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  .fs-close {
    right: 0.8rem;
    top: 0.8rem;
  }

  .fs-detail {
    max-height: 35vh;
  }
}

.panel section { margin-bottom: 1.4rem; }

.panel h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--c-muted);
  margin: 0 0 0.6rem 0;
  font-weight: bold;
}

.panel label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  cursor: pointer;
  line-height: 1.3;
}

.panel label input { margin: 0; }

.color-swatch {
  display: inline-block;
  width: 18px;
  height: 3px;
  margin-right: 4px;
}

.legend { font-size: 0.85rem; line-height: 1.8; }

.node-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 6px;
}

.node-dot.canonical { background: #1c1917; border: 2px solid #b8860b; box-sizing: border-box; }
.node-dot.secondary { background: var(--c-faint); }

button {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--c-border-soft);
  background: var(--c-panel-alt);
  color: var(--c-text);
  cursor: pointer;
  margin-right: 0.4rem;
  margin-bottom: 0.3rem;
}

button:hover { background: var(--c-border); }

input[type="search"] {
  width: 100%;
  padding: 0.45rem 0.6rem;
  font-family: Georgia, serif;
  font-size: 0.9rem;
  color: var(--c-text);
  background: var(--c-panel);
  border: 1px solid var(--c-border-soft);
  outline: none;
  transition: border-color 0.18s ease, background 0.18s ease;
}

input[type="search"]:focus {
  border-color: #b8860b;
  background: var(--c-panel);
}

body.dark-mode input[type="search"]:focus {
  background: var(--c-panel-alt);
}

.search-count {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--c-muted);
  font-style: italic;
  min-height: 1em;
}

.graph-area {
  position: relative;
  overflow: hidden;
  background: var(--c-graph);
}

#bg-decor {
  position: absolute;
  inset: -50px;                   /* extra margin so parallax doesn't reveal edges */
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 1px 1px, var(--c-graph-dot) 1px, transparent 0);
  background-size: 24px 24px;
  transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.3, 1);
  will-change: transform;
}

#bg-decor svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0.75;                  /* light mode: visible enough to show parallax movement */
}

body.dark-mode #bg-decor svg {
  opacity: 0.28;                  /* dark mode: clearly decorative, doesn't fight the graph */
}

#cy {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: transparent;
}

/* Detail panel */
.detail h2 {
  margin: 0 0 0.2rem 0;
  font-size: 1.25rem;
  line-height: 1.25;
}

.detail .author {
  color: var(--c-muted);
  font-style: italic;
  margin-bottom: 0.6rem;
}

.detail .meta {
  font-size: 0.85rem;
  color: var(--c-text-soft);
  margin-bottom: 0.8rem;
  line-height: 1.7;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--c-border);
}

.detail .canonical-badge {
  display: inline-block;
  background: #b8860b;
  color: white;
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  margin-left: 0.4rem;
  font-family: sans-serif;
  font-weight: bold;
  vertical-align: middle;
}

.detail h4 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--c-muted);
  margin: 1rem 0 0.3rem 0;
}

.detail p, .detail li {
  font-size: 0.92rem;
  line-height: 1.55;
  margin: 0.3rem 0;
}

.detail ul { padding-left: 1.2rem; }
.detail .placeholder { color: var(--c-faint); font-style: italic; }

.detail .edge-note {
  font-size: 0.95rem;
  line-height: 1.6;
  padding: 0.7rem 0.9rem;
  background: var(--c-bg);
  border-left: 4px solid;
  margin-top: 0.8rem;
}

.themes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.3rem;
}

.theme-tag {
  font-size: 0.72rem;
  background: var(--c-border);
  color: var(--c-text-soft);
  padding: 0.15rem 0.55rem;
  border-radius: 3px;
  font-family: sans-serif;
}

/* Node image in detail panel */
.node-image {
  margin: 0 -1.2rem 1rem -1.2rem;
  background: #1c1917;
  text-align: center;
  position: relative;
}

.node-image img {
  max-width: 100%;
  max-height: 480px;
  width: auto;
  height: auto;
  display: inline-block;
  object-fit: contain;
  cursor: zoom-in;
  transition: filter 0.2s ease;
}

.node-image img:hover {
  filter: brightness(1.08);
}

.node-image .fs-button {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(28, 25, 23, 0.85);
  color: #d6c48f;
  border: 1px solid #b8860b;
  padding: 0.25rem 0.6rem;
  font-family: sans-serif;
  font-size: 0.75rem;
  cursor: pointer;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  transition: background 0.15s ease;
}

.node-image .fs-button:hover {
  background: #1c1917;
}

.node-image figcaption {
  padding: 0.4rem 0.9rem;
  font-size: 0.7rem;
  color: var(--c-faint);
  background: #1c1917;
  font-family: sans-serif;
  line-height: 1.5;
  text-align: left;
}

.node-image .image-strategy {
  color: #d6c48f;
  font-style: italic;
  margin-bottom: 0.25rem;
}

.node-image .image-caveat {
  margin: 0 -1.2rem;
  padding: 0.5rem 0.9rem;
  background: #2a2620;
  color: #c9c1b0;
  font-size: 0.75rem;
  font-family: sans-serif;
  line-height: 1.5;
  border-top: 1px solid #3a342d;
  border-bottom: 1px solid #3a342d;
  text-align: left;
}

.node-image .image-caveat strong {
  color: #e0c88b;
}

.node-image figcaption a {
  color: #d6c48f;
  text-decoration: none;
}

.node-image figcaption a:hover {
  text-decoration: underline;
}

.image-missing {
  margin: 0 -1.2rem 1rem -1.2rem;
  padding: 1rem 1.2rem;
  background: var(--c-text);
  color: var(--c-faint);
  font-size: 0.85rem;
  font-style: italic;
  text-align: center;
  border-top: 3px solid #b8860b;
  border-bottom: 1px solid var(--c-text-soft);
}

/* Edge detail rendering */
.edge-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.4rem;
}

.edge-work {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
  line-height: 1.35;
  text-align: center;
}

.edge-work.clickable {
  /* reset button styles: look like a div but behave like a button */
  background: transparent;
  border: 1px solid transparent;
  color: inherit;
  font-family: inherit;
  padding: 0.35rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.edge-work.clickable:hover {
  background: #efeae0;
  border-color: var(--c-border-soft);
}

.edge-work.clickable:active {
  transform: scale(0.98);
}

.edge-work.clickable .edge-thumb {
  transition: filter 0.15s ease;
}

.edge-work.clickable:hover .edge-thumb {
  filter: brightness(1.08);
}

.edge-work.clickable:focus-visible {
  outline: 2px solid #b8860b;
  outline-offset: 2px;
}

.edge-thumb {
  width: 100%;
  max-width: 130px;
  height: 90px;
  object-fit: cover;
  align-self: center;
  border: 1px solid var(--c-border-soft);
}

.edge-arrow {
  font-size: 1.8rem;
  font-weight: bold;
  text-align: center;
}

.edge-work .small {
  color: var(--c-muted);
  font-size: 0.75rem;
  font-style: italic;
}

/* Detail panel content fade */
.detail {
  transition: opacity 0.18s ease-out;
}

/* =====================================================================
   PRESENTATION MODE
   ===================================================================== */

.pres-hidden { display: none !important; }

/* Buttons used across strip header and play nav */
.pres-btn {
  font-family: inherit;
  font-size: 0.82rem;
  padding: 0.4rem 0.8rem;
  background: #2a2620;
  color: var(--c-border);
  border: 1px solid var(--c-text-soft);
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.pres-btn:hover { background: #3a342d; border-color: #b8860b; }
.pres-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.pres-btn-primary {
  background: #b8860b;
  border-color: #b8860b;
  color: #1c1917;
  font-weight: bold;
}
.pres-btn-primary:hover { background: #d4a743; border-color: #d4a743; }

.pres-btn-danger { color: #e6a09e; }
.pres-btn-danger:hover { background: #5a2e2b; border-color: #b8535a; color: #f7e5e2; }

/* Header toggle */
.pres-toggle {
  margin-left: 0.6rem;
  background: transparent;
  color: var(--c-header-text);
  border: 1px solid var(--c-muted);
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.35rem 0.9rem;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.pres-toggle:hover { background: rgba(255,255,255,0.08); border-color: #b8860b; }

body.presentation-prep .pres-toggle {
  background: #b8860b;
  color: #1c1917;
  border-color: #b8860b;
}

/* Utility: elements only visible in prep mode */
.pres-prep-only { display: none; }
body.presentation-prep .pres-prep-only { display: inline-block; }

/* Strip at bottom of viewport */
#presentation-strip {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  background: #1c1917;
  border-top: 3px solid #b8860b;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  max-height: 220px;
  color: var(--c-border);
}

.strip-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.9rem;
  border-bottom: 1px solid #3a342d;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.strip-label { font-size: 0.9rem; font-family: Georgia, serif; }
.strip-count-wrap { color: var(--c-faint); font-size: 0.8rem; margin-left: 0.3rem; }
.strip-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.strip-slides {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.6rem 0.9rem;
  min-height: 130px;
}

.strip-empty {
  color: var(--c-faint);
  font-style: italic;
  font-size: 0.85rem;
  padding: 2rem 0 0 0.4rem;
  align-self: center;
}

.slide {
  flex: 0 0 auto;
  width: 110px;
  background: #2a2620;
  border: 1px solid #3a342d;
  position: relative;
  cursor: grab;
  transition: border-color 0.15s ease, transform 0.15s ease;
  display: flex;
  flex-direction: column;
}

.slide:hover { border-color: #b8860b; }
.slide:active { cursor: grabbing; }
.slide.slide-dragging { opacity: 0.4; }

.slide-num {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: rgba(0,0,0,0.7);
  color: #d4a743;
  border-radius: 50%;
  text-align: center;
  line-height: 20px;
  font-size: 0.72rem;
  font-weight: bold;
  z-index: 2;
  font-family: sans-serif;
}

.slide-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  background: rgba(0,0,0,0.7);
  color: #e6a09e;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  z-index: 2;
  padding: 0;
}
.slide-remove:hover { background: #5a2e2b; color: white; }

.slide-thumb {
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  background: #1c1917;
}
.slide-thumb img { width: 100%; height: 100%; object-fit: cover; }
.slide-noimg { width: 100%; height: 100%; background: #3a342d; }

.slide-title {
  font-size: 0.72rem;
  padding: 0.3rem 0.35rem;
  color: var(--c-border);
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-family: Georgia, serif;
}

/* Play-mode full-screen view */
#presentation-view {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #0a0907;
  color: #f0ece1;
  display: flex;
  flex-direction: column;
  animation: pres-fade-in 0.28s ease-out;
}

@keyframes pres-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.pres-exit-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 2.4rem;
  height: 2.4rem;
  background: rgba(255,255,255,0.08);
  color: #f0ece1;
  border: 1px solid var(--c-text-soft);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  transition: background 0.15s ease;
}
.pres-exit-btn:hover { background: rgba(255,255,255,0.18); border-color: #b8860b; }

.pres-content {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr min(480px, 38%);
  overflow: hidden;
  min-height: 0;
}

.pres-image-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 2rem 2rem 2rem;
  min-height: 0;
}

.pres-image-wrap img {
  max-width: 100%;
  max-height: calc(100vh - 10rem);
  object-fit: contain;
  box-shadow: 0 6px 40px rgba(0, 0, 0, 0.7);
  animation: pres-img-in 0.32s ease-out;
}

@keyframes pres-img-in {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.pres-caption {
  margin-top: 0.8rem;
  font-size: 0.78rem;
  color: var(--c-faint);
  font-family: sans-serif;
  text-align: center;
  max-width: 80%;
}
.pres-caption a { color: #d4a743; text-decoration: none; }
.pres-caption a:hover { text-decoration: underline; }

.pres-details {
  padding: 2rem 1.8rem;
  overflow-y: auto;
  background: #13110f;
  border-left: 1px solid #2a2620;
  animation: pres-slide-in 0.32s ease-out;
}

@keyframes pres-slide-in {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Override detail-panel colours inside dark presentation view */
.pres-details h2 { color: #f0ece1; font-size: 1.4rem; margin: 0 0 0.3rem 0; }
.pres-details .author { color: #c9c1b0; }
.pres-details .meta { color: #c9c1b0; border-bottom-color: #3a342d; }
.pres-details .meta strong { color: var(--c-border); }
.pres-details h4 { color: var(--c-faint); }
.pres-details p, .pres-details li { color: var(--c-border); }
.pres-details .theme-tag { background: #2a2620; color: #c9c1b0; }
.pres-details .canonical-badge { background: #d4a743; color: #1c1917; }
.pres-details .edge-note { background: #2a2620; color: var(--c-border); }
.pres-details .fitxa-toolbar { display: none; }  /* no add/export buttons during play */
.pres-details .image-caveat { background: #2a2620; color: #c9c1b0; border-color: #3a342d; }
.pres-details .image-strategy { color: #d4a743; }

.pres-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  padding: 0.8rem;
  background: #0a0907;
  border-top: 1px solid #2a2620;
}

.pres-nav-btn {
  width: 3rem;
  height: 3rem;
  background: #1c1917;
  color: #f0ece1;
  border: 1px solid var(--c-text-soft);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
  font-family: sans-serif;
}

.pres-nav-btn:hover:not(:disabled) { background: #3a342d; border-color: #b8860b; }
.pres-nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.pres-counter {
  color: var(--c-faint);
  font-family: sans-serif;
  font-size: 0.9rem;
  min-width: 5rem;
  text-align: center;
  letter-spacing: 0.06em;
}

/* Responsive for the strip and play view */
@media (max-width: 900px) {
  #presentation-strip {
    max-height: 180px;
  }
  .slide { width: 90px; }
  .slide-thumb { aspect-ratio: 1; }
  .pres-content { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .pres-details { border-left: none; border-top: 1px solid #2a2620; max-height: 40vh; padding: 1rem 1.2rem; }
  .pres-image-wrap { padding: 2rem 1rem 0.5rem 1rem; }
  .pres-image-wrap img { max-height: 45vh; }
  .pres-exit-btn { top: 0.6rem; right: 0.6rem; }
}

/* Hide the regular controls/detail panels while actively playing — graph
   is hidden by the play-mode full-screen overlay anyway, but we also don't
   want the mobile drawers to animate behind it. */
body.presentation-play #panel-backdrop,
body.presentation-play .detail,
body.presentation-play .controls { display: none !important; }

/* When prep mode is active, shift the main map content up so the strip
   doesn't cover the bottom of the graph. */
body.presentation-prep .layout {
  height: calc(100vh - 52px - 220px);
}

@media (max-width: 900px) {
  body.presentation-prep .layout { height: calc(100vh - 52px - 180px); }
}

/* ---- Period / theme filter groups ---- */
details.filter-group { margin: 0; }

details.filter-group > summary.filter-summary {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--c-muted);
  font-weight: bold;
  cursor: pointer;
  padding: 0.3rem 1rem 0.3rem 0;
  position: relative;
  list-style: none;
  user-select: none;
}
details.filter-group > summary.filter-summary::-webkit-details-marker { display: none; }
details.filter-group > summary.filter-summary::after {
  content: '›';
  position: absolute;
  right: 0;
  top: 0.2rem;
  font-size: 1rem;
  color: var(--c-faint);
  transition: transform 0.18s ease;
}
details.filter-group[open] > summary.filter-summary::after {
  transform: rotate(90deg);
}

.filter-count {
  font-weight: normal;
  text-transform: none;
  letter-spacing: 0;
  color: var(--c-faint);
  margin-left: 0.3rem;
  font-family: sans-serif;
}

.filter-actions {
  display: flex;
  gap: 0.3rem;
  margin: 0.3rem 0 0.4rem 0;
}

.mini-btn {
  padding: 0.1rem 0.5rem;
  font-size: 0.7rem;
  font-family: sans-serif;
  letter-spacing: 0.04em;
  border: 1px solid var(--c-border-soft);
  background: var(--c-panel-alt);
  color: var(--c-muted);
  cursor: pointer;
  margin: 0;
  transition: background 0.15s ease, color 0.15s ease;
}
.mini-btn:hover { background: var(--c-border); color: var(--c-text); }

.filter-list {
  max-height: 220px;
  overflow-y: auto;
  padding-right: 0.3rem;
}

.filter-list label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0;
  font-size: 0.82rem;
  cursor: pointer;
  line-height: 1.25;
  margin: 0;
}

.filter-list input { margin: 0; }

/* ---- Help modal ---- */
#help-modal {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(14, 13, 12, 0.85);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4rem 1.5rem 3rem;
  overflow-y: auto;
  animation: help-fade-in 0.22s ease-out;
}
#help-modal.help-hidden { display: none; }

@keyframes help-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.help-close {
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: 2.4rem;
  height: 2.4rem;
  background: var(--c-panel);
  color: var(--c-text);
  border: 1px solid var(--c-border-soft);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  z-index: 2;
  transition: background 0.15s ease;
}
.help-close:hover { background: var(--c-border); }

.help-content {
  background: var(--c-panel);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  padding: 2rem 2.2rem;
  max-width: 720px;
  width: 100%;
  line-height: 1.55;
  animation: help-slide-in 0.24s ease-out;
}

@keyframes help-slide-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.help-content h2 {
  margin: 0 0 1.2rem 0;
  font-size: 1.5rem;
  font-family: Georgia, serif;
  border-bottom: 2px solid #b8860b;
  padding-bottom: 0.4rem;
}

.help-content h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--c-muted);
  margin: 1.5rem 0 0.5rem 0;
  font-weight: bold;
  font-family: sans-serif;
}

.help-content ul, .help-content ol { padding-left: 1.3rem; margin: 0.3rem 0; }
.help-content li { margin: 0.3rem 0; font-size: 0.9rem; }
.help-content p { font-size: 0.9rem; margin: 0.4rem 0; }

.help-content kbd {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  font-family: sans-serif;
  font-size: 0.78rem;
  background: var(--c-panel-alt);
  border: 1px solid var(--c-border-soft);
  border-bottom-width: 2px;
  color: var(--c-text);
  margin: 0 0.05rem;
}

.help-content code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.82rem;
  background: var(--c-panel-alt);
  padding: 0.05rem 0.3rem;
  color: var(--c-text-soft);
}

.help-shortcuts {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.help-shortcuts td, .help-shortcuts th {
  padding: 0.35rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--c-border);
}
.help-shortcuts th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-muted);
  background: var(--c-panel-alt);
  font-weight: bold;
  padding-top: 0.6rem;
}
.help-shortcuts td:first-child { white-space: nowrap; }

.help-credit {
  margin-top: 1.6rem;
  padding-top: 1rem;
  border-top: 1px solid var(--c-border);
}
.help-credit h3 { margin-bottom: 0.5rem; }
.help-credit p {
  color: var(--c-muted);
  font-size: 0.9rem;
  line-height: 1.55;
  margin: 0 0 0.7rem;
}
.help-credit p strong { color: var(--c-text); }

.help-links {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  font-size: 0.88rem;
}
.help-links a { color: #b8860b; text-decoration: none; }
.help-links a:hover { text-decoration: underline; }

/* Lightning tip box */
.tip-box {
  margin-top: 0.8rem;
  padding: 0.9rem 1rem;
  border: 1px solid rgba(247, 147, 26, 0.28);
  border-radius: 8px;
  background: rgba(247, 147, 26, 0.06);
}
.tip-box__head {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-bottom: 0.7rem;
}
.tip-box__title {
  font-weight: bold;
  color: var(--c-text);
  font-size: 0.95rem;
}
.tip-box__sub {
  color: var(--c-muted);
  font-size: 0.8rem;
}
.tip-box__row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.tip-box__addr {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.6rem;
  background: var(--c-panel-alt, rgba(0, 0, 0, 0.03));
  border: 1px solid var(--c-border-soft);
  border-radius: 5px;
  color: #b8860b;
  font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tip-box__copy {
  flex-shrink: 0;
  padding: 0.35rem 0.75rem;
  border: 1px solid #F7931A;
  background: transparent;
  color: #F7931A;
  border-radius: 5px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tip-box__copy:hover { background: #F7931A; color: #fff; }
.tip-box__copy.is-copied {
  background: #22c55e;
  border-color: #22c55e;
  color: #fff;
}
.tip-box__qr {
  margin-top: 0.8rem;
}
.tip-box__qr-canvas {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 180px;
  padding: 0.7rem;
  background: #fff;
  border-radius: 6px;
}
.tip-box__qr-canvas img,
.tip-box__qr-canvas canvas { display: block; border-radius: 3px; }
.tip-box__qr-msg { color: #888; font-size: 0.85rem; }

@media (max-width: 900px) {
  #help-modal { padding: 1rem; }
  .help-content { padding: 1.3rem; }
  .help-close { top: 0.4rem; right: 0.4rem; }
}

/* Copy-link feedback on the detail button */
.node-action.copy-ok {
  background: #d4a743;
  border-color: #b8860b;
  color: #1c1917;
}

/* Print container: hidden on screen; @media print reveals it */
#print-container { display: none; }

/* Action buttons inside the detail panel (below meta grid) */
.fitxa-toolbar {
  margin: 0.6rem 0 0.8rem 0;
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.node-action {
  font-family: inherit;
  font-size: 0.78rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--c-border-soft);
  background: var(--c-bg);
  color: var(--c-text);
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.node-action:hover {
  background: var(--c-border);
  border-color: #b8860b;
}

.node-action:disabled {
  opacity: 0.6;
  cursor: wait;
}

.detail > * {
  animation: fade-in 0.2s ease-out;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Fullscreen modal */
#fullscreen {
  position: fixed;
  inset: 0;
  background: rgba(14, 13, 12, 0.97);
  display: grid;
  grid-template-columns: 1fr 440px;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.22s ease;
}

#fullscreen.fs-hidden {
  opacity: 0;
  pointer-events: none;
}

.fs-close {
  position: absolute;
  top: 0.8rem;
  right: 460px;
  background: transparent;
  border: 1px solid var(--c-muted);
  color: var(--c-header-text);
  font-size: 1.4rem;
  line-height: 1;
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  cursor: pointer;
  z-index: 2;
  border-radius: 2px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.fs-close:hover {
  background: var(--c-text);
  border-color: #b8860b;
}

.fs-image-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  overflow: hidden;
  min-height: 0;
}

#fs-img {
  max-width: 100%;
  max-height: calc(100vh - 8rem);
  object-fit: contain;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
  animation: fs-zoom-in 0.26s ease-out;
}

@keyframes fs-zoom-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

#fs-caption {
  margin-top: 1rem;
  color: var(--c-faint);
  font-size: 0.8rem;
  font-family: sans-serif;
  text-align: center;
  max-width: 80%;
}

#fs-caption a {
  color: #d6c48f;
  text-decoration: none;
}

#fs-caption a:hover {
  text-decoration: underline;
}

.fs-detail {
  background: var(--c-panel);
  color: var(--c-text);
  overflow-y: auto;
  padding: 1.5rem 1.4rem;
  animation: fs-slide-in 0.26s ease-out;
}

@keyframes fs-slide-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.fs-detail h2 {
  margin: 0 0 0.2rem 0;
  font-size: 1.3rem;
  line-height: 1.25;
}

.fs-detail .author {
  color: var(--c-muted);
  font-style: italic;
  margin-bottom: 0.8rem;
}

.fs-detail .meta {
  font-size: 0.85rem;
  line-height: 1.7;
  margin-bottom: 1rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--c-border);
}

.fs-detail h4 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--c-muted);
  margin: 1rem 0 0.3rem 0;
}

.fs-detail p, .fs-detail li {
  font-size: 0.92rem;
  line-height: 1.55;
  margin: 0.3rem 0;
}

.fs-detail ul { padding-left: 1.2rem; }

.fs-detail .canonical-badge {
  display: inline-block;
  background: #b8860b;
  color: white;
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  margin-left: 0.4rem;
  font-family: sans-serif;
  font-weight: bold;
  vertical-align: middle;
}

.fs-detail .themes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.3rem;
}

.fs-detail .theme-tag {
  font-size: 0.72rem;
  background: var(--c-border);
  color: var(--c-text-soft);
  padding: 0.15rem 0.55rem;
  border-radius: 3px;
  font-family: sans-serif;
}

/* =====================================================================
   PRINT STYLES
   Trigger with the "Exportar fitxes (PDF)" button; user saves as PDF
   from the browser dialog. One A4 page per artwork; the whole app UI
   is hidden.
   ===================================================================== */
@media print {
  html, body { background: white !important; }

  /* Hide everything except the print container */
  body > header,
  body > .layout,
  body > #fullscreen,
  body > .panel-backdrop { display: none !important; }

  #print-container { display: block !important; }

  @page {
    size: A4;
    margin: 1.6cm 1.5cm;
  }

  body {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 10.5pt;
    line-height: 1.45;
    color: #1a1a1a;
  }

  .print-cover {
    page-break-after: always;
    text-align: center;
    padding-top: 4cm;
  }
  .print-cover h1 { font-size: 28pt; font-weight: normal; margin: 0 0 0.3em 0; letter-spacing: 0.04em; }
  .print-cover .lead { font-size: 14pt; color: #444; font-style: italic; margin-bottom: 2em; }
  .print-cover .meta { font-size: 10pt; color: #666; }

  .print-fitxa {
    page-break-after: always;
    break-inside: avoid-page;
  }
  .print-fitxa:last-child { page-break-after: auto; }

  .print-fitxa header.fitxa-head {
    border-bottom: 2px solid #1a1a1a;
    padding-bottom: 0.4em;
    margin-bottom: 0.7em;
  }

  .print-fitxa h1 {
    margin: 0;
    font-size: 17pt;
    font-weight: normal;
  }

  .print-fitxa .author {
    margin: 0.15em 0 0 0;
    font-style: italic;
    color: #444;
    font-size: 11pt;
  }

  .print-fitxa .badge {
    display: inline-block;
    font-size: 8.5pt;
    background: #1a1a1a;
    color: white;
    padding: 0.08em 0.55em;
    vertical-align: middle;
    margin-left: 0.5em;
    font-family: Arial, sans-serif;
    letter-spacing: 0.04em;
  }

  .print-fitxa .img-wrap {
    text-align: center;
    margin: 0.6em 0 1em 0;
  }

  .print-fitxa .img-wrap img {
    max-width: 100%;
    max-height: 8.5cm;
    object-fit: contain;
  }

  .print-fitxa .img-caption {
    font-size: 8.5pt;
    color: #666;
    margin-top: 0.3em;
    font-style: italic;
    font-family: Arial, sans-serif;
  }

  .print-fitxa .meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 1.4em;
    row-gap: 0.25em;
    font-size: 9.5pt;
    margin: 0 0 0.7em 0;
    padding: 0.5em 0;
    border-top: 1px solid #bbb;
    border-bottom: 1px solid #bbb;
  }

  .print-fitxa .meta-grid span.k { font-weight: bold; color: #444; margin-right: 0.25em; }

  .print-fitxa .themes-line {
    font-size: 9pt;
    color: #555;
    margin: 0 0 0.9em 0;
    font-family: Arial, sans-serif;
  }

  .print-fitxa h3 {
    font-size: 9.5pt;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #555;
    margin: 1em 0 0.25em 0;
    font-weight: bold;
    font-family: Arial, sans-serif;
    page-break-after: avoid;
  }

  .print-fitxa p {
    margin: 0.25em 0;
    text-align: justify;
    orphans: 3;
    widows: 3;
  }

  .print-fitxa ul {
    padding-left: 1.1em;
    margin: 0.3em 0;
  }

  .print-fitxa li { margin: 0.18em 0; }

  .print-fitxa .conn-list {
    padding-left: 0;
    list-style: none;
  }

  .print-fitxa .conn-list li {
    font-size: 9.5pt;
    margin: 0.35em 0;
    padding-left: 1.2em;
    position: relative;
  }

  .print-fitxa .conn-list li::before {
    content: "·";
    position: absolute;
    left: 0.3em;
    font-weight: bold;
    color: #888;
  }

  .print-fitxa .conn-type {
    font-weight: bold;
    font-family: Arial, sans-serif;
    font-size: 8.5pt;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #333;
  }

  .print-fitxa .conn-arrow { color: #777; margin: 0 0.3em; }

  .print-fitxa .conn-note {
    color: #555;
    font-size: 9pt;
    display: block;
    margin-top: 0.15em;
    font-style: italic;
    padding-left: 0.2em;
  }

  .print-fitxa .caveat-box {
    border-left: 3px solid #666;
    padding: 0.35em 0.7em;
    margin: 0.5em 0;
    font-size: 9pt;
    color: #555;
    background: #f5f5f5;
    font-family: Arial, sans-serif;
  }
}

