/* ==========================================================================
   Daily Tools — stylesheet
   Mobile-first. Light theme is the default; dark theme via [data-theme="dark"].
   No CSS frameworks, no web fonts (system font stack = zero font requests).
   ========================================================================== */

/* ---------- 1. Design tokens ---------- */
:root {
  --brand:        #2563eb;
  --brand-strong: #1d4ed8;
  --brand-soft:   #dbeafe;

  --bg:           #f7f8fa;
  --bg-elev:      #ffffff;
  --bg-elev-2:    #f1f3f7;
  --border:       #e3e6ec;
  --border-strong:#cfd4de;

  --text:         #16181d;
  --text-soft:    #5b6270;
  --text-faint:   #8b92a1;

  --shadow-sm: 0 1px 2px rgba(16, 20, 30, .06);
  --shadow-md: 0 4px 14px rgba(16, 20, 30, .08);
  --shadow-lg: 0 12px 32px rgba(16, 20, 30, .12);

  --radius:    14px;
  --radius-sm: 9px;
  --radius-pill:999px;

  --wrap: 1180px;
  --gap: 16px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;
}

[data-theme="dark"] {
  --brand:        #60a5fa;
  --brand-strong: #3b82f6;
  --brand-soft:   #17233d;

  --bg:           #0b1220;
  --bg-elev:      #131a2a;
  --bg-elev-2:    #1a2333;
  --border:       #263148;
  --border-strong:#35425e;

  --text:         #e8ecf4;
  --text-soft:    #a3adc2;
  --text-faint:   #74809a;

  --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);
}

/* ---------- 2. Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 148px; /* clears the sticky header on anchor jumps */
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

h1, h2, h3 { line-height: 1.25; letter-spacing: -.015em; margin: 0 0 .5em; }
h1 { font-size: clamp(1.65rem, 1.2rem + 2.2vw, 2.6rem); font-weight: 800; }
h2 { font-size: clamp(1.25rem, 1.05rem + 1vw, 1.6rem); font-weight: 750; }
h3 { font-size: 1.02rem; font-weight: 700; }
p  { margin: 0 0 1rem; }
a  { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { max-width: 100%; }
kbd {
  font-family: var(--mono); font-size: .78em; padding: .1em .4em;
  border: 1px solid var(--border-strong); border-bottom-width: 2px;
  border-radius: 5px; background: var(--bg-elev-2); color: var(--text-soft);
}
code { font-family: var(--mono); font-size: .86em; color: var(--text-soft); }

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

.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: 0; z-index: 100;
  background: var(--brand); color: #fff; padding: 10px 16px;
  border-radius: 0 0 var(--radius-sm) 0; font-weight: 600;
}
.skip-link:focus { left: 0; }

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

/* ---------- 3. Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
@supports not (backdrop-filter: blur(1px)) { .site-header { background: var(--bg-elev); } }

.header-inner {
  display: flex; align-items: center; gap: 12px;
  padding-block: 12px;
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); flex: 0 0 auto; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 1.06rem; font-weight: 800; letter-spacing: -.02em; }
.brand-text small { font-size: .7rem; color: var(--text-faint); }

/* Search */
.search { position: relative; flex: 1 1 auto; max-width: 460px; margin-left: auto; }
.search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--text-faint); pointer-events: none;
}
#search-input {
  width: 100%; height: 42px; padding: 0 38px 0 38px;
  font: inherit; font-size: .94rem; color: var(--text);
  background: var(--bg-elev-2);
  border: 1.5px solid var(--border); border-radius: var(--radius-pill);
  transition: border-color .15s, background .15s;
  -webkit-appearance: none; appearance: none;
}
#search-input::placeholder { color: var(--text-faint); }
#search-input:focus {
  outline: none; background: var(--bg-elev);
  border-color: var(--brand);
  box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--brand) 18%, transparent);
}
#search-input::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; display: grid; place-items: center;
  font-size: 20px; line-height: 1; color: var(--text-faint);
  background: none; border: 0; border-radius: 50%; cursor: pointer;
}
.search-clear:hover { background: var(--bg-elev-2); color: var(--text); }

