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

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #05070a;
  color: #f5f5f5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  padding: 0.75rem 1rem;
  background: linear-gradient(90deg, #05070a, #141b2b);
  border-bottom: 1px solid #1e2535;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  overflow: visible;
  position: relative;
  z-index: 50;
}

.header-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.55rem;
  width: 100%;
}

.header-primary {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
  /* Horizontal scroll for logo+tabs only — avoids overflow on .header-bar clipping the search dropdown. */
  overflow-x: auto;
  overflow-y: visible;
  min-width: 0;
}

.header-world-tools {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  overflow: visible;
  position: relative;
  z-index: 60;
}

.mobile-world-controls-toggle {
  display: none;
}

.mobile-world-tools-body {
  display: contents;
}

/* Coffee/Library: remove from layout so the header is only logo + tabs (no empty strip). */
body:not(.active-tab-world) .header-world-tools {
  display: none;
}

header h1 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #e2e8f0;
}

.brand-logo-wrap {
  display: flex;
  align-items: center;
}

.brand-logo {
  display: block;
  height: 40px;
  width: auto;
  max-width: min(52vw, 320px);
  object-fit: contain;
}

.data-attribution {
  font-size: 0.65rem;
  color: #64748b;
  line-height: 1.35;
}

.data-attribution a {
  color: #7dd3fc;
  text-decoration: none;
}

.data-attribution a:hover {
  text-decoration: underline;
}

.top-tabs {
  display: flex;
  gap: 0.3rem;
  flex-wrap: nowrap;
  align-items: center;
  /* If the viewport is narrow, scroll horizontally instead of wrapping Support to a second row. */
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.top-tabs::-webkit-scrollbar {
  height: 4px;
}

.top-tabs::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 999px;
}

.top-tab {
  background: #0f172a;
  border: 1px solid #1f2937;
  color: #e5e7eb;
  border-radius: 7px;
  padding: 0.26rem 0.48rem;
  font-size: 0.76rem;
  cursor: pointer;
  flex-shrink: 0;
}

.top-tab:hover {
  background: #1e293b;
}

.top-tab.is-active {
  border-color: #38bdf8;
  background: #0b3b57;
  color: #dbeafe;
}

.support-btn,
.contact-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  background: #0f172a;
  border: 1px solid #1f2937;
  color: #e5e7eb;
  border-radius: 7px;
  padding: 0.26rem 0.52rem;
  font-size: 0.74rem;
  font-weight: 600;
  flex-shrink: 0;
}

.support-btn:hover,
.contact-btn:hover {
  background: #1e293b;
  border-color: #38bdf8;
  color: #dbeafe;
}

.year-controls {
  display: flex;
  flex-direction: column;
  gap: 0.24rem;
  font-size: 0.7rem;
  padding: 0.22rem 0.32rem;
  border: 1px solid rgba(56, 189, 248, 0.22);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(2, 6, 23, 0.86), rgba(15, 23, 42, 0.86));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.country-search {
  position: relative;
  display: block;
  flex: 1 1 auto;
  min-width: 220px;
  max-width: 360px;
  margin: 0;
  padding: 0.22rem 0.32rem;
  overflow: visible;
  z-index: 70;
  border: 1px solid rgba(56, 189, 248, 0.22);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(2, 6, 23, 0.86), rgba(15, 23, 42, 0.86));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.country-search input[type="search"] {
  width: 100%;
  background: #020617;
  border: 1px solid #334155;
  color: #f8fafc;
  border-radius: 6px;
  padding: 0.15rem 0.3rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.country-search input[type="search"]::placeholder {
  color: #94a3b8;
}

.country-search-suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
  background: #020617;
  border: 1px solid #1f2937;
  border-radius: 8px;
  /* Up to 20 rows (~0.9rem * ~1.35 line-height + padding); cap by viewport */
  max-height: min(22rem, calc(100vh - 9rem));
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.country-search-suggestions.hidden {
  display: none;
}

.country-search-suggestion-item {
  padding: 0.3rem 0.48rem;
  color: #e5e7eb;
  cursor: pointer;
  font-size: 0.84rem;
}

.country-search-suggestion-item:hover,
.country-search-suggestion-item.active {
  background: #1e293b;
}

.year-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.35rem;
}

.year-controls label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #cbd5f5;
}

.year-input-label {
  margin: 0;
}

