:root {
  color-scheme: light;
  --ink: #1f2933;
  --muted: #697586;
  --line: #d8dee8;
  --paper: #f7f8fb;
  --panel: #ffffff;
  --accent: #b08a42;
  --accent-strong: #8d6a2d;
  --shadow: 0 16px 40px rgba(31, 41, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

html {
  scroll-padding-top: 92px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 220px;
}

.brand-home {
  display: block;
  width: 58px;
  height: 58px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
}

.brand-logo {
  display: block;
  width: 58px;
  height: 58px;
  border: 1px solid rgba(176, 138, 66, 0.55);
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 8px 22px rgba(176, 138, 66, 0.2);
}

.brand-home:hover .brand-logo {
  box-shadow: 0 10px 26px rgba(176, 138, 66, 0.32);
}

h1 {
  margin: 0;
  font-size: clamp(21px, 3.1vw, 34px);
  line-height: 1.05;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

h1 span {
  color: var(--ink);
}

h1 em {
  color: var(--accent-strong);
  font-style: normal;
}

h1 small {
  color: var(--muted);
  font-size: 0.62em;
  font-weight: 800;
  letter-spacing: 0.12em;
}

p {
  margin: 4px 0 0;
  color: var(--muted);
}

.tools {
  display: flex;
  align-items: end;
  gap: 12px;
}

.search {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.search-control {
  display: grid;
  grid-template-columns: 1fr 46px;
  width: min(44vw, 420px);
  min-width: 220px;
}

.search input {
  width: 100%;
  min-width: 0;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: 6px;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  color: var(--ink);
  background: #fff;
  font: inherit;
}

.search input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(191, 52, 52, 0.15);
}

.search-button {
  display: grid;
  width: 46px;
  height: 42px;
  place-items: center;
  padding: 0;
  border-left: 1px solid var(--line);
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.search-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.pdf-link,
button {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 16px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.pdf-link {
  display: inline-grid;
  place-items: center;
}

button:hover,
.pdf-link:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

main {
  padding: 18px clamp(16px, 4vw, 48px) 48px;
}

.summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
  color: var(--muted);
}

.summary strong {
  display: block;
  color: var(--ink);
  font-size: 18px;
}

.filter-row {
  margin: 0 0 18px;
}

.category-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0;
}

.category-button {
  display: inline-flex;
  align-items: center;
  height: 38px;
  padding: 0 13px;
  border-color: var(--line);
  color: var(--ink);
}

.category-button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: rgba(176, 138, 66, 0.12);
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 18px;
}

.page-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(31, 41, 51, 0.06);
  cursor: zoom-in;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.page-card:hover {
  transform: translateY(-2px);
  border-color: rgba(191, 52, 52, 0.5);
  box-shadow: var(--shadow);
}

.page-card img {
  display: block;
  width: 100%;
  aspect-ratio: 0.71;
  object-fit: cover;
  background: #edf0f5;
}

.cover-card img {
  height: 100%;
  aspect-ratio: auto;
}

.page-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  font-size: 14px;
}

.page-label span {
  color: var(--muted);
}

.viewer {
  width: min(96vw, 1180px);
  height: min(94vh, 920px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: #101419;
  color: #fff;
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.4);
}

.viewer::backdrop {
  background: rgba(13, 18, 24, 0.72);
}

.viewer-bar {
  display: grid;
  grid-template-columns: 42px 1fr 42px 42px;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: #171d24;
}

.viewer-bar button {
  width: 42px;
  padding: 0;
  border-color: rgba(255, 255, 255, 0.16);
  color: #fff;
  background: #232b34;
  font-size: 26px;
}

#viewerTitle {
  text-align: center;
}

.viewer-stage {
  height: calc(100% - 62px);
  overflow: auto;
  display: grid;
  place-items: start center;
  padding: 16px;
}

.viewer-stage img {
  max-width: 100%;
  height: auto;
  background: #fff;
}

.empty {
  grid-column: 1 / -1;
  padding: 48px 0;
  color: var(--muted);
  text-align: center;
}

.scroll-top-button {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  padding: 0;
  border-color: rgba(176, 138, 66, 0.36);
  border-radius: 50%;
  color: var(--accent-strong);
  background: rgba(255, 255, 255, 0.68);
  box-shadow: 0 12px 28px rgba(31, 41, 51, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease, background 180ms ease;
  backdrop-filter: blur(8px);
  font-size: 24px;
}

.scroll-top-button.is-visible {
  opacity: 0.78;
  pointer-events: auto;
  transform: translateY(0);
}

.scroll-top-button:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.92);
}

@media (max-width: 760px) {
  .topbar {
    position: sticky;
    display: grid;
    gap: 12px;
    padding: 12px 14px;
  }

  .brand {
    gap: 10px;
    min-width: 0;
  }

  .brand-home,
  .brand-logo {
    width: 46px;
    height: 46px;
  }

  h1 {
    font-size: clamp(18px, 6vw, 24px);
    white-space: normal;
  }

  h1 small {
    display: block;
    margin-top: 2px;
    font-size: 0.56em;
  }

  .tools {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: stretch;
    gap: 8px;
  }

  .search {
    min-width: 0;
  }

  .search input {
    width: 100%;
    min-width: 0;
    height: 44px;
    font-size: 15px;
  }

  .search-control {
    width: 100%;
    min-width: 0;
    grid-template-columns: 1fr 44px;
  }

  .search-button {
    width: 44px;
    height: 44px;
  }

  #clearSearch {
    height: 44px;
    padding: 0 12px;
  }

  main {
    padding: 12px 10px 36px;
  }

  .filter-row {
    margin-bottom: 12px;
    overflow: hidden;
  }

  .category-filters {
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
  }

  .category-filters::-webkit-scrollbar {
    display: none;
  }

  .category-button {
    flex: 0 0 auto;
    height: 38px;
    padding: 0 12px;
    white-space: nowrap;
    font-size: 14px;
  }

  .catalog-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .page-card {
    border-radius: 7px;
  }

  .page-card:hover {
    transform: none;
  }

  .page-label {
    gap: 6px;
    padding: 8px;
    font-size: 13px;
  }

  .page-label span {
    max-width: 52%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .viewer {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border-radius: 0;
  }

  .viewer-bar {
    grid-template-columns: 44px 1fr 44px 44px;
    gap: 6px;
    padding: 8px;
  }

  .viewer-bar button {
    width: 44px;
    height: 44px;
  }

  #viewerTitle {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .viewer-stage {
    height: calc(100dvh - 60px);
    padding: 8px;
  }

  .scroll-top-button {
    right: 14px;
    bottom: 14px;
    width: 44px;
    height: 44px;
    font-size: 22px;
  }
}

@media (max-width: 380px) {
  .tools {
    grid-template-columns: 1fr;
  }

  #clearSearch {
    justify-self: end;
  }

  .catalog-grid {
    gap: 8px;
  }

  .page-label {
    display: grid;
  }

  .page-label span {
    max-width: none;
  }
}
