/* ==========================================================
   ToolBox — Apple-inspired minimal design system
   ========================================================== */

:root {
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
        "Helvetica Neue", "Segoe UI", "PingFang SC", "Hiragino Sans GB",
        "Microsoft YaHei", sans-serif;
    --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
    --radius-sm: 10px;
    --radius: 16px;
    --radius-lg: 22px;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --theme-dur: 0s;      /* theme switch is insta-snapshot: fully in-frame */
    --build: "20260919z"; /* visible build marker — bump on every deploy */
    --badge-text: "v20260919z"; /* keep in sync with --build */
}

[data-theme="light"] {
    color-scheme: light;
    --bg: #f5f5f7;
    --bg-subtle: #fbfbfd;
    --surface: #ffffff;
    --surface-2: #f2f2f7;
    --nav: var(--bg);
    --text: #1d1d1f;
    --text-secondary: #6e6e73;
    --text-muted: #aeaeb2;
    --hairline: rgba(0, 0, 0, 0.12);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 8px 28px rgba(0, 0, 0, 0.06);
    --shadow-hover: 0 2px 6px rgba(0, 0, 0, 0.05), 0 16px 44px rgba(0, 0, 0, 0.10);
    --accent: #0071e3;
    --accent-hover: #0077ed;
    --accent-soft: rgba(0, 113, 227, 0.08);
    --danger: #d70015;
    --success: #248a3d;
    --search-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23aeaeb2' stroke-width='1.7' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3-3'/%3E%3C/svg%3E");
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #000000;
    --bg-subtle: #0d0d0f;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --nav: var(--bg);
    --text: #f5f5f7;
    --text-secondary: #98989d;
    --text-muted: #626266;
    --hairline: rgba(255, 255, 255, 0.12);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 10px 32px rgba(0, 0, 0, 0.35);
    --shadow-hover: 0 2px 6px rgba(0, 0, 0, 0.5), 0 18px 48px rgba(0, 0, 0, 0.5);
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --accent-soft: rgba(10, 132, 255, 0.12);
    --danger: #ff453a;
    --success: #30d158;
    --search-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23626266' stroke-width='1.7' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3-3'/%3E%3C/svg%3E");
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* Mobile tap-handling resets (see Hermes: Root-Cause-and-CSS-Fix-for-Mobile-Tap-Flash.md).
   Only tap-highlight is stripped; touch-callout (long-press copy menu) is kept
   because text/output copy is core to this tool site. */
* {
    -webkit-tap-highlight-color: transparent;
}

@media (min-width: 641px) {
    :focus:not(:focus-visible) { outline: none; }
}

/* ==========================================================
   Tool icon layers — keep SVGs off main layer so taps never repaint a flash
   ========================================================== */
.icon-btn svg, .card-icon svg, .drawer-close svg {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Unified color transition — all elements must animate in sync on theme switch.
   No box-shadow here: it is the most expensive property to animate on low-end
   phones (restrict the cost to hover cards only). */
*, *::before, *::after {
    transition: background-color var(--theme-dur) var(--ease), color var(--theme-dur) var(--ease),
                border-color var(--theme-dur) var(--ease);
}

[data-theme] body { transition: background-color var(--theme-dur) var(--ease), color var(--theme-dur) var(--ease); }

html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; overflow-x: hidden; }

/* Anti-FOUC: hide translatable text until the language is applied.
   Prevents an EN->ZH flash on browsers that paint before DOMContentLoaded. */
html.i18n-pending [data-i18n],
html.i18n-pending .tool-head h1,
html.i18n-pending .tool-head p { visibility: hidden; }

body {
    font-family: var(--font);
    font-size: 15px;
    font-weight: 400;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    overflow-x: hidden;
    transition: background-color var(--theme-dur) var(--ease), color var(--theme-dur) var(--ease), border-color var(--theme-dur) var(--ease);
    min-height: 100vh;
}

::selection {
    background: rgba(0, 113, 227, 0.22);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 6px;
    border: 2px solid transparent;
    background-clip: content-box;
}

button {
    font-family: var(--font);
    -webkit-tap-highlight-color: transparent;
}

/* ==========================================================
   Top navigation
   ========================================================== */
.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--nav);
}

