:root {
  --paper: #f5f1e8;
  --paper-raised: #fffdf7;
  --ink: #1c1a15;
  --ink-soft: #5a5646;
  --rule: #d8d0bc;
  --rule-strong: #b9ae8c;
  --accent: #2f5f4f;
  --accent-soft: #dde9e2;
  --focus: #1c1a15;
  --radius: 3px;
  --radius-sm: 3px;
  --radius-md: 6px;
}

/* ---------- Dark theme ----------
   Toggled via [data-theme="dark"] on <html> (set by the anti-FOUC inline
   script in index.html). Same token names as the light palette above are
   redefined here — every rule below already reads var(--paper)/var(--ink)/
   etc., so the whole page repaints without touching component styles. */
html[data-theme="dark"] {
  --paper: #1b1914;
  --paper-raised: #262319;
  --ink: #ece6d6;
  --ink-soft: #b7ae95;
  --rule: #3a362a;
  --rule-strong: #55503e;
  --accent: #7fbf9f;
  --accent-soft: #1f352c;
  --focus: #ece6d6;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

body {
  margin: 0;
  background: var(--paper);
  background-image:
    linear-gradient(var(--rule) 1px, transparent 1px);
  background-size: 100% 2.4rem;
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  line-height: 1.5;
  min-height: 100vh;
  /* Defense-in-depth for 320-500px viewports (see also the #filter-input
     min-width:0 + .table-wrap overflow-x:auto fixes below, the actual
     root causes found via CDP testing). */
  overflow-x: hidden;
}

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Masthead (standardized 2-line header — same class names as
   the portal/web-countdown; keep in sync if this pattern changes) ---------- */

.masthead {
  padding-bottom: 1.15rem;
}

.masthead-rule {
  border: none;
  border-top: 2px solid var(--ink);
  margin: 0 0 2.5rem;
}

.masthead-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.masthead-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.home-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  flex-shrink: 0;
  border-radius: 50%;
  color: var(--ink-soft);
  text-decoration: none;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.home-icon:hover {
  background: var(--accent-soft);
  color: var(--ink);
}

.home-icon:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .home-icon {
    transition: none;
  }
}

.brand-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  background: var(--ink);
  color: var(--paper);
  font-size: 1.05rem;
}

.brand-tile img {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
  /* External <img> SVGs do not inherit currentColor. Brand-tile is ink-on-paper
     inverted (dark tile / paper glyph). Force monochrome paint to match. */
  filter: brightness(0) invert(1);
}
html[data-theme="dark"] .brand-tile img {
  /* Dark theme: --ink tile is light; keep icon dark. */
  filter: brightness(0);
}


.brand-title {
  font-size: clamp(1.3rem, 3.2vw, 1.6rem);
  margin: 0;
  min-width: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.masthead-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

.theme-toggle {
  position: relative;
  width: 2.1rem;
  height: 2.1rem;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule-strong);
  border-radius: 50%;
  background: var(--paper-raised);
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease, transform 0.1s ease;
}

.theme-toggle:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.theme-toggle:active {
  transform: scale(0.94);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.theme-icon {
  position: absolute;
  width: 1.1rem;
  height: 1.1rem;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.theme-icon--sun {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.theme-icon--moon {
  opacity: 0;
  transform: scale(0.5) rotate(-40deg);
}

html[data-theme="dark"] .theme-icon--sun {
  opacity: 0;
  transform: scale(0.5) rotate(40deg);
}

html[data-theme="dark"] .theme-icon--moon {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle,
  .theme-icon {
    transition: none;
  }
}

.masthead-sub {
  font-family: "SFMono-Regular", "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 0.6rem 0 0;
  max-width: 46ch;
}

.reference {
  max-width: 720px;
  margin: 2.5rem auto 0;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

#filter-input {
  flex: 1;
  min-width: 0;
  font-family: "SFMono-Regular", "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.95rem;
  padding: 0.65rem 0.8rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--ink);
}

#filter-input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.result-count {
  font-family: "SFMono-Regular", "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.table-wrap {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  font-family: "SFMono-Regular", "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  background: var(--paper-raised);
}

tbody tr {
  border-bottom: 1px solid var(--rule);
}

tbody tr:last-child {
  border-bottom: none;
}

tbody td {
  padding: 0.55rem 0.9rem;
  font-family: "SFMono-Regular", "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.85rem;
}

td.char-cell {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-size: 1rem;
  color: var(--accent);
  width: 3rem;
}

td.name-cell {
  color: var(--ink-soft);
}

.table-wrap {
  max-height: 60vh;
  overflow-y: auto;
  /* Safety net: 5 monospace columns (incl. an unwrappable 8-char Bin
     column) can outgrow very narrow viewports even with tight padding.
     Scrolling lives inside this box, never on the page itself. */
  overflow-x: auto;
}

.empty-state {
  padding: 2rem;
  text-align: center;
  color: var(--ink-soft);
  font-family: "SFMono-Regular", "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.85rem;
}

.page-footer {
  margin-top: 2.5rem;
  text-align: center;
  font-family: "SFMono-Regular", "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.app-version {
  margin-top: 0.35rem;
  opacity: 0.6;
}

.app-version:empty {
  display: none;
}

/* ---------- Mobile (320-500px) ----------
   Verified via CDP at 320/375/414/500px. #filter-input's missing
   min-width:0 (fixed above) pushed .result-count off-screen at 320px; the
   5-column table needs tighter cell padding at this width or its 8-char
   Bin column forces the inner .table-wrap scrollbar (harmless, page itself
   never scrolls). This block also lifts the masthead's two interactive
   controls to the 44x44px minimum touch target. */
@media (max-width: 500px) {
  .home-icon,
  .theme-toggle {
    width: 2.75rem;
    height: 2.75rem;
  }

  /* When the title wraps and pushes .masthead-actions to its own line,
     margin-left: auto keeps it pinned to the right instead of collapsing
     to flex-start (space-between has nothing to distribute for a lone
     item on a wrapped line). */
  .masthead-actions {
    margin-left: auto;
  }

  thead th,
  tbody td {
    padding: 0.55rem 0.5rem;
  }

  td.char-cell {
    width: 2rem;
  }
}
