/* SenpaiScope — light/dark theming is driven by [data-theme] on <html>,
   which app.js sets from localStorage (falling back to the OS preference). */

:root {
  color-scheme: light;

  --bg:            #f6f7fb;
  --bg-elevated:   #ffffff;
  --bg-sunken:     #eceef5;
  --border:        #dfe3ee;
  --border-strong: #c6ccdd;
  --text:          #161a26;
  --text-muted:    #5d6478;
  --text-faint:    #878ea3;

  --accent:        #6c4df6;
  --accent-hover:  #5a3ae0;
  --accent-soft:   #ece7ff;
  --accent-text:   #ffffff;

  --good:          #12a150;
  --warn:          #d98600;

  --shadow-sm: 0 1px 2px rgba(18, 22, 38, .06), 0 1px 3px rgba(18, 22, 38, .05);
  --shadow-md: 0 4px 12px rgba(18, 22, 38, .08), 0 2px 4px rgba(18, 22, 38, .05);
  --shadow-lg: 0 12px 32px rgba(18, 22, 38, .12);

  --radius:    14px;
  --radius-sm: 9px;
  --wrap:      1120px;
}

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

  --bg:            #0e1017;
  --bg-elevated:   #171a24;
  --bg-sunken:     #10131b;
  --border:        #262b39;
  --border-strong: #394054;
  --text:          #eaecf3;
  --text-muted:    #a2a9bd;
  --text-faint:    #737b91;

  --accent:        #8b6bff;
  --accent-hover:  #9b80ff;
  --accent-soft:   #241e42;
  --accent-text:   #0e1017;

  --good:          #34d17e;
  --warn:          #f0a83a;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, .45);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, .55);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color .18s ease, color .18s ease;
}

h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -.012em; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: .875em;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: .08em .38em;
}

.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 20px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--accent-text);
  padding: 10px 16px; border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------- header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 14px;
  padding-bottom: 14px;
}

.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand-mark { font-size: 30px; line-height: 1; flex-shrink: 0; }
.brand h1 { font-size: 1.2rem; }
.tagline { margin: 1px 0 0; font-size: .82rem; color: var(--text-muted); }

.theme-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  font: inherit; font-size: .85rem; font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, transform .12s ease, background-color .15s ease;
}
.theme-toggle:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.theme-icon { font-size: 1rem; line-height: 1; }

/* ---------------------------------------------------------------- search */
.search-section { padding: 40px 0 8px; }

.search-box { position: relative; max-width: 660px; margin: 0 auto; }

.search-field {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 4px 8px 4px 16px;
  box-shadow: var(--shadow-md);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.search-field:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-md), 0 0 0 4px var(--accent-soft);
}

.search-icon { font-size: 1.05rem; opacity: .75; flex-shrink: 0; }

#search-input {
  flex: 1; min-width: 0;
  padding: 14px 0;
  background: none; border: 0; outline: none;
  color: var(--text); font: inherit; font-size: 1.03rem;
}
#search-input::placeholder { color: var(--text-faint); }
#search-input::-webkit-search-cancel-button { display: none; }

.search-clear {
  background: none; border: 0; cursor: pointer;
  color: var(--text-faint); font-size: 1rem;
  padding: 8px 10px; border-radius: 8px; line-height: 1;
}
.search-clear:hover { color: var(--text); background: var(--bg-sunken); }

.suggestions {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0; z-index: 25;
  margin: 0; padding: 6px; list-style: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: min(58vh, 440px); overflow-y: auto;
}

.suggestion {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer;
}
.suggestion:hover, .suggestion.active { background: var(--accent-soft); }