.header-inner {
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 20px;
    height: 58px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand {
    display: inline-flex;
    align-items: center;
    height: 40px;
    gap: 8px;
    font-size: 17px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.01em;
    color: var(--text);
    text-decoration: none;
}

.brand:hover { opacity: 0.8; }

.header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 40px;
    padding: 0 14px;
    border: none;
    border-radius: 20px;
    background: transparent;
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    transition: background-color var(--theme-dur) var(--ease), color var(--theme-dur) var(--ease), border-color var(--theme-dur) var(--ease);
}

.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { opacity: 0.7; }

.icon-btn svg { width: 22px; height: 22px; stroke-width: 1.8; }
.icon-btn .btn-label { min-width: 40px; text-align: left; line-height: 1; }

/* theme icon is injected inline into <span id="themeIcon">; on it the svg sits on
   the line box text baseline and drifts ~1px above the other icons. Make the
   wrapper a zero-line-height flex container so its svg centers exactly. */
#themeIcon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

/* sun/moon glyph is delicate and reads thinner than the globe's ring at 1.8;
   bump so the strokes match the side icons visually. */
#themeIcon svg { stroke-width: 2; }

/* ==========================================================
   Hero (home)
   ========================================================== */
.hero {
    text-align: center;
    padding: 48px 20px 16px;
    max-width: 760px;
    margin: 0 auto;
}

.hero h1 {
    font-size: clamp(40px, 7vw, 68px);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
    line-height: 1.05;
    margin-bottom: 18px;
}

.hero p {
    font-size: clamp(17px, 2.4vw, 21px);
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.search-wrap {
    position: relative;
    max-width: 440px;
    margin: 0 auto;
}

.search-wrap input[type="text"] {
    width: 100%;
    height: 52px;
    padding: 0 18px 0 46px;
    font-size: 16px;   /* >=16px prevents iOS forced focus zoom */
    font-family: var(--font);
    color: var(--text);
    background-color: var(--surface);
    background-image: var(--search-icon);
    background-repeat: no-repeat;
    background-position: 16px center;
    background-size: 17px 17px;
    border: 1px solid var(--hairline);
    border-radius: 26px;
    outline: none;
    box-shadow: var(--shadow);
    transition: background-color var(--theme-dur) var(--ease), color var(--theme-dur) var(--ease), border-color var(--theme-dur) var(--ease);
    appearance: none;
}

.search-wrap input[type="text"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.search-wrap input::placeholder { color: var(--text-muted); }

.search-shortcut {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-family: var(--font);
    font-size: 11px;
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    border-radius: 6px;
    padding: 2px 7px;
}

/* ==========================================================
   Tool grid (home)
   ========================================================== */
.tools-section {
    max-width: 1080px;
    margin: 0 auto;
    padding: 4px 20px 96px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}

.tool-card {
    display: flex;
    flex-direction: column;
    padding: 24px 22px;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s var(--ease), background-color var(--theme-dur) var(--ease), color var(--theme-dur) var(--ease), border-color var(--theme-dur) var(--ease);
    animation: rise 0.5s var(--ease) both;
}

.tool-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
}

.tool-card.hidden { display: none; }

.tool-card .card-icon {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--accent);
    margin-bottom: 16px;
}

.tool-card .card-icon svg { width: 20px; height: 20px; stroke-width: 1.7; }

.tool-card h3 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-bottom: 5px;
}

.tool-card p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.45;
}

@keyframes rise {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 0;
    color: var(--text-muted);
}

/* ==========================================================
   Tool page
   ========================================================== */
.tool-page {
    max-width: 640px;
    margin: 0 auto;
    padding: 24px 20px 96px;
}

