:root {
  --ground: #0E0F11;
  --text: #ECEDEE;
  --muted: #A3A9B0;
  --soft: #C3C8CD;
  --hairline: rgba(255, 255, 255, .12);
  --line: #23272C;
  --line-strong: #3A3F45;
  --surface: #14161A;
  --surface-hover: #1F2328;
  --art-ground: #0B0C0E;
  --dialog: #191C20;
  --accent: #4FA3FF;
  --link: #8FC3FF;
  --mono: "Roboto Mono", ui-monospace, monospace;
  /* Open decision in the plan: set to 0 if dialogs should be square too. */
  --dialog-radius: 8px;
  --gap: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font-family: Roboto, system-ui, sans-serif;
  font-weight: 300;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--link); }
a:hover { color: #BFDCFF; }

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

[hidden] { display: none !important; }

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

/* Header */
.site-header {
  max-width: 1240px;
  margin: 0 auto;
  padding: 36px 32px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.brand {
  margin: 0;
  font-weight: 700;
  font-size: 34px;
  letter-spacing: .14em;
  text-transform: uppercase;
  text-align: center;
}
.brand-line { width: min(560px, 80%); height: 1px; background: var(--accent); opacity: .6; }
.brand-sub { margin: 0; font-size: 14px; color: var(--muted); text-align: center; letter-spacing: .02em; }

/* Book row: muted at rest, full color on hover. */
.navy { background: #132240; }
.red { background: #451515; }
.ochre { background: #6B5116; }
.books {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--hairline);
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
}
.book {
  appearance: none;
  border: 0;
  padding: 0 16px;
  margin: 0;
  min-width: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  height: 470px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  transition: background-color .3s ease;
}
.book:focus-visible { outline-offset: -4px; }
.book.navy { background: #12161E; }
.book.navy:hover, .book.navy:focus-visible { background: #1B3363; }
.book.red { background: #1B1416; }
.book.red:hover, .book.red:focus-visible { background: #6A1E1E; }
.book.ochre { background: #1C1812; }
.book.ochre:hover, .book.ochre:focus-visible { background: #8F6C1D; }
.cover {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 390px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .4);
  transition: transform .3s ease, box-shadow .3s ease;
}
.book:hover .cover, .book:focus-visible .cover {
  transform: scale(1.05);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .5);
}
.book-title { font-size: 16px; font-weight: 400; color: #F3F4F5; text-align: center; }

/* Files */
.files {
  max-width: 1240px;
  margin: 0 auto;
  padding: 40px 32px 64px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.files-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.files-title { margin: 0; font-weight: 700; font-size: 15px; letter-spacing: .14em; text-transform: uppercase; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  appearance: none;
  cursor: pointer;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: transparent;
  color: #DADDE0;
  font: inherit;
  font-size: 13px;
}
.chip:hover { border-color: #8A9097; }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: #111; font-weight: 400; }

.search {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 44px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line-strong);
}
.search:focus-within { border-bottom-color: var(--accent); }
.search input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text);
  font: inherit;
  font-size: 16px;
}
.search input::placeholder { color: #7D838A; }
.search input::-webkit-search-cancel-button { display: none; }
.count { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }

.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid #23476F;
  color: #CFE3FF;
  font-size: 14px;
}
.notice svg { flex: none; }
.notice span { flex: 1; }
.notice button {
  appearance: none;
  border: 0;
  padding: 0 8px;
  min-height: 32px;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
}

.grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--gap); }
.empty { margin: 32px 0; text-align: center; color: var(--muted); font-size: 14px; }

.tile {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  height: 268px;
  padding: 10px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform .2s ease, background-color .2s ease, border-color .2s ease;
}
.tile:hover, .tile:focus-visible {
  background: var(--surface-hover);
  border-color: #4A5057;
  transform: scale(1.03);
}
.tile-art {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 8px;
  background: var(--art-ground);
  display: flex;
  align-items: center;
  justify-content: center;
}
.tile-art img { display: block; width: 100%; height: 100%; object-fit: contain; }
.tile-art img[src*="/logos/"] { width: 72%; height: 72%; }
.tile-art svg { width: 132px; height: 132px; max-width: 100%; max-height: 100%; }
.tile-3d {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  background: var(--art-ground);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
}
.tile-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 0 2px; }
.tile-name {
  font-size: 13px;
  font-weight: 400;
  line-height: 1.25;
  min-height: 2.5em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tile-meta { font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* Dialogs: books and items */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(5, 6, 8, .88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}
.dialog {
  width: min(980px, 100%);
  max-height: 100%;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--dialog-radius);
  background: var(--dialog);
  display: flex;
  flex-wrap: wrap;
}
.dialog-body { flex: 1 1 340px; min-width: 0; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.dialog-title { flex: 1; margin: 0; padding-top: 6px; font-size: 24px; font-weight: 700; line-height: 1.2; }
.card-head { display: flex; align-items: flex-start; gap: 12px; }
.card-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; padding-top: 4px; }
.card-titles .dialog-title { padding-top: 0; flex: none; }
.card-cat { font-family: var(--mono); font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.card-meta { font-family: var(--mono); font-size: 12px; color: #C9CDD2; }
.card-desc { margin: 0; font-size: 15px; line-height: 1.6; color: var(--soft); }
.card-links { display: flex; flex-direction: column; gap: 6px; font-size: 13px; line-height: 1.35; }
.card-download { margin-top: auto; }

.book-card-cover {
  flex: 1 1 320px;
  min-height: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.book-card-cover img { display: block; width: auto; height: auto; max-width: 100%; max-height: 420px; box-shadow: 0 10px 24px rgba(0, 0, 0, .4); }
.book-card-tagline { margin: 0; font-size: 16px; font-weight: 400; line-height: 1.45; color: var(--text); }
.book-card-desc { font-size: 14px; line-height: 1.6; color: var(--soft); }
.book-card-desc p { margin: 0 0 10px; }
.book-card-desc p:last-child { margin-bottom: 0; }
.book-card-meta { font-family: var(--mono); font-size: 12px; color: #C9CDD2; line-height: 1.5; }
.book-card-actions { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.book-card-row { display: flex; flex-wrap: wrap; gap: 8px; }
.book-card-row .btn { flex: 1 1 140px; }
/* With a two-part bonus, the parts sit side by side under the PDF button. */
.book-card-row .btn:first-child:nth-last-child(3) { flex-basis: 100%; }
/* On one line when it fits. Otherwise the label sits over the size, with no separator. */
.btn-bonus { container-type: inline-size; }
.bonus-label { display: flex; justify-content: center; white-space: pre; line-height: 1.25; }
@container (max-width: 175px) {
  .bonus-label { flex-direction: column; padding: 4px 0; }
  .bonus-sep { display: none; }
}

/* 3D viewer and item image */
.viewer {
  flex: 1 1 460px;
  min-width: 0;
  min-height: 460px;
  background: var(--art-ground);
  display: flex;
  flex-direction: column;
}
.viewer-stage { position: relative; flex: 1; min-height: 340px; padding: 20px; display: flex; align-items: center; justify-content: center; }
.viewer-poster { display: block; max-width: 100%; max-height: 460px; object-fit: contain; }
.viewer-poster[src*="/logos/"] { width: 240px; height: 240px; }
.viewer-art svg { display: block; width: 240px; height: 240px; }
.viewer-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
  outline-offset: -2px;
}
.viewer-canvas.is-dragging { cursor: grabbing; }
.viewer.is-ready .viewer-poster { visibility: hidden; }
.viewer.is-failed .viewer-canvas { display: none; }
.viewer-status { min-height: 18px; padding: 0 16px 8px; text-align: center; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.viewer-loading, .viewer.is-loading .viewer-hint, .viewer.is-failed .viewer-status { display: none; }
.viewer.is-loading .viewer-loading { display: inline; }
.viewer-parts { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 0 16px 16px; }

.icon-btn {
  appearance: none;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  flex: none;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #C9CDD2;
}
.icon-btn:hover { color: #fff; }

.video {
  appearance: none;
  border: 0;
  padding: 0;
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--art-ground);
  cursor: pointer;
  overflow: hidden;
  flex: none;
}
.video img { display: block; width: 100%; height: 100%; object-fit: cover; opacity: .8; transition: opacity .2s ease; }
.video:hover img { opacity: 1; }
.video-play {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  background: rgba(11, 12, 14, .7);
  border: 1px solid var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-frame { display: block; flex: none; width: 100%; aspect-ratio: 16 / 9; border: 0; background: var(--art-ground); }

.btn {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  border-radius: 0;
  font: inherit;
  font-size: 14px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  appearance: none;
  flex: none;
}
.btn-primary { border: 0; background: var(--text); color: #111; font-weight: 500; }
.btn-primary:hover { background: #fff; color: #111; }
.btn-line { border: 1px solid #4A4F55; background: none; color: var(--text); font-weight: 400; }
.btn-line:hover { border-color: #8A9097; color: #fff; }
.btn[aria-disabled="true"] { color: #7D838A; border-color: var(--line); cursor: not-allowed; }

/* Reader */
.reader {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(5, 6, 8, .97);
  display: flex;
  flex-direction: column;
}
.reader-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}
.reader-title { flex: 1; min-width: 0; font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-count { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.reader-bar .btn { min-height: 36px; font-size: 13px; }
.reader-zoom { display: flex; gap: 4px; }
.reader-zoom button { width: 36px; height: 36px; border: 1px solid var(--line-strong); }
.reader-body { flex: 1; min-height: 0; display: flex; align-items: center; gap: 16px; padding: 16px; }
.reader-nav { flex: none; width: 44px; height: 44px; border: 1px solid var(--line-strong); color: var(--text); }
.reader-nav:disabled { color: #4A4F55; border-color: var(--line); cursor: default; }
.reader-stage { flex: 1; min-width: 0; height: 100%; overflow: auto; display: flex; }
.reader-pages { margin: auto; display: flex; gap: 2px; }
.reader-pages canvas { display: block; background: #F2EFE8; }
.reader-status { margin: auto; color: var(--muted); font-size: 14px; text-align: center; }

/* Footer */
.site-footer {
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 32px 36px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: #8E949B;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

@media (max-width: 1100px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .book { height: 400px; }
  .cover { max-height: 320px; }
}

/* Phones: dialogs take the whole screen. */
@media (max-width: 700px) {
  .site-header { padding: 28px 16px 18px; }
  .brand { font-size: 20px; }
  .brand-line { width: 240px; }
  .books {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: 190px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .book { height: 280px; gap: 10px; padding: 0 12px; }
  .cover { max-height: 220px; }
  .book-title { font-size: 12px; }
  .files { padding: 20px 16px 40px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .tile { height: 214px; padding: 8px; gap: 8px; }
  .tile-art { padding: 4px; }
  .tile-art svg { width: 96px; height: 96px; }
  .tile:hover { transform: none; }
  .site-footer { padding: 20px 16px 28px; }
  .modal { padding: 0; align-items: stretch; }
  .dialog { width: 100%; height: 100%; max-height: none; border: 0; border-radius: 0; align-content: flex-start; }
  .dialog-body { flex-basis: 100%; padding: 16px; }
  .dialog-title { font-size: 20px; }
  .book-card-cover { flex-basis: 100%; min-height: 220px; }
  .book-card-cover img { max-height: 190px; }
  .viewer { flex-basis: 100%; min-height: 0; }
  .viewer-stage { min-height: 300px; height: 44vh; }
  .viewer-poster { max-height: 100%; }
  .reader-body { padding: 8px; gap: 8px; }
  .reader-nav { position: absolute; bottom: 8px; z-index: 1; background: rgba(5, 6, 8, .8); }
  .reader-nav.prev { left: 8px; }
  .reader-nav.next { right: 8px; }
  .reader-stage { padding-bottom: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
