/* ==========================================================================
   SP Search — Design System
   Palette: Professional Blue / Ink / Surface / Slate
   Type:    Plus Jakarta Sans (brand) · Inter (UI/body)
   ========================================================================== */

:root {
  --paper: #F8F9FC;
  --paper-raised: #FFFFFF;
  --ink: #0F1117;
  --slate: #64697A;
  --slate-light: #9EA3B0;
  --mist: #E8EAF0;
  --mist-strong: #D0D3DC;

  --primary: #1E40AF;
  --primary-hover: #1D3899;
  --primary-soft: rgba(30, 64, 175, 0.08);

  --accent: #2563EB;
  --accent-soft: rgba(37, 99, 235, 0.1);

  --success: #059669;
  --warn: #D97706;

  --radius-full: 999px;
  --radius-xl: 20px;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;

  --shadow-xs: 0 1px 2px rgba(15, 17, 23, 0.05);
  --shadow-sm: 0 2px 6px rgba(15, 17, 23, 0.07);
  --shadow-md: 0 8px 28px rgba(15, 17, 23, 0.10);
  --shadow-lg: 0 20px 56px rgba(15, 17, 23, 0.14);

  --font-brand: "Plus Jakarta Sans", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Menlo, "Courier New", monospace;

  --header-max: 660px;
  --content-max: 780px;

  --transition-fast: 150ms ease;
  --transition-med: 300ms cubic-bezier(.22, 1, .36, 1);
}

/* ==========================================================================
   Dark Mode — Rich professional dark palette with depth & hierarchy
   ========================================================================== */

html[data-theme="dark"] {
  /* Layered dark surfaces — NOT pure black */
  --paper:        #111318;   /* base page background   */
  --paper-raised: #1C1F28;   /* cards, inputs, surfaces */
  --paper-float:  #252933;   /* elevated elements       */

  --ink:          #E8EBF4;   /* primary text            */
  --slate:        #9198AA;   /* secondary text          */
  --slate-light:  #5C6270;   /* muted / disabled        */

  --mist:         #1F222E;   /* subtle dividers / hover */
  --mist-strong:  #2C3042;   /* borders                 */

  /* Blue — slightly brighter for dark bg legibility */
  --primary:      #4F8EF7;
  --primary-hover: #6BA5FF;
  --primary-soft: rgba(79, 142, 247, 0.15);

  --accent:       #60A5FA;
  --accent-soft:  rgba(96, 165, 250, 0.13);

  --warn: #F59E0B;

  /* Shadows have tinted glow, not pure black */
  --shadow-xs: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.45),
               inset 0 1px 0 rgba(255, 255, 255, 0.04);
  --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.5),
               inset 0 1px 0 rgba(255, 255, 255, 0.05);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.6),
               0 0 0 1px rgba(255, 255, 255, 0.04);
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition-med), color var(--transition-med);
}

/* Dark mode body gets a subtle blue-tinted gradient for depth */
html[data-theme="dark"] body {
  background: linear-gradient(160deg, #13161F 0%, #111318 60%, #0E1119 100%);
  background-attachment: fixed;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button { font-family: inherit; }

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--primary);
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  z-index: 100;
  font-weight: 600;
}
.skip-link:focus { left: 12px; top: 12px; }

kbd {
  font-family: var(--font-mono);
  font-size: 0.75em;
  background: var(--mist);
  border-radius: 4px;
  padding: 2px 6px;
  border: 1px solid var(--mist-strong);
  border-bottom-width: 2px;
  color: var(--slate);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  padding: 11px 24px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: transform var(--transition-fast), background var(--transition-fast),
              border-color var(--transition-fast), box-shadow var(--transition-fast),
              color var(--transition-fast);
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(30, 64, 175, 0.25);
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 14px rgba(30, 64, 175, 0.3);
}
html[data-theme="dark"] .btn-primary {
  box-shadow: 0 2px 12px rgba(79, 142, 247, 0.35);
}
html[data-theme="dark"] .btn-primary:hover {
  box-shadow: 0 4px 20px rgba(79, 142, 247, 0.45);
}