.tool-head {
    margin-bottom: 36px;
}

.tool-head h1 {
    font-size: clamp(28px, 4.5vw, 40px);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}

.tool-head p {
    font-size: 15px;
    color: var(--text-secondary);
}

.section {
    margin-bottom: 28px;
}

/* Drag & drop upload zone (image tools) */
.drop-zone {
    border: 1.5px dashed var(--hairline);
    border-radius: var(--radius);
    padding: 22px 18px;
    text-align: center;
    transition: border-color var(--theme-dur) var(--ease), background-color var(--theme-dur) var(--ease);
    cursor: pointer;
}

.drop-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.drop-zone .drop-hint {
    margin-top: 10px;
    font-size: 13px;
    color: var(--text-muted);
}

.prose {
    max-width: 720px;
}

.prose p {
    color: var(--text-secondary);
    font-size: 14.5px;
    line-height: 1.75;
    margin-bottom: 16px;
}

.section-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.section-label .hint {
    text-transform: none;
    font-weight: 400;
    letter-spacing: 0;
    color: var(--text-muted);
}

/* Inputs */
textarea,
input[type="text"],
input[type="number"],
input[type="password"],
input[type="datetime-local"],
select {
    width: 100%;
    font-family: var(--font);
    font-size: 16px;   /* >=16px prevents iOS forced focus zoom */
    line-height: 1.45;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    outline: none;
    transition: background-color var(--theme-dur) var(--ease), color var(--theme-dur) var(--ease), border-color var(--theme-dur) var(--ease);
    appearance: none;
}

textarea:focus,
input:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

textarea { resize: vertical; min-height: 108px; }

textarea.code,
input.code,
select.code {
    font-family: var(--mono);
    font-size: 13px;
}

@media (max-width: 640px) {
    /* iOS forces focus-zoom on inputs < 16px — keep editable fields readable on mobile */
    textarea.code, input.code, select.code, textarea.output, input.output {
        font-size: 16px;
    }
}

textarea.output {
    background: var(--surface-2);
    font-family: var(--mono);
    font-size: 13px;
    resize: vertical;
}

input.output { font-family: var(--mono); font-size: 13px; }

/* Inline helper grid used by some tool pages (e.g. bulk rename) */
.input-grid input,
.input-grid select {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

/* Buttons */
.btn-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 44px;
    padding: 0 22px;
    font-size: 15px;
    font-weight: 500;
    border-radius: 22px;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: filter 0.2s var(--ease), transform 0.1s var(--ease), background-color var(--theme-dur) var(--ease), color var(--theme-dur) var(--ease), border-color var(--theme-dur) var(--ease);
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface); }

.btn-ghost {
    height: 34px;
    padding: 0 14px;
    font-size: 13px;
    border-radius: 17px;
    border: 1px solid var(--hairline);
    background: var(--surface);
    color: var(--text);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn-sm {
    height: 34px;
    padding: 0 16px;
    font-size: 13px;
    border-radius: 17px;
}

/* Secondary actions inside a button row match the primary button height */
.btn-row .btn-sm {
    height: 44px;
    padding: 0 22px;
    font-size: 15px;
    border-radius: 22px;
}
.btn-row .btn-ghost {
    height: 44px;
    padding: 0 22px;
    font-size: 15px;
    font-weight: 500;
    border-radius: 22px;
}

/* Segmented control */
.segmented {
    display: inline-flex;
    padding: 3px;
    border-radius: 11px;
    background: var(--surface-2);
    border: 1px solid var(--hairline);
}

.segmented button {
    height: 34px;
    padding: 0 18px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--theme-dur) var(--ease), color var(--theme-dur) var(--ease), border-color var(--theme-dur) var(--ease);
}

.segmented button.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

/* Standalone segmented controls stretch to the section width with equal buttons */
.section > .segmented {
    display: flex;
    width: 100%;
}
.section > .segmented button {
    flex: 1 1 0;
    white-space: nowrap;
}

