:root {
  --library-ink: #212529;
  --library-muted: #6c757d;
  --library-border: #dee2e6;
  --library-amber: #b45309;
  --library-amber-soft: rgba(245, 158, 11, 0.14);
  --library-paper: #fffdf8;
  --library-mat: #ece8df;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

body {
  margin: 0;
  background: #f8f9fa;
  color: var(--library-ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.foxchase-site-header {
  position: relative;
  z-index: 3000;
  width: 100%;
  background: #fff;
  border-bottom: 1px solid var(--library-border);
}

.foxchase-header-wrap {
  position: relative;
  min-height: 66px;
  padding: 0 12px;
  display: flex;
  align-items: center;
}

.foxchase-brand {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
  color: var(--library-ink);
  text-decoration: none;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.foxchase-brand:hover { color: var(--library-amber); }
.foxchase-brand-logo { width: 42px; height: 42px; object-fit: contain; flex: 0 0 42px; }
.foxchase-main-nav { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }

.foxchase-navigation {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid var(--library-border);
  border-radius: 999px;
  box-shadow: 0 .125rem .25rem rgba(0, 0, 0, .2);
}

.foxchase-navigation a {
  display: block;
  color: #495057;
  text-decoration: none;
  font-size: .92rem;
  font-weight: 500;
  line-height: 1.4;
  padding: 8px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.foxchase-navigation a:hover { color: #111; background: #f1f3f5; }
.foxchase-navigation a.active { color: var(--library-amber); background: var(--library-amber-soft); font-weight: 700; }
.foxchase-menu-toggle { display: none; }

.library-main { width: min(1280px, calc(100% - 32px)); margin: 0 auto; padding: 64px 0 76px; }
.library-hero { max-width: 850px; margin: 0 auto 38px; text-align: center; }
.library-kicker { margin: 0 0 10px; color: var(--library-amber); font-size: .8rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.library-hero h1 { margin: 0 0 14px; color: #0f1c3f; font-size: clamp(2.15rem, 5vw, 4.1rem); line-height: 1.05; letter-spacing: -.035em; }
.library-subtitle { margin: 0 auto 12px; max-width: 760px; color: #495057; font-size: clamp(1.05rem, 2vw, 1.3rem); line-height: 1.55; }
.library-physical-note { margin: 0; color: var(--library-muted); font-size: .96rem; }

.library-tools {
  margin: 0 0 30px;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--library-border);
  border-radius: 16px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .045);
}

.library-filter-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 16px; }
.library-filter {
  min-height: 40px;
  padding: 8px 13px;
  border: 1px solid #ced4da;
  border-radius: 999px;
  background: #fff;
  color: #495057;
  font: inherit;
  font-size: .9rem;
  font-weight: 650;
  cursor: pointer;
}
.library-filter:hover { border-color: #adb5bd; background: #f8f9fa; }
.library-filter[aria-pressed="true"] { border-color: #f59e0b; background: var(--library-amber-soft); color: var(--library-amber); }

.library-tool-row { display: grid; grid-template-columns: minmax(220px, 1fr) auto auto; gap: 12px; align-items: center; max-width: 850px; margin: 0 auto; }
.library-search-wrap { position: relative; }
.library-search-icon { position: absolute; left: 14px; top: 50%; color: #868e96; transform: translateY(-50%); pointer-events: none; }
.library-search {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px 10px 42px;
  border: 1px solid #ced4da;
  border-radius: 10px;
  background: #fff;
  color: var(--library-ink);
  font: inherit;
}
.library-random {
  min-height: 46px;
  padding: 10px 17px;
  border: 1px solid #d97706;
  border-radius: 10px;
  background: #f59e0b;
  color: #23170a;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  white-space: nowrap;
}
.library-random:hover { background: #fbbf24; }
.library-random:disabled { opacity: .5; cursor: not-allowed; }
.library-result-count { min-width: 68px; color: var(--library-muted); font-size: .88rem; text-align: right; }

.library-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 24px; }
.library-card { min-width: 0; }
.library-card-trigger {
  width: 100%;
  height: 100%;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--library-border);
  border-radius: 16px;
  background: var(--library-paper);
  color: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 4px 13px rgba(28, 25, 23, .06);
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.library-photo-frame { display: grid; place-items: center; width: 100%; aspect-ratio: 3 / 4; padding: 12px; overflow: hidden; background: var(--library-mat); border-bottom: 1px solid #d8d2c6; }
.library-photo { display: block; width: 100%; height: 100%; object-fit: contain; }
.library-card-copy { display: flex; flex: 1; flex-direction: column; padding: 17px; }
.library-card-title { display: block; margin-bottom: 6px; color: #0f1c3f; font-size: 1.05rem; font-weight: 800; line-height: 1.3; }
.library-card-author { display: block; margin-bottom: 14px; color: var(--library-muted); font-size: .89rem; line-height: 1.45; }
.library-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.library-tag { display: inline-flex; align-items: center; min-height: 25px; padding: 4px 8px; border-radius: 999px; background: #f1f3f5; color: #555d65; font-size: .72rem; font-weight: 700; line-height: 1.25; }
.library-empty { margin: 36px 0 0; padding: 34px; border: 1px dashed #adb5bd; border-radius: 14px; color: var(--library-muted); text-align: center; }

.book-dialog { width: min(920px, calc(100% - 28px)); max-height: min(820px, calc(100dvh - 28px)); padding: 0; overflow: hidden; border: 0; border-radius: 18px; background: #fff; box-shadow: 0 28px 80px rgba(0, 0, 0, .32); }
.book-dialog::backdrop { background: rgba(12, 18, 32, .72); backdrop-filter: blur(3px); }
.book-dialog-close { position: absolute; z-index: 2; top: 12px; right: 12px; width: 42px; height: 42px; border: 1px solid rgba(255, 255, 255, .55); border-radius: 50%; background: rgba(17, 24, 39, .78); color: #fff; font-size: 1.4rem; line-height: 1; cursor: pointer; }
.book-dialog-layout { display: grid; grid-template-columns: minmax(300px, 1.05fr) minmax(280px, .95fr); min-height: 520px; }
.book-dialog-photo-wrap { display: grid; place-items: center; padding: 26px; background: var(--library-mat); }
.book-dialog-photo { display: block; max-width: 100%; max-height: min(72vh, 700px); object-fit: contain; }
.book-dialog-copy { align-self: center; padding: 44px; }
.book-dialog-kicker { margin: 0 0 9px; color: var(--library-amber); font-size: .76rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.book-dialog-title { margin: 0 0 12px; color: #0f1c3f; font-size: clamp(1.7rem, 4vw, 2.65rem); line-height: 1.08; }
.book-dialog-author { margin: 0 0 12px; color: #495057; font-size: 1.08rem; line-height: 1.5; }
.book-dialog-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 22px; }
.book-dialog-meta [hidden] { display: none; }
.book-dialog-edition,
.book-dialog-pages { display: inline-block; margin: 0; padding: 5px 9px; border-left: 3px solid #f59e0b; color: var(--library-muted); font-size: .9rem; font-weight: 700; }
.book-dialog-categories { margin-top: 8px; }

.library-social { padding: 8px 16px; display: flex; justify-content: center; gap: 8px; background: #212529; }
.library-social a { display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px; border: 1px solid currentColor; border-radius: 6px; text-decoration: none; font-size: .875rem; }
.library-social-x { color: #6ea8fe; }
.library-social-coffee { color: #ffda6a; }
.library-footer { padding: 20px; color: #000; font-size: 14px; text-align: center; }
.library-footer p:first-child { margin: 0 0 5px; }
.library-footer p:last-child { max-width: 800px; margin: 0 auto; color: #555; font-size: 12px; }

:where(a, button, input):focus-visible { outline: 3px solid #f59e0b; outline-offset: 3px; }

@media (hover: hover) and (pointer: fine) {
  .library-card-trigger:hover { transform: translateY(-5px); border-color: #c7bda9; box-shadow: 0 14px 28px rgba(28, 25, 23, .13); }
}

@media (max-width: 1120px) {
  .foxchase-header-wrap { padding: 0 18px; justify-content: space-between; }
  .foxchase-brand { min-width: 0; font-size: 1rem; }
  .foxchase-brand-logo { width: 36px; height: 36px; flex-basis: 36px; }
  .foxchase-main-nav { position: static; transform: none; margin-left: auto; }
  .foxchase-menu-toggle { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 42px; height: 42px; margin: 0; padding: 9px; background: #111; border: 1px solid rgba(255,255,255,.22); border-radius: 8px; cursor: pointer; }
  .foxchase-menu-toggle span { display: block; width: 22px; height: 2px; margin: 2px 0; background: #fff; border-radius: 2px; }
  .foxchase-navigation { display: none; position: absolute; top: calc(100% + 10px); left: 18px; right: 18px; width: auto; padding: 10px; flex-direction: column; align-items: stretch; gap: 2px; background: #111; border: 1px solid rgba(255,255,255,.16); border-radius: 12px; box-shadow: 0 14px 30px rgba(0,0,0,.55); }
  .foxchase-navigation.is-open { display: flex; }
  .foxchase-navigation a { width: 100%; padding: 12px 14px; color: #f4f4f4; border-radius: 8px; text-align: left; }
  .foxchase-navigation a:hover { color: #fff; background: rgba(255,255,255,.08); }
  .library-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .library-main { padding-top: 42px; }
  .library-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
  .book-dialog { overflow-y: auto; }
  .book-dialog-layout { grid-template-columns: 1fr; }
  .book-dialog-photo-wrap { padding: 22px; }
  .book-dialog-photo { max-height: 56vh; }
  .book-dialog-copy { padding: 28px; }
}

@media (max-width: 620px) {
  .library-main { width: min(100% - 24px, 1280px); padding: 34px 0 52px; }
  .library-hero { margin-bottom: 28px; }
  .library-tools { padding: 14px; }
  .library-filter-list { justify-content: flex-start; flex-wrap: nowrap; margin-inline: -2px; padding: 2px 2px 10px; overflow-x: auto; }
  .library-filter { flex: 0 0 auto; }
  .library-tool-row { grid-template-columns: 1fr; }
  .library-random { width: 100%; }
  .library-result-count { min-width: 0; text-align: left; }
  .library-grid { grid-template-columns: 1fr; gap: 18px; }
  .library-card-trigger { display: grid; grid-template-columns: 42% 1fr; min-height: 230px; }
  .library-photo-frame { height: 100%; min-height: 230px; aspect-ratio: auto; border-right: 1px solid #d8d2c6; border-bottom: 0; }
  .library-card-copy { padding: 16px; }
  .library-card-title { font-size: 1rem; }
  .book-dialog-copy { padding: 24px 22px 28px; }
  .library-social { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .001ms !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}
