:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --text: #0f172a;
  --muted: #5b6577;
  --border: #e2e7ef;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --primary-soft: #e8f0fe;
  --good: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 4px 16px rgba(15, 23, 42, 0.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --surface: #121a2e;
    --surface-2: #19223a;
    --text: #e6eaf2;
    --muted: #9aa6bd;
    --border: #253050;
    --primary: #5b8cff;
    --primary-ink: #0b1020;
    --primary-soft: #1a2a52;
    --good: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); margin: 0.3em 0 0.2em; }
h2 { font-size: 1.35rem; margin: 1.6em 0 0.5em; }
.h3, h3 { font-size: 1.05rem; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.lead { font-size: 1.1rem; color: var(--muted); margin: 0 0 1.2em; max-width: 60ch; }

/* Header / footer */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.header-inner { display: flex; align-items: center; gap: 16px; height: 60px; }
.logo { font-weight: 700; color: var(--text); display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo:hover { text-decoration: none; }
.logo-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: #fff; font-size: 16px; }
.search { margin-left: auto; flex: 0 1 320px; }
.search input { width: 100%; }
.site-footer { margin-top: 64px; padding: 32px 0; border-top: 1px solid var(--border); background: var(--surface); }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 24px; margin-bottom: 16px; }
.footer-inner p { max-width: 46ch; margin: 8px 0 0; }
.footer-links { display: flex; flex-wrap: wrap; gap: 8px 20px; align-content: flex-start; }
.footer-links a { color: var(--muted); }

/* Home */
.hero { padding: 40px 0 8px; }
.hero h1 { max-width: 22ch; }
.cat h2 { margin-top: 1.8em; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.tool-card {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.15s;
}
.tool-card:hover { border-color: var(--primary); text-decoration: none; transform: translateY(-1px); }
.tool-card strong { display: block; }
.tool-card .small { display: block; line-height: 1.4; margin-top: 2px; }
.tool-icon { font-size: 22px; line-height: 1; padding-top: 2px; }

/* Tool page */
.crumbs { margin-top: 20px; color: var(--muted); }
.crumbs a { color: var(--muted); }
.tool-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.page-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 40px; margin-top: 8px; }
@media (max-width: 860px) { .page-grid { grid-template-columns: minmax(0, 1fr); gap: 0; } }
.sidebar .related { display: grid; gap: 10px; }
.sidebar h2 { margin-top: 2em; }
.prose { max-width: 72ch; }
.prose.narrow { margin: 0 auto; padding-top: 24px; }
.prose li { margin: 0.3em 0; }
.prose code, .formula {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.92em;
}
.formula { display: block; padding: 10px 14px; margin: 1em 0; overflow-x: auto; white-space: nowrap; }
.faq details { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0 16px; margin: 8px 0; }
.faq summary { cursor: pointer; padding: 12px 0; font-weight: 600; }
.faq details > div { padding-bottom: 12px; color: var(--muted); }

/* Forms */
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span, .label { font-size: 0.875rem; font-weight: 600; }
input[type="text"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 220px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.input-group { display: flex; }
.input-group input { border-radius: 10px 0 0 10px; }
.input-group select { width: auto; border-radius: 0 10px 10px 0; border-left: 0; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 0.95rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.checks { display: flex; flex-wrap: wrap; gap: 10px 20px; margin: 14px 0; }
input[type="range"] { width: 100%; accent-color: var(--primary); }
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 10px; padding: 10px 18px; min-height: 44px;
  border: 1px solid var(--primary); background: var(--primary); color: var(--primary-ink);
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
}
.btn:hover { filter: brightness(1.05); text-decoration: none; }
.btn.secondary { background: transparent; color: var(--primary); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; margin-bottom: 16px; flex-wrap: wrap; }
.seg button { font: inherit; font-size: 0.9rem; border: 0; background: transparent; color: var(--muted); padding: 7px 14px; border-radius: 8px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* Results */
.results { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-top: 20px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.stat .label { color: var(--muted); font-weight: 500; display: block; }
.stat .value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat.primary { background: var(--primary-soft); border-color: transparent; }
.stat.primary .value { color: var(--primary); }
.note { margin-top: 14px; color: var(--muted); font-size: 0.9rem; }
.error { color: var(--bad); font-size: 0.9rem; margin-top: 10px; }
.bar { height: 12px; border-radius: 99px; background: var(--surface-2); overflow: hidden; display: flex; margin-top: 16px; border: 1px solid var(--border); }
.bar > span { display: block; height: 100%; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.table-wrap { overflow-x: auto; margin-top: 16px; border: 1px solid var(--border); border-radius: 12px; max-height: 420px; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 12px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }

/* Files */
.drop {
  display: grid; place-items: center; text-align: center; gap: 6px; padding: 32px 16px; cursor: pointer;
  border: 2px dashed var(--border); border-radius: var(--radius); background: var(--surface-2); color: var(--muted);
}
.drop.over, .drop:hover { border-color: var(--primary); color: var(--text); }
.drop strong { color: var(--text); font-size: 1.05rem; }
.drop input { display: none; }
.files { display: grid; gap: 10px; margin-top: 16px; }
.file-row { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.file-row img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; flex: none; background: var(--border); }
.file-row .meta { flex: 1; min-width: 0; }
.file-row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; width: 36px; height: 36px; cursor: pointer; flex: none; }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.good { color: var(--good); }

/* Password */
.output-line { display: flex; gap: 8px; }
.output-line input { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 1.15rem; }
.meter { height: 8px; border-radius: 99px; background: var(--surface-2); margin-top: 10px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; transition: width 0.2s, background 0.2s; }

/* Ads */
.ad { margin: 20px 0; min-height: 90px; text-align: center; }
.ad-placeholder {
  display: grid; place-items: center; border: 1px dashed var(--border); border-radius: 10px;
  color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; background: var(--surface-2);
}

@media (max-width: 560px) {
  .header-inner { height: auto; padding: 10px 16px; flex-wrap: wrap; }
  .search { flex: 1 1 100%; }
  .tool-box { padding: 16px; }
  .stat .value { font-size: 1.25rem; }
}

.btn.secondary[aria-pressed="true"] { background: var(--primary-soft); }
