/* ==========================================================
   ToolHuby - shared stylesheet
   Light and dark themes via [data-theme] on <html>
   ========================================================== */

:root {
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 12px;
  --max-width: 1180px;
  --ease: 200ms ease;
}

[data-theme="light"] {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --header-bg: rgba(255, 255, 255, 0.82);
  --text: #111827;
  --muted: #4b5563;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-hover: #4338ca;
  --border: #6b7280;
  --line: #d9dee8;
  --focus: #4338ca;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --ad-bg: #f1f3f9;
}

[data-theme="dark"] {
  --bg: #0b1020;
  --surface: #161d30;
  --surface-2: #1e2741;
  --header-bg: rgba(11, 16, 32, 0.78);
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #818cf8;
  --accent-text: #0b1020;
  --accent-hover: #a5b4fc;
  --border: #64748b;
  --line: #2a3450;
  --focus: #a5b4fc;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --ad-bg: #121a2e;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  transition: background-color var(--ease), color var(--ease);
}
img, svg { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.6em; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
ul, ol { padding-left: 1.2em; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.container { max-width: var(--max-width); margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); }
.sr-only {
  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: 8px; z-index: 1000;
  background: var(--accent); color: var(--accent-text);
  padding: 10px 16px; border-radius: 8px; font-weight: 700;
}
.skip-link:focus { left: 16px; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--header-bg);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  position: relative;
  max-width: var(--max-width); margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; gap: 16px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 1.15rem; color: var(--text); text-decoration: none;
}
.brand:hover { color: var(--text); }
.brand svg { width: 32px; height: 32px; flex-shrink: 0; }

.primary-nav {
  margin-left: auto; display: flex; align-items: center; gap: 4px;
}
.nav-link, .mega-trigger {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 8px; border: 0; background: transparent;
  color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.nav-link:hover, .mega-trigger:hover, .nav-link[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.mega-trigger svg { width: 14px; height: 14px; transition: transform var(--ease); }
.mega-trigger[aria-expanded="true"] svg { transform: rotate(180deg); }

.has-mega { position: relative; }
.mega-panel {
  position: absolute; top: calc(100% + 12px); right: 0;
  width: min(880px, 92vw);
  display: none; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18); padding: 22px;
}
.has-mega.open .mega-panel { display: grid; }
.mega-title { font-weight: 800; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); margin: 0 0 8px; }
.mega-panel ul { list-style: none; margin: 0; padding: 0; }
.mega-panel li a { display: block; padding: 5px 0; color: var(--text); text-decoration: none; font-size: 0.95rem; }
.mega-panel li a:hover { color: var(--accent); text-decoration: underline; }
.mega-all { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 12px; }

.icon-btn {
  width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
  transition: background-color var(--ease), border-color var(--ease);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.nav-toggle { display: none; }

/* ---------- Hero ---------- */
.hero { padding-top: 56px; padding-bottom: 28px; text-align: center; }
.hero p.lead { font-size: 1.1rem; color: var(--muted); max-width: 680px; margin: 0 auto 24px; }
.hero-search { max-width: 560px; margin: 0 auto; }
.hero-search label { display: block; text-align: left; font-weight: 600; margin-bottom: 6px; }
.hero-search input {
  width: 100%; padding: 14px 16px; font: inherit; font-size: 1rem;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.hero-search input::placeholder { color: var(--muted); }
.search-status { margin-top: 8px; font-size: 0.9rem; color: var(--muted); text-align: left; min-height: 1.4em; }

/* ---------- Sections and cards ---------- */
.section { padding-top: 28px; padding-bottom: 28px; }
.section-title { text-align: left; margin-bottom: 18px; }
.category-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px;
}
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow);
}
.card-icon {
  width: 42px; height: 42px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--accent); margin-bottom: 12px;
}
.card-icon svg { width: 22px; height: 22px; }
.card h2 { font-size: 1.15rem; margin-bottom: 6px; }
.card h2 a { color: var(--text); text-decoration: none; }
.card h2 a:hover { color: var(--accent); }
.card .card-desc { color: var(--muted); font-size: 0.95rem; margin-bottom: 10px; }
.tool-list { list-style: none; margin: 0; padding: 0; }
.tool-list li { border-top: 1px solid var(--line); }
.tool-list li a { display: block; padding: 8px 0; text-decoration: none; font-weight: 500; }
.tool-list li a:hover { text-decoration: underline; }

.popular-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px;
}
.popular-grid .card p { color: var(--muted); font-size: 0.95rem; margin: 0; }
.popular-grid .card a.card-link { font-weight: 700; text-decoration: none; }

.prose { max-width: 780px; }
.prose h2 { margin-top: 1.6em; }

.faq details {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 12px;
}
.faq summary { cursor: pointer; font-weight: 700; }
.faq details p { margin: 10px 0 0; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 10px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 700;
  text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--accent-hover); color: var(--accent-text); }
.btn-outline { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-outline:hover { background: var(--surface-2); color: var(--accent); }

/* ---------- Tool page building blocks ---------- */
.tool-box {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow);
}
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.field .hint { display: block; font-size: 0.875rem; color: var(--muted); margin-top: 4px; }
.field input[type="text"], .field input[type="number"], .field input[type="email"],
.field input[type="search"], .field select, .field textarea {
  width: 100%; padding: 11px 13px; font: inherit;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}
.field textarea { min-height: 140px; resize: vertical; }
.error-msg { color: #b91c1c; font-size: 0.9rem; font-weight: 600; margin-top: 4px; }
[data-theme="dark"] .error-msg { color: #fca5a5; }
.result-box {
  margin-top: 18px; padding: 16px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--line);
  white-space: pre-wrap; word-break: break-word;
}
.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.data-table th, table.data-table td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; }
table.data-table th { color: var(--muted); font-weight: 700; }

/* ---------- Ad slots ---------- */
.ad-slot {
  margin: 24px auto; min-height: 120px; padding: 12px;
  border: 1px dashed var(--border); border-radius: var(--radius); background: var(--ad-bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); font-size: 0.8rem; text-align: center;
}
.ad-slot .ad-label { text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; margin-bottom: 6px; }

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 64px; padding: 36px 0 28px;
  background: var(--surface); border-top: 1px solid var(--line);
}
.footer-grid {
  display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 28px;
}
.footer-grid h2 { font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.footer-grid ul { list-style: none; margin: 0; padding: 0; }
.footer-grid li { margin-bottom: 8px; }
.footer-grid a { color: var(--text); text-decoration: none; }
.footer-grid a:hover { text-decoration: underline; color: var(--accent); }
.footer-bottom {
  margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line);
  font-size: 0.875rem; color: var(--muted);
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px;
}