/* Result panel */
.result {
    margin-top: 14px;
    padding: 16px 18px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    font-family: var(--mono);
    font-size: 13px;
    word-break: break-word;
    white-space: pre-wrap;
    line-height: 1.6;
}

.result:empty { display: none; }

/* Alerts */
.alert {
    display: none;
    font-size: 13px;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 14px;
}
.alert.show { display: block; }
.alert.error { background: var(--accent-soft); color: var(--danger); }
.alert.info { background: var(--surface-2); color: var(--text-secondary); }

/* Inline alert for invalid color etc. */
.field-note {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

/* ==========================================================
   Shared tool widgets
   ========================================================== */
.item-list {
    margin-top: 14px;
    border: 1px solid var(--hairline);
    border-radius: var(--radius-sm);
    background: var(--surface);
    overflow: hidden;
}

.item-list .row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    border-top: 1px solid var(--hairline);
    font-family: var(--mono);
    font-size: 12.5px;
    word-break: break-all;
}

.item-list .row:first-child { border-top: none; }

.item-list .row .row-idx {
    color: var(--text-muted);
    flex-shrink: 0;
    min-width: 22px;
}

.item-list .row .old-name {
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 34%;
    flex-shrink: 1;
}
.item-list .row .arrow {
    color: var(--text-muted);
    flex-shrink: 0;
}
.item-list .row .new-name {
    flex: 1;
    min-width: 0;
    width: auto;
    border: 1px solid var(--hairline);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text);
    font-family: var(--mono);
    font-size: 12.5px;
    padding: 6px 8px;
    outline: none;
}
.item-list .row .new-name:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-top: 14px;
}

.stat {
    text-align: center;
    padding: 20px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.stat .value {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

.stat .label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 3px;
}

.meter {
    height: 6px;
    border-radius: 3px;
    background: var(--surface-2);
    overflow: hidden;
    margin-top: 14px;
}

.meter .fill {
    height: 100%;
    border-radius: 3px;
    width: 0%;
    transition: width 0.4s var(--ease), background-color 0.4s var(--ease);
}

.meter .fill.ok { background: var(--success); width: 100%; }

.fill.weak { background: var(--danger); }
.fill.fair { background: #ff9f0a; }
.fill.good { background: var(--accent); }
.fill.strong { background: var(--success); }

.meter-caption {
    font-size: 12px;
    margin-top: 6px;
    color: var(--text-secondary);
}

.range-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.range-row input[type="range"] {
    flex: 1;
    accent-color: var(--accent);
    height: 28px;
    cursor: pointer;
}

.range-row .value {
    font-family: var(--mono);
    font-size: 14px;
    font-weight: 600;
    min-width: 40px;
    text-align: center;
    color: var(--text);
}

.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 0;
    font-size: 15px;
    cursor: pointer;
    user-select: none;
}

.check-row input[type="checkbox"],
.check-row input[type="radio"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
    margin: 0;
}

.flag-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 20px;
    margin: 6px 0 4px;
}

.flag-row label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-family: var(--mono);
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
}

.flag-row input { accent-color: var(--accent); }

/* Hash rows */
.hash-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 11px 0;
    border-top: 1px solid var(--hairline);
}
.hash-row:first-child { border-top: none; }

