/* ===== TrendPulse AI — styles ===== */
:root {
  --grad: linear-gradient(135deg, #7c3aed 0%, #ec4899 50%, #f59e0b 100%);
  --accent: #7c3aed;
  --accent-2: #ec4899;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  --maxw: 1200px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #0b0f1a;
  --bg-2: #121829;
  --card: #161d31;
  --card-2: #1d2640;
  --text: #e8ecf6;
  --muted: #9aa6c2;
  --border: #243049;
}

[data-theme="light"] {
  --bg: #f5f6fb;
  --bg-2: #ffffff;
  --card: #ffffff;
  --card-2: #f3f4fb;
  --text: #1a2036;
  --muted: #5a6480;
  --border: #e4e7f2;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win, even over class display rules
   like .modal{display:flex} / .btn{display:inline-flex}. */
[hidden] { display: none !important; }

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 64px;
}

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 18px; }

a { color: inherit; text-decoration: none; }

/* ===== Splash ===== */
.splash {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; background: var(--bg);
  transition: opacity 0.5s ease, visibility 0.5s ease;
}
.splash.hidden { opacity: 0; visibility: hidden; }
.splash-logo { font-size: 72px; animation: pulse 1.4s ease-in-out infinite; }
.splash-name { font-size: 30px; font-weight: 800; letter-spacing: -0.5px; }
.splash-name span {
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.splash-bar { width: 180px; height: 5px; border-radius: 99px; background: var(--border); overflow: hidden; }
.splash-bar span { display: block; height: 100%; width: 40%; background: var(--grad); animation: load 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }
@keyframes load { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }

/* ===== Ticker ===== */
.ticker {
  background: var(--grad); color: #fff; overflow: hidden; white-space: nowrap;
  font-size: 13px; font-weight: 600; padding: 6px 0; position: relative;
}
.ticker-track { display: inline-block; padding-left: 100%; animation: scroll 38s linear infinite; }
.ticker-track span { margin: 0 26px; opacity: 0.95; }
.ticker:hover .ticker-track { animation-play-state: paused; }
@keyframes scroll { 0% { transform: translateX(0); } 100% { transform: translateX(-100%); } }

/* ===== Header ===== */
.header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg-2) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; gap: 16px; height: 62px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 20px; }
.brand-icon { font-size: 24px; }
.brand-name strong { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.nav { display: flex; gap: 6px; margin-left: 8px; }
.nav-link {
  background: none; border: none; color: var(--muted); font: inherit; font-weight: 600;
  padding: 8px 14px; border-radius: 99px; cursor: pointer; display: flex; align-items: center; gap: 6px;
}
.nav-link:hover { color: var(--text); background: var(--card); }
.nav-link.active { color: #fff; background: var(--accent); }
.saved-count {
  background: rgba(255,255,255,0.25); border-radius: 99px; padding: 1px 8px; font-size: 12px;
}
.nav-link:not(.active) .saved-count { background: var(--card-2); }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; font-size: 17px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; transition: transform .15s;
}
.icon-btn:hover { transform: translateY(-1px); }
.menu-toggle { display: none; }
.install-btn { animation: bob 2s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

/* ===== Buttons ===== */
.btn {
  font: inherit; font-weight: 600; border: 1px solid var(--border); cursor: pointer;
  padding: 9px 16px; border-radius: 12px; background: var(--card); color: var(--text);
  transition: transform .15s, filter .15s; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { transform: translateY(-1px); }
.btn-accent { background: var(--grad); color: #fff; border: none; }
.btn-accent:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; }

/* ===== Layout ===== */
.main { padding-top: 22px; }
.layout { display: grid; grid-template-columns: 1fr 320px; gap: 22px; align-items: start; }
.panel {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 18px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 17px; }
.section-head { margin: 6px 0 18px; }

/* ===== Chart panel ===== */
.chart-panel { margin-bottom: 20px; }
.chart-wrap { position: relative; width: 100%; }

/* ===== Controls ===== */
.controls { margin-bottom: 18px; display: flex; flex-direction: column; gap: 14px; }
.search-box { position: relative; }
.search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); opacity: .6; }
.search-box input {
  width: 100%; padding: 13px 14px 13px 40px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--card); color: var(--text); font: inherit;
}
.search-box input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--card); color: var(--muted);
  padding: 8px 16px; border-radius: 99px; cursor: pointer; font: inherit; font-weight: 600; font-size: 14px;
  transition: all .15s;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--grad); color: #fff; border-color: transparent; }
.control-row { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; }
.slider-label, .sort-label { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; font-weight: 600; }
.slider-label input[type="range"] { accent-color: var(--accent); width: 160px; }
.sort-label select {
  background: var(--card); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; font: inherit;
}

/* ===== Card grid ===== */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 11px; position: relative;
  animation: fadeUp .45s ease both;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 99px; background: var(--card-2); color: var(--muted); }
.badge.cat { background: var(--grad); color: #fff; }
.src-badge { font-size: 11px; font-weight: 700; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.src-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); }

.card-title { font-size: 15.5px; font-weight: 700; line-height: 1.35; margin: 0; }
.card-title a:hover { color: var(--accent); }
.card-summary { font-size: 13px; color: var(--muted); margin: 0; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted); }