.year-label-row input[type="number"] {
  width: 4.35rem;
  background: #020617;
  border: 1px solid #334155;
  color: #f8fafc;
  border-radius: 6px;
  padding: 0.15rem 0.3rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.year-step-buttons {
  display: flex;
  gap: 0.25rem;
}

.year-step-buttons button {
  background: #0f172a;
  color: #dbeafe;
  border: 1px solid #334155;
  border-radius: 6px;
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
}

.year-step-buttons button:hover {
  background: #1e293b;
  border-color: #38bdf8;
}

#yearLabel {
  font-weight: 600;
  color: #38bdf8;
}

#yearRange {
  width: 100%;
  accent-color: #38bdf8;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.tab-content {
  position: relative;
}

.tab-content.hidden {
  display: none;
}

.tab-content.is-active {
  display: block;
}

.tab-content[data-content-id="coffee-shop"].is-active,
.tab-content[data-content-id="library"].is-active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.tab-content[data-content-id="world"].is-active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  position: relative;
  /* Map fills the tab; details panel is absolutely positioned on top (see .details-panel). */
  overflow: hidden;
}

.map-shell {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.map-shell #map {
  flex: 1;
  width: 100%;
  min-height: 0;
  height: auto;
}

/* Historical-basemaps citation over the map (above Mapbox attribution). */
.map-data-citation {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 36px;
  z-index: 10;
  font-size: 0.62rem;
  color: #94a3b8;
  text-align: center;
  line-height: 1.35;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
  pointer-events: none;
}

.map-data-citation a {
  color: #7dd3fc;
  pointer-events: auto;
  text-decoration: none;
}

.map-data-citation a:hover {
  text-decoration: underline;
}

.map-data-citation .map-ai-generated-note {
  display: block;
  margin-top: 0.35em;
}

/* Default: in-flow sidebar (Coffee Shop, Library). World tab overrides below. */
.conflict-cards-panel {
  position: relative;
  flex: 0 0 auto;
  width: 188px;
  min-width: 188px;
  z-index: 1;
  align-self: flex-start;
}

.tab-content[data-content-id="library"] .conflict-cards-panel {
  overflow-x: hidden;
  overscroll-behavior-x: none;
}

.conflict-cards-list {
  display: flex;
  flex-direction: column;
  gap: 0.72rem;
}

.conflict-card {
  width: 100%;
  border: 1px solid #1f2937;
  border-radius: 8px;
  background: #0f172a;
  color: #e5e7eb;
  font-size: 0.92rem;
  text-align: left;
  padding: 0.68rem 0.72rem;
  min-height: 44px;
  cursor: pointer;
}

.conflict-card:hover {
  background: #1e293b;
}

.conflict-card.is-selected,
.conflict-card.is-active {
  border-color: #38bdf8;
  background: #0b3b57;
  color: #dbeafe;
}

.overlay-control {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 31;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.45rem;
}

.overlay-caret {
  min-height: 30px;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  border: 1px solid #1f2937;
  background: rgba(2, 6, 23, 0.9);
  color: #e2e8f0;
  cursor: pointer;
  font-weight: 700;
  line-height: 1.1;
  font-size: 0.8rem;
}

.overlay-caret:hover {
  background: rgba(30, 41, 59, 0.95);
}

.overlay-panel {
  width: 240px;
  border: 1px solid #1f2937;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.95);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.42);
  padding: 0.6rem 0.7rem;
}

.overlay-panel.hidden {
  display: none;
}

.overlay-panel-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #94a3b8;
  margin-bottom: 0.45rem;
}

.overlay-toggle-btn {
  width: 100%;
  border: 1px solid #1f2937;
  border-radius: 8px;
  background: #0f172a;
  color: #e5e7eb;
  font-size: 0.9rem;
  padding: 0.42rem 0.55rem;
  text-align: center;
  cursor: pointer;
}

.overlay-toggle-btn:hover {
  background: #1e293b;
}

.overlay-toggle-btn.is-on {
  background: #0b3b57;
  border-color: #38bdf8;
  color: #dbeafe;
}

.overlay-status {
  margin-top: 0.4rem;
  color: #94a3b8;
  font-size: 0.8rem;
  line-height: 1.3;
}

/* Mapbox popups (border click) */
.mapboxgl-popup-content {
  background-color: #020617 !important; /* near‑pure black */
  color: #f9fafb !important; /* very light text */
  border-radius: 8px;
  border: 1px solid #111827;
  padding: 8px 10px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.8);
}

.mapboxgl-popup-tip {
  border-top-color: #020617 !important;
}

.mapboxgl-popup-content .popup-years {
  font-size: 0.9em;
  color: #94a3b8;
}

.tab-placeholder-card {
  margin: 1rem;
  border: 1px solid #1f2937;
  border-radius: 12px;
  background: #0a1220;
  padding: 1rem;
  max-width: 680px;
}