.btn-ghost {
  background: transparent;
  border-color: var(--mist-strong);
  color: var(--slate);
}
.btn-ghost:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}
html[data-theme="dark"] .btn-ghost {
  border-color: #2C3042;
  color: var(--slate);
}
html[data-theme="dark"] .btn-ghost:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(79, 142, 247, 0.12);
}

.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--slate);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--mist); color: var(--ink); }

/* ==========================================================================
   Header
   ========================================================================== */

.header {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px clamp(16px, 5vw, 48px) 8px;
  transition: padding var(--transition-med);
}

.header-row {
  width: 100%;
  max-width: var(--header-max);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  flex-shrink: 0;
}
.brand-mark {
  display: inline-flex;
  flex-shrink: 0;
  transition: transform var(--transition-med);
}
.brand:hover .brand-mark { transform: scale(1.05); }

.brand-name {
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.header-tools { display: inline-flex; gap: 4px; align-items: center; }

.icon-moon { display: none; }
html[data-theme="dark"] .icon-sun { display: none; }
html[data-theme="dark"] .icon-moon { display: inline-flex; }

.tagline {
  font-family: var(--font-brand);
  font-weight: 700;
  color: var(--slate);
  font-size: 1.05rem;
  margin: 20px 0 24px;
  text-align: center;
  letter-spacing: -0.01em;
  transition: opacity var(--transition-fast), margin var(--transition-med);
}

.hint {
  color: var(--slate-light);
  font-size: 0.8rem;
  margin: 16px 0 4px;
  text-align: center;
  transition: opacity var(--transition-fast);
  padding: 0 16px;
}

/* --- Search form & compass ring --- */

.search-form {
  width: 100%;
  max-width: var(--header-max);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.search-box {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper-raised);
  border: 1.5px solid var(--mist-strong);
  border-radius: var(--radius-full);
  padding: 13px 18px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}
.search-box:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--slate-light);
}
.search-box.is-focused {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft), var(--shadow-md);
}

/* Dark mode: search box gets a clearly elevated surface with visible border */
html[data-theme="dark"] .search-box {
  background: #1C1F2A;
  border-color: #313649;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.05);
}
html[data-theme="dark"] .search-box:hover {
  border-color: #4a5180;
  box-shadow: 0 4px 20px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.06);
}
html[data-theme="dark"] .search-box.is-focused {
  border-color: var(--primary);
  background: #1E2130;
  box-shadow: 0 0 0 3px rgba(79,142,247,0.2), 0 4px 20px rgba(0,0,0,0.45);
}

.search-icon {
  position: relative;
  width: 22px;
  height: 22px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--slate);
}

.icon-ring {
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  opacity: 0;
  background: conic-gradient(from 0deg, var(--primary), var(--accent), var(--primary));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
  transition: opacity var(--transition-fast);
}
.search-box.is-focused .icon-ring { opacity: 0.85; }
.search-box.is-loading .icon-ring {
  opacity: 1;
  animation: spin 0.85s linear infinite;
}
.search-box.is-loading .icon-glass { opacity: 0.2; }

@keyframes spin { to { transform: rotate(360deg); } }

#searchInput {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 400;
  min-width: 0;
}
#searchInput::placeholder { color: var(--slate-light); }

.clear-btn {
  flex: none;
  border: none;
  background: var(--mist);
  color: var(--slate);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.clear-btn:hover { background: var(--mist-strong); color: var(--ink); }

.search-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  transition: opacity var(--transition-fast);
}

/* ==========================================================================
   HOME state
   ========================================================================== */

body.home .header {
  flex: 1;
  justify-content: center;
  padding-top: 8vh;
  padding-bottom: 8vh;
}
body.home .tagline { display: block; }

/* ==========================================================================
   RESULTS state — slim sticky top bar
   ========================================================================== */

