/* Toolstead site stylesheet. Zero framework, dark mode included.
   Comments are English on purpose, and clipped to one line: see README 2.1. */

:root {
  color-scheme: light dark;

  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-sunken: #eceef2;
  --fg: #16181d;
  --fg-muted: #5b616e;
  --fg-faint: #858b98;
  --border: #d9dce3;
  --border-strong: #b9bec9;

  --accent: #1f5eff;
  --accent-hover: #1a4fd8;
  --accent-fg: #ffffff;

  --ok: #0b7a3b;
  --ok-bg: #e8f6ee;
  --warn: #8a5300;
  --warn-bg: #fdf3e2;
  --error: #b3170f;
  --error-bg: #fdecea;

  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 1px 2px rgb(16 18 22 / 6%), 0 4px 12px rgb(16 18 22 / 5%);

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

  --wrap: 1120px;
  --gutter: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --bg-soft: #171a21;
    --bg-sunken: #1e222b;
    --fg: #eceef2;
    --fg-muted: #a2a9b8;
    --fg-faint: #767d8c;
    --border: #2b303b;
    --border-strong: #3c424f;

    --accent: #659bff;
    --accent-hover: #82aeff;
    --accent-fg: #0b1220;

    --ok: #5fd08b;
    --ok-bg: #13301f;
    --warn: #e5b463;
    --warn-bg: #33280f;
    --error: #ff8a80;
    --error-bg: #3a1614;

    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 30%);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.6 var(--font-sans); overflow-wrap: break-word; }
img { max-width: 100%; height: auto; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

.visually-hidden { position: absolute !important; 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(--accent); color: var(--accent-fg); padding: 10px 16px; border-radius: 0 0 var(--radius) 0; }
.skip-link:focus { left: 0; }

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; font-weight: 650; }
h1 { font-size: clamp(1.65rem, 1.2rem + 2vw, 2.35rem); letter-spacing: -.02em; }
h2 { font-size: clamp(1.3rem, 1.1rem + 1vw, 1.65rem); margin-top: 2em; }
h3 { font-size: 1.12rem; margin-top: 1.6em; }
p { margin: 0 0 1em; }
.lede { font-size: 1.075rem; color: var(--fg-muted); max-width: 68ch; }
.muted { color: var(--fg-muted); }
.small { font-size: .875rem; }
code, kbd, pre, samp { font-family: var(--font-mono); font-size: .9em; }
code { background: var(--bg-sunken); padding: .12em .38em; border-radius: var(--radius-sm); }
pre { background: var(--bg-sunken); padding: 14px 16px; border-radius: var(--radius); overflow-x: auto; border: 1px solid var(--border); }
pre code { background: none; padding: 0; }

/* `hidden` must actually hide: an author `display` beats the element-level UA rule (README 2.1). */
[hidden] { display: none !important; }

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

