/* ==========================================================================
   WebFactory tool page — base styles + component kit
   Light and dark via prefers-color-scheme, overridable with [data-theme].
   The builder appends tool-specific rules under "TOOL STYLES" at the end.
   ========================================================================== */

:root {
  --bg: #f6f7fb;
  --bg-2: #ffffff;
  --bg-3: #eef0f6;
  --fg: #13151c;
  --fg-2: #3c4150;
  --muted: #6b7184;
  --line: #dfe2ec;
  --line-2: #c9cdda;
  --accent: #5b4bdb;
  --accent-2: #0ea5c6;
  --accent-fg: #ffffff;
  --accent-soft: rgba(91, 75, 219, 0.10);
  --danger: #c62845;
  --ok: #178a4c;
  --warn: #b26a00;
  --shadow: 0 1px 2px rgba(16, 18, 28, 0.06), 0 12px 32px -16px rgba(16, 18, 28, 0.25);
  --radius: 14px;
  --radius-sm: 9px;
  --gutter: 16px;
  --container: 1040px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Inter, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0f14;
    --bg-2: #161822;
    --bg-3: #1d2030;
    --fg: #eceef5;
    --fg-2: #c3c7d6;
    --muted: #8b90a5;
    --line: #262a3a;
    --line-2: #343950;
    --accent: #8b7cf6;
    --accent-2: #22d3ee;
    --accent-fg: #0e0f14;
    --accent-soft: rgba(139, 124, 246, 0.16);
    --danger: #ff6b84;
    --ok: #4ade80;
    --warn: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -20px rgba(0, 0, 0, 0.8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0f14;
  --bg-2: #161822;
  --bg-3: #1d2030;
  --fg: #eceef5;
  --fg-2: #c3c7d6;
  --muted: #8b90a5;
  --line: #262a3a;
  --line-2: #343950;
  --accent: #8b7cf6;
  --accent-2: #22d3ee;
  --accent-fg: #0e0f14;
  --accent-soft: rgba(139, 124, 246, 0.16);
  --danger: #ff6b84;
  --ok: #4ade80;
  --warn: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -20px rgba(0, 0, 0, 0.8);
  color-scheme: dark;
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  min-height: 100vh;
}
img, svg, video, canvas { max-width: 100%; height: auto; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; line-height: 1.15; letter-spacing: -0.015em; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
code, pre, kbd { font-family: var(--mono); font-size: 0.92em; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.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: 16px; top: -60px; z-index: 100; background: var(--accent); color: var(--accent-fg); padding: 10px 14px; border-radius: 8px; }
.skip-link:focus { top: 12px; }
.container { width: 100%; max-width: calc(var(--container) + var(--gutter) * 2); margin-inline: auto; padding-inline: var(--gutter); }
@media (min-width: 720px) { :root { --gutter: 28px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } html { scroll-behavior: auto; } }

/* ---------- Header ---------- */
.site-header { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.site-header__inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 58px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--fg); font-weight: 700; font-size: 17px; letter-spacing: -0.01em; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand__icon { border-radius: 8px; flex: none; }
.brand__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-nav { display: flex; align-items: center; gap: 2px; }
.site-nav a { color: var(--fg-2); font-size: 14px; font-weight: 500; padding: 8px 10px; border-radius: 8px; white-space: nowrap; }
.site-nav a:hover { background: var(--bg-3); color: var(--fg); text-decoration: none; }
@media (max-width: 640px) { .site-nav a:not(.site-nav__more) { display: none; } }
.theme-toggle { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); color: var(--fg-2); cursor: pointer; margin-left: 4px; }
.theme-toggle:hover { color: var(--fg); border-color: var(--line-2); }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; }
}

/* ---------- Hero ---------- */
.hero { padding-top: clamp(28px, 6vw, 56px); padding-bottom: 20px; text-align: center; }
.hero__title { font-size: clamp(30px, 5.5vw, 48px); font-weight: 800; letter-spacing: -0.03em; text-wrap: balance; }
.hero__lead { margin: 14px auto 0; max-width: 62ch; font-size: clamp(16px, 2vw, 19px); color: var(--fg-2); text-wrap: pretty; }
.badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 20px; list-style: none; }
.badges li { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line); color: var(--fg-2); font-size: 13px; font-weight: 500; }
.badges svg { width: 16px; height: 16px; color: var(--ok); flex: none; }

/* ---------- Tool card ---------- */
.tool-card { margin-top: 22px; padding: clamp(16px, 3vw, 28px); background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.tool-card > * + * { margin-top: 16px; }

/* Dropzone */
.dropzone { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 180px; padding: 28px 16px; text-align: center; border: 2px dashed var(--line-2); border-radius: var(--radius); background: var(--bg-3); color: var(--fg-2); cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.dropzone:hover, .dropzone:focus-visible, .dropzone.is-dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone__input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.dropzone__icon { width: 36px; height: 36px; color: var(--accent); }
.dropzone__title { font-weight: 600; color: var(--fg); font-size: 17px; }
.dropzone__hint { font-size: 13.5px; color: var(--muted); }
.dropzone .link { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.dropzone--compact { min-height: 96px; padding: 16px; }

/* Forms */
.options { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field__label { font-size: 13.5px; font-weight: 600; color: var(--fg-2); }
.field__hint { font-size: 12.5px; color: var(--muted); }
.input, input[type="text"], input[type="number"], input[type="url"], input[type="email"], input[type="search"], input[type="password"], input[type="date"], input[type="time"], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line-2); background: var(--bg-2); color: var(--fg); min-height: 42px;
}
textarea { min-height: 140px; resize: vertical; line-height: 1.5; }
textarea.mono, .mono { font-family: var(--mono); font-size: 13.5px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; border-color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 18px; height: 18px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14.5px; cursor: pointer; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }
.grid-2 { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; min-height: 42px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--bg-2); color: var(--fg); font-weight: 600; font-size: 15px; cursor: pointer; white-space: nowrap; transition: transform 0.12s, background 0.15s, border-color 0.15s; }
.btn:hover { text-decoration: none; background: var(--bg-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--fg) 12%); }
.btn--ghost { background: transparent; }
.btn--danger { color: var(--danger); }
.btn--small { padding: 6px 10px; min-height: 32px; font-size: 13.5px; border-radius: 8px; }
.btn--block { width: 100%; }
.btn--kofi { background: #ff5e5b; border-color: #ff5e5b; color: #fff; }
.btn--kofi:hover { background: #ff4542; }
.btn svg { width: 18px; height: 18px; }

@media (pointer: coarse) { .btn, .chip, .tab, input[type="file"], select { min-height: 44px; } }

/* Results & feedback */
.results:empty { display: none; }
.result { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-3); }
.result__thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; background: var(--bg-2); border: 1px solid var(--line); flex: none; }
.result__meta { flex: 1 1 160px; min-width: 0; }
.result__name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result__info { font-size: 13px; color: var(--muted); }
.result + .result { margin-top: 8px; }
.stat { font-variant-numeric: tabular-nums; }
.stat--ok { color: var(--ok); } .stat--warn { color: var(--warn); } .stat--danger { color: var(--danger); }
.progress { width: 100%; height: 8px; border-radius: 999px; background: var(--bg-3); overflow: hidden; border: 1px solid var(--line); }
.progress > span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.2s; }
.alert { padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--bg-3); font-size: 14.5px; }
.alert--error { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--bg-2)); }
.alert--ok { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); color: var(--ok); background: color-mix(in srgb, var(--ok) 8%, var(--bg-2)); }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; padding: 10px 16px; border-radius: 10px; background: var(--fg); color: var(--bg); font-size: 14px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Tables, code, preview */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--bg-3); font-weight: 600; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
.code { padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--bg-3); font-family: var(--mono); font-size: 13.5px; line-height: 1.5; overflow: auto; max-height: 420px; }
.preview { display: grid; place-items: center; min-height: 160px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: repeating-conic-gradient(var(--bg-3) 0 25%, var(--bg-2) 0 50%) 0 0 / 20px 20px; }
.preview img, .preview canvas, .preview video { max-height: 420px; border-radius: 6px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { padding: 10px 14px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--fg-2); font-weight: 600; cursor: pointer; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 600; }
.swatch { width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line-2); display: inline-block; vertical-align: middle; }
.kbd { display: inline-block; padding: 1px 6px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 6px; background: var(--bg-2); font-size: 12px; }

/* ---------- Sections ---------- */
.section { padding-block: clamp(36px, 6vw, 64px); }
.section__title { font-size: clamp(22px, 3.2vw, 30px); font-weight: 700; margin-bottom: 18px; }
.steps { list-style: none; display: grid; gap: 12px; counter-reset: step; }
@media (min-width: 720px) { .steps { grid-template-columns: repeat(3, 1fr); } }
.steps li { counter-increment: step; padding: 18px 18px 18px 56px; position: relative; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); color: var(--fg-2); font-size: 15px; }
.steps li::before { content: counter(step); position: absolute; left: 16px; top: 16px; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: var(--accent-fg); font-weight: 700; font-size: 14px; }
.steps strong { color: var(--fg); display: block; margin-bottom: 2px; }
.faq { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-2); padding: 0 16px; }
.faq + .faq { margin-top: 10px; }
.faq summary { cursor: pointer; padding: 14px 0; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--accent); font-weight: 400; font-size: 20px; line-height: 1; }
.faq[open] summary::after { content: "–"; }
.faq p { padding: 0 0 16px; color: var(--fg-2); font-size: 15px; }
.support-card { text-align: center; padding: clamp(22px, 4vw, 36px); border-radius: var(--radius); background: linear-gradient(135deg, var(--accent-soft), transparent 70%), var(--bg-2); border: 1px solid var(--line); }
.support-card p { max-width: 56ch; margin: 10px auto 18px; color: var(--fg-2); }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding: 28px 0 36px; margin-top: 20px; font-size: 14px; color: var(--muted); }
.site-footer p + p { margin-top: 12px; }
.site-footer__links a { color: var(--fg-2); }
.site-footer__disclosure { max-width: 80ch; font-size: 13.5px; line-height: 1.55; }
.site-footer__disclosure strong { color: var(--fg-2); }
.sw-status:empty { display: none; }

/* ==========================================================================
   TOOL STYLES — the builder adds tool-specific rules below this line
   ========================================================================== */

/* Workspace: preview on the left, options on the right (stacked on phones) */
.pn { display: grid; gap: 22px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 820px) { .pn { grid-template-columns: minmax(0, 340px) minmax(0, 1fr); align-items: start; } }
.pn__preview { margin: 0; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
@media (min-width: 820px) { .pn__preview { position: sticky; top: 76px; } }
.pn__stage { min-height: 240px; padding: 12px; }
.pn__stage canvas { display: block; max-height: none; border-radius: 3px; box-shadow: 0 1px 2px rgba(16, 18, 28, 0.18), 0 8px 22px -12px rgba(16, 18, 28, 0.45); }
.pn__stepper { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pn__indicator { font-size: 14px; font-weight: 600; color: var(--fg-2); }
.pn__caption { font-size: 14px; color: var(--fg-2); text-align: center; overflow-wrap: anywhere; }
.pn__caption strong { color: var(--fg); font-variant-numeric: tabular-nums; }
.pn__keys { text-align: center; }
@media (pointer: coarse) { .pn__keys { display: none; } }

.pn__options { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.pn__file { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; min-width: 0; }
.pn__file strong { overflow-wrap: anywhere; }
.pn__fieldset { border: 0; margin: 0; padding: 0; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.pn__fieldset legend { padding: 0; margin-bottom: 8px; }

/* 3×3 position picker: real radio buttons, the label is the visible cell */
.pn__pos { display: grid; grid-template-columns: repeat(3, 34px); grid-template-rows: repeat(3, 34px); gap: 5px; padding: 6px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--bg-3); width: max-content; }
.pn__pos input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.pn__pos label { display: grid; place-items: center; border-radius: 7px; border: 1px solid var(--line); background: var(--bg-2); cursor: pointer; transition: background 0.12s, border-color 0.12s; }
.pn__pos label::after { content: ""; width: 12px; height: 4px; border-radius: 2px; background: var(--line-2); }
.pn__pos label:hover { border-color: var(--accent); }
.pn__pos input:checked + label { background: var(--accent); border-color: var(--accent); }
.pn__pos input:checked + label::after { background: var(--accent-fg); }
.pn__pos input:focus-visible + label { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.pn__fields { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pn__wide { grid-column: 1 / -1; }
.pn__fields .check { align-items: flex-start; line-height: 1.4; }
.pn__fields .check input { flex: none; margin-top: 1px; }
.pn__color { width: 100%; min-height: 42px; padding: 4px; border-radius: var(--radius-sm); border: 1px solid var(--line-2); background: var(--bg-2); cursor: pointer; }
.pn__warn { color: var(--warn); font-weight: 600; }
input[aria-invalid="true"] { border-color: var(--warn); }

.pn__progress { display: flex; flex-direction: column; gap: 6px; }
.pn__result .btn { white-space: normal; text-align: center; overflow-wrap: anywhere; max-width: 100%; }
.pn__ok { width: 28px; height: 28px; color: var(--ok); flex: none; }
.results > * + * { margin-top: 10px; }
