:root {
  --bg: #16211c;
  --surface: #1c2820;
  --surface-2: #24352a;
  --ink: #ede6d6;
  --ink-muted: #94a693;
  --ink-faint: #6a7a6a;
  --brass: #c9a227;
  --brass-soft: rgba(201, 162, 39, 0.14);
  --rule: rgba(237, 230, 214, 0.10);
  --rule-strong: rgba(237, 230, 214, 0.18);
  --tab-1: #c9a227;
  --tab-2: #7a9b7e;
  --tab-3: #a05a5a;
  --tab-4: #5e7a96;
  --tab-5: #9b7ec9;
  --focus: #e8c65a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 15% 0%, rgba(201,162,39,0.06), transparent 45%),
    radial-gradient(circle at 85% 100%, rgba(122,155,126,0.05), transparent 50%);
  padding-bottom: calc(24px + var(--safe-bottom));
}

::selection { background: var(--brass-soft); color: var(--ink); }

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

button, input, select { font-family: inherit; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--rule-strong);
  padding: calc(16px + var(--safe-top)) 16px 14px;
}

.topbar-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.eyebrow {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--brass);
}

h1 {
  font-family: 'Fraunces', serif;
  font-optical-sizing: auto;
  font-weight: 600;
  font-size: 28px;
  margin: 2px 0 0;
  letter-spacing: -0.01em;
}

.filters-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  color: var(--ink);
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  min-height: 40px;
  position: relative;
}

.filters-btn svg { width: 15px; height: 15px; color: var(--brass); }

.filters-btn .badge {
  background: var(--brass);
  color: #16211c;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  font-weight: 600;
  border-radius: 999px;
  min-width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.search-field {
  position: relative;
}

.search-field input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
  padding: 12px 14px 12px 40px;
  color: var(--ink);
  font-size: 15px;
  min-height: 46px;
  -webkit-appearance: none;
  appearance: none;
}

.search-field input::placeholder { color: var(--ink-faint); }
.search-field input:focus { border-color: var(--brass); background: var(--surface-2); }

.search-field svg {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--ink-faint);
  pointer-events: none;
}

.count-line {
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--ink-muted);
}

.count-line .count-num {
  font-family: 'JetBrains Mono', monospace;
  color: var(--brass);
}

/* Card list */
#list {
  padding: 4px 0 0;
}

.card {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--rule);
  min-height: 44px;
}

.spine {
  width: 4px;
  flex-shrink: 0;
  background: var(--tab-1);
}

.card-body {
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.card-title {
  font-family: 'Fraunces', serif;
  font-size: 16.5px;
  font-weight: 500;
  line-height: 1.3;
  overflow-wrap: break-word;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}

.series-badge {
  background: var(--brass-soft);
  color: var(--brass);
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 11px;
  white-space: nowrap;
}

.series-name {
  color: var(--ink-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-author {
  color: var(--ink-muted);
  font-size: 13.5px;
  line-height: 1.35;
}

/* State messages */
.state-msg {
  padding: 56px 24px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 14.5px;
}

.state-msg .big {
  font-family: 'Fraunces', serif;
  font-size: 19px;
  color: var(--ink);
  display: block;
  margin-bottom: 6px;
}

.loading-more, .end-message {
  text-align: center;
  padding: 18px;
  color: var(--ink-faint);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.04em;
}

#sentinel { height: 1px; }

/* Bottom sheet */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  visibility: hidden;
  pointer-events: none;
}

.sheet[data-open="true"] {
  visibility: visible;
  pointer-events: auto;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 16, 12, 0.55);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.sheet[data-open="true"] .sheet-backdrop { opacity: 1; }

.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--rule-strong);
  border-radius: 18px 18px 0 0;
  padding: 10px 20px calc(20px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 85vh;
  overflow-y: auto;
}

.sheet[data-open="true"] .sheet-panel { transform: translateY(0); }

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--rule-strong);
  border-radius: 3px;
  margin: 6px auto 14px;
}

.sheet-panel h2 {
  font-family: 'Fraunces', serif;
  font-size: 19px;
  font-weight: 500;
  margin: 0 0 16px;
}

.field-group {
  margin-bottom: 16px;
}

.field-group label {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 7px;
}

select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--rule-strong);
  border-radius: 9px;
  color: var(--ink);
  padding: 12px 12px;
  font-size: 15px;
  min-height: 46px;
  -webkit-appearance: none;
  appearance: none;
}

select:focus { border-color: var(--brass); }

.dir-toggle {
  display: flex;
  gap: 8px;
}

.dir-toggle button {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--rule-strong);
  color: var(--ink-muted);
  border-radius: 9px;
  padding: 11px 10px;
  font-size: 13.5px;
  min-height: 44px;
}

.dir-toggle button.active {
  border-color: var(--brass);
  color: var(--brass);
  background: var(--brass-soft);
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.ghost-btn, .primary-btn {
  flex: 1;
  border-radius: 10px;
  padding: 13px 14px;
  font-size: 14.5px;
  font-weight: 500;
  min-height: 48px;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--rule-strong);
  color: var(--ink-muted);
}

.primary-btn {
  background: var(--brass);
  border: 1px solid var(--brass);
  color: #16211c;
}

/* Slightly wider viewports (tablet/desktop): center the column, keep the mobile layout */
@media (min-width: 640px) {
  .topbar, #list, .loading-more, .end-message, #sentinel {
    max-width: 640px;
    margin-left: auto;
    margin-right: auto;
  }
  .topbar { left: 0; right: 0; }
  .sheet-panel {
    max-width: 640px;
    left: 50%;
    right: auto;
    transform: translate(-50%, 100%);
  }
  .sheet[data-open="true"] .sheet-panel { transform: translate(-50%, 0); }
}

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