/* ==========================================================================
   Manhwa Recommender — design system (DesignTemplate-derived, dark-first)
   Tokens → components → motion → status. Author as CSS variables.
   ========================================================================== */

:root {
  /* Surfaces & text */
  --bg: #05070a;
  --surface: #0d1219;
  --surface-2: #111821;
  --raised: #0b0f15;
  --hairline: rgba(255, 255, 255, 0.08);
  --hairline-strong: rgba(255, 255, 255, 0.14);
  --text: #e6edf3;
  --muted: #9aa7b4;
  --dim: #6b7785;

  /* Accent */
  --accent: #22d3ee;
  --accent-600: #0ea5c4;
  --accent-glow: rgba(34, 211, 238, 0.35);
  --accent-subtle: rgba(34, 211, 238, 0.10);

  /* Semantic */
  --success: #34d399;
  --warning: #fbbf24;
  --error: #fb7185;
  --neutral: #717b8a;

  /* Type */
  --font-display: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Inter", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  /* Scale */
  --h1: clamp(2rem, 4.5vw, 3rem);
  --h2: 1.6rem;
  --h3: 1.08rem;
  --body: 0.95rem;
  --small: 0.82rem;
  --caption: 0.7rem;

  /* Radii */
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-full: 999px;

  /* Layout */
  --container: 1280px;
  --header-h: 64px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  font-size: var(--body);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(1000px 500px at 85% -10%, rgba(34, 211, 238, 0.08), transparent 60%),
    radial-gradient(800px 450px at 0% 0%, rgba(124, 92, 255, 0.07), transparent 55%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Numeric convention — mono + tabular nums everywhere digits appear. */
.num, [class*="match-val"], .meta, .footer-inner {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.muted { color: var(--muted); }
.small { font-size: var(--small); }
h1, h2, h3, .brand-text { font-family: var(--font-display); }

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

/* ------------------------------------------------------------------ Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--hairline);
}
.header-inner {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 20px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  flex-shrink: 0;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--bg);
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  border-radius: var(--radius-md);
}
.brand-text { font-weight: 700; letter-spacing: -0.02em; font-size: 1.05rem; }
.brand-accent { color: var(--accent); }

.search-box {
  position: relative;
  flex: 1 1 auto;
  max-width: 560px;
}
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--dim);
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 11px 14px 11px 42px;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 160ms, box-shadow 160ms;
}
#search::placeholder { color: var(--dim); }
#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.header-actions { display: flex; gap: 10px; flex-shrink: 0; }

/* ------------------------------------------------------------------ Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-weight: 600;
  font-size: var(--small);
  padding: 9px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--hairline-strong);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: transform 140ms ease, border-color 160ms, background 160ms;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.ghost { background: transparent; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-600));
  color: var(--bg);
  border-color: transparent;
}

/* ------------------------------------------------------------------ Hero */
.hero { padding: 44px 0 26px; }
.hero-title {
  margin: 0 0 10px;
  font-size: var(--h1);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
}
.hero-accent {
  background: linear-gradient(90deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-sub { margin: 0; color: var(--muted); max-width: 620px; }

/* ------------------------------------------------------------------ Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.controls { margin-bottom: 26px; }
.control { margin-bottom: 18px; }
.control:last-child { margin-bottom: 0; }
.control-label {
  display: block;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--small);
  color: #d7dcff;
  margin-bottom: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.control-body { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ------------------------------------------------------------------ Chips */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit;
  font-size: var(--small);
  padding: 6px 13px;
  border-radius: var(--radius-full);
  border: 1px solid var(--hairline-strong);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  transition: all 150ms ease;
  white-space: nowrap;
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip.on {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow) inset;
}
.chip.genre { cursor: default; }
.chip.genre:hover { transform: none; }

/* ---------------------------------------------------------------- Custom moods */
.mood-row { display: flex; flex-direction: column; gap: 8px; }
.mood-add-btn { align-self: flex-start; padding: 5px 13px; font-size: var(--caption); }
.mood-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--hairline-strong);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  font-size: var(--small);
  transition: all 150ms ease;
  user-select: none;
}
.mood-tag:hover { border-color: var(--accent); color: var(--text); }
.mood-tag:has(input:checked) {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow) inset;
}
.mood-tag input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.mood-tag input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 999px;
}
.mood-tag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 7px; }
.custom-mood-list { display: flex; flex-direction: column; gap: 7px; }
.custom-mood-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
}
.custom-mood-name { font-weight: 600; font-size: var(--small); }
#moodNameInput {
  width: 100%;
  padding: 10px 14px;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  outline: none;
}
#moodNameInput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

/* ------------------------------------------------------------------ Liked */
.liked-search { width: 100%; max-width: 420px; position: relative; margin-bottom: 8px; }
#likedSearch {
  width: 100%;
  padding: 10px 14px;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  outline: none;
}
#likedSearch:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.liked-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 12px;
  border-radius: var(--radius-full);
  background: var(--accent-subtle);
  border: 1px solid rgba(34, 211, 238, 0.35);
  color: var(--accent);
  font-size: var(--small);
}
.pill-x {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.pill-x:hover { color: var(--text); }

.suggestions {
  position: absolute;
  z-index: 30;
  min-width: 100%;
  margin-top: 6px;
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  display: none;
  max-height: 280px;
  overflow-y: auto;
}
.suggestions.show { display: block; }
.sug {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: var(--small);
  color: var(--muted);
  padding: 9px 14px;
  background: transparent;
  border: none;
  cursor: pointer;
}
.sug:hover { background: var(--surface-2); color: var(--text); }

/* ------------------------------------------------------------------ Toggle */
.control-inline { display: flex; gap: 22px; margin-top: 4px; }
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: var(--small);
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle span {
  width: 38px; height: 21px;
  border-radius: var(--radius-full);
  background: var(--raised);
  border: 1px solid var(--hairline-strong);
  position: relative;
  transition: background 160ms;
  flex-shrink: 0;
}
.toggle span::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--dim);
  transition: transform 160ms, background 160ms;
}
.toggle input:checked + span { background: var(--accent-subtle); border-color: var(--accent); }
.toggle input:checked + span::after { transform: translateX(17px); background: var(--accent); }
.toggle input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-glow); }

/* ------------------------------------------------------------------ Results */
.results-head { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 0 6px; }
.results-count { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: var(--h2); }

.status-line {
  display: none;
  margin: 0 2px 12px;
  font-size: var(--small);
  font-family: var(--font-mono);
  min-height: 0;
}
.status-line.show { display: block; }
.status-line.loading { color: var(--accent); }
.status-line.ok { color: var(--success); }
.status-line.error { color: var(--error); }
.status-line.searching { color: var(--accent); }

/* ------------------------------------------------------------------ Grid + cards */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 20px;
  padding-bottom: 40px;
}
.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform 180ms ease, border-color 180ms, box-shadow 180ms;
  opacity: 0;
  transform: translateY(14px);
}
.card.in {
  opacity: 1;
  transform: none;
  transition: opacity 320ms ease, transform 320ms ease, border-color 180ms, box-shadow 180ms;
}
.card:hover {
  transform: translateY(-5px);
  border-color: var(--accent);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--accent-glow);
}

.cover-wrap {
  position: relative;
  aspect-ratio: 300 / 424;
  background: var(--raised);
  overflow: hidden;
}
.cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 300ms ease;
}
.card:hover .cover { transform: scale(1.04); }
.rank {
  position: absolute;
  left: 10px; top: 10px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--caption);
  padding: 4px 9px;
  border-radius: var(--radius-full);
  background: rgba(5, 7, 10, 0.78);
  color: var(--accent);
  backdrop-filter: blur(4px);
  border: 1px solid var(--hairline);
}
.badge {
  position: absolute;
  right: 10px; top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--caption);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 9px;
  border-radius: var(--radius-full);
  background: rgba(5, 7, 10, 0.78);
  backdrop-filter: blur(4px);
  border: 1px solid var(--hairline);
}
.badge .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--neutral);
}
.badge.live .dot { background: var(--accent); animation: pulse 1.6s infinite; }
.badge.done .dot { background: var(--success); }
.badge.warn .dot { background: var(--warning); }
.badge.off .dot { background: var(--neutral); }

.card-body { padding: 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.title {
  margin: 0;
  font-size: var(--h3);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.genres { display: flex; flex-wrap: wrap; gap: 5px; }
.origin {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: var(--small);
  font-weight: 600;
  color: var(--muted);
}
.meta {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--dim);
  font-size: var(--small);
}
.meta .sep { color: var(--hairline-strong); }
.themes { display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-size: 0.66rem;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--hairline);
}