.tab-placeholder-card h2 {
  margin: 0 0 0.5rem 0;
}

.tab-placeholder-card p {
  margin: 0;
  color: #cbd5f5;
}

.coffee-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
}

.coffee-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  border: 1px solid #1f2937;
  border-radius: 12px;
  background: #0a1220;
  padding: 0.65rem 0.75rem;
}

.coffee-panel > h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.2;
  color: #e2e8f0;
  text-align: center;
}

.coffee-role-toggle {
  margin-top: 0.35rem;
  display: flex;
  gap: 0.3rem;
  justify-content: center;
}

.coffee-role-btn {
  border: 1px solid #1f2937;
  border-radius: 8px;
  background: #0f172a;
  color: #e5e7eb;
  font-size: 0.84rem;
  padding: 0.32rem 0.56rem;
  cursor: pointer;
}

.coffee-role-btn:hover {
  background: #1e293b;
}

.coffee-role-btn.is-active {
  border-color: #38bdf8;
  background: #0b3b57;
  color: #dbeafe;
}

.coffee-loading {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: none;
}

.coffee-loading.hidden {
  display: none;
}

.coffee-loading-spinner,
.details-panel-spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid rgba(148, 163, 184, 0.4);
  border-top-color: #38bdf8;
  animation: coffee-spin 0.85s linear infinite;
}

@keyframes coffee-spin {
  to {
    transform: rotate(360deg);
  }
}

.coffee-status {
  margin-top: 0.6rem;
  color: #94a3b8;
  font-size: 0.9rem;
}

.coffee-leader-hovercard {
  position: fixed;
  z-index: 210;
  width: min(300px, calc(100vw - 24px));
  border: 1px solid #334155;
  border-radius: 12px;
  background: linear-gradient(180deg, #0f172a 0%, #020617 100%);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.65);
  overflow: hidden;
  pointer-events: none;
}

.coffee-leader-hovercard:not([hidden]) {
  pointer-events: auto;
}

.coffee-leader-hovercard.hovercard-opens-source:not([hidden]) {
  cursor: pointer;
}

.coffee-leader-hovercard[hidden] {
  display: none !important;
}

.coffee-leader-hovercard-inner {
  padding: 0.65rem 0.75rem;
  max-height: min(340px, calc(100vh - 32px));
  overflow-y: auto;
  border-left: 3px solid transparent;
}

.coffee-leader-hovercard-inner--green {
  border-left-color: rgba(34, 197, 94, 0.85);
}

.coffee-leader-hovercard-inner--red {
  border-left-color: rgba(248, 113, 113, 0.85);
}

.coffee-leader-hovercard-layout {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
}

.coffee-leader-hovercard-media {
  flex-shrink: 0;
  width: 64px;
  height: 80px;
  border-radius: 6px;
  overflow: hidden;
  background: #0f172a;
  border: 1px solid #334155;
}

.coffee-leader-hovercard-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.coffee-leader-hovercard-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: #64748b;
  background: #0f172a;
}

.coffee-leader-hovercard-body {
  min-width: 0;
  flex: 1;
}

.coffee-leader-hovercard-name {
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.2;
  color: #e2e8f0;
  margin-bottom: 0.35rem;
}

.coffee-leader-hovercard-bio {
  margin: 0 0 0.4rem 0;
  font-size: 0.74rem;
  line-height: 1.45;
  color: #94a3b8;
}

.coffee-leader-hovercard-open-hint {
  margin: 0 0 0.25rem 0;
  font-size: 0.65rem;
  font-weight: 600;
  color: #7dd3fc;
}

.coffee-leader-hovercard-portrait-credit {
  margin: 0.35rem 0 0 0;
  font-size: 0.62rem;
  line-height: 1.4;
  color: #64748b;
}

.coffee-leader-hovercard-portrait-credit-label {
  font-weight: 600;
  color: #94a3b8;
}

.coffee-leader-hovercard-portrait-credit a {
  color: #94a3b8;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.coffee-leader-hovercard-portrait-credit a:hover {
  color: #cbd5e1;
}

.details-source-footer {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #1f2937;
  font-size: 0.72rem;
  line-height: 1.45;
  color: #94a3b8;
}

.details-source-footer p {
  margin: 0 0 0.55rem 0;
}

.details-source-footer p:last-child {
  margin-bottom: 0;
}

.details-source-footer a {
  color: #38bdf8;
  text-decoration: none;
}

.details-source-footer a:hover {
  text-decoration: underline;
}

