:root {
  --bg: #ffffff;
  --text: #202122;
  --muted: #54595d;
  --box: #f8f9fa;
  --border: #a2a9b1;
  --rule: #eaecf0;
  --link: #3366cc;
  --visited: #795cb2;
  --placeholder: #eaecf0;
  --font: -apple-system, "Segoe UI", Roboto, Lato, Helvetica, Arial, sans-serif;
  --serif: "Linux Libertine", Georgia, Times, serif;
}

:root[data-theme="dark"] {
  --bg: #101418;
  --text: #eaecf0;
  --muted: #a2a9b1;
  --box: #202122;
  --border: #54595d;
  --rule: #27292d;
  --link: #88a3e8;
  --visited: #a799cd;
  --placeholder: #27292d;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101418;
    --text: #eaecf0;
    --muted: #a2a9b1;
    --box: #202122;
    --border: #54595d;
    --rule: #27292d;
    --link: #88a3e8;
    --visited: #a799cd;
    --placeholder: #27292d;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

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

/* ---------- thin navbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 6px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

.topbar button,
.topbar nav a {
  font: inherit;
  background: none;
  border: 0;
  padding: 2px 8px;
  color: var(--link);
  cursor: pointer;
}

.topbar button:hover { text-decoration: underline; }

.topbar button.active {
  color: var(--text);
  font-weight: bold;
  border-bottom: 2px solid var(--link);
}

.topbar .brand {
  font-family: var(--serif);
  font-size: 18px;
  color: var(--text) !important;
  margin-right: 8px;
}

.hatnote {
  margin: 10px 16px 0;
  padding-left: 1.6em;
  font-style: italic;
  color: var(--muted);
}

/* ---------- collage ---------- */
#collage {
  position: relative;          /* boxes are placed by wiki.js (see layout()) */
  margin: 12px 16px 32px;
}

/* hide boxes until they've been placed, then let filter/resize moves glide */
#collage:not(.ready) .infobox { visibility: hidden; }
/* moves (filter, resize, late images) glide with a soft settle; hover eases out slower than it eases in.
   z-index waits for the shrink to finish, so a card never snaps behind its neighbours mid-animation */
#collage.ready .infobox {
  transition:
    top .45s cubic-bezier(.22, 1, .36, 1),
    left .45s cubic-bezier(.22, 1, .36, 1),
    transform .28s cubic-bezier(.22, 1, .36, 1),
    box-shadow .28s ease,
    border-color .28s ease,
    z-index 0s linear .28s;
}

/* hover: lift the card toward the reader so it's obvious which one you're on */
@media (hover: hover) {
  #collage.ready .infobox:hover {
    z-index: 5;
    transform: translateY(-5px) scale(1.02);
    border-color: var(--link);
    box-shadow: 0 14px 30px rgba(0, 0, 0, .18), 0 3px 8px rgba(0, 0, 0, .10);
    transition:
      top .45s cubic-bezier(.22, 1, .36, 1),
      left .45s cubic-bezier(.22, 1, .36, 1),
      transform .18s cubic-bezier(.22, 1, .36, 1),
      box-shadow .18s ease,
      border-color .18s ease,
      z-index 0s;
  }
}
@media (prefers-reduced-motion: reduce) {
  #collage.ready .infobox:hover { transform: none; }
}

.infobox {
  position: absolute;
  z-index: 1;
  background: var(--box);
  border: 1px solid var(--border);
  padding: 3px;
  overflow-wrap: anywhere;
}

@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

.infobox.hidden { display: none; }

.infobox .title {
  margin: 0;
  padding: 4px 6px 6px;
  text-align: center;
  font-size: 125%;
  font-weight: bold;
  line-height: 1.3;
}

.infobox .title.italic { font-style: italic; }

.infobox figure { margin: 0 0 4px; text-align: center; }

.infobox img,
.infobox .noimg {
  display: block;
  width: 100%;
}

.infobox img { height: auto; }

.infobox .default-img {
  display: block;
  width: 100%;
  max-height: 200px;
  background: var(--placeholder);
  color: var(--border);
}

.infobox .noimg {
  display: grid;
  place-items: center;
  background: var(--placeholder);
  color: var(--muted);
  font-size: 12px;
}

.infobox figcaption {
  padding: 4px 6px;
  font-size: 95%;
  line-height: 1.4;
}

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

.infobox th,
.infobox td {
  padding: 3px 6px;
  vertical-align: top;
  text-align: left;
}

.infobox th { width: 38%; font-weight: bold; }

.infobox .head-band {
  background: var(--rule);
  text-align: center;
  font-size: 90%;
  font-weight: bold;
  padding: 2px;
  text-transform: capitalize;
}

sup.cn,
sup.ref { font-size: 75%; white-space: nowrap; }

.infobox .map { padding: 4px 3px 2px; text-align: center; font-size: 85%; }

.infobox .map iframe {
  display: block;
  width: 100%;
  height: 180px;
  border: 1px solid var(--border);
  margin-bottom: 2px;
}

.infobox.flash { outline: 3px solid var(--link); }

@media (max-width: 560px) {
  .topbar { flex-direction: column; align-items: flex-start; }
}

/* logos: a centred square, same size whatever the box width */
.infobox img.logo {
  width: 55%;
  max-width: 180px;
  aspect-ratio: 1;
  object-fit: contain;
  margin: 6px auto;
}

/* ---------- thin footer, matches the navbar ---------- */
.bottombar {
  padding: 6px 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}

/* book covers: smaller and centred, like a real infobox */
.infobox img.cover {
  width: 50%;
  max-width: 170px;
  margin: 6px auto;
  border: 1px solid var(--border);
}

/* YouTube embeds keep a 16:9 shape */
.infobox .video { position: relative; aspect-ratio: 16 / 9; background: #000; }
.infobox .video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* wide logos on a coloured background (e.g. NYU banners): give them breathing room */
.infobox figure img[style*="background"]:not(.logo) { padding: 10px 12px; box-sizing: border-box; }

/* ---------- phones: compact tiles (picture + title), tap one to open the full card ---------- */
.infobox .vthumb { display: none; }

#collage.compact .infobox { cursor: pointer; -webkit-tap-highlight-color: transparent; }
#collage.compact .infobox figcaption,
#collage.compact .infobox table,
#collage.compact .infobox .map,
#collage.compact .infobox .video { display: none; }
#collage.compact .infobox .vthumb { display: block; aspect-ratio: 16 / 9; object-fit: cover; }
#collage.compact .infobox .title { font-size: 100%; padding: 3px 4px 4px; }
#collage.compact .infobox figure { margin: 0; }
#collage.compact .infobox img:not(.logo):not(.cover) { max-height: 150px; object-fit: cover; }
#collage.compact .infobox img.logo { width: 60%; margin: 4px auto; }
#collage.compact .infobox img.cover { width: 60%; margin: 4px auto; }
#collage.compact .infobox .default-img { max-height: 90px; }
#collage.compact .infobox .noimg { height: 90px !important; }
#collage.compact.ready .infobox:active { transform: scale(.96); transition-duration: .1s; }
#collage .infobox.lifted { visibility: hidden; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: rgba(0, 0, 0, .45);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.lightbox .infobox.expanded {
  position: relative;
  width: min(100%, 440px);
  max-height: calc(100dvh - 48px);
  overflow: auto;
  overscroll-behavior: contain;
  transform-origin: top left;
  box-shadow: 0 28px 70px rgba(0, 0, 0, .4);
  will-change: transform, clip-path;
}