.hash-row .hash-label {
    width: 72px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.hash-row .hash-value {
    flex: 1;
    font-family: var(--mono);
    font-size: 12.5px;
    padding: 9px 12px;
    background: var(--surface-2);
    border-radius: 8px;
    word-break: break-all;
    cursor: pointer;
}

.hash-row .hash-value:hover { color: var(--accent); }

/* Color preview */
.color-preview {
    height: 88px;
    border-radius: var(--radius-sm);
    margin-top: 16px;
    border: 1px solid var(--hairline);
    transition: background-color var(--theme-dur) var(--ease), border-color var(--theme-dur) var(--ease);
}

.format-table { width: 100%; border-collapse: collapse; margin-top: 14px; }

.format-table td {
    padding: 11px 12px;
    border-top: 1px solid var(--hairline);
    font-size: 13.5px;
}

.format-table td:first-child {
    width: 84px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.format-table td:last-child {
    font-family: var(--mono);
    cursor: pointer;
}

.format-table td:last-child:hover { color: var(--accent); }

/* Regex highlight */
.regex-box {
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.8;
    white-space: pre-wrap;
    word-break: break-word;
}
.regex-box mark {
    background: var(--accent-soft);
    color: inherit;
    border-radius: 3px;
    padding: 1px 2px;
    outline: 1px solid rgba(0, 113, 227, 0.25);
}

/* QR? none */

/* JWT JSON blocks */
.json-block {
    margin-top: 6px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow: auto;
}

/* ==========================================================
   Footer
   ========================================================== */
.site-footer {
    text-align: center;
    padding: 36px 20px 60px;
    font-size: 12.5px;
    color: var(--text-muted);
}

/* ==========================================================
   Toast
   ========================================================== */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 22px;
    border-radius: 999px;
    background: var(--text);
    color: var(--bg);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-hover);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s var(--ease), transform 0.28s var(--ease), background-color var(--theme-dur) var(--ease), color var(--theme-dur) var(--ease);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ==========================================================
   Site navigation (breadcrumb links in header)
   ========================================================== */
.site-nav {
    display: flex;
    gap: 2px;
    margin-left: 4px;
}

.site-nav a {
    display: inline-flex;
    align-items: center;
    height: 40px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    line-height: 1;
    padding: 0 16px;
    border-radius: 999px;
    transition: color var(--theme-dur) var(--ease), background-color var(--theme-dur) var(--ease), border-color var(--theme-dur) var(--ease);
}

.site-nav a:hover { color: var(--text); background: var(--surface-2); }
.site-nav a.active { color: var(--text); }

/* ==========================================================
   Changelog timeline
   ========================================================== */
.changelog-page {
    max-width: 720px;
    margin: 0 auto;
    padding: 24px 20px 96px;
}

.changelog-head {
    margin-bottom: 40px;
}

.changelog-head h1 {
    font-size: clamp(28px, 4.5vw, 40px);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}

.changelog-head p {
    font-size: 15px;
    color: var(--text-secondary);
}

.timeline {
    position: relative;
    padding-left: 34px;
}

.timeline::before {
    content: "";
    position: absolute;
    left: 10px;
    top: 6px;
    bottom: 6px;
    width: 2px;
    background: var(--hairline);
}

.timeline-item {
    position: relative;
    padding-bottom: 42px;
}

.timeline-item:last-child { padding-bottom: 0; }

.timeline-item::before {
    content: "";
    position: absolute;
    left: -31px;
    top: 7px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.timeline-item.latest::before {
    background: var(--success);
    box-shadow: 0 0 0 4px rgba(48, 209, 88, 0.16);
}

.timeline-item .meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.timeline-item .version {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--accent);
    font-family: var(--mono);
}

.timeline-item .badge-new {
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: var(--success);
    border-radius: 999px;
    padding: 2px 9px;
}

.timeline-item .date {
    font-size: 13px;
    color: var(--text-muted);
}

.timeline-item .title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.35;
    margin-bottom: 10px;
}

.timeline-item ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.timeline-item li {
    position: relative;
    padding: 4px 0 4px 22px;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
}

.timeline-item li::before {
    content: "";
    position: absolute;
    left: 6px;
    top: 13px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text-muted);
}

/* ==========================================================
   Mobile drawer menu
   ========================================================== */
.menu-btn {
    display: none;
}

.drawer {
    position: fixed;
    inset: 0;
    z-index: 120;
    visibility: hidden;
    transition: visibility 0s linear 0.35s;
}

.drawer.open {
    visibility: visible;
    transition: visibility 0s;
}

.drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: opacity 0.35s var(--ease);
}