.library-doc-hovercard {
  position: fixed;
  z-index: 200;
  width: min(300px, calc(100vw - 24px));
  border: 1px solid #334155;
  border-radius: 12px;
  background: linear-gradient(180deg, #0f172a 0%, #020617 100%);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  pointer-events: none;
}

.library-doc-hovercard:not([hidden]) {
  pointer-events: auto;
}

.library-doc-hovercard.hovercard-opens-source:not([hidden]) {
  cursor: pointer;
}

.library-doc-hovercard[hidden] {
  display: none !important;
}

.library-doc-hovercard-inner {
  padding: 0.75rem 0.85rem;
  max-height: min(380px, calc(100vh - 32px));
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.library-doc-hovercard-inner::-webkit-scrollbar {
  display: none;
}

.library-doc-hovercard-kicker {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #38bdf8;
  margin-bottom: 0.35rem;
}

.library-doc-hovercard-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #f1f5f9;
  line-height: 1.25;
  margin-bottom: 0.25rem;
}

.library-doc-hovercard-source {
  font-size: 0.72rem;
  color: #94a3b8;
  margin-bottom: 0.45rem;
}

.library-doc-hovercard-summary {
  margin: 0 0 0.55rem 0;
  font-size: 0.8rem;
  line-height: 1.45;
  color: #cbd5e1;
}

.library-doc-hovercard-footer {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding-top: 0.35rem;
  border-top: 1px solid rgba(51, 65, 85, 0.6);
}

.library-doc-hovercard-hint {
  font-size: 0.7rem;
  color: #7dd3fc;
  font-weight: 600;
}

.library-doc-hovercard-hint--muted {
  color: #94a3b8;
  font-weight: 400;
}

.coffee-video-box {
  margin-top: 0.5rem;
  width: 100%;
  max-width: 860px;
  margin-left: auto;
  margin-right: auto;
  border: 1px solid #1f2937;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  position: relative;
}

.coffee-video {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: block;
  background: #000;
}

.coffee-video-ai-note {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 0.35rem 0.5rem 0.4rem;
  font-size: 0.62rem;
  color: #94a3b8;
  text-align: center;
  line-height: 1.35;
  z-index: 2;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

.coffee-leader-overlay {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(98%, 860px);
  z-index: 2;
  display: flex;
  flex-wrap: nowrap;
  gap: 0.2rem;
  justify-content: center;
  pointer-events: none;
}

.coffee-leader-btn {
  pointer-events: auto;
  flex: 1 1 0;
  min-width: 0;
  border: 1px solid rgba(148, 163, 184, 0.75);
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.72);
  color: #e5e7eb;
  font-size: 0.64rem;
  line-height: 1.1;
  padding: 0.22rem 0.3rem;
  cursor: pointer;
  backdrop-filter: blur(2px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.coffee-leader-btn:hover {
  border-color: #7dd3fc;
  color: #e0f2fe;
}

.coffee-leader-btn--green {
  border-color: rgba(34, 197, 94, 0.85);
  background: rgba(6, 78, 59, 0.82);
  color: #bbf7d0;
}

.coffee-leader-btn--green:hover {
  border-color: #4ade80;
  color: #ecfdf5;
}

.coffee-leader-btn--red {
  border-color: rgba(248, 113, 113, 0.9);
  background: rgba(127, 29, 29, 0.82);
  color: #fecaca;
}

.coffee-leader-btn--red:hover {
  border-color: #f87171;
  color: #fff1f2;
}

.library-layout {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  overflow-x: hidden;
  overscroll-behavior-x: none;
}

.library-shelf-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  border: 1px solid #1f2937;
  border-radius: 12px;
  background: #0a1220;
  padding: 0.65rem 0.75rem;
  overflow-x: hidden;
}

.library-shelf-panel h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.2;
  color: #e2e8f0;
}

.library-shelf-subtitle {
  color: #94a3b8;
  margin: 0.2rem 0 0.45rem 0;
  font-size: 0.78rem;
  line-height: 1.3;
}

.library-doc-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.library-bookshelf-scene {
  overflow-x: hidden;
  min-width: 0;
  border: 1px solid #3f2b1d;
  border-radius: 12px;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 221, 168, 0.08), transparent 35%),
    radial-gradient(circle at 80% 20%, rgba(255, 196, 126, 0.06), transparent 30%),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.015) 0px,
      rgba(255, 255, 255, 0.015) 2px,
      rgba(0, 0, 0, 0.02) 2px,
      rgba(0, 0, 0, 0.02) 7px
    ),
    linear-gradient(180deg, #2a1b12 0%, #1e140d 100%);
  padding: 1.1rem 1rem;
  min-height: 620px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), inset 0 -18px 35px rgba(0, 0, 0, 0.22);
}