.site-header { border-bottom: 1px solid var(--border); background: var(--bg); position: sticky; top: 0; z-index: 20; }
/* Header: brand | nav (fills the middle) | language switcher (far right). See README 2.1. */
.site-header__inner { display: flex; align-items: center; gap: 16px; min-height: 60px; }
.brand { font-weight: 700; font-size: 1.05rem; text-decoration: none; color: var(--fg); white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; }
.brand__mark { width: 20px; height: 20px; flex: 0 0 auto; display: block; }
.site-nav { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.site-nav a { padding: 7px 11px; border-radius: var(--radius-sm); text-decoration: none; color: var(--fg-muted); font-size: .9375rem; }
.site-nav a:hover { background: var(--bg-soft); color: var(--fg); }
.site-nav a[aria-current="page"] { color: var(--fg); font-weight: 600; background: var(--bg-soft); }

/* Language switcher: build-time link pair, zero JS, present on every page (README 2.1). */
.lang-switcher { display: flex; align-items: center; gap: 2px; margin-left: auto; font-size: .8125rem; white-space: nowrap; }
.lang-switcher__current,
.lang-switcher__link { padding: 4px 8px; border-radius: var(--radius-sm); text-decoration: none; }
.lang-switcher__current { color: var(--fg); font-weight: 600; background: var(--bg-soft); }
.lang-switcher__link { color: var(--fg-muted); }
.lang-switcher__link:hover { color: var(--fg); background: var(--bg-soft); }

main { padding-block: 28px 56px; }

.site-footer { border-top: 1px solid var(--border); background: var(--bg-soft); padding-block: 32px 40px; margin-top: 56px; font-size: .9375rem; }
.site-footer__grid { display: grid; gap: 28px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.site-footer h2 { font-size: .8125rem; text-transform: uppercase; letter-spacing: .06em; color: var(--fg-faint); margin: 0 0 10px; }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.site-footer a { color: var(--fg-muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); text-decoration: underline; }

.breadcrumb { font-size: .875rem; color: var(--fg-muted); margin-bottom: 14px; }
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; }
.breadcrumb li + li::before { content: "/"; margin-right: 6px; color: var(--fg-faint); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 15px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg); color: var(--fg); font-size: .9375rem; font-weight: 500; cursor: pointer; transition: background-color .12s, border-color .12s; text-decoration: none; }
.btn:hover:not(:disabled) { background: var(--bg-soft); border-color: var(--fg-faint); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--ghost { border-color: transparent; background: var(--bg-soft); color: var(--fg-muted); }
.btn--ghost:hover:not(:disabled) { color: var(--fg); }
.btn--small { padding: 5px 10px; font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.actions--secondary { margin-top: 10px; }

.card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }

.tool { display: grid; gap: 18px; }

/* Tool page: input left, output right from 900px up - the result must not fall below
   the fold. align-items:start stops the left pane stretching the right one (README 2.1). */
.tool-grid { display: grid; gap: 16px; align-items: start; grid-template-columns: minmax(0,1fr); margin-bottom: 28px; }
@media (min-width: 900px) { .tool-grid { grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 20px; } }
.tool-pane { display: grid; gap: 10px; align-content: start; }
.tool-pane--output { min-height: 300px; }

/* Every line above the image costs the user a scroll: clamp the lede to two. */
.tool-h1 { font-size: clamp(1.35rem, 1.1rem + 1vw, 1.7rem); margin-bottom: .3em; }
.lede--compact { font-size: .95rem; margin-bottom: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.field__label-hint { font-weight: 400; color: var(--fg-faint); font-size: .875rem; }

/* Empty state keeps the right pane at height so pasting does not shift layout. */
.preview--empty { min-height: 240px; gap: 6px; }
.preview__empty-title { margin: 0; font-weight: 600; color: var(--fg-muted); }
.preview__empty-hint { margin: 0; font-size: .875rem; color: var(--fg-faint); text-align: center; }

/* Home page: tool directory */
.tool-section { margin-block: 26px; }
.tool-section__title { font-size: .8125rem; text-transform: uppercase; letter-spacing: .06em; color: var(--fg-faint); margin-bottom: 12px; }
.badge { font-size: .6875rem; text-transform: none; letter-spacing: 0; background: var(--bg-sunken); color: var(--fg-muted); padding: 2px 7px; border-radius: 100px; vertical-align: middle; }
.tool-card__title { font-size: 1.0625rem; margin: 0; }
.tool-card__desc { margin: 0; color: var(--fg-muted); font-size: .9rem; }
/* Roadmap cards are deliberately non-clickable and visually weaker: they are
   a roadmap, not a promise. */
.tool-card--planned { opacity: .7; border-style: dashed; cursor: default; }
.home-note { margin-top: 32px; }
.home-note__title { margin-top: 0; font-size: 1.15rem; }

.paste-area { width: 100%; min-height: 200px; padding: 12px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--bg); font-family: var(--font-mono); font-size: .8125rem; line-height: 1.5; resize: vertical; tab-size: 4; }
.paste-area::placeholder { color: var(--fg-faint); }
.paste-area--short { min-height: 110px; }

/* File-channel drop target: deliberately ONE line, see README 2.1. Logic in paste-area.mjs. */
.drop-zone { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: center; gap: 6px; padding: 9px 14px; border: 1px dashed var(--border-strong); border-radius: var(--radius); text-align: center; cursor: pointer; background: var(--bg-soft); transition: border-color .12s, background-color .12s; }
.drop-zone:hover, .drop-zone.is-over { border-color: var(--accent); background: var(--bg); }
.drop-zone__title { font-weight: 600; font-size: .875rem; }
.drop-zone__hint { font-size: .8125rem; color: var(--fg-muted); }

.input-notice { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--warn); border-left-width: 4px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn); font-size: .9rem; }
.input-notice__text { flex: 1 1 260px; }

