:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f1f2f4;
  --text: #1c1e22;
  --text-dim: #5c6270;
  --border: #dfe1e6;
  --border-strong: #c8ccd4;
  --accent: #2f6f4f;
  --accent-text: #ffffff;
  --accent-soft: #e8f1eb;
  --focus: #2f6f4f;
  --shadow: 0 1px 2px rgba(20, 24, 33, 0.06), 0 4px 12px rgba(20, 24, 33, 0.05);
  --radius: 12px;
}

:root[data-theme='dark'] {
  --bg: #15171c;
  --surface: #1d2027;
  --surface-2: #24282f;
  --text: #e9ebef;
  --text-dim: #9aa2b1;
  --border: #2e333c;
  --border-strong: #3d434e;
  --accent: #6cc39a;
  --accent-text: #10231a;
  --accent-soft: #23342b;
  --focus: #6cc39a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #15171c;
    --surface: #1d2027;
    --surface-2: #24282f;
    --text: #e9ebef;
    --text-dim: #9aa2b1;
    --border: #2e333c;
    --border-strong: #3d434e;
    --accent: #6cc39a;
    --accent-text: #10231a;
    --accent-soft: #23342b;
    --focus: #6cc39a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  width: 100%;
  max-width: 62rem;
  margin: 0 auto;
  padding: 0 1.25rem;
}

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

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -3rem;
  z-index: 10;
  padding: 0.5rem 0.9rem;
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  text-decoration: none;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 0;
}

:where(a, button, input, select):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- header ---------- */

.header {
  padding: 2.5rem 0 1.5rem;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

h1 {
  margin: 0;
  font-size: clamp(1.65rem, 5vw, 2.3rem);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.tagline {
  max-width: 46rem;
  margin: 0.6rem 0 0;
  color: var(--text-dim);
  font-size: 1rem;
}

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.icon-btn svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.i-moon {
  display: none;
}

:root[data-theme='dark'] .i-sun {
  display: none;
}

:root[data-theme='dark'] .i-moon {
  display: block;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .i-sun {
    display: none;
  }

  :root:not([data-theme='light']) .i-moon {
    display: block;
  }
}

/* ---------- toolbar ---------- */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 0.75rem 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .toolbar {
    background: var(--bg);
  }
}

.toolbar-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.search {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

.search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  width: 1.1rem;
  height: 1.1rem;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 1.9;
  stroke-linecap: round;
  pointer-events: none;
}

#filter {
  width: 100%;
  height: 2.9rem;
  padding: 0 2.6rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}

#filter::placeholder {
  color: var(--text-dim);
}

#filter::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.clear-btn {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  display: grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  transform: translateY(-50%);
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}

.clear-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.clear-btn svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.lang {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-dim);
  font-size: 0.85rem;
}

#lang {
  height: 2.9rem;
  padding: 0 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

/* ---------- list ---------- */

main {
  padding-bottom: 3rem;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  margin: 1.5rem 0 0.75rem;
}

.section-title {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.count {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.book {
  padding: 1.1rem 1.15rem 1.25rem;
  margin-bottom: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.book-name {
  margin: 0 0 0.85rem;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.chips {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3rem, 1fr));
  gap: 0.5rem;
}

.chip {
  display: grid;
  place-items: center;
  min-height: 2.75rem;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

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

.chip:active {
  transform: translateY(1px);
}

.chip[hidden] {
  display: none;
}

.empty {
  max-width: 34rem;
  margin: 2rem auto;
  padding: 1.25rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-dim);
  text-align: center;
}

/* ---------- footer ---------- */

.footer {
  padding: 1.75rem 0 2.5rem;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.82rem;
}

.footer p {
  max-width: 46rem;
  margin: 0;
}

.footer-meta {
  margin-top: 0.5rem;
}

.footer a,
.empty a {
  color: var(--accent);
}

/* ---------- small screens ---------- */

@media (max-width: 34rem) {
  .wrap {
    padding: 0 1rem;
  }

  .header {
    padding: 1.75rem 0 1rem;
  }

  .toolbar-inner {
    flex-wrap: wrap;
  }

  .search {
    flex: 1 1 100%;
  }

  .lang {
    margin-left: auto;
  }

  .lang span {
    font-size: 0.8rem;
  }

  .book {
    padding: 1rem 0.9rem 1.1rem;
  }

  .chips {
    grid-template-columns: repeat(auto-fill, minmax(2.9rem, 1fr));
  }
}

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