:root {
  --bg: #f7f7fb;
  --surface: #ffffff;
  --surface-2: #f1f1f7;
  --border: #e3e3ee;
  --text: #1b1b2f;
  --muted: #5d5d78;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;
  --success: #15803d;
  --danger: #b91c1c;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 20, 50, .05), 0 4px 16px rgba(20, 20, 50, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f1a; --surface: #181826; --surface-2: #20202f; --border: #2c2c40;
    --text: #ececf5; --muted: #a2a2bd; --primary: #8b86ff; --primary-hover: #a5a1ff;
    --primary-soft: #23224a; --success: #4ade80; --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0f1a; --surface: #181826; --surface-2: #20202f; --border: #2c2c40;
  --text: #ececf5; --muted: #a2a2bd; --primary: #8b86ff; --primary-hover: #a5a1ff;
  --primary-soft: #23224a; --success: #4ade80; --danger: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

*, *::before, *::after { 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 var(--font); display: flex; flex-direction: column; min-height: 100vh;
}
main { flex: 1; }
a { color: var(--primary); }
a:hover { color: var(--primary-hover); }
img, canvas { max-width: 100%; }
h1, h2, h3 { line-height: 1.25; }
.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--primary); color: #fff; padding: 8px 12px; border-radius: 8px; z-index: 10; }
.skip-link:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.site-header__inner { display: flex; align-items: center; gap: 16px; height: 60px; }
.logo { font-weight: 800; font-size: 1.2rem; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 6px; }
.logo__mark { width: 30px; height: 30px; }
.site-nav { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; }
.site-nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: .95rem; white-space: nowrap; }
.site-nav a:hover { background: var(--surface-2); color: var(--text); }
.theme-toggle { border: 1px solid var(--border); background: var(--surface); color: var(--text); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 1.05rem; flex-shrink: 0; }
@media (max-width: 640px) { .site-nav { display: none; } .theme-toggle { margin-left: auto; } }

/* Home */
.hero { padding: 56px 0 32px; text-align: center; }
.hero h1 { font-size: clamp(1.9rem, 5vw, 3rem); margin: 0 0 12px; letter-spacing: -.02em; }
.accent { color: var(--primary); }
.hero__lead { color: var(--muted); font-size: 1.1rem; max-width: 640px; margin: 0 auto 28px; }
.search input { width: 100%; max-width: 520px; padding: 14px 18px; font-size: 1rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.category { margin: 36px 0; }
.category h2 { font-size: 1.3rem; margin: 0 0 14px; }
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.tool-card { display: flex; gap: 12px; align-items: flex-start; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); text-decoration: none; color: var(--text); transition: border-color .15s, transform .15s; }
.tool-card:hover { border-color: var(--primary); transform: translateY(-2px); color: var(--text); }
.tool-card__icon { font-size: 1.5rem; line-height: 1; padding-top: 2px; }
.tool-card__body { display: flex; flex-direction: column; gap: 2px; }
.tool-card__body span { color: var(--muted); font-size: .9rem; line-height: 1.45; }
.no-results { text-align: center; color: var(--muted); }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin: 48px 0; }
.features div { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.features h3 { margin: 0 0 6px; font-size: 1.05rem; }
.features p { margin: 0; color: var(--muted); }

/* Tool page */
.breadcrumb { font-size: .875rem; color: var(--muted); margin: 20px 0 0; }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--primary); }
.tool-header { margin: 12px 0 20px; }
.tool-header h1 { font-size: clamp(1.7rem, 4vw, 2.3rem); margin: 0 0 6px; letter-spacing: -.015em; }
.tool-header p { color: var(--muted); margin: 0; font-size: 1.05rem; max-width: 720px; }
.tool { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
@media (max-width: 520px) { .tool { padding: 14px; } }

.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 36px 16px; border: 2px dashed var(--border); border-radius: var(--radius); background: var(--surface-2); text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.is-over { border-color: var(--primary); background: var(--primary-soft); }
.dropzone strong { font-size: 1.05rem; }
.dropzone small { color: var(--muted); }
.dropzone__icon { font-size: 2rem; }
.dropzone input { display: none; }

.controls { display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: flex-end; margin: 18px 0 0; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); min-width: 0; }
.field--grow { flex: 1 1 220px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: .95rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
input[type="text"], input[type="number"], input[type="url"], input[type="email"], input[type="tel"], input[type="password"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 12px; min-width: 0;
}
input[type="number"] { width: 110px; }
input[type="range"] { accent-color: var(--primary); width: 200px; max-width: 100%; }
input[type="color"] { width: 48px; height: 38px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); padding: 3px; }
textarea { width: 100%; min-height: 240px; resize: vertical; line-height: 1.5; }
textarea.mono, .mono { font-family: var(--mono); font-size: .9rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: .95rem; padding: 10px 18px; border-radius: var(--radius-sm); border: 1px solid transparent; background: var(--primary); color: #fff; cursor: pointer; text-decoration: none; transition: background .15s; }
.btn:hover { background: var(--primary-hover); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--sm { padding: 6px 12px; font-size: .85rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.file-list { list-style: none; padding: 0; margin: 18px 0 0; display: flex; flex-direction: column; gap: 8px; }
.file-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); flex-wrap: wrap; }
.file-item__thumb { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; background: var(--border); flex-shrink: 0; }
.file-item__info { flex: 1 1 160px; min-width: 0; }
.file-item__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item__meta { font-size: .85rem; color: var(--muted); }
.file-item__actions { display: flex; gap: 6px; flex-wrap: wrap; }
.good { color: var(--success); font-weight: 600; }
.bad { color: var(--danger); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; }
.stat b { display: block; font-size: 1.5rem; line-height: 1.2; }
.stat span { font-size: .85rem; color: var(--muted); }

.output-box { display: flex; gap: 8px; align-items: stretch; }
.output-box input { flex: 1; font-family: var(--mono); font-size: 1.1rem; }
.status { margin: 12px 0 0; font-size: .95rem; min-height: 1.4em; }
.status.is-error { color: var(--danger); }
.status.is-ok { color: var(--success); }
.preview { margin-top: 18px; text-align: center; }
.preview img, .preview canvas { border-radius: var(--radius-sm); border: 1px solid var(--border); max-height: 420px; }
.meter { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.meter span { display: block; height: 100%; width: 0; border-radius: 99px; transition: width .2s, background .2s; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }

.ad-slot { margin: 24px 0; min-height: 100px; }

/* Crop */
.crop-wrap { text-align: center; margin-top: 16px; }
.crop-stage { position: relative; display: inline-block; max-width: 100%; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; line-height: 0; cursor: crosshair; }
.crop-stage img { display: block; max-width: 100%; max-height: 70vh; pointer-events: none; }
.crop-box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .55); cursor: move;
  background-image: linear-gradient(rgba(255,255,255,.35), rgba(255,255,255,.35)), linear-gradient(rgba(255,255,255,.35), rgba(255,255,255,.35)), linear-gradient(90deg, rgba(255,255,255,.35), rgba(255,255,255,.35)), linear-gradient(90deg, rgba(255,255,255,.35), rgba(255,255,255,.35));
  background-size: 100% 1px, 100% 1px, 1px 100%, 1px 100%; background-position: 0 33.33%, 0 66.66%, 33.33% 0, 66.66% 0; background-repeat: no-repeat; }
.crop-handle { position: absolute; width: 18px; height: 18px; background: #fff; border: 2px solid var(--primary); border-radius: 50%; }
.crop-handle[data-h="nw"] { left: -10px; top: -10px; cursor: nwse-resize; }
.crop-handle[data-h="ne"] { right: -10px; top: -10px; cursor: nesw-resize; }
.crop-handle[data-h="sw"] { left: -10px; bottom: -10px; cursor: nesw-resize; }
.crop-handle[data-h="se"] { right: -10px; bottom: -10px; cursor: nwse-resize; }

/* PDF page grid */
.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; margin-top: 18px; }
.page-thumb { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; font: inherit; color: var(--muted); font-size: .85rem; }
.page-thumb:hover { border-color: var(--primary); }
.page-thumb__frame { width: 100%; aspect-ratio: 1; display: grid; place-items: center; }
.page-thumb img { max-width: 80%; max-height: 80%; box-shadow: var(--shadow); transition: transform .2s; background: #fff; }

/* Diff */
.diff { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .85rem; margin-top: 16px; }
.diff-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: 16px; }
.diff-wrap .diff { margin: 0; }
.diff td { padding: 2px 8px; vertical-align: top; white-space: pre-wrap; word-break: break-word; }
.diff td.ln { color: var(--muted); text-align: right; user-select: none; width: 1%; white-space: nowrap; border-right: 1px solid var(--border); }
.diff td.sign { width: 1%; user-select: none; }
.diff tr.add { background: rgba(22, 163, 74, .14); }
.diff tr.del { background: rgba(220, 38, 38, .13); }
.diff tr.add mark { background: rgba(22, 163, 74, .4); color: inherit; border-radius: 3px; }
.diff tr.del mark { background: rgba(220, 38, 38, .4); color: inherit; border-radius: 3px; text-decoration: line-through; }
.diff tr.gap td { text-align: center; color: var(--muted); background: var(--surface-2); }

/* Color */
.swatch { width: 100%; min-height: 160px; border-radius: var(--radius); border: 1px solid var(--border); display: grid; place-items: center; font-weight: 700; font-size: 1.3rem; }
.swatch-row { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; margin-top: 8px; }
.swatch-row button { aspect-ratio: 1; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; padding: 0; }
.color-fields { display: flex; flex-direction: column; gap: 10px; }
.color-fields .output-box input { font-size: 1rem; }
.picker-canvas { max-width: 100%; max-height: 420px; cursor: crosshair; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.kv { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: .92rem; }
.kv th, .kv td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; word-break: break-all; }
.kv th { color: var(--muted); font-weight: 600; width: 30%; word-break: normal; }

/* Article content */
.prose { max-width: 760px; margin: 40px 0; }
.prose h2 { font-size: 1.45rem; margin: 36px 0 10px; }
.prose h3 { font-size: 1.12rem; margin: 24px 0 6px; }
.prose p, .prose li { color: var(--text); }
.prose ol, .prose ul { padding-left: 1.3em; }
.prose li { margin: 4px 0; }
.prose details { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 16px; margin: 8px 0; background: var(--surface); }
.prose summary { font-weight: 600; cursor: pointer; }
.prose details p { margin: 8px 0 0; color: var(--muted); }
.prose table { border-collapse: collapse; width: 100%; font-size: .95rem; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.prose th { background: var(--surface-2); }
.prose code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.page { margin-top: 32px; }
.page h1 { font-size: 2rem; margin: 0 0 8px; }

.related { margin: 40px 0 56px; }
.related h2 { font-size: 1.3rem; }

/* Footer */
.site-footer { background: var(--surface); border-top: 1px solid var(--border); padding: 36px 0 20px; font-size: .92rem; }
.footer-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 20px; }
.footer-grid h3 { font-size: .95rem; margin: 0 0 8px; }
.footer-grid ul { list-style: none; margin: 0; padding: 0; }
.footer-grid li { margin: 4px 0; }
.footer-grid a, .footer-bottom a { color: var(--muted); text-decoration: none; }
.footer-grid a:hover, .footer-bottom a:hover { color: var(--primary); }
.footer-bottom { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; border-top: 1px solid var(--border); margin-top: 28px; padding-top: 16px; color: var(--muted); }
.footer-bottom p { margin: 0; }
.footer-bottom nav { display: flex; gap: 16px; flex-wrap: wrap; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; }
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