.library-shelf-row {
  position: relative;
  margin-bottom: 2.6rem;
  padding-top: 1.45rem;
}

.library-shelf-name {
  position: absolute;
  top: 0;
  left: 8px;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #f3e8d8;
}

/* Books sit above the wooden plank */
.library-books-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
  padding-left: 8px;
  padding-right: 8px;
  margin-bottom: 0;
  min-height: 2.5rem;
  max-width: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
}

.library-shelf-plank {
  height: 16px;
  width: 100%;
  margin-top: 2px;
  border-radius: 9px;
  background:
    linear-gradient(180deg, rgba(255, 224, 179, 0.26) 0%, rgba(255, 224, 179, 0) 30%),
    linear-gradient(180deg, #74482f 0%, #503222 100%);
  box-shadow:
    inset 0 -2px 0 rgba(0, 0, 0, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 2px 3px rgba(0, 0, 0, 0.34);
}

.library-shelf-empty-slot {
  flex: 1 1 auto;
  min-height: 2.5rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.72rem;
  font-style: italic;
  color: rgba(197, 183, 164, 0.65);
}

.library-shelf-empty {
  color: #c5b7a4;
  font-size: 0.78rem;
  opacity: 0.9;
  padding: 0.2rem 0.35rem;
}

.library-book {
  box-sizing: border-box;
  width: 130px;
  max-width: 100%;
  min-height: 96px;
  border: 1px solid rgba(15, 23, 42, 0.72);
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, #415569 0%, #293a4b 100%);
  color: #e2e8f0;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  text-align: center;
  font-size: 0.72rem;
  line-height: 1.15;
  position: relative;
  overflow-x: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow:
    inset 2px 0 0 rgba(255, 255, 255, 0.07),
    inset -1px 0 0 rgba(0, 0, 0, 0.38),
    0 1px 0 rgba(0, 0, 0, 0.45),
    0 5px 7px rgba(0, 0, 0, 0.28);
}

.library-book::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.36);
}

.library-book::after {
  content: "";
  position: absolute;
  top: -2px;
  left: 2px;
  right: 2px;
  height: 3px;
  border-radius: 2px 2px 0 0;
  background: rgba(232, 226, 211, 0.9);
}

.library-book:hover {
  transform: translateY(-2px);
  border-color: #7dd3fc;
}

.library-book.library-book--no-link {
  cursor: default;
  opacity: 0.78;
}

.library-book.library-book--no-link:hover {
  transform: none;
  border-color: rgba(15, 23, 42, 0.72);
}