body.results .header {
  align-items: stretch;
  padding: 12px clamp(12px, 4vw, 40px);
  border-bottom: 1px solid var(--mist);
  position: sticky;
  top: 0;
  background: var(--paper);
  z-index: 20;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
html[data-theme="dark"] body.results .header {
  background: rgba(17, 19, 24, 0.85);
  border-bottom-color: #252934;
  box-shadow: 0 1px 24px rgba(0,0,0,0.5);
}
body.results .header-row { max-width: none; }
body.results .brand-name { font-size: 1.2rem; }
body.results .tagline,
body.results .hint { display: none; }

body.results .search-form {
  flex-direction: row;
  max-width: none;
  margin-top: 10px;
  gap: 8px;
  align-items: center;
}
body.results .search-box {
  padding: 9px 16px;
  flex: 1;
  min-width: 0;
}
body.results #searchInput { font-size: 0.95rem; }
body.results .search-actions #curiousBtn { display: none; }
body.results .search-actions .btn { padding: 9px 18px; font-size: 0.85rem; }

/* Results mobile breakpoint */
@media (max-width: 640px) {
  body.results .search-form { flex-wrap: wrap; }
  body.results .search-box { order: 1; flex-basis: 100%; }
  body.results .search-actions { order: 2; flex-basis: 100%; justify-content: flex-start; }
}

/* ==========================================================================
   Main / Results area
   ========================================================================== */

main {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 clamp(14px, 4vw, 40px) 60px;
  flex: 1;
}

.tabs {
  display: flex;
  gap: 0;
  margin: 16px 0 4px;
  border-bottom: 1.5px solid var(--mist);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  appearance: none;
  border: none;
  background: none;
  color: var(--slate);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1.5px;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.tab:hover { color: var(--ink); }
.tab.is-active {
  color: var(--primary);
  border-color: var(--primary);
}
.tab:disabled { color: var(--slate-light); cursor: default; }
.tab .tab-count {
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 0.78em;
  margin-left: 5px;
  color: var(--slate-light);
}

.status-line {
  color: var(--slate-light);
  font-size: 0.82rem;
  font-family: var(--font-mono);
  margin: 12px 0 8px;
}
.status-line.is-error { color: var(--warn); }

.results-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* --- Result card --- */

.result-card {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  padding: 14px 12px;
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.result-card:hover {
  background: var(--mist);
  border-color: var(--mist-strong);
}
html[data-theme="dark"] .result-card:hover {
  background: #1E2130;
  border-color: #2C3145;
  box-shadow: 0 2px 16px rgba(0,0,0,0.35);
}

.result-main { flex: 1; min-width: 0; }

.result-breadcrumb {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.8rem;
  color: var(--slate);
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.result-favicon {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  flex: none;
  object-fit: cover;
  background: var(--mist);
}
.result-host { font-family: var(--font-mono); font-size: 0.78rem; }
.result-date::before { content: "·"; margin-right: 6px; color: var(--mist-strong); }

.result-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
}

.result-title {
  font-size: 1.06rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  display: inline-block;
  line-height: 1.35;
  letter-spacing: -0.01em;
}
.result-title:hover { color: var(--primary); text-decoration: underline; }

.result-desc {
  color: var(--slate);
  font-size: 0.9rem;
  margin: 5px 0 0;
  line-height: 1.6;
}
.result-desc mark {
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 3px;
  padding: 0 2px;
}

.result-thumb {
  flex: none;
  width: 100px;
  height: 76px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--mist);
}
.result-thumb img { width: 100%; height: 100%; object-fit: cover; }

@media (max-width: 560px) {
  .result-thumb { display: none; }
  .result-title { font-size: 1rem; }
  .result-desc { font-size: 0.875rem; }
}

/* --- Top stories row (All tab) --- */

.top-stories-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--slate-light);
  margin: 12px 12px 10px;
}

.top-stories {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 2px 12px 16px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--mist);
  scrollbar-width: thin;
  scrollbar-color: var(--mist-strong) transparent;
  -webkit-overflow-scrolling: touch;
}