/* Score meter */
.score-row { display: flex; align-items: center; gap: 10px; }
.meter { flex: 1; height: 8px; border-radius: 99px; background: var(--card-2); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 99px; transition: width .6s ease; }
.score-label { font-size: 12px; font-weight: 700; white-space: nowrap; }
.hot { color: #ef4444; } .hot-bar { background: linear-gradient(90deg,#f97316,#ef4444); }
.rising { color: #f59e0b; } .rising-bar { background: linear-gradient(90deg,#fbbf24,#f59e0b); }
.emerging { color: #3b82f6; } .emerging-bar { background: linear-gradient(90deg,#60a5fa,#3b82f6); }

.spark { width: 100%; height: 34px; display: block; }

/* Card actions */
.card-actions { display: flex; gap: 8px; margin-top: 2px; }
.card-actions .btn { flex: 1; justify-content: center; padding: 8px 10px; font-size: 13px; }
.act-icon {
  width: 38px; flex: 0 0 38px; padding: 0; justify-content: center;
}
.act-icon.active { background: var(--grad); color: #fff; border: none; }

/* ===== Skeletons ===== */
.skeleton {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.sk-line { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--card-2) 25%, var(--border) 37%, var(--card-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
.sk-line.lg { height: 18px; width: 80%; }
.sk-line.sm { width: 40%; }
.sk-block { height: 40px; border-radius: 8px; background: linear-gradient(90deg, var(--card-2) 25%, var(--border) 37%, var(--card-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ===== Sidebar ===== */
.top-list { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
.top-list li {
  counter-increment: rank; display: flex; gap: 11px; padding: 10px 0; border-bottom: 1px solid var(--border);
  align-items: center;
}
.top-list li:last-child { border-bottom: none; }
.top-list li::before {
  content: counter(rank); font-weight: 800; font-size: 14px; width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center; border-radius: 8px;
  background: var(--card-2); color: var(--muted); flex: 0 0 26px;
}
.top-list li:nth-child(-n+3)::before { background: var(--grad); color: #fff; }
.top-item-title { font-size: 13px; font-weight: 600; line-height: 1.3; }
.top-item-meta { font-size: 11px; color: var(--muted); }

.signup .muted { font-size: 13px; margin: 0 0 12px; }
.alert-form { display: flex; flex-direction: column; gap: 8px; }
.alert-form input { padding: 11px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--card); color: var(--text); font: inherit; }

.muted { color: var(--muted); }
.accent { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ===== Empty state ===== */
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-illustration { font-size: 64px; margin-bottom: 8px; }
.empty-state h3 { margin: 6px 0; color: var(--text); }
.empty-state .btn { margin-top: 14px; }

/* ===== About ===== */
.about h1 { font-size: 30px; margin-top: 0; }
.about h3 { margin-top: 22px; }
.about ul { padding-left: 18px; }
.about li { margin: 6px 0; }
.about code { background: var(--card-2); padding: 2px 7px; border-radius: 6px; font-size: 13px; }

/* ===== Footer ===== */
.footer { border-top: 1px solid var(--border); margin-top: 30px; padding: 20px 0; color: var(--muted); }
.footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.footer-nav { display: flex; gap: 18px; }
.footer-nav button, .footer-nav a { background: none; border: none; color: var(--muted); font: inherit; cursor: pointer; }
.footer-nav button:hover, .footer-nav a:hover { color: var(--text); }

/* ===== FAB ===== */
.fab {
  position: fixed; right: 18px; bottom: 18px; z-index: 40;
  width: 54px; height: 54px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--grad); color: #fff; font-size: 22px; box-shadow: var(--shadow);
  transition: transform .15s;
}
.fab:hover { transform: scale(1.08); }

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); animation: fadeIn .25s ease; }
.modal-card {
  position: relative; background: var(--bg-2); border: 1px solid var(--border); border-radius: 20px;
  width: 100%; max-width: 540px; max-height: 86vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow); animation: modalIn .3s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(24px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 0; }
.modal-head h3 { margin: 0; }
.modal-sub { padding: 4px 20px 0; color: var(--muted); font-size: 14px; }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 0 20px 20px; }
.idea-html h1, .idea-html h2, .idea-html h3 { font-size: 16px; margin: 14px 0 4px; }
.idea-html ol, .idea-html ul { padding-left: 20px; }
.idea-html li { margin: 8px 0; }
.idea-html strong { color: var(--accent-2); }

.spinner-wrap { text-align: center; padding: 30px 0; color: var(--muted); }
.spinner {
  width: 44px; height: 44px; border-radius: 50%; margin: 0 auto 14px;
  border: 4px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--card); color: var(--text); border: 1px solid var(--border);
  padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); z-index: 300;
  font-weight: 600; font-size: 14px; animation: toastIn .25s ease;
}
.toast.err { border-color: #ef4444; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { order: -1; }
}
@media (max-width: 680px) {
  .nav { display: none; position: absolute; top: 62px; left: 0; right: 0; flex-direction: column;
    background: var(--bg-2); border-bottom: 1px solid var(--border); padding: 10px; margin: 0; }
  .nav.open { display: flex; }
  .menu-toggle { display: inline-flex; }
  .install-btn { display: none; }
  .control-row { flex-direction: column; align-items: stretch; }
  .slider-label input[type="range"] { flex: 1; width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