/* ---------- Responsive ---------- */
@media (max-width: 1020px) {
  .mega-panel { width: min(640px, 92vw); grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 899px) {
  .nav-toggle { display: inline-flex; }
  .primary-nav {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 2px;
    background: var(--surface); border-bottom: 1px solid var(--line);
    padding: 12px 20px 16px; margin: 0; box-shadow: 0 12px 24px rgba(15, 23, 42, 0.12);
  }
  .primary-nav.open { display: flex; }
  .nav-link, .mega-trigger { width: 100%; justify-content: space-between; padding: 12px; }
  .mega-panel {
    position: static; width: auto; box-shadow: none; border: 0;
    grid-template-columns: 1fr; padding: 4px 0 8px 12px; gap: 12px; background: transparent;
  }
  .has-mega.open .mega-panel { display: grid; }
  .category-grid, .popular-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .footer-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .category-grid, .popular-grid { grid-template-columns: 1fr; }
  .footer-grid { grid-template-columns: 1fr; }
  .hero { padding-top: 36px; }
  .brand { font-size: 1.02rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------- Print ---------- */
@media print {
  .site-header, .site-footer, .ad-slot, .no-print, .skip-link { display: none !important; }
  body { background: #fff; color: #000; }
  .card, .tool-box { box-shadow: none; border: 1px solid #000; }
  a { color: #000; text-decoration: none; }
}

/* ---------- Tool-specific components ---------- */
.tool-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.field input[type="file"] { width: 100%; font: inherit; color: var(--text); }
.field input[type="color"] {
  width: 64px; height: 42px; padding: 2px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); cursor: pointer;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; font-weight: 600; min-height: 42px; }
.checkbox-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.score-number { font-size: 2.75rem; font-weight: 800; line-height: 1; margin: 6px 0 4px; color: var(--accent); }
.score-band { font-weight: 700; margin-bottom: 14px; }
.table-wrap { overflow-x: auto; }
.thumb-preview {
  width: 168px; max-width: 100%; aspect-ratio: 16 / 9; border-radius: 10px;
  background: #1f2937 center / cover no-repeat; border: 1px solid var(--line);
  display: flex; flex-direction: column; justify-content: flex-start;
  padding: 8px; overflow: hidden;
}
.thumb-preview span { line-height: 1.15; overflow-wrap: anywhere; }
.preview-caption { font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
@media (max-width: 600px) {
  .tool-controls { grid-template-columns: 1fr; }
}

/* ---------- Internal link suggester and hook counter ---------- */
mark.hit {
  background: rgba(129, 140, 248, 0.25); color: inherit; padding: 0 3px; border-radius: 4px;
  box-shadow: inset 0 -2px 0 var(--accent);
}
.link-list li { margin-bottom: 18px; }
.link-list .suggestion-meta { font-size: 0.9rem; color: var(--muted); margin: 4px 0 0; }
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.range-row input[type="number"] {
  width: 96px; padding: 10px 12px; font: inherit;
  border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 12px; text-align: center; }
.stat strong { display: block; font-size: 1.5rem; color: var(--accent); line-height: 1.2; }
.stat span { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
@media (max-width: 600px) { .stat-grid { grid-template-columns: 1fr; } }

/* ---------- Dynamic rows, tickers and option groups (tools 6-10) ---------- */
.item-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.item-row {
  display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px; align-items: end;
}
.item-row .field { margin-bottom: 0; }
.item-row .field label { font-size: 0.85rem; }
.item-row .remove-btn {
  height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.item-row .remove-btn:hover { background: var(--surface-2); }
@media (max-width: 600px) {
  .item-row { grid-template-columns: 1fr 1fr; }
  .item-row .field:first-child { grid-column: 1 / -1; }
}
.ticker {
  font-size: 2.2rem; font-weight: 800; color: var(--accent);
  font-variant-numeric: tabular-nums; line-height: 1.1; margin: 4px 0;
}
.option-group { display: flex; flex-wrap: wrap; gap: 10px; }
.option-group label {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); cursor: pointer; font-weight: 600;
}
.option-group input { accent-color: var(--accent); width: 16px; height: 16px; }
.warning-box {
  border-left: 4px solid var(--accent); background: var(--surface-2);
  padding: 12px 16px; border-radius: 0 10px 10px 0; margin-top: 16px; font-size: 0.95rem;
}

/* ---------- Print-only tracker, caption preview, and dynamic subject rows (tools 16-20) ---------- */
.print-area { margin-top: 20px; }
.print-area h3 { font-size: 1.1rem; margin-bottom: 6px; }
.print-area table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.print-area th, .print-area td { border: 1px solid #6b7280; padding: 4px 6px; text-align: left; color: #111827; background: transparent; }
.print-area thead { display: table-header-group; }
.print-area td.check { width: 60px; }
.print-area th:first-child, .print-area td:first-child { width: 48px; }
.print-area th:nth-child(2), .print-area td:nth-child(2) { width: 130px; white-space: nowrap; }
.caption-preview {
  width: 343px; max-width: 100%; padding: 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); font-size: 15px; line-height: 1.45;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.caption-preview .more { color: var(--accent); font-weight: 700; }
.caption-preview .hidden-part { color: var(--muted); }
.subject-row {
  display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto;
  gap: 10px; align-items: end; margin-bottom: 10px;
}
.subject-row .field { margin-bottom: 0; }
.schedule-table td.break { color: var(--muted); }
@media (max-width: 600px) {
  .subject-row { grid-template-columns: 1fr; }
}
@media print {
  body * { visibility: hidden !important; }
  .print-area, .print-area * { visibility: visible !important; }
  .print-area { position: absolute; left: 0; top: 0; width: 100%; margin: 0; }
  .print-area .print-title { color: #000; }
}

/* ---- Article typography (set per article in the writer) ---- */
.art-font-serif { font-family: Georgia, "Times New Roman", serif; }
.art-font-mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.art-size-large { font-size: 1.15rem; line-height: 1.8; }
.art-body figure { margin: 24px 0; }
.art-body figure img { max-width: 100%; height: auto; border-radius: 10px; display: block; }
.art-body blockquote { margin: 18px 0; padding: 4px 16px; border-left: 4px solid #6366f1; opacity: .92; }
.art-body ol { padding-left: 22px; }
