/* ----------  Design tokens  ---------- */
:root {
  --accent: #c4633a;
  --accent-light: #f0d9cc;
  --accent-dark: #9c4a28;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --bg: #fafaf8;
  --surface: #ffffff;
  --border: #e2e2de;
  --border-hover: #c4c4c0;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.1);
  --transition: 0.18s ease;
  --max-width: 1200px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Consolas", monospace;
}

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

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ----------  Header  ---------- */
.site-header {
  padding: 3rem 0 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.site-header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin-top: 0.75rem;
  color: var(--text-muted);
  font-size: 1.05rem;
  max-width: 65ch;
}

/* ----------  Controls bar  ---------- */
.controls-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
}

.controls-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

#search-input {
  flex: 1 1 240px;
  min-width: 0;
  font-family: var(--font);
  font-size: 0.95rem;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  transition: border-color var(--transition);
}

#search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.control-field {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.control-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

#sort-select {
  font-family: var(--font);
  font-size: 0.85rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
}

.view-btn {
  font-family: var(--font);
  font-size: 0.82rem;
  padding: 0.4rem 0.75rem;
  border: 0;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.view-btn + .view-btn {
  border-left: 1px solid var(--border);
}

.view-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ----------  Filter panel  ---------- */
.filter-panel {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0 0.9rem;
}

.facet-groups {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.facet-group {
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.45rem;
}

.facet-group:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.facet-summary {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.4rem 0;
  user-select: none;
  list-style-position: outside;
}

.facet-summary:hover {
  color: var(--text);
}

.facet-selected:not(:empty) {
  display: inline-block;
  margin-left: 0.4rem;
  min-width: 1.1rem;
  padding: 0 0.3rem;
  border-radius: 100px;
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  text-align: center;
  letter-spacing: 0;
}

.facet-group .chips {
  padding: 0.15rem 0 0.35rem;
}

.chip.empty {
  opacity: 0.35;
  cursor: default;
}

/* ----------  Layout  ---------- */
.main-layout {
  padding-top: 2rem;
  padding-bottom: 4rem;
}

/* ----------  Clear button  ---------- */
.clear-btn {
  flex-shrink: 0;
  font-family: var(--font);
  font-size: 0.82rem;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.clear-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ----------  Chips  ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-width: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.82rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  white-space: normal;
  word-break: break-word;
  line-height: 1.35;
}

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

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.chip .chip-count {
  font-size: 0.7rem;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}


/* ----------  Results bar  ---------- */
.results-bar {
  margin-bottom: 1rem;
}

.result-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ----------  Card grid  ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}

/* ----------  Card  ---------- */
.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem 1.25rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow var(--transition), border-color var(--transition);
  /* Skip layout and paint for off-screen cards — the whole point at 160 entries. */
  content-visibility: auto;
  contain-intrinsic-size: auto 260px;
}

.card:hover {
  box-shadow: var(--shadow-hover);
  border-color: var(--border-hover);
}

.card:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.card-name {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-top: 0.5rem;
}

.card-region {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0.3rem 0 0.55rem;
}

.card-description {
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 0.85rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-video-flag {
  align-self: flex-start;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-dark);
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.4rem;
  margin-bottom: 0.6rem;
}

/* ----------  Kind tag  ---------- */
.kind-tag {
  align-self: flex-start;
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  white-space: nowrap;
}