/* Theme toggle */
.theme-toggle {
  flex: 0 0 auto; width: 42px; height: 42px; display: grid; place-items: center;
  background: var(--bg-elev-2); border: 1.5px solid var(--border);
  border-radius: 50%; color: var(--text-soft); cursor: pointer;
  transition: color .15s, border-color .15s, transform .15s;
}
.theme-toggle:hover { color: var(--brand); border-color: var(--brand); transform: rotate(12deg); }
.theme-toggle svg { width: 19px; height: 19px; }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* Category nav (horizontally scrollable on mobile) */
.category-nav { border-top: 1px solid var(--border); background: var(--bg-elev); }
.category-nav ul {
  display: flex; gap: 4px; list-style: none; margin: 0; padding: 8px 0;
  overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none;
  scroll-snap-type: x proximity;
}
.category-nav ul::-webkit-scrollbar { display: none; }
.chip {
  display: inline-block; white-space: nowrap; scroll-snap-align: start;
  padding: 7px 13px; border-radius: var(--radius-pill);
  font-size: .84rem; font-weight: 600; color: var(--text-soft);
  border: 1px solid transparent; transition: background .15s, color .15s;
}
.chip:hover { background: var(--bg-elev-2); color: var(--text); text-decoration: none; }
.chip.is-active { background: var(--brand); color: #fff; }
[data-theme="dark"] .chip.is-active { color: #08111f; }

/* ---------- 4. Hero ---------- */
.hero { padding-block: clamp(26px, 5vw, 52px) 8px; text-align: center; }
.hero-sub {
  max-width: 62ch; margin-inline: auto; color: var(--text-soft);
  font-size: clamp(.96rem, .9rem + .3vw, 1.06rem);
}
.hero-sub strong { color: var(--text); font-weight: 650; }

.hero-stats {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 12px;
  list-style: none; margin: 22px 0 0; padding: 0;
}
.hero-stats li {
  display: flex; align-items: baseline; gap: 6px;
  padding: 7px 15px; border-radius: var(--radius-pill);
  background: var(--bg-elev); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.hero-stats strong { font-size: 1.02rem; color: var(--brand); font-weight: 800; }
.hero-stats span { font-size: .8rem; color: var(--text-soft); }

.result-status {
  margin: 18px 0 6px; padding: 11px 16px;
  background: var(--brand-soft); color: var(--brand-strong);
  border-radius: var(--radius-sm); font-size: .9rem; font-weight: 600;
}
[data-theme="dark"] .result-status { color: var(--text); }
.search-hint { font-size: .82rem; color: var(--text-faint); margin: 14px 0 0; }

/* ---------- 5. Categories & cards ---------- */
.category { padding-block: clamp(22px, 3.5vw, 36px); scroll-margin-top: 150px; }
.category[hidden] { display: none; }

.category-head { margin-bottom: 16px; }
.category-head h2 { display: flex; align-items: center; gap: 10px; }
.category-head h2::before {
  content: ""; width: 5px; height: 1.05em; border-radius: 3px;
  background: linear-gradient(180deg, var(--brand), color-mix(in srgb, var(--brand) 45%, #38bdf8));
  flex: 0 0 auto;
}
.category-head p { margin: 2px 0 0; color: var(--text-soft); font-size: .92rem; }

.grid {
  display: grid; gap: var(--gap); margin: 0; padding: 0; list-style: none;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
}

.card { min-width: 0; }
.card[hidden] { display: none; }
.card > a {
  display: flex; flex-direction: column; gap: 3px; height: 100%;
  padding: 14px 16px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.card > a:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--brand) 55%, var(--border));
  box-shadow: var(--shadow-md);
  text-decoration: none;
}
.card-title {
  display: flex; align-items: center; gap: 7px;
  font-weight: 700; font-size: .99rem; color: var(--text); letter-spacing: -.01em;
}
.card-title::after {
  content: "↗"; font-size: .74em; color: var(--text-faint);
  margin-left: auto; opacity: 0; transition: opacity .16s;
  font-weight: 500;
}
.card > a:hover .card-title::after { opacity: 1; color: var(--brand); }
.card-desc { font-size: .855rem; color: var(--text-soft); line-height: 1.5; }
.card-url {
  margin-top: 5px; font-family: var(--mono); font-size: .74rem;
  color: var(--text-faint); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

/* Highlight search matches */
.card mark {
  background: color-mix(in srgb, var(--brand) 26%, transparent);
  color: inherit; border-radius: 3px; padding: 0 2px;
}

/* ---------- 6. Closing + FAQ ---------- */
.closing { padding-block: clamp(26px, 4vw, 44px) 12px; }
.closing-grid {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.closing-grid article {
  padding: 16px 18px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.closing-grid h3 { color: var(--brand-strong); }
[data-theme="dark"] .closing-grid h3 { color: var(--brand); }
.closing-grid p { margin: 0; font-size: .89rem; color: var(--text-soft); }

.faq { padding-block: clamp(20px, 3vw, 34px) 44px; }
.faq details {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 8px; overflow: hidden;
}
.faq summary {
  cursor: pointer; padding: 13px 16px; font-weight: 650; font-size: .93rem;
  list-style: none; position: relative; padding-right: 42px;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "+"; position: absolute; right: 16px; top: 50%;
  transform: translateY(-50%); font-size: 1.25rem; font-weight: 400;
  color: var(--brand); transition: transform .18s;
}
.faq details[open] summary::after { content: "\2212"; }
.faq details[open] summary { border-bottom: 1px solid var(--border); }
.faq details p { margin: 0; padding: 12px 16px; font-size: .89rem; color: var(--text-soft); }

/* ---------- 7. Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border); background: var(--bg-elev);
  padding-block: 26px; margin-top: 12px;
}
.footer-inner { display: grid; gap: 12px; justify-items: center; text-align: center; }
.footer-inner p { margin: 0; font-size: .89rem; color: var(--text-soft); }
.footer-inner nav ul {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px;
  list-style: none; margin: 0; padding: 0;
}
.footer-inner nav a { font-size: .87rem; font-weight: 600; }
.fine-print { font-size: .78rem !important; color: var(--text-faint) !important; }

.noscript-note {
  padding: 12px 16px; margin-bottom: 24px; font-size: .88rem;
  background: var(--brand-soft); color: var(--brand-strong);
  border-radius: var(--radius-sm);
}
[data-theme="dark"] .noscript-note { color: var(--text); }

/* ---------- 8. Responsive ---------- */
@media (max-width: 860px) {
  .header-inner { flex-wrap: wrap; padding-block: 10px; }
  .brand { flex: 1 1 auto; }
  .search { order: 3; flex: 1 0 100%; max-width: none; margin-left: 0; }
  .theme-toggle { order: 2; }
  html { scroll-padding-top: 190px; }
  .category, .category-head { scroll-margin-top: 190px; }
}

@media (max-width: 560px) {
  body { font-size: 15.5px; }
  .wrap { padding-inline: 14px; }
  .brand-text small { display: none; }
  .hero { text-align: left; }
  .hero-sub, .hero-stats { margin-inline: 0; }
  .hero-stats { justify-content: flex-start; gap: 8px; }
  .hero-stats li { padding: 6px 12px; }
  .grid { grid-template-columns: 1fr; gap: 10px; }
  .card > a { padding: 13px 14px; }
  .card-url { display: none; }
  .category-nav ul { padding: 7px 0; }
}

/* Very small screens: two columns still fit for short cards */
@media (max-width: 380px) {
  .grid { grid-template-columns: 1fr; }
}

/* ---------- 9. Motion & print ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .001ms !important; animation-duration: .001ms !important; }
  .card > a:hover { transform: none; }
}

@media print {
  .site-header, .category-nav, .search-hint, .theme-toggle, .skip-link { display: none !important; }
  body { background: #fff; color: #000; }
  .card > a { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .category { break-inside: avoid; }
}