.library-book.book-variant-0 {
  background: linear-gradient(180deg, #6b2f3d 0%, #4a1f29 100%);
}
.library-book.book-variant-1 {
  background: linear-gradient(180deg, #2f4d69 0%, #213449 100%);
}
.library-book.book-variant-2 {
  background: linear-gradient(180deg, #536a2f 0%, #3a4a22 100%);
}
.library-book.book-variant-3 {
  background: linear-gradient(180deg, #5a3c74 0%, #3d2850 100%);
}
.library-book.book-variant-4 {
  background: linear-gradient(180deg, #6b4a2f 0%, #4a3422 100%);
}
.library-book.book-variant-5 {
  background: linear-gradient(180deg, #3d6a63 0%, #2a4a45 100%);
}
.library-book.book-variant-6 {
  background: linear-gradient(180deg, #6a5b2f 0%, #4b4122 100%);
}
.library-book.book-variant-7 {
  background: linear-gradient(180deg, #3f3f66 0%, #2a2a47 100%);
}


.library-doc-item {
  border: 1px solid #1f2937;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.7);
  padding: 0.7rem;
}

.library-doc-item a {
  color: #7dd3fc;
  font-weight: 600;
  text-decoration: none;
}

.library-doc-item a:hover {
  text-decoration: underline;
}

.library-doc-meta {
  margin-top: 0.2rem;
  color: #94a3b8;
  font-size: 0.84rem;
}

@media (min-width: 768px) {
  /* One row: logo + tabs (left), search + year (right), like the original layout. */
  .header-bar {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    flex-wrap: nowrap;
    /* Do not set overflow here — overflow-x:auto forces overflow-y:auto and clips the country dropdown. */
    overflow: visible;
  }

  .header-primary {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    /* Keep tab row on one line; don’t shrink below logo + tabs (avoids Support wrapping). */
    flex: 0 0 auto;
    flex-shrink: 0;
    min-width: max-content;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
  }

  .brand-logo-wrap {
    flex-shrink: 0;
  }

  .top-tabs {
    flex-wrap: nowrap;
    overflow-x: visible;
  }

  header h1 {
    font-size: 1.1rem;
  }

  .brand-logo {
    height: 48px;
    max-width: min(46vw, 340px);
  }

  .header-world-tools {
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    flex: 1 1 auto;
    margin-left: auto;
    /* Reserve space like the visible search+year strip so flex layout doesn’t change when tab switches. */
    min-width: min(680px, max(48vw, 300px));
    flex-shrink: 1;
  }

  .mobile-world-controls-toggle {
    display: none;
  }

  .mobile-world-tools-body {
    display: contents;
  }

  /* Search sits flush left of year controls; pair stays on the right (margin on search only). */
  .country-search {
    flex: 0 1 auto;
    min-width: 260px;
    max-width: 420px;
    margin: 0;
    margin-left: auto;
  }

  .year-controls {
    flex: 0 0 auto;
    flex-shrink: 0;
    min-width: 0;
    width: 176px;
    max-width: 176px;
    margin-left: 0;
    padding: 0.28rem 0.4rem;
    gap: 0.32rem;
  }

  .year-label-row input[type="number"] {
    width: 4.25rem;
    min-width: 0;
    font-size: 0.8rem;
    padding: 0.18rem 0.34rem;
  }

  .year-step-buttons button {
    width: 26px;
    height: 26px;
    font-size: 0.82rem;
  }

  #yearRange {
    height: 12px;
    min-height: 12px;
  }

  /* World conflict presets: fixed map column (panel lives in header for mobile flow). */
  body.active-tab-world #conflictCardsPanel {
    position: fixed;
    left: 14px;
    top: 138px;
    width: 188px;
    min-width: unset;
    flex: none;
    align-self: unset;
    z-index: 30;
  }
}

.details-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 100%);
  z-index: 25;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(10, 18, 32, 0.97), rgba(5, 7, 10, 0.98));
  border-left: 1px solid #1e2535;
  box-shadow: -8px 0 28px rgba(0, 0, 0, 0.55);
  border-radius: 12px 0 0 12px;
  backdrop-filter: blur(10px);
}

.details-panel.hidden {
  display: none;
}

.details-panel-header {
  flex-shrink: 0;
  padding: 0.85rem 0.9rem;
  border-bottom: 1px solid #1e2535;
}

.details-panel-title {
  min-width: 0;
}

.details-panel-kicker {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #38bdf8;
  margin-bottom: 0.25rem;
}

.details-panel-title h2 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.2;
  color: #e2e8f0;
  word-break: break-word;
}

.details-panel-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0.9rem;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE / legacy Edge */
}

.details-panel-body.is-loading {
  display: flex;
  align-items: center;
  justify-content: center;
}

.details-panel-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
  padding: 1rem;
}

.details-panel-loading-label {
  font-size: 0.88rem;
  color: #94a3b8;
  max-width: 16rem;
  line-height: 1.35;
}

.details-panel-body::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.details-section {
  margin-bottom: 1rem;
}

.details-section-title {
  font-size: 0.85rem;
  color: #94a3b8;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.details-prop-table {
  width: 100%;
  border-collapse: collapse;
}

.details-prop-table td {
  padding: 0.35rem 0;
  vertical-align: top;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.25);
  font-size: 0.9rem;
}

.details-prop-key {
  width: 42%;
  color: #94a3b8;
  padding-right: 0.6rem;
}

.details-prop-val {
  color: #e5e7eb;
  word-break: break-word;
}

.details-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.details-badge {
  border: 1px solid #1f2937;
  background: rgba(2, 6, 23, 0.6);
  border-radius: 999px;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
  color: #cbd5f5;
}

.leader-photo-wrap {
  margin-top: 0.55rem;
}

.leader-photo {
  display: block;
  width: 100%;
  max-width: 240px;
  max-height: 220px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid #1f2937;
  background: #000;
}

.leader-photo-attribution {
  margin-top: 0.3rem;
  font-size: 0.78rem;
  color: #94a3b8;
}

.leader-photo-attribution a {
  color: #38bdf8;
  text-decoration: none;
}

.leader-photo-attribution a:hover {
  text-decoration: underline;
}

@media (min-width: 768px) {
  .coffee-panel > h2 {
    margin-bottom: 0.65rem;
  }

  .coffee-role-toggle {
    margin-top: 0;
    margin-bottom: 0.5rem;
  }

  .coffee-video-box {
    margin-top: 1rem;
  }
}

@media (max-width: 767px) {
  body {
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
  }

  header {
    padding-top: calc(0.55rem + env(safe-area-inset-top, 0px));
    padding-left: calc(0.65rem + env(safe-area-inset-left, 0px));
    padding-right: calc(0.65rem + env(safe-area-inset-right, 0px));
    padding-bottom: 0.55rem;
  }

  .brand-logo {
    height: 56px;
    max-width: min(78vw, 320px);
  }

  .brand-logo-wrap {
    justify-content: center;
  }

  .top-tabs {
    justify-content: center;
  }

  .country-search {
    min-width: 0;
    max-width: none;
    width: 100%;
    order: 2;
    padding: 0.18rem 0.26rem;
  }

  .header-world-tools {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    gap: 0.35rem;
  }

  .mobile-world-tools-body {
    order: 3;
    display: none;
    width: 100%;
    min-width: 0;
  }

  body.mobile-world-controls-open.active-tab-world .mobile-world-tools-body {
    display: block;
  }

  .mobile-world-controls-toggle {
    display: inline-flex;
    order: 2;
    align-self: flex-end;
    height: 38px;
    width: auto;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid #334155;
    background: #0f172a;
    color: #dbeafe;
    font-size: 0.86rem;
    line-height: 1;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    gap: 0.4rem;
  }

  .mobile-world-controls-toggle-year {
    font-weight: 800;
    font-size: 0.86rem;
    color: #e2e8f0;
    letter-spacing: 0.01em;
  }

  .mobile-world-controls-toggle-icon {
    font-size: 0.98rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  body.active-tab-world .mobile-world-controls-toggle {
    position: fixed;
    top: var(--mobile-world-overlay-top, 170px);
    left: auto;
    right: calc(10px + env(safe-area-inset-right, 0px));
    z-index: 45;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
  }

  body.active-tab-world .mobile-world-tools-body {
    position: fixed;
    top: calc(var(--mobile-world-overlay-top, 170px) + 46px);
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    z-index: 44;
    border: 1px solid #1f2937;
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(2, 6, 23, 0.94), rgba(15, 23, 42, 0.96));
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
    width: min(90vw, 390px);
    padding: 0.28rem;
    max-height: min(32vh, 250px);
    max-height: min(32dvh, 250px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  body.active-tab-world .mobile-world-tools-body .country-search {
    padding: 0;
  }

  body.active-tab-world .mobile-world-tools-body .year-controls {
    gap: 0.1rem;
    padding: 0.1rem 0.14rem;
  }

  body.active-tab-world .mobile-world-tools-body .country-search input[type="search"] {
    min-height: 32px;
    padding: 0.14rem 0.22rem;
    font-size: 14px;
  }

  body.active-tab-world .mobile-world-tools-body .year-label-row input[type="number"] {
    min-height: 30px;
    padding: 0.14rem 0.22rem;
    font-size: 0.7rem;
  }

  .mobile-world-controls-toggle:hover {
    background: #1e293b;
    border-color: #38bdf8;
  }

  .mobile-world-controls-toggle:focus-visible {
    outline: 2px solid #38bdf8;
    outline-offset: 2px;
  }

  .header-world-tools .year-controls {
    order: 2;
    gap: 0.1rem;
    padding: 0.12rem 0.18rem;
    font-size: 0.55rem;
  }

  .top-tab,
  .support-btn,
  .contact-btn {
    min-height: 42px;
    padding-top: 0.44rem;
    padding-bottom: 0.44rem;
  }

  .top-tab {
    font-size: 0.76rem;
  }

  .year-step-buttons button {
    min-width: 30px;
    min-height: 30px;
    width: auto;
    height: auto;
  }

  .year-label-row input[type="number"] {
    min-height: 30px;
    padding: 0.16rem 0.24rem;
    font-size: 0.7rem;
  }

  .country-search input[type="search"] {
    min-height: 32px;
    padding: 0.16rem 0.24rem;
    font-size: 14px;
  }

  #yearRange {
    height: 3px;
  }

  .country-search-suggestions {
    max-height: min(18rem, calc(100vh - 11rem));
    max-height: min(18rem, calc(100dvh - 11rem));
  }

  /* World: conflict strip directly below tabs on mobile. */
  body.active-tab-world #conflictCardsPanel {
    order: 1;
    position: relative;
    left: auto;
    right: auto;
    top: auto;
    bottom: auto;
    width: 100%;
    min-width: 0;
    max-width: none;
    z-index: 1;
    flex: 0 0 auto;
    align-self: stretch;
  }

  body.active-tab-world #conflictCardsPanel .conflict-cards-list {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 0.35rem;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 2px 0 4px;
    margin: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  body.active-tab-world #conflictCardsPanel .conflict-cards-list::-webkit-scrollbar {
    display: none;
  }

  body.active-tab-world #conflictCardsPanel .conflict-card {
    flex: 0 0 auto;
    width: auto;
    min-width: 6.8rem;
    max-width: 35vw;
    white-space: normal;
    text-align: center;
    line-height: 1.2;
    font-size: 0.78rem;
    padding: 0.48rem 0.5rem;
    min-height: 34px;
  }

  .map-data-citation {
    bottom: calc(36px + env(safe-area-inset-bottom, 0px));
    font-size: 0.58rem;
    padding: 0 4px;
  }

  .coffee-layout,
  .library-layout {
    flex-direction: column;
    padding: 0.65rem;
    padding-left: calc(0.65rem + env(safe-area-inset-left, 0px));
    padding-right: calc(0.65rem + env(safe-area-inset-right, 0px));
    padding-bottom: calc(0.65rem + env(safe-area-inset-bottom, 0px));
  }

  .coffee-layout .conflict-cards-panel,
  .library-layout .conflict-cards-panel {
    width: 100%;
    min-width: 0;
  }

  .coffee-layout .conflict-cards-list,
  .library-layout .conflict-cards-list {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 0.35rem;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 2px 0 4px;
    margin: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .coffee-layout .conflict-cards-list::-webkit-scrollbar,
  .library-layout .conflict-cards-list::-webkit-scrollbar {
    display: none;
  }

  .coffee-layout .conflict-card,
  .library-layout .conflict-card {
    flex: 0 0 auto;
    width: auto;
    min-width: 6.8rem;
    max-width: 35vw;
    white-space: normal;
    text-align: center;
    line-height: 1.2;
    font-size: 0.78rem;
    padding: 0.48rem 0.5rem;
    min-height: 34px;
  }

  .coffee-role-btn {
    min-height: 34px;
    padding: 0.26rem 0.55rem;
    font-size: 0.78rem;
  }

  .library-bookshelf-scene {
    min-height: min(420px, 52vh);
    min-height: min(420px, 52dvh);
    padding: 0.85rem 0.65rem;
  }

  .library-book {
    width: min(130px, 42vw);
  }

  .details-panel {
    width: 100%;
    left: 0;
    right: 0;
    border-radius: 12px 12px 0 0;
    border-left: none;
    border-top: 1px solid #1e2535;
    top: auto;
    bottom: 0;
    max-height: min(72vh, 100%);
    max-height: min(72dvh, 100%);
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.55);
    z-index: 40;
    will-change: height;
  }

  .details-panel-header {
    cursor: ns-resize;
    touch-action: none; /* allow vertical drag gesture */
  }

  .details-panel {
    transition: height 0.18s ease;
  }

  .details-panel-body {
    padding-bottom: calc(0.9rem + env(safe-area-inset-bottom, 0px));
  }

  .details-panel-body.is-loading {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }

  .map-shell #map {
    flex: 1;
    min-height: min(52vh, 420px);
    min-height: min(52dvh, 420px);
    height: auto;
  }

  .mapboxgl-ctrl-top-right {
    top: calc(8px + env(safe-area-inset-top, 0px)) !important;
    right: calc(8px + env(safe-area-inset-right, 0px)) !important;
    display: none !important;
  }

  .coffee-panel,
  .library-shelf-panel {
    padding: 0.5rem 0.6rem;
  }

  .coffee-panel > h2,
  .library-shelf-panel > h2 {
    font-size: 0.98rem;
  }

  .library-shelf-subtitle {
    margin: 0.12rem 0 0.35rem 0;
    font-size: 0.72rem;
  }

  .coffee-role-toggle {
    margin-top: 0.28rem;
  }

  .coffee-video-box {
    margin-top: 0.4rem;
    /* Mobile: reserve space for the "person" buttons so they sit above the video,
       instead of overlaying it. */
    padding-top: 2.45rem;
  }

  .coffee-video {
    position: relative;
    z-index: 1;
  }

  .coffee-leader-overlay {
    top: 0.55rem;
    z-index: 5;
    flex-wrap: nowrap;
    row-gap: 0;
    justify-content: center;
    width: min(98%, 860px);
    max-width: calc(100vw - 12px);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .coffee-leader-btn {
    flex: 1 1 0;
    min-width: 0;
    max-width: calc(33.333% - 0.1rem);
    min-height: 24px;
    font-size: 0.52rem;
    padding: 0.14rem 0.12rem;
    white-space: nowrap;
    line-height: 1;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