.drawer.open .drawer-backdrop { opacity: 1; }

.drawer-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 292px;
    max-width: 85vw;
    background: var(--surface);
    border-left: 1px solid var(--hairline);
    box-shadow: var(--shadow-hover);
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1),
        background-color var(--theme-dur) var(--ease), border-color var(--theme-dur) var(--ease);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.drawer.open .drawer-panel { transform: translateX(0); }

.drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    padding: 0 22px;
    border-bottom: 1px solid var(--hairline);
}

.drawer-head .brand { font-size: 17px; }

.drawer-close {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: grid;
    place-items: center;
}

.drawer-close:hover { background: var(--surface-2); }
.drawer-close svg { width: 18px; height: 18px; stroke-width: 1.7; }

.drawer-nav {
    padding: 14px 22px 28px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.drawer-nav a {
    padding: 13px 14px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
    transition: background-color var(--theme-dur) var(--ease), color var(--theme-dur) var(--ease);
}

.drawer-nav a:hover { background: var(--surface-2); }
.drawer-nav a:active { background: var(--accent-soft); }
.drawer-nav a.active { color: var(--accent); }

.drawer-foot {
    margin-top: auto;
    padding: 18px 22px 28px;
    font-size: 12px;
    color: var(--text-muted);
}

/* ==========================================================
   Footer
   ========================================================== */
.site-footer {
    border-top: 1px solid var(--hairline);
    padding: 48px 20px 40px;
}

.footer-inner {
    max-width: 1080px;
    margin: 0 auto;
}

.footer-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr;
    gap: 32px;
    text-align: left;
    margin-bottom: 36px;
}

.footer-col h4 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin: 0 0 14px;
}

.footer-col a {
    display: block;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13.5px;
    line-height: 2;
    transition: color var(--theme-dur) var(--ease);
}

.footer-col a:hover { color: var(--text); }

.footer-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 12px;
}


.footer-tagline {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.7;
    margin: 0 0 18px;
    max-width: 260px;
}

.footer-friend {
    display: flex;
    gap: 10px;
    margin-top: 6px;
}

.footer-friend a {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    color: var(--text-secondary);
    border: 1px solid var(--hairline);
    border-radius: 50%;
    transition: color var(--theme-dur) var(--ease), border-color var(--theme-dur) var(--ease);
}

.footer-friend a:hover { color: var(--text); border-color: var(--text-muted); }

.footer-friend a svg { width: 17px; height: 17px; stroke: currentColor; stroke-width: 1.8; fill: none; }

.footer-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    border-top: 1px solid var(--hairline);
    padding-top: 20px;
}

.footer-note {
    font-size: 12.5px;
    color: var(--text-muted);
    line-height: 1.7;
    margin: 0;
}

/* ==========================================================
   Responsive
   ========================================================== */
@media (max-width: 640px) {
    .grid { grid-template-columns: 1fr; }
    .footer-grid { grid-template-columns: 1fr 1fr; gap: 24px; }
    .footer-brand-col { grid-column: 1 / -1; }
    .hero { padding: 32px 20px 16px; }
    .tool-page { padding: 16px 20px 64px; }
    .changelog-page { padding: 16px 20px 64px; }
    .header-inner { padding: 0 14px; }
    .icon-btn .btn-label { display: none; }
    .icon-btn { padding: 0; width: 44px; height: 44px; justify-content: center; }
    .header-inner { height: 60px; padding: 0 9px 0 20px; }
    .search-shortcut { display: none; }

    .site-nav { display: none; }
    .menu-btn { display: inline-flex; }
    .header-actions { gap: 2px; }
}

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

@media (min-width: 641px) and (hover: hover) and (pointer: fine) {
    /* Desktop/mouse only: re-add box-shadow so card hover stays smooth
       (shadow animation is skipped on touch devices where it is costly). */
    .tool-card {
        transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease),
            background-color var(--theme-dur) var(--ease), color var(--theme-dur) var(--ease),
            border-color var(--theme-dur) var(--ease);
    }
}