.tool-status { font-size: .9rem; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--bg-soft); color: var(--fg-muted); border-left: 3px solid var(--border-strong); }
.tool-status--ok { color: var(--ok); background: var(--ok-bg); border-left-color: var(--ok); }
.tool-status--warn { color: var(--warn); background: var(--warn-bg); border-left-color: var(--warn); }
.tool-status--error { color: var(--error); background: var(--error-bg); border-left-color: var(--error); }

.diagnostics { display: grid; gap: 16px; }
.diag-headline { font-size: 1.05rem; font-weight: 650; margin: 0; padding: 12px 14px; border-radius: var(--radius); border-left: 4px solid var(--border-strong); background: var(--bg-soft); }
.diag-headline--ok { color: var(--ok); background: var(--ok-bg); border-left-color: var(--ok); }
.diag-headline--repaired { color: var(--warn); background: var(--warn-bg); border-left-color: var(--warn); }
.diag-headline--error { color: var(--error); background: var(--error-bg); border-left-color: var(--error); }
.diag-section { display: grid; gap: 8px; }
.diag-title { font-size: .9375rem; margin: 0; color: var(--fg-muted); font-weight: 600; }
.diag-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.diag-list--fixed li { color: var(--ok); font-size: .9rem; }
.diag-list--fixed li::before { content: "\2713 "; font-weight: 700; }
.diag-item { display: flex; gap: 9px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--bg-soft); font-size: .9rem; line-height: 1.55; }
.diag-item__icon { font-weight: 700; flex: 0 0 auto; }
.diag-item--error { background: var(--error-bg); color: var(--error); }
.diag-item--warn { background: var(--warn-bg); color: var(--warn); }
.diag-item--ok { background: var(--ok-bg); color: var(--ok); }
.diag-hex { margin: 0; font-size: .8125rem; letter-spacing: .04em; word-break: break-all; white-space: pre-wrap; }
.diag-note { font-size: .8125rem; color: var(--fg-muted); margin: 0; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.diag-table, .batch-table { border-collapse: collapse; width: 100%; font-size: .875rem; }
.diag-table th, .diag-table td, .batch-table th, .batch-table td { text-align: left; padding: 7px 11px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.diag-table thead th, .batch-table thead th { background: var(--bg-soft); font-weight: 600; color: var(--fg-muted); }
.diag-table tbody tr:last-child td, .batch-table tbody tr:last-child td { border-bottom: 0; }

/* Checkerboard behind the image so transparent PNGs are obvious at a glance. */
.preview { display: grid; place-items: center; min-height: 160px; padding: 20px; background: linear-gradient(45deg, var(--bg-soft) 25%, transparent 25%, transparent 75%, var(--bg-soft) 75%) 0 0 / 18px 18px, linear-gradient(45deg, var(--bg-soft) 25%, transparent 25%, transparent 75%, var(--bg-soft) 75%) 9px 9px / 18px 18px, var(--bg); border: 1px solid var(--border); border-radius: var(--radius); }
.preview__img { max-width: 100%; max-height: 52vh; width: auto; height: auto; }
.preview__hit { display: grid; gap: 12px; place-items: center; }
.preview__note, .preview__fail-hint, .preview__probing { font-size: .875rem; color: var(--fg-muted); margin: 0; text-align: center; }
.preview__fail { color: var(--error); font-weight: 600; margin: 0; text-align: center; }

.meta { display: grid; gap: 2px; margin: 0; }
.meta__row { display: flex; justify-content: space-between; gap: 16px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.meta__row:last-child { border-bottom: 0; }
.meta__label { color: var(--fg-muted); margin: 0; }
.meta__value { margin: 0; font-family: var(--font-mono); font-size: .85rem; text-align: right; }
.meta__row--warn .meta__value { color: var(--warn); }
.meta-warn { font-size: .875rem; color: var(--warn); background: var(--warn-bg); padding: 10px 12px; border-radius: var(--radius-sm); margin: 8px 0 0; }

.encode-controls { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.field { display: grid; gap: 5px; align-content: start; } /* no row stretching: a taller field in the same row would otherwise inflate this one's control */
.field__label { font-size: .875rem; font-weight: 600; color: var(--fg-muted); }
.field__control { padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg); width: 100%; }
.field__hint { font-size: .8125rem; color: var(--fg-faint); margin: 0; font-family: var(--font-mono); }
.output { width: 100%; min-height: 150px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-sunken); font-family: var(--font-mono); font-size: .8125rem; resize: vertical; }

.tool-options { margin-top: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-soft); }
.tool-options > summary { padding: 10px 14px; cursor: pointer; font-size: .9rem; font-weight: 600; color: var(--fg-muted); }
.tool-options > summary::marker { color: var(--fg-faint); }
.tool-options[open] > summary { border-bottom: 1px solid var(--border); margin-bottom: 0; color: var(--fg); }
.tool-options__hint { font-weight: 400; color: var(--fg-faint); }
.tool-options__grid { display: grid; gap: 16px; padding: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.field__check { display: flex; align-items: flex-start; gap: 8px; font-size: .9375rem; font-weight: 600; cursor: pointer; }
/* Enlarged hit target for touch (accessibility). */
.field__check input { width: 18px; height: 18px; margin: 1px 0 0; flex: 0 0 auto; accent-color: var(--accent); }

.batch { display: grid; gap: 14px; }
.batch-summary { margin: 0; font-size: .9rem; color: var(--fg-muted); }
.batch-progress { width: 100%; height: 6px; }
.batch-table .row--error td { color: var(--error); }
.cell-name { font-family: var(--font-mono); font-size: .8125rem; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.cell-note { color: var(--fg-faint); }

/* 13. Ad slots - rendered ONLY when ADS.enabled; fixed height for CLS (why: README 2.1). */

.ad-slot { min-height: 100px; margin-block: 20px; display: grid; place-items: center; background: var(--bg-soft); border: 1px dashed var(--border); border-radius: var(--radius); color: var(--fg-faint); font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; }
.ad-slot--leaderboard { min-height: 90px; }
.ad-slot--mobile { min-height: 100px; }
@media (min-width: 900px) { .ad-slot--mobile { display: none; } }
@media (max-width: 899px) { .ad-slot--leaderboard { min-height: 100px; } }

/* 14. Home page card grid - same class name as the tool page's, scoped differently. */

.tool-section .tool-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-block: 0; align-items: stretch; }
.tool-card { display: grid; gap: 6px; text-decoration: none; color: inherit; }
.tool-card:hover { border-color: var(--accent); }

.prose { max-width: 72ch; }
.prose h2 { margin-top: 2.2em; }
.prose h3 { margin-top: 1.8em; }
.prose ul, .prose ol { padding-left: 1.35em; }
.prose li { margin-bottom: .35em; }
.prose blockquote { margin: 1.4em 0; padding: 2px 0 2px 16px; border-left: 3px solid var(--border-strong); color: var(--fg-muted); }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2.4em 0; }

.faq { display: grid; gap: 6px; max-width: 72ch; }
.faq details { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--bg); }
.faq summary { cursor: pointer; font-weight: 600; }
.faq summary::marker { color: var(--fg-faint); }
.faq details[open] summary { margin-bottom: 8px; }
.faq p { margin: 0; color: var(--fg-muted); }

.related { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.post-list { list-style: none; padding: 0; display: grid; gap: 18px; }
.post-list li { padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.post-list h2 { font-size: 1.125rem; margin: 0 0 4px; }
.post-list a { text-decoration: none; }
.post-list a:hover { text-decoration: underline; }

@media (max-width: 640px) {
  :root { --gutter: 14px; }
  /* Brand + switcher stay on line 1, nav wraps to line 2; order:3 stops it pushing them out. */
  .site-header__inner { min-height: 54px; gap: 12px; flex-wrap: wrap; padding-block: 8px; }
  .site-nav { width: 100%; order: 3; margin-left: 0; overflow-x: auto; padding-bottom: 4px; }
  .site-nav a { white-space: nowrap; }
  .card { padding: 15px; }
  .paste-area { min-height: 140px; }
  .actions .btn { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  .site-header, .site-footer, .ad-slot, .actions { display: none !important; }
  .card { box-shadow: none; border-color: #ccc; }
}
