/* -----------------------------------------------------------------------------
 * styles.css — WebNovel Advanced Search
 * A compact dark theme. Layout is a two-column grid (filters + results) that
 * collapses to a single column on narrow screens.
 * ---------------------------------------------------------------------------*/

/* The `hidden` HTML attribute must always win, even over rules that set an
 * explicit `display` (e.g. `.btn-more { display: block }`). Author styles
 * normally beat the UA `[hidden]` rule, which would leave hidden elements
 * visible — this guarantees they collapse. */
[hidden] {
  display: none !important;
}

:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-elev-2: #1f242e;
  --border: #2a303c;
  --text: #e7ebf0;
  --text-dim: #9aa4b2;
  --accent: #ff7a59;
  --accent-2: #4f8cff;
  --danger: #ff5d6c;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  line-height: 1.5;
}

.wrap {
  /* Desktop: no fixed max width, just a 5vw gutter on each side. */
  width: calc(100% - 10vw);
  margin-inline: auto;
}

@media (max-width: 820px) {
  /* Mobile: keep the original tight 1rem gutter on each side. */
  .wrap {
    width: calc(100% - 2rem);
  }
}

/* Header ------------------------------------------------------------------ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.9rem;
  flex-wrap: wrap;
}

.logo {
  font-size: 1.25rem;
  margin: 0;
  font-weight: 700;
}

.logo span {
  color: var(--accent);
  font-weight: 600;
}

.snapshot-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.gh-link {
  display: inline-flex;
  align-items: center;
  color: var(--text-dim);
  transition: color 0.12s ease, transform 0.12s ease;
}

.gh-link:hover {
  color: var(--text);
  transform: translateY(-1px);
}

/* Layout ------------------------------------------------------------------ */
.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1.5rem;
  padding-block: 1.5rem;
  align-items: start;
}

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

/* Filters ----------------------------------------------------------------- */
.filters {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}

@media (max-width: 820px) {
  .filters {
    position: static;
    max-height: none;
  }
}

.field {
  margin-bottom: 1.1rem;
}

.field.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.field-label {
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
  font-weight: 600;
}

.field-label small {
  color: var(--accent);
  font-weight: 700;
}

.input {
  width: 100%;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
  font-size: 0.9rem;
  outline: none;
}

.input:focus {
  border-color: var(--accent-2);
}

.input.small {
  padding: 0.4rem 0.6rem;
  font-size: 0.82rem;
  margin-bottom: 0.5rem;
}

/* Segmented control */
.segmented {
  display: flex;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.seg {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--text-dim);
  padding: 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.seg.active {
  background: var(--accent);
  color: #1a1108;
}

/* Tag cloud */
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  max-height: 220px;
  overflow-y: auto;
  padding: 0.2rem;
}

.tag-cloud.selected-only {
  max-height: none;
}

.tag {
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  font-size: 0.78rem;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

/* Small count pill showing how many books carry a tag. */
.tag-count {
  background: var(--bg);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 0 0.35rem;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.4;
}

.tag.include .tag-count,
.tag.exclude .tag-count {
  background: rgba(0, 0, 0, 0.25);
  color: inherit;
}

.tag:hover {
  border-color: var(--accent-2);
  color: var(--text);
}

.tag.include {
  background: rgba(79, 140, 255, 0.18);
  border-color: var(--accent-2);
  color: #cfe0ff;
}

.tag.exclude {
  background: rgba(255, 93, 108, 0.16);
  border-color: var(--danger);
  color: #ffd0d5;
  text-decoration: line-through;
}

/* AND / OR match-mode toggle shown next to the Included / Excluded headers. */
.tag-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.4rem;
}

.tag-head .field-label {
  margin-bottom: 0;
}

.segmented.mini {
  width: auto;
  flex: 0 0 auto;
}

.segmented.mini .seg {
  flex: 0 0 auto;
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
}

.hint {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin: 0.4rem 0 0;
}

.btn-reset {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  padding: 0.55rem;
  cursor: pointer;
  font-weight: 600;
}

.btn-reset:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* Sidebar action row: Share + Reset side by side. */
.sidebar-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-share {
  flex: 1;
  background: var(--accent, #6c8cff);
  border: 1px solid transparent;
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 0.55rem;
  cursor: pointer;
  font-weight: 600;
}

.btn-share:hover {
  filter: brightness(1.08);
}

/* Brief "Copied!" confirmation state after a successful share. */
.btn-share.copied {
  background: var(--success, #2faa6a);
}

.sidebar-actions .btn-reset {
  flex: 1;
}

/* Results ----------------------------------------------------------------- */
.results-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.result-count {
  font-weight: 700;
}

.active-filters {
  color: var(--text-dim);
  font-size: 0.85rem;
}

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

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
}

.card-cover {
  aspect-ratio: 3 / 4;
  width: 100%;
  object-fit: cover;
  background: var(--bg-elev-2);
}

.card-body {
  padding: 0.6rem 0.7rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
}

.card-title {
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-author {
  font-size: 0.76rem;
  color: var(--text-dim);
}

.card-meta {
  display: flex;
  gap: 0.6rem;
  font-size: 0.74rem;
  color: var(--text-dim);
  margin-top: auto;
  flex-wrap: wrap;
}

.card-meta .star {
  color: var(--accent);
}

.badge {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent-2);
  font-weight: 700;
}

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 3rem 1rem;
}

.btn-more {
  display: block;
  margin: 1.5rem auto 0;
  background: var(--accent);
  color: #1a1108;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1.4rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-more:hover {
  filter: brightness(1.05);
}

/* End-of-list note shown when every matching result is already on screen. */
.end-of-list {
  text-align: center;
  margin: 1.5rem auto 0;
  color: var(--text-dim);
  font-weight: 600;
}

/* Footer ------------------------------------------------------------------ */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 2rem;
  padding-block: 1.2rem;
}

.site-footer p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.footer-links {
  margin-top: 0.5rem !important;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.footer-links a {
  color: var(--accent-2);
  text-decoration: none;
  font-weight: 600;
}

.footer-links a:hover {
  text-decoration: underline;
}
