:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --fg: #1a1d21;
  --muted: #667085;
  --border: #e4e7ec;
  --accent: #2563eb;
  --active: #eef2f7;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --surface: #181d23;
    --fg: #e8ebef;
    --muted: #94a0ad;
    --border: #2a323c;
    --accent: #7aa5f8;
    --active: #202730;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
}

.app-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-bar h1 {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  margin: -8px 0 -8px -8px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--accent);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:active { background: var(--active); }

.search-row {
  padding: 10px 14px 4px;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
}

#search {
  width: 100%;
  padding: 10px 14px;
  font-size: 16px; /* 16px+ prevents iOS focus zoom */
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
}

#search:focus { border-color: var(--accent); }

#items {
  max-width: 680px;
  margin: 8px auto calc(env(safe-area-inset-bottom) + 24px);
  padding: 0 14px;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  text-decoration: none;
  color: inherit;
}

.row:active { background: var(--active); }

.row-icon {
  flex-shrink: 0;
  width: 26px;
  text-align: center;
  font-size: 22px;
  line-height: 1;
}

.row-num {
  font-size: 16px;
  font-weight: 600;
  color: var(--muted);
}

.row-body { flex: 1; min-width: 0; }

.row-title {
  font-size: 16px;
  font-weight: 500;
  overflow-wrap: break-word;
}

.row-sub {
  margin-top: 2px;
  font-size: 13px;
  color: var(--muted);
}

.row-chevron {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 20px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 24px;
}

.version {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 8px 0 calc(env(safe-area-inset-bottom) + 16px);
}

#viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#viewer[hidden] { display: none; }

#version-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

#version-bar[hidden] { display: none; }

.version-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 9px 14px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.version-summary .vs-text {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.version-summary .vs-caret {
  flex-shrink: 0;
  transition: transform 0.15s;
}

.version-summary[aria-expanded="true"] .vs-caret {
  transform: rotate(180deg);
}

.version-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 12px;
  padding: 2px 14px 10px;
}

.version-controls[hidden] { display: none; }

.facet {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.facet label {
  font-size: 11px;
  color: var(--muted);
  padding-left: 2px;
}

.version-select,
.facet select {
  padding: 6px 8px;
  font-size: 14px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 46vw;
}

.pills {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}

.pills .pill {
  padding: 6px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}

.pills .pill[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--surface);
  font-weight: 500;
}

.pills .pill.na {
  color: var(--muted);
  opacity: 0.55;
}

.facet-note {
  align-self: center;
  font-size: 11px;
  font-style: italic;
  color: var(--muted);
}

#frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: #fff;
}