.kind-ecosystem  { color: #2f6f4f; border-color: #cbe3d6; background: #eef7f2; }
.kind-enterprise { color: #2b5c86; border-color: #cbdcea; background: #eef4f9; }
.kind-model      { color: #7a4a99; border-color: #ddd0e8; background: #f5eff9; }
.kind-policy     { color: #9c4a28; border-color: var(--accent-light); background: #fbf0ea; }
.kind-method     { color: #8a6414; border-color: #e8dcbe; background: #f9f4e6; }
.kind-tool       { color: #446; border-color: #d5d5e0; background: #f0f0f5; }

/* ----------  List view  ---------- */
.list-view {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.list-head,
.list-row {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) auto minmax(0, 1.4fr) 4.5rem minmax(0, 1.4fr);
  gap: 0.75rem;
  align-items: center;
  padding: 0.6rem 1rem;
  text-align: left;
}

.list-head {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.list-row {
  width: 100%;
  font-family: var(--font);
  font-size: 0.87rem;
  color: var(--text);
  background: var(--surface);
  border: 0;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}

.list-row:first-of-type {
  border-top: 0;
}

.list-row:hover,
.list-row:focus-visible {
  background: var(--bg);
  outline: none;
}

.list-name {
  font-weight: 600;
}

.list-region,
.list-year,
.list-mech {
  color: var(--text-muted);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-year {
  font-variant-numeric: tabular-nums;
}

/* ----------  Card video  ---------- */
.card-video {
  margin-bottom: 0.85rem;
}

.video-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--border);
}

.video-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.video-play {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.video-play img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Play badge */
.video-play::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 48px;
  height: 48px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--accent) center/14px 16px no-repeat;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 16'%3E%3Cpath fill='%23fff' d='M2 1.5v13l11-6.5z'/%3E%3C/svg%3E");
  opacity: 0.88;
  transition: opacity var(--transition), transform var(--transition);
}

.video-play:hover::after {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.08);
}

.video-play:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 3px var(--accent);
}

.video-caption {
  margin-top: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ----------  Leverage badges  ---------- */
.leverages {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.75rem;
  align-content: flex-start;
  min-width: 0;
}

.leverage-badge {
  display: inline-block;
  font-size: 0.76rem;
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-sm);
  background: var(--accent-light);
  color: var(--accent-dark);
  border: 1px solid transparent;
  max-width: 100%;
  white-space: normal;
  word-break: break-word;
  line-height: 1.3;
}

.leverage-label {
  display: inline;
}

.leverage-badge .strength-dots {
  display: inline-block;
  white-space: nowrap;
  margin-left: 0.3rem;
  vertical-align: middle;
}

.strength-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.35;
  margin-left: 2px;
}

.strength-dot.filled {
  opacity: 1;
}

.leverage-more {
  display: inline-block;
  font-size: 0.76rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-hover);
  color: var(--text-muted);
  line-height: 1.3;
}

/* ----------  Detail modal  ---------- */
.detail-modal {
  width: min(680px, calc(100vw - 2rem));
  max-height: min(86vh, 900px);
  /* The universal `margin: 0` in the reset above kills the UA stylesheet's
     `margin: auto` on dialog:modal, which is what centres it against inset: 0. */
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.22);
  overflow: visible;
}

.detail-modal::backdrop {
  background: rgba(20, 18, 16, 0.45);
}

.modal-body {
  padding: 1.75rem;
  overflow-y: auto;
  max-height: min(86vh, 900px);
}

.modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  z-index: 1;
  width: 2rem;
  height: 2rem;
  font-size: 1.4rem;
  line-height: 1;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.modal-close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.detail-title {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0.6rem 0 0.25rem;
  padding-right: 2rem;
}

.detail-title a {
  color: var(--text);
}

.detail-title a:hover {
  color: var(--accent);
  text-decoration: none;
}

.detail-region {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.9rem;
}

.detail-description {
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: 0.75rem;
}

.detail-scope {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.55;
  padding-left: 0.85rem;
  border-left: 2px solid var(--accent-light);
  margin-bottom: 1rem;
}

.detail-domains {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
}

.detail-domain {
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 100px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

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

.detail-section h4 {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.detail-leverages,
.detail-links {
  list-style: none;
}

.detail-leverage {
  padding: 0.7rem 0;
  border-top: 1px solid var(--border);
}

.detail-leverage:first-child {
  border-top: 0;
  padding-top: 0;
}

.detail-leverage-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.detail-leverage-name {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--accent-dark);
}

.detail-leverage-desc {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text);
}

.detail-links li {
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.detail-relateds {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.detail-related {
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 0.28rem 0.65rem;
  border-radius: 100px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
}

.detail-related:hover,
.detail-related:focus-visible {
  border-color: var(--accent);
  color: var(--accent-dark);
  outline: none;
}

/* ----------  Empty state  ---------- */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ----------  Crosswalk  ---------- */
.crosswalk {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 3rem 0;
}

.crosswalk-heading {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.crosswalk-intro {
  color: var(--text-muted);
  font-size: 1rem;
  max-width: 65ch;
  margin-bottom: 2rem;
}

.crosswalk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

.crosswalk-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  background: var(--bg);
}

.crosswalk-concept {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.65rem;
  color: var(--accent-dark);
}

.crosswalk-ecosystems {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.crosswalk-ecosystem {
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  border-radius: 100px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

/* ----------  Footer  ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  text-align: center;
}

.site-footer p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ----------  Narrow screens  ---------- */
@media (max-width: 720px) {
  .site-header {
    padding: 2rem 0 1.5rem;
  }

  .controls-inner {
    gap: 0.5rem;
  }

  #search-input {
    flex: 1 1 100%;
  }

  .result-count {
    margin-left: auto;
  }

  /* The list grid collapses to name + kind; the rest moves into the modal. */
  .list-head {
    display: none;
  }

  .list-row {
    grid-template-columns: minmax(0, 1fr) auto;
    row-gap: 0.25rem;
  }

  .list-row .list-region {
    grid-column: 1 / -1;
  }

  .list-row .list-year,
  .list-row .list-mech {
    display: none;
  }

  .modal-body {
    padding: 1.25rem;
  }
}