.match { display: flex; align-items: center; gap: 8px; }
.match-label { font-size: var(--caption); text-transform: uppercase; letter-spacing: 0.06em; color: var(--dim); }
.match-val { font-size: var(--small); color: var(--accent); font-weight: 700; margin-left: auto; }
.bar {
  position: relative;
  flex: 1;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--raised);
  overflow: hidden;
  min-width: 60px;
}
.bar-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, var(--accent), #a78bfa);
  border-radius: var(--radius-full);
  transition: width 400ms ease;
}

.desc {
  margin: 0;
  font-size: var(--small);
  color: var(--muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ------------------------------------------------------------------ Footer */
.site-footer {
  border-top: 1px solid var(--hairline);
  background: var(--surface);
  padding: 20px 0;
  margin-top: 20px;
}
.footer-inner { color: var(--dim); font-size: var(--small); }
.footer-inner a { color: var(--accent); text-decoration: none; }
.footer-inner a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ Motion */
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.8); }
}

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

/* -------------------------------------------------- Details modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  position: relative;
  width: min(560px, 100%);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
.modal-scroll { overflow-y: auto; padding: 20px 22px; }
.modal-close {
  position: absolute;
  top: 10px; right: 12px;
  z-index: 2;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: none;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); border-color: var(--hairline-strong); }
.modal-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 18px; }
.modal-cover {
  width: 88px; height: 124px;
  flex: none;
  border-radius: var(--radius-md);
  object-fit: cover;
  border: 1px solid var(--hairline);
  background: var(--raised);
}
.modal-title {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: var(--h3);
  font-weight: 700;
  line-height: 1.15;
}
.modal-meta { color: var(--muted); font-size: var(--small); }
.modal-section { margin-bottom: 18px; }
.modal-section:last-child { margin-bottom: 2px; }
.modal-section-label {
  display: block;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--small);
  color: #d7dcff;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 9px;
}
.modal-copy-main { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.copy-hint { flex: 1 1 auto; min-width: 120px; }
.alt-list { display: flex; flex-direction: column; gap: 7px; }
.alt-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
}
.alt-text { flex: 1 1 auto; font-size: var(--small); word-break: break-word; }
.modal-desc { margin: 0; font-size: var(--medium); line-height: 1.6; color: var(--text); white-space: pre-wrap; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.btn.tiny { padding: 5px 10px; font-size: var(--caption); font-weight: 600; }

/* "You might also like" suggestions inside the detail modal */
.suggest-grid {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.suggest-item {
  flex: 0 0 auto;
  width: 122px;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  transition: border-color 150ms ease, transform 150ms ease;
}
.suggest-item:hover, .suggest-item:focus-visible {
  border-color: var(--accent);
  transform: translateY(-2px);
  outline: none;
}
.suggest-cover {
  width: 100%;
  height: 152px;
  object-fit: cover;
  display: block;
  background: var(--raised);
}
.suggest-body { padding: 7px 8px 9px; }
.suggest-title {
  margin: 0;
  font-size: var(--small);
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.suggest-meta {
  margin-top: 4px;
  font-size: var(--caption);
  color: var(--muted);
}
.suggest-match {
  margin-top: 5px;
  display: flex;
  align-items: baseline;
  gap: 5px;
}
.suggest-match .match-label {
  font-size: var(--caption);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Copy toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 12px);
  z-index: 300;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--hairline-strong);
  color: var(--text);
  font-size: var(--small);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Details button on cards */
.info-btn {
  position: absolute;
  right: 10px; bottom: 10px;
  z-index: 3;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: none;
  border-radius: var(--radius-full);
  background: rgba(11, 15, 21, 0.72);
  backdrop-filter: blur(4px);
  color: var(--text);
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 160ms, background 160ms, color 160ms, transform 140ms;
}
.info-btn:hover { opacity: 1; background: var(--accent); color: var(--bg); transform: scale(1.06); }

/* ------------------------------------------------------------------ Responsive */
@media (max-width: 640px) {
  .header-inner { gap: 12px; }
  .brand-text { display: none; }
  .hero { padding: 32px 0 20px; }
  .panel { padding: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .card { opacity: 1; transform: none; }
}