.story-chip {
  flex: none;
  width: 190px;
  text-decoration: none;
  color: var(--ink);
  border-radius: var(--radius-lg);
  padding: 8px;
  border: 1px solid transparent;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.story-chip:hover { background: var(--mist); text-decoration: none; border-color: var(--mist-strong); }
html[data-theme="dark"] .story-chip:hover {
  background: #1E2130;
  border-color: #2C3145;
  text-decoration: none;
}

.story-thumb {
  width: 100%;
  height: 90px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--mist);
  margin-bottom: 8px;
}
.story-thumb img { width: 100%; height: 100%; object-fit: cover; }

.story-title {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.35;
  margin: 0 0 4px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  letter-spacing: -0.005em;
}

.story-meta {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--slate-light);
  margin: 0;
}

/* --- Empty / error / loading states --- */

.state-panel {
  text-align: center;
  padding: 72px 20px;
  color: var(--slate);
}
.state-panel h2 {
  font-family: var(--font-brand);
  font-weight: 700;
  color: var(--ink);
  font-size: 1.35rem;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}
.state-panel p { margin: 0 auto; max-width: 44ch; font-size: 0.92rem; }
.state-panel .btn { margin-top: 20px; }

.skeleton-card { display: flex; gap: 18px; padding: 16px 12px; }
.skeleton-lines { flex: 1; }
.skeleton-line {
  height: 11px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--mist) 25%, var(--mist-strong) 37%, var(--mist) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  margin-bottom: 10px;
}
.skeleton-line.w-30 { width: 30%; height: 9px; }
.skeleton-line.w-60 { width: 60%; height: 15px; }
.skeleton-line.w-90 { width: 90%; }
.skeleton-line.w-80 { width: 80%; }

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* --- Pagination --- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 32px;
  flex-wrap: wrap;
}
.page-indicator {
  font-family: var(--font-mono);
  color: var(--slate);
  font-size: 0.82rem;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
  text-align: center;
  color: var(--slate-light);
  font-size: 0.78rem;
  padding: 22px 16px 26px;
}
body.results .site-footer {
  border-top: 1px solid var(--mist);
  margin-top: 8px;
}
html[data-theme="dark"] .site-footer {
  border-top-color: #1F222E;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.footer-api,
.footer-credit {
  margin: 0;
  line-height: 1.4;
}

.footer-sep {
  color: var(--mist-strong);
  font-size: 0.9rem;
  user-select: none;
}

/* API link — muted */
.footer-api a {
  color: var(--slate);
  text-decoration: none;
  transition: color var(--transition-fast);
}
.footer-api a:hover { color: var(--primary); text-decoration: underline; }

/* Creator credit — slightly more prominent */
.footer-credit a {
  color: var(--slate);
  font-weight: 600;
  text-decoration: none;
  transition: color var(--transition-fast);
}
.footer-credit a:hover {
  color: var(--primary);
  text-decoration: underline;
}
html[data-theme="dark"] .footer-credit a {
  color: var(--slate);
}
html[data-theme="dark"] .footer-credit a:hover {
  color: var(--primary);
}

/* ==========================================================================
   Mobile-first responsive tweaks
   ========================================================================== */

/* Phones — up to 480px */
@media (max-width: 480px) {
  body.home .header {
    padding-top: 6vh;
    padding-bottom: 6vh;
  }

  .brand-name { font-size: 1.25rem; }

  .tagline {
    font-size: 0.95rem;
    margin: 16px 0 20px;
  }

  .search-box { padding: 12px 14px; }

  #searchInput { font-size: 0.95rem; }

  .btn { padding: 10px 20px; font-size: 0.875rem; }

  .search-actions { gap: 8px; }

  .hint { font-size: 0.75rem; }

  .result-card { padding: 12px 8px; gap: 12px; }

  .top-stories { gap: 10px; padding: 2px 8px 14px; }
  .story-chip { width: 160px; }

  .pagination { gap: 10px; }
  .pagination .btn { padding: 9px 16px; font-size: 0.82rem; }
}

/* Tablets — 481px to 768px */
@media (min-width: 481px) and (max-width: 768px) {
  .brand-name { font-size: 1.35rem; }
  .tagline { font-size: 1rem; }
}

/* ==========================================================================
   Reduced motion
   ========================================================================== */

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