:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --text: #171a26;
  --muted: #586074;
  --border: #dcdfea;
  --accent: #4338ca;
  --accent-text: #3730a3;
  --accent-soft: #e8e8fb;
  --ok: #047857;
  --ok-soft: #dcf5ea;
  --err: #b42318;
  --err-soft: #fde7e5;
  --mark: #fde68a;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11131a;
    --surface: #191c26;
    --surface-2: #222634;
    --text: #e7e9f1;
    --muted: #9aa1b5;
    --border: #2e3343;
    --accent: #8b8cf6;
    --accent-text: #a5a6ff;
    --accent-soft: #272a4d;
    --ok: #4ade9b;
    --ok-soft: #133528;
    --err: #ff8a80;
    --err-soft: #3d1d1b;
    --mark: #6b5513;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
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, sans-serif;
  overflow-wrap: break-word;
}
a { color: var(--accent-text); }
[hidden] { display: none !important; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 8px; z-index: 10; }

.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; min-height: 56px; flex-wrap: wrap; }
.logo { font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.logo-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: #4338ca; color: #fff; font-size: .95rem; }
.site-header nav { display: flex; gap: 16px; flex-wrap: wrap; }
.site-header nav a { color: var(--muted); text-decoration: none; font-size: .95rem; }
.site-header nav a:hover { color: var(--accent-text); }

main { padding-top: 24px; padding-bottom: 48px; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.2; margin: .3em 0 .4em; }
h2 { font-size: 1.3rem; margin: 1.8em 0 .5em; }
h3 { font-size: 1.05rem; margin: 1.4em 0 .4em; }
.lead { font-size: 1.08rem; color: var(--muted); max-width: 760px; margin-bottom: .5em; }
.muted { color: var(--muted); margin-top: -.3em; }
.crumbs { font-size: .9rem; color: var(--muted); }
.crumbs a { color: var(--muted); }
.local-badge { display: inline-block; font-size: .9rem; color: var(--ok); background: var(--ok-soft); border-radius: 10px; padding: 4px 12px; margin: 0 0 8px; }

.hero { padding: 16px 0 8px; }
.cards { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.cards a { display: block; height: 100%; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); text-decoration: none; color: var(--text); transition: border-color .15s; }
.cards a:hover { border-color: var(--accent); }
.cards strong { display: block; margin-bottom: 2px; }
.cards span { color: var(--muted); font-size: .92rem; }
.why { max-width: 760px; }

/* ---------- tool area ---------- */
.tool { margin: 16px 0 8px; display: grid; gap: 14px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.panel > :first-child { margin-top: 0; }
.panel > :last-child { margin-bottom: 0; }
.panel-title { font-size: 1rem; font-weight: 700; margin: 0 0 10px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 760px) { .cols { grid-template-columns: 1fr; } }

.controls { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; margin: 10px 0; }
.controls:first-child { margin-top: 0; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span, .field > label:first-child { font-weight: 600; font-size: .9rem; }
.field.grow { flex: 1 1 220px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: .95rem; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; }
.help { color: var(--muted); font-size: .85rem; }

input[type=text], input[type=number], input[type=datetime-local], input[type=search], input[type=url], input[type=password], select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0; max-width: 100%;
}
input[type=number] { width: 110px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=range] { accent-color: var(--accent); width: 180px; max-width: 100%; }
input[type=color] { width: 48px; height: 38px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
textarea { width: 100%; display: block; resize: vertical; min-height: 160px; line-height: 1.5; }
textarea.mono, .mono { font-family: var(--mono); font-size: .9rem; }
textarea[readonly] { background: var(--surface-2); }

.btn, button { font: inherit; font-size: .92rem; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; line-height: 1.3; }
.btn:hover, button:hover { border-color: var(--accent); color: var(--accent-text); }
.btn.primary, button.primary { background: #4338ca; border-color: #4338ca; color: #fff; }
.btn.primary:hover, button.primary:hover { background: #3730a3; color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed=true] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }

.dropzone { display: block; border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px 16px; text-align: center; background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone:focus-within, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone strong { display: block; font-size: 1.05rem; }
.dropzone span { color: var(--muted); font-size: .9rem; }
.dropzone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

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

.note { font-size: .9rem; color: var(--muted); margin: 8px 0; }
.note.warn, .note.err { color: var(--err); }
.note.ok { color: var(--ok); }
.status-err { background: var(--err-soft); color: var(--err); border-radius: 8px; padding: 8px 12px; font-size: .92rem; }
.status-ok { background: var(--ok-soft); color: var(--ok); border-radius: 8px; padding: 8px 12px; font-size: .92rem; }

.out-pre { font-family: var(--mono); font-size: .88rem; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; margin: 0; overflow: auto; max-height: 480px; white-space: pre-wrap; word-break: break-all; }
.kv { width: 100%; border-collapse: collapse; font-size: .93rem; table-layout: fixed; }
.kv th, .kv td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
.kv th { width: 34%; color: var(--muted); font-weight: 600; }
.kv td.mono { font-size: .86rem; }
.kv td .btn { padding: 3px 9px; font-size: .8rem; margin-left: 6px; }

/* image file lists */
.files { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.file { display: grid; grid-template-columns: 72px 1fr auto; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.file img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.file .meta { min-width: 0; font-size: .9rem; }
.file .meta b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .meta span { color: var(--muted); }
.saving { color: var(--ok); font-weight: 600; }
.bigger { color: var(--err); font-weight: 600; }
@media (max-width: 520px) {
  .file { grid-template-columns: 56px 1fr; }
  .file img { width: 56px; height: 56px; }
  .file .actions { grid-column: 1 / -1; }
}
.preview { max-width: 100%; max-height: 420px; display: block; margin: 0 auto; border-radius: 8px; background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 50% / 20px 20px; }

/* crop */
.crop-stage { position: relative; display: inline-block; max-width: 100%; touch-action: none; user-select: none; -webkit-user-select: none; line-height: 0; }
.crop-stage img { max-width: 100%; max-height: 70vh; display: block; }
.crop-box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .5); outline: 1px solid rgba(0, 0, 0, .6); cursor: move; }
.crop-wrap { overflow: hidden; text-align: center; }
.crop-handle { position: absolute; width: 16px; height: 16px; background: #fff; border: 1px solid #333; border-radius: 3px; }
.crop-handle[data-h=nw] { left: -9px; top: -9px; cursor: nwse-resize; }
.crop-handle[data-h=ne] { right: -9px; top: -9px; cursor: nesw-resize; }
.crop-handle[data-h=sw] { left: -9px; bottom: -9px; cursor: nesw-resize; }
.crop-handle[data-h=se] { right: -9px; bottom: -9px; cursor: nwse-resize; }

/* diff */
.diff { font-family: var(--mono); font-size: .86rem; background: var(--surface-2); border-radius: 8px; overflow: auto; max-height: 560px; }
.diff div { white-space: pre-wrap; word-break: break-all; padding: 1px 10px 1px 34px; position: relative; min-height: 1.4em; }
.diff div::before { position: absolute; left: 12px; color: var(--muted); }
.diff .add { background: var(--ok-soft); }
.diff .add::before { content: "+"; color: var(--ok); }
.diff .del { background: var(--err-soft); }
.diff .del::before { content: "−"; color: var(--err); }
.diff .same { color: var(--muted); }
.diff .gap { color: var(--muted); font-style: italic; }

/* regex */
.hl { font-family: var(--mono); font-size: .9rem; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; word-break: break-all; max-height: 360px; overflow: auto; margin: 0; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.regex-row { display: flex; align-items: center; gap: 4px; font-family: var(--mono); }
.regex-row input { font-family: var(--mono); }
.regex-row .slash { color: var(--muted); font-size: 1.2rem; }

/* qr / color */
.qr-out { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.qr-out img { width: min(100%, 320px); height: auto; image-rendering: pixelated; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.swatch { height: 120px; border-radius: 10px; border: 1px solid var(--border); display: grid; place-items: center; font-weight: 700; font-size: 1.1rem; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 6px; }
.swatches button { height: 44px; padding: 0; border-radius: 6px; font-size: .72rem; font-family: var(--mono); }

.pw-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.pw-list li { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border-radius: 8px; padding: 6px 6px 6px 12px; }
.pw-list code { flex: 1; font-family: var(--mono); font-size: 1rem; word-break: break-all; }
.meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--err); transition: width .2s; }
.meter i.mid { background: #d97706; }
.meter i.good { background: var(--ok); }

.clock { font-family: var(--mono); font-size: clamp(1.6rem, 6vw, 2.4rem); font-weight: 700; font-variant-numeric: tabular-nums; }

/* content */
.content { max-width: 780px; }
.content .formula, .content pre { font-family: var(--mono); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow-x: auto; white-space: pre; font-size: .9rem; }
.content code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); border-radius: 4px; padding: 1px 4px; }
.content pre code { background: none; padding: 0; }
.content table { border-collapse: collapse; width: 100%; font-size: .95rem; display: block; overflow-x: auto; }
.content th, .content td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.content th { background: var(--surface); }
details { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; }
details summary { cursor: pointer; font-weight: 600; }
details p { margin: .6em 0 .2em; }
.related { margin-top: 32px; }

.prose { max-width: 760px; }
.site-footer { border-top: 1px solid var(--border); background: var(--surface); font-size: .9rem; color: var(--muted); }
.footer-inner { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 16px; padding-bottom: 16px; }
.footer-inner p { margin: 0; }
.footer-inner nav { display: flex; gap: 14px; }
.footer-inner a { color: var(--muted); }
.sr-copy { position: fixed; left: -9999px; top: 0; }
.regex-row #pattern { flex: 1; min-width: 0; }
.regex-row #flags { width: 4.5em; }
.table-scroll { overflow-x: auto; }
.table-scroll .kv { table-layout: auto; min-width: 100%; }
.table-scroll .kv th { width: auto; }