/* Touch devices / narrow phones: theme switch must feel instant; drop the
   blur layer on the sticky header (backdrop-filter is a major GPU cost). */
@media (min-width: 641px) and (pointer: coarse) {
    .site-header {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
}
@media (max-width: 640px) {
    :root {
        --theme-dur: 0s;
    }
    .site-header {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
}

/* ==========================================================
   Build badge — permanent version marker (bump --build, mirror in core.js)
   ========================================================== */
.build-badge {
    position: fixed;
    right: 12px;
    bottom: 12px;
    z-index: 200;
    padding: 5px 11px;
    border-radius: 999px;
    font: 600 11px/1 var(--font);
    letter-spacing: 0.03em;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--hairline);
    box-shadow: var(--shadow);
    opacity: 0.85;
    pointer-events: none;
}
.build-badge.stale {
    color: #fff;
    background: var(--danger);
    border-color: var(--danger);
}

/* ==========================================================
   Text diff view
   ========================================================== */
#out { font-family: var(--mono); }
.dl {
    display: flex;
    gap: 8px;
    padding: 1px 10px;
    border-radius: 6px;
}
.ds {
    flex: 0 0 1em;
    text-align: center;
    color: var(--text-muted);
    user-select: none;
}
.dt { white-space: pre-wrap; word-break: break-word; }
.deq { color: var(--text-secondary); }
.ddel { background: rgba(215, 0, 21, 0.09); color: var(--danger); }
.dins { background: rgba(36, 138, 61, 0.12); color: var(--success); }
[data-theme="dark"] .ddel { background: rgba(255, 69, 58, 0.16); }
[data-theme="dark"] .dins { background: rgba(48, 209, 88, 0.14); }
/* ==========================================================
   Blog
   ========================================================== */
.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    margin: 0 0 10px;
}
.breadcrumbs a { color: var(--text-secondary); text-decoration: none; }
.breadcrumbs a:hover { color: var(--text); }
.crumb-sep { opacity: 0.6; }

.post-subtitle {
    margin: 6px 0 0;
    font-size: 19px;
    font-weight: 400;
    color: var(--text-secondary);
}
.post-meta {
    margin: 14px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}

.post-body {
    max-width: 720px;
    margin: 0 auto;
    font-size: 17px;
    line-height: 1.8;
    color: var(--text);
}
.post-body h2 {
    font-size: 22px;
    font-weight: 700;
    margin: 34px 0 12px;
    letter-spacing: -0.01em;
}
.post-body h2:first-child { margin-top: 0; }
.post-body p { margin: 0 0 16px; }
.post-body ul { margin: 0 0 18px; padding-left: 22px; }
.post-body li { margin: 6px 0; }
.post-body a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--hairline); }
.post-body a:hover { border-bottom-color: var(--accent); }
.post-body code {
    font-family: var(--mono);
    font-size: 0.92em;
    background: var(--muted);
    padding: 1px 6px;
    border-radius: 5px;
}

.post-cta {
    margin: 40px auto 8px;
    max-width: 720px;
    text-align: center;
}
.post-cta .btn { font-size: 16px; padding: 12px 26px; }

.post-card { display: flex; flex-direction: column; text-decoration: none; }
.post-card h3 { margin-bottom: 4px; }
.post-card-desc {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.7;
    margin: 0 0 12px;
    flex: 1;
}
.post-card-meta { color: var(--text-muted); font-size: 12px; margin: 0; }

/* zh/en toggling blocks (blog etc.): shown/hidden by <html lang> */
.lang-en { display: none; }
html[lang="en"] .lang-zh { display: none; }
html[lang="en"] .lang-en { display: revert; }

/* ==========================================================
   PDF to Image
   ========================================================== */
.pdf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}