.suggestion img {
  width: 40px; height: 56px; object-fit: cover; border-radius: 6px;
  background: var(--bg-sunken); flex-shrink: 0;
}
.suggestion-body { min-width: 0; flex: 1; }
.suggestion-title {
  font-weight: 570; font-size: .94rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.suggestion-sub {
  font-size: .78rem; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.suggestion-empty { padding: 16px; text-align: center; color: var(--text-muted); font-size: .9rem; }

.corpus-note {
  max-width: 660px; margin: 12px auto 0;
  text-align: center; font-size: .8rem; color: var(--text-faint);
  min-height: 1.2em;
}

/* -------------------------------------------------------------- selected */
.selected { margin: 26px 0 4px; }

.selected-card {
  display: flex; gap: 18px; align-items: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.selected-card img {
  width: 74px; height: 104px; object-fit: cover; border-radius: 9px;
  background: var(--bg-sunken); flex-shrink: 0;
}
.selected-body { min-width: 0; flex: 1; }
.selected-eyebrow {
  font-size: .7rem; font-weight: 650; letter-spacing: .09em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 3px;
}
.selected-body h2 { font-size: 1.24rem; }
.selected-meta { margin-top: 5px; font-size: .86rem; color: var(--text-muted); }
.selected-synopsis {
  margin: 9px 0 0; font-size: .87rem; color: var(--text-muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  line-clamp: 2; overflow: hidden;
}

/* --------------------------------------------------------------- filters */
.filters {
  margin: 22px 0 6px; padding: 18px 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.filters-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.filters-head h2 { font-size: .96rem; }

.link-btn {
  background: none; border: 0; padding: 4px 6px; cursor: pointer;
  color: var(--accent); font: inherit; font-size: .84rem; font-weight: 550;
  border-radius: 6px;
}
.link-btn:hover { background: var(--accent-soft); }

.filter-grid {
  display: grid; gap: 18px 24px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.filter label {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  font-size: .82rem; font-weight: 570; color: var(--text-muted);
  margin-bottom: 8px;
}
.filter output {
  font-variant-numeric: tabular-nums;
  font-weight: 650; color: var(--accent); font-size: .84rem;
}

input[type="range"] {
  width: 100%; height: 4px; margin: 8px 0;
  -webkit-appearance: none; appearance: none;
  background: var(--bg-sunken); border-radius: 999px; outline: none; cursor: pointer;
  border: 1px solid var(--border);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 17px; height: 17px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-elevated);
  box-shadow: var(--shadow-sm); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-elevated);
  box-shadow: var(--shadow-sm); cursor: pointer;
}

.year-inputs { display: flex; align-items: center; gap: 8px; }
.year-inputs span { color: var(--text-faint); }

input[type="number"], select {
  width: 100%; padding: 9px 11px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font: inherit; font-size: .88rem; outline: none;
}
input[type="number"]:focus, select:focus { border-color: var(--accent); }

.switch {
  display: flex; align-items: center; gap: 9px;
  margin-top: 16px; cursor: pointer;
  font-size: .84rem; color: var(--text-muted); user-select: none;
}
.switch input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.switch:hover { color: var(--text); }

.genre-exclude { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 14px; }
.genre-exclude summary {
  cursor: pointer; font-size: .84rem; font-weight: 570; color: var(--text-muted);
  list-style: none; display: flex; align-items: center; gap: 8px;
}
.genre-exclude summary::-webkit-details-marker { display: none; }
.genre-exclude summary::before {
  content: "▸"; display: inline-block; transition: transform .15s ease; color: var(--text-faint);
}
.genre-exclude[open] summary::before { transform: rotate(90deg); }

.chip-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  background: var(--accent); color: var(--accent-text);
  border-radius: 999px; font-size: .72rem; font-weight: 700;
}

.genre-list {
  display: flex; flex-wrap: wrap; gap: 7px;
  margin-top: 13px; max-height: 210px; overflow-y: auto;
}

.genre-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  background: var(--bg); border: 1px solid var(--border-strong);
  border-radius: 999px; font-size: .8rem; cursor: pointer;
  user-select: none; transition: background-color .12s ease, border-color .12s ease;
}
.genre-chip:hover { border-color: var(--accent); }
.genre-chip input { margin: 0; accent-color: var(--accent); cursor: pointer; }
.genre-chip:has(input:checked) {
  background: var(--accent-soft); border-color: var(--accent);
  color: var(--accent); font-weight: 570;
  text-decoration: line-through; text-decoration-thickness: 1px;
}

/* --------------------------------------------------------------- results */
.results { padding: 22px 0 56px; }

.results-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 16px;
}
.results-head h2 { font-size: 1.06rem; }
.results-count { font-size: .84rem; color: var(--text-muted); }

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

.card {
  display: flex; flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.card-main { display: flex; gap: 14px; padding: 14px; }

.card-thumb {
  width: 88px; height: 124px; flex-shrink: 0;
  object-fit: cover; border-radius: 9px;
  background: var(--bg-sunken);
}

.card-body { min-width: 0; flex: 1; display: flex; flex-direction: column; }

.card-title {
  font-size: .99rem; font-weight: 620; margin: 0 0 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  line-clamp: 2; overflow: hidden;
}
.card-title a { color: var(--text); }
.card-title a:hover { color: var(--accent); }

.card-alt {
  font-size: .76rem; color: var(--text-faint); margin-bottom: 7px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.card-meta {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 9px;
}
.pill {
  font-size: .72rem; padding: 2px 8px; border-radius: 999px;
  background: var(--bg-sunken); border: 1px solid var(--border);
  color: var(--text-muted); white-space: nowrap;
}
.pill-score { color: var(--good); font-weight: 620; }

.card-genres {
  font-size: .77rem; color: var(--text-muted); margin-top: auto;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  line-clamp: 2; overflow: hidden;
}

/* similarity badge */
.sim-badge {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  flex-shrink: 0; width: 58px;
}
.sim-ring {
  --pct: 0;
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--bg-sunken) 0);
  position: relative;
}
.sim-ring::after {
  content: ""; position: absolute; inset: 4px;
  background: var(--bg-elevated); border-radius: 50%;
}
.sim-value {
  position: relative; z-index: 1;
  font-size: .82rem; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.sim-label {
  font-size: .62rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); text-align: center; line-height: 1.2;
}

/* why section */
.why { border-top: 1px solid var(--border); }
.why summary {
  padding: 10px 14px; cursor: pointer; list-style: none;
  font-size: .81rem; font-weight: 570; color: var(--accent);
  display: flex; align-items: center; gap: 7px;
}
.why summary::-webkit-details-marker { display: none; }
.why summary::before {
  content: "▸"; display: inline-block; transition: transform .15s ease;
}
.why[open] summary::before { transform: rotate(90deg); }
.why summary:hover { background: var(--accent-soft); }

.why-body { padding: 2px 14px 14px; }
.why-list { margin: 0 0 12px; padding-left: 18px; font-size: .83rem; color: var(--text-muted); }
.why-list li { margin-bottom: 3px; }

.breakdown { display: grid; gap: 6px; }
.breakdown-row {
  display: grid; grid-template-columns: 84px 1fr 38px;
  align-items: center; gap: 9px;
  font-size: .74rem; color: var(--text-muted);
}
.bar { height: 5px; background: var(--bg-sunken); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.breakdown-val { text-align: right; font-variant-numeric: tabular-nums; }

/* Accounts for the gap between the content breakdown above and the headline
   match percentage, which also folds in rating, audience and format. */
.why-adjust {
  margin-top: 10px; padding-top: 9px;
  border-top: 1px solid var(--border);
  font-size: .72rem; color: var(--text-muted);
}

.card-links { padding: 0 14px 14px; }
.mal-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .79rem; font-weight: 550;
}

/* ------------------------------------------------------- empty / states */
.empty-state {
  text-align: center; padding: 56px 20px;
  color: var(--text-muted); max-width: 560px; margin: 0 auto;
}
.empty-emoji { font-size: 2.6rem; margin: 0 0 10px; }
.empty-state h2 { font-size: 1.14rem; color: var(--text); margin-bottom: 7px; }
.empty-state p { margin: 0 0 6px; font-size: .92rem; }

.examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.example-btn {
  padding: 7px 14px; background: var(--bg-elevated);
  border: 1px solid var(--border-strong); border-radius: 999px;
  color: var(--text); font: inherit; font-size: .84rem; cursor: pointer;
  transition: border-color .12s ease, transform .12s ease;
}
.example-btn:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }

.notice {
  padding: 16px 18px; border-radius: var(--radius);
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-left: 4px solid var(--warn);
  font-size: .9rem;
}
.notice-error { border-left-color: #e0475b; }

/* skeletons */
.skeleton-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.skeleton {
  height: 152px; border-radius: var(--radius);
  background: linear-gradient(100deg, var(--bg-elevated) 30%, var(--bg-sunken) 50%, var(--bg-elevated) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border: 1px solid var(--border);
}
@keyframes shimmer {
  from { background-position: 180% 0; }
  to   { background-position: -80% 0; }
}

/* ---------------------------------------------------------------- footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0 34px;
  font-size: .8rem; color: var(--text-faint);
  text-align: center;
}
.site-footer p { margin: 0 0 5px; }
.footer-stats { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 720px) {
  .wrap { padding: 0 14px; }
  .header-inner { padding-top: 11px; padding-bottom: 11px; }
  .brand h1 { font-size: 1.04rem; }
  .tagline { display: none; }
  .theme-label { display: none; }
  .theme-toggle { padding: 9px 11px; }

  .search-section { padding: 26px 0 6px; }
  #search-input { font-size: 16px; }  /* keeps iOS from zooming on focus */

  .card-grid, .skeleton-grid { grid-template-columns: 1fr; }
  .card-thumb { width: 72px; height: 102px; }
  .sim-badge { width: 50px; }
  .sim-ring { width: 44px; height: 44px; }
  .sim-value { font-size: .74rem; }

  .selected-card { gap: 13px; padding: 13px; }
  .selected-card img { width: 58px; height: 82px; }
  .selected-body h2 { font-size: 1.06rem; }

  .filter-grid { grid-template-columns: 1fr; gap: 15px; }
  .breakdown-row { grid-template-columns: 74px 1fr 34px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ------------------------------------------------------------------ V2 */
/* Medium switch: anime | manga */
.medium-switch {
  display: inline-flex; gap: 2px; margin: 0 auto 14px;
  padding: 3px; border-radius: 999px;
  background: var(--bg-sunken); border: 1px solid var(--border);
}
.medium-tab {
  appearance: none; border: 0; cursor: pointer;
  padding: 7px 20px; border-radius: 999px;
  font: inherit; font-size: .84rem; font-weight: 600;
  color: var(--text-muted); background: transparent;
  transition: background .15s ease, color .15s ease;
}
.medium-tab:hover { color: var(--text); }
.medium-tab.is-active { background: var(--accent); color: #fff; }
.medium-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* "Hide what I've seen" — revealed only when the toggle is switched on. */
.list-panel {
  margin: 10px 0 4px; padding: 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg-sunken);
}
.list-panel-intro {
  margin: 0 0 10px; font-size: .78rem; line-height: 1.5; color: var(--text-muted);
}
.list-form { display: flex; flex-wrap: wrap; gap: 8px; }
.list-form select, .list-form input {
  font: inherit; font-size: .84rem; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text);
}
.list-form input { flex: 1 1 180px; min-width: 0; }
.primary-btn {
  appearance: none; border: 0; cursor: pointer;
  padding: 8px 16px; border-radius: 8px;
  font: inherit; font-size: .84rem; font-weight: 600;
  background: var(--accent); color: #fff;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:disabled { opacity: .6; cursor: progress; }

.list-status { margin: 9px 0 0; font-size: .78rem; color: var(--text-muted); }
.list-status.is-error { color: #e5484d; }  /* stays legible on both themes */
.list-status.is-warn  { color: var(--warn); }

.list-connected {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin-top: 10px; font-size: .78rem; color: var(--text-muted);
}
.link-btn.danger { color: #e5484d; }

@media (max-width: 480px) {
  .list-form { flex-direction: column; align-items: stretch; }
}
