@import url('https://fonts.googleapis.com/css2?family=Mulish:wght@400;500;600;700;800&display=swap');

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

body {
  font-family: 'Mulish', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #F2F2F2;
  color: #333333;
  min-height: 100vh;
  font-size: 15px;
}

/* ── Header ── */
.site-header {
  background: #ffffff;
  color: #002348;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(44,62,80,.08);
  border-bottom: 1px solid #e8e8e8;
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
h1 { font-size: 1.2rem; font-weight: 800; letter-spacing: -.02em; color: #002348; }
.header-sub { font-size: .75rem; color: #888; margin-top: 2px; }

.main-nav { display: flex; gap: 8px; }
.nav-btn {
  background: transparent;
  border: 1.5px solid rgba(0,35,72,.25);
  color: rgba(0,35,72,.65);
  padding: 6px 18px;
  border-radius: 3px;
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-family: inherit;
  transition: all .15s;
}
.nav-btn:hover { background: rgba(0,35,72,.06); color: #002348; border-color: rgba(0,35,72,.5); }
.nav-btn.active { background: #F58700; color: #fff; border-color: #F58700; }

/* ── Loading overlay ── */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(242,242,242,.96);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.loading-overlay.hidden { display: none; }
.loading-box { text-align: center; color: #555; }
.spinner {
  width: 38px; height: 38px;
  border: 3px solid #ddd; border-top-color: #F58700;
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Main layout ── */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}
.tab-content { display: block; }
.tab-content.hidden { display: none; }
.hidden { display: none !important; }

/* ── Search section ── */
.search-section { margin-bottom: 24px; }
.search-row { display: flex; gap: 8px; margin-bottom: 8px; }

#search-input {
  flex: 1;
  padding: 11px 16px;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid #d2d2d2;
  border-radius: 3px;
  outline: none;
  transition: border-color .15s;
  background: #fff;
  color: #333;
}
#search-input:focus { border-color: #F58700; }
#search-input::placeholder { color: #aaa; }

#search-btn {
  background: #F58700; color: #fff;
  border: none; padding: 11px 26px;
  border-radius: 3px;
  font-size: .9rem; font-weight: 700;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: .05em;
  cursor: pointer; white-space: nowrap;
  transition: background .15s;
}
#search-btn:hover { background: #d97800; }

.search-actions { display: flex; gap: 10px; align-items: center; }

/* ── Search term chips ── */
#search-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  min-height: 0; margin-bottom: 6px;
}
#search-chips:empty { margin-bottom: 0; }

.term-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff;
  border: 1.5px solid var(--chip-color, #ccc);
  border-left: 4px solid var(--chip-color, #ccc);
  border-radius: 3px; padding: 4px 8px 4px 10px;
  font-size: .83rem; color: #333;
}
.term-chip-label { font-weight: 600; }
.term-chip-count { font-size: .75rem; color: #888; }
.chip-remove {
  background: none; border: none; cursor: pointer;
  color: #bbb; font-size: 1rem; line-height: 1; padding: 0 0 0 2px;
}
.chip-remove:hover { color: #F58700; }

.whole-word-label {
  display: flex; align-items: center; gap: 6px;
  font-size: .82rem; color: #555; cursor: pointer;
  user-select: none;
}
.whole-word-label input[type="checkbox"] {
  width: 14px; height: 14px; accent-color: #F58700; cursor: pointer;
}
.search-actions-sep {
  flex: 1;
}

/* ── Data info tooltip ── */
.info-wrap { position: relative; display: inline-flex; align-items: center; }
.info-btn {
  background: none;
  border: 1.5px solid #bbb;
  color: #999;
  border-radius: 50%;
  width: 17px; height: 17px;
  font-size: .65rem; font-weight: 700; font-style: italic;
  font-family: Georgia, serif;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  transition: border-color .15s, color .15s;
  flex-shrink: 0;
}
.info-btn:hover { border-color: #F58700; color: #F58700; }
.info-tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 11px 14px;
  font-size: .8rem;
  color: #444;
  line-height: 1.6;
  width: 290px;
  box-shadow: 0 4px 18px rgba(0,0,0,.13);
  z-index: 50;
  pointer-events: none;
}
.info-tooltip.visible { display: block; }

.ghost-btn {
  background: none; border: 1px solid #d2d2d2;
  padding: 4px 12px; border-radius: 3px;
  cursor: pointer; font-size: .8rem; color: #555;
  font-family: inherit;
  transition: background .12s;
}
.ghost-btn:hover { background: #e8e8e8; }

/* ── Landing: top word chips ── */
.section-label {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: #888; margin-bottom: 12px;
}
#global-top-words { display: flex; flex-wrap: wrap; gap: 8px; }
.word-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid #d2d2d2;
  border-radius: 3px; padding: 5px 13px;
  font-size: .85rem; cursor: pointer;
  transition: all .15s;
  font-weight: 500;
}
.word-chip:hover { background: #F58700; color: #fff; border-color: #F58700; }
.chip-count { font-size: .72rem; color: #aaa; font-weight: 600; }
.word-chip:hover .chip-count { color: rgba(255,255,255,.8); }

/* ── Easter egg video ── */
#easter-egg {
  float: right;
  height: 78px;
  width: 78px;
  object-fit: cover;
  border-radius: 4px;
  margin: -3px 0 -3px 12px;
}

/* ── Results summary ── */
#results-summary {
  margin-bottom: 18px;
  padding: 11px 15px;
  background: #fff8ee;
  border-left: 4px solid #F58700;
  border-radius: 3px;
  font-size: .9rem;
  line-height: 1.5;
}
#results-summary strong { font-weight: 700; }
#results-summary.no-results { background: #fce4ec; border-color: #c0392b; }

/* ── Cards ── */
.card {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  border: 1px solid #e8e8e8;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-header h3 { font-size: .9rem; font-weight: 700; color: #002348; text-transform: uppercase; letter-spacing: .05em; }
.dl-btn {
  background: none; border: 1px solid #d2d2d2;
  padding: 4px 10px; border-radius: 3px;
  cursor: pointer; font-size: .75rem; color: #666;
  font-family: inherit;
}
.dl-btn:hover { background: #f5f5f5; }

.chart-wrap { position: relative; }
.card-subtitle { font-size: .82rem; color: #777; margin: -8px 0 14px; line-height: 1.5; }

/* ── Badge ── */
.badge {
  background: #F58700; color: #fff;
  font-size: .7rem; font-weight: 700;
  padding: 2px 8px; border-radius: 3px;
}

/* ── Matches list ── */
.ep-match-group {
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid #f0f0f0;
}
.ep-match-group:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.ep-match-header {
  display: flex; align-items: baseline; flex-wrap: wrap;
  gap: 6px; margin-bottom: 8px;
}
.ep-num { font-size: .7rem; font-weight: 700; color: #aaa; text-transform: uppercase; letter-spacing: .05em; }
.ep-title-link {
  font-weight: 700; font-size: .9rem;
  color: #002348; text-decoration: none;
}
.ep-title-link:hover { color: #F58700; }
.ep-date { font-size: .78rem; color: #aaa; }
.ep-hit-count { font-size: .78rem; color: #888; margin-left: auto; }

.seg-match { display: flex; gap: 10px; padding: 5px 0; font-size: .85rem; align-items: flex-start; }
.seg-ts {
  flex-shrink: 0; font-family: monospace; font-size: .75rem;
  color: #F58700; font-weight: 700; padding-top: 1px; min-width: 58px;
}
.seg-text { color: #444; line-height: 1.55; }
.seg-text mark { background: #fff3cd; color: inherit; border-radius: 2px; padding: 0 1px; }

/* ── Episodes table ── */
.episodes-toolbar {
  display: flex; gap: 16px; align-items: center;
  flex-wrap: wrap; margin-bottom: 14px;
}
.episodes-toolbar label {
  font-size: .85rem; color: #555;
  display: flex; align-items: center; gap: 6px;
  font-weight: 500;
}
.episodes-toolbar select {
  padding: 4px 8px; border: 1px solid #d2d2d2;
  border-radius: 3px; font-size: .85rem; background: #fff;
  font-family: inherit; color: #333;
}
.ep-count-label { font-size: .8rem; color: #888; margin-left: auto; }

.table-scroll { overflow-x: auto; }
#ep-table {
  width: 100%; border-collapse: collapse; font-size: .85rem;
}
#ep-table th {
  background: #002348; color: #fff;
  padding: 10px 12px; text-align: left;
  font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
  white-space: nowrap;
}
#ep-table td {
  padding: 8px 12px; border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}
#ep-table tbody tr:hover td { background: #FFF8EE; }
#ep-table tbody tr:last-child td { border-bottom: none; }

.type-badge {
  font-size: .66rem; padding: 2px 7px; border-radius: 3px;
  font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap;
}
.type-full    { background: #e8f5e9; color: #2e7d32; }
.type-qa      { background: #e3f2fd; color: #1565c0; }
.type-special { background: #fff3e0; color: #e65100; }
.type-short   { background: #fce4ec; color: #880e4f; }

.ep-links a {
  font-size: .78rem; color: #F58700;
  text-decoration: none; margin-right: 8px; white-space: nowrap;
  font-weight: 600;
}
.ep-links a:hover { text-decoration: underline; }

/* ── Similar spellings panel ── */
.similar-card { padding: 14px 18px; }
.similar-header {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  margin-bottom: 10px;
}
.similar-title { font-size: .85rem; font-weight: 700; color: #002348; }
.similar-hint  { font-size: .75rem; color: #aaa; }
#similar-list  { display: flex; flex-wrap: wrap; gap: 7px; }

.sim-chip {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: 3px; padding: 4px 12px;
  font-size: .82rem; cursor: pointer; border: 1.5px solid;
  transition: all .15s;
  font-weight: 500;
}
.sim-chip.dist-1 {
  background: #fff8ee; border-color: #F58700; color: #7c4000;
}
.sim-chip.dist-1:hover { background: #F58700; color: #fff; border-color: #F58700; }
.sim-chip.dist-2 {
  background: #f3f4f6; border-color: #ccc; color: #555;
}
.sim-chip.dist-2:hover { background: #e0e0e0; border-color: #aaa; }

.sim-count { font-size: .72rem; font-weight: 700; opacity: .7; }

/* ── Stories intro ── */
.stories-intro {
  margin-bottom: 20px;
  color: #444;
  font-size: .9rem;
  line-height: 1.65;
}
.stories-intro p { margin-bottom: 10px; }
.stories-intro p:last-child { margin-bottom: 0; }
.stories-intro ul { margin: 6px 0 10px 20px; }
.stories-intro li { margin-bottom: 6px; }
.stories-intro code { font-family: monospace; background: #f0f0f0; padding: 1px 4px; border-radius: 2px; font-size: .85em; }
.stories-intro p:empty { display: none; }

/* ── Footer ── */
.site-footer {
  text-align: center; padding: 28px;
  color: #aaa; font-size: .8rem;
}
.site-footer a { color: #F58700; text-decoration: none; font-weight: 600; }
.site-footer a:hover { text-decoration: underline; }

/* ── Responsive ── */
@media (max-width: 640px) {
  .header-inner { flex-direction: column; align-items: flex-start; gap: 10px; }
  .search-row { flex-direction: column; }
  #search-btn { width: 100%; }
  main { padding: 14px; }
  .card { padding: 14px; }
}