.pdf-page {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.pdf-page img {
    width: 100%;
    border-radius: 6px;
    background: #fff;
}

.pdf-page a {
    font-size: 13px;
    text-align: center;
    color: var(--text);
    text-decoration: none;
}

/* ==========================================================
   PDF ⇄ Word
   ========================================================== */
.pw-opt {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.pw-opt .hint {
    display: block;
    font-weight: 400;
}

.doc-preview {
    margin-top: 4px;
    padding: 32px 36px;
    background: #fff;
    color: #1c1c1e;
    border: 1px solid var(--hairline);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    font-size: 14px;
    line-height: 1.65;
    overflow-x: auto;
    max-width: 780px;
}

.doc-preview h1, .doc-preview h2, .doc-preview h3,
.doc-preview h4, .doc-preview h5, .doc-preview h6 {
    margin: 1.1em 0 0.4em;
    line-height: 1.3;
    font-weight: 600;
}
.doc-preview h1 { font-size: 1.6em; }
.doc-preview h2 { font-size: 1.35em; }
.doc-preview h3 { font-size: 1.18em; }
.doc-preview h4 { font-size: 1.05em; }
.doc-preview h5 { font-size: 0.95em; }
.doc-preview h6 { font-size: 0.88em; }

.doc-preview p {
    margin: 0 0 6px;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.doc-preview strong { font-weight: 700; }
.doc-preview em { font-style: italic; }
.doc-preview u { text-decoration: underline; }
.doc-preview s { text-decoration: line-through; }

.doc-preview img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 6px 0;
}

.doc-preview table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
    font-size: 13px;
}
.doc-preview td,
.doc-preview th {
    border: 1px solid #c9c9cd;
    padding: 5px 9px;
    vertical-align: top;
}
.doc-preview td p { margin: 0 0 4px; }
.doc-preview td p:last-child { margin-bottom: 0; }

@media print {
    .site-header,
    .site-footer,
    .drawer,
    .toast,
    #mainContent,
    .tool-head { display: none !important; }
    #previewShell { display: block !important; }
    body,
    .tool-page { background: #fff !important; }
    .tool-page {
        max-width: none;
        padding: 0;
    }
    #previewShell .section-label,
    #previewShell .btn-row { display: none !important; }
    .doc-preview {
        border: none;
        box-shadow: none;
        border-radius: 0;
        padding: 0;
        max-width: none;
        font-size: 12px;
        line-height: 1.5;
    }
    .doc-preview a { color: #000; }
}

/* ==========================================================
   Camera test
   ========================================================== */
.video-box {
    position: relative;
    width: 100%;
    max-width: 720px;
    aspect-ratio: 16 / 9;
    border-radius: var(--radius-sm);
    background: #000;
    border: 1px solid var(--hairline);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.video-box video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.video-box .video-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 13px;
    pointer-events: none;
}

/* ==========================================================
   Keyboard test
   ========================================================== */
.kb {
    user-select: none;
    -webkit-user-select: none;
    margin-top: 4px;
}
.kb-row {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
}
.kb-row:last-child { margin-bottom: 0; }
.key {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    height: 44px;
    padding: 0 4px;
    border-radius: 8px;
    border: 1px solid var(--hairline);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    box-shadow: 0 2px 0 var(--hairline);
    transition: background-color var(--theme-dur) var(--ease), color var(--theme-dur) var(--ease),
        border-color var(--theme-dur) var(--ease), box-shadow var(--theme-dur) var(--ease),
        transform 0.05s var(--ease);
}
.key.pressed {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 1px 0 var(--accent-hover);
    transform: translateY(1px);
}
.chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 30px;
    margin-top: 6px;
}
.chip {
    padding: 6px 12px;
    border-radius: 16px;
    background: var(--accent);
    color: #fff;
    font-family: var(--mono);
    font-size: 12.5px;
}
.stat .value.mono { font-family: var(--mono); font-size: 20px; }
@media (max-width: 640px) {
    .kb-row { gap: 4px; margin-bottom: 4px; }
    .key { height: 38px; font-size: 10.5px; }
}
