:root {
    --bg: #f5f7fb;
    --bg-elevated: #ffffff;
    --bg-panel: #ffffff;
    --bg-input: #fafbfc;
    --border: #e2e8f0;
    --border-soft: #eef2f7;
    --text: #1e293b;
    --muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-soft: rgba(59, 130, 246, 0.1);
    --ok: #16a34a;
    --ok-soft: rgba(22, 163, 74, 0.1);
    --danger: #dc2626;
    --danger-soft: rgba(220, 38, 38, 0.1);
    --warn: #d97706;
    --add: #dcfce7;
    --add-text: #15803d;
    --del: #fee2e2;
    --del-text: #b91c1c;
    --radius: 14px;
    --shadow: 0 8px 28px rgba(15, 23, 42, 0.06);
    --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    --mono: Consolas, "Cascadia Code", "Courier New", monospace;
}

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

html, body {
    min-height: 100%;
}

body {
    font-family: var(--font);
    color: var(--text);
    background:
        radial-gradient(1000px 480px at 8% -8%, rgba(59, 130, 246, 0.07), transparent 55%),
        radial-gradient(800px 420px at 92% 0%, rgba(14, 165, 233, 0.05), transparent 50%),
        var(--bg);
    line-height: 1.5;
}

button, textarea, input, select {
    font: inherit;
    color: inherit;
}

a {
    color: var(--accent);
    text-decoration: none;
}

.app {
    max-width: 1280px;
    margin: 0 auto;
    padding: 28px 20px 48px;
}

.app.is-json-fullscreen {
    max-width: none;
    padding: 12px 16px 16px;
    min-height: 100vh;
}

/* 全屏：隐藏顶部 header；导航会移入 panel-toolbar */
.app.is-json-fullscreen .site-header,
.app.is-json-fullscreen .footer-note {
    display: none !important;
}

.app.is-json-fullscreen #panel-json,
.app.is-json-fullscreen .panel.active {
    display: block !important;
    min-height: calc(100vh - 32px);
    /* 避免工具栏内下拉菜单被裁切 */
    overflow: visible;
}

.app.is-json-fullscreen .json-stack {
    min-height: calc(100vh - 160px);
}

.app.is-json-fullscreen .editor-input {
    min-height: 100px;
    max-height: 140px;
    height: 120px;
}

.app.is-json-fullscreen .editor-output {
    min-height: calc(100vh - 320px);
    height: calc(100vh - 320px);
}

/* JSON 页：整体限制在一屏内，不超出屏幕高度 */
html:has(.app-json),
body:has(.app-json) {
    height: 100%;
    overflow: hidden;
}

.app-json {
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    min-height: 0;
    box-sizing: border-box;
    padding-top: 16px;
    padding-bottom: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.app-json .site-header {
    flex-shrink: 0;
    margin-bottom: 12px;
}

.app-json .footer-note {
    flex-shrink: 0;
    margin-top: 10px;
    margin-bottom: 0;
}

.app-json #panel-json,
.app-json #panel-json.active {
    flex: 1 1 auto;
    min-height: 0;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
}

.app-json .panel-toolbar,
.app-json .panel-status-bar {
    flex-shrink: 0;
}

.app-json .json-stack {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 16px 14px;
    overflow: hidden;
}

.app-json .editor-col-input {
    flex-shrink: 0;
}

.app-json .editor-input {
    min-height: 72px;
    height: 88px;
    max-height: 120px;
    resize: vertical;
}

.app-json .editor-col-output {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.app-json .editor-col-output .field-label {
    flex-shrink: 0;
}

.app-json .editor-output {
    flex: 1 1 auto;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    resize: none;
}

.app-json .json-stack:has(.editor-col-input.is-collapsed) .editor-output {
    min-height: 0 !important;
    height: auto !important;
}

/* 全屏时仍限制在视口内（导航并入工具栏） */
.app-json.is-json-fullscreen {
    height: 100vh;
    max-height: 100vh;
    padding: 12px 16px;
}

.app-json.is-json-fullscreen #panel-json,
.app-json.is-json-fullscreen .panel.active {
    min-height: 0 !important;
    height: auto;
    display: flex !important;
    flex-direction: column;
    flex: 1 1 auto;
    overflow: visible;
}

.app-json.is-json-fullscreen .panel-toolbar {
    position: relative;
    z-index: 30;
    overflow: visible;
}

.app-json.is-json-fullscreen .json-stack {
    min-height: 0;
    flex: 1;
}

.app-json.is-json-fullscreen .editor-input {
    min-height: 72px;
    max-height: 100px;
    height: 80px;
}

.app-json.is-json-fullscreen .editor-output {
    min-height: 0 !important;
    height: auto !important;
}

/* 文本对比全屏 */
.app.is-diff-fullscreen {
    max-width: none;
    padding: 12px 16px 16px;
    min-height: 100vh;
}

/* 全屏：隐藏顶部 header；导航会移入 panel-toolbar */
.app.is-diff-fullscreen .site-header,
.app.is-diff-fullscreen .footer-note {
    display: none !important;
}

.app.is-diff-fullscreen .panel.active {
    display: block !important;
    min-height: calc(100vh - 32px);
    overflow: visible;
}

.app.is-diff-fullscreen .panel-toolbar {
    position: relative;
    z-index: 30;
    overflow: visible;
}

.app.is-diff-fullscreen .compare-grid .editor {
    min-height: 100px;
    height: 110px;
    max-height: 160px;
}

.app.is-diff-fullscreen .diff-box {
    min-height: calc(100vh - 300px);
    max-height: calc(100vh - 260px);
}

/* Header / intro */
.site-header {
    margin-bottom: 22px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 14px;
}

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: linear-gradient(145deg, #60a5fa, #3b82f6);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.28);
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
}

.brand h1 {
    font-size: 1.55rem;
    font-weight: 650;
    letter-spacing: 0.2px;
}

.brand p {
    color: var(--muted);
    font-size: 0.92rem;
    margin-top: 2px;
}

.intro-cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.intro-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: var(--shadow);
}

.intro-card h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.intro-card p {
    color: var(--muted);
    font-size: 0.86rem;
}

/* 首页 */
.home-lead {
    color: var(--muted);
    margin: 8px 0 18px;
    font-size: 0.95rem;
}

.tool-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.md5-output {
    min-height: 120px !important;
    height: 140px !important;
    font-size: 1.05rem;
    letter-spacing: 0.04em;
    word-break: break-all;
}

/* 多图合成 GIF */
.app-gif .gif-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.gif-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}

.gif-frames {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 520px;
    overflow: auto;
    padding-right: 4px;
}

.gif-frame {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fafbfc;
}

.gif-frame-thumb {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 8px;
    border: 1px solid var(--border);
    background:
        linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
        linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
        linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
    background-size: 12px 12px;
    background-position: 0 0, 0 6px, 6px -6px, -6px 0;
    background-color: #fff;
}

.gif-frame-meta {
    min-width: 0;
}

.gif-frame-name {
    font-weight: 650;
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gif-frame-info {
    color: var(--muted);
    font-size: 0.82rem;
    margin-top: 4px;
}

.gif-frame-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.gif-preview-box {
    min-height: 220px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow: hidden;
}

.gif-preview-box img {
    max-width: 100%;
    max-height: 360px;
    object-fit: contain;
}

.gif-preview-empty {
    color: var(--muted);
    font-size: 0.92rem;
}

.gif-frames-empty {
    color: var(--muted);
    font-size: 0.9rem;
    padding: 18px 12px;
    border: 1px dashed var(--border);
    border-radius: 12px;
    text-align: center;
}

@media (max-width: 860px) {
    .gif-layout {
        grid-template-columns: 1fr;
    }
}

/* 图片 缩放|压缩 */
.app-img .img-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.img-source-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.img-url-label {
    flex-shrink: 0;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--muted);
}

.img-url-input {
    flex: 1 1 220px;
    min-width: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 9px 12px;
    outline: none;
    color: var(--text);
}

.img-url-input:focus {
    border-color: rgba(59, 130, 246, 0.55);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.img-drop {
    border: 2px dashed var(--border);
    border-radius: 12px;
    background: var(--bg-input);
    min-height: 168px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: text;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
    outline: none;
    flex-shrink: 0;
}

.img-drop:hover {
    border-color: rgba(59, 130, 246, 0.45);
    background: #f8fafc;
}

.img-drop:focus-visible,
.img-drop.is-focused {
    border-color: var(--accent);
    background: #f8fafc;
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.img-drop.is-dragover {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.img-drop-inner {
    text-align: center;
    padding: 22px 18px;
    pointer-events: none;
}

.img-drop-inner strong {
    display: block;
    font-size: 1.05rem;
    margin-bottom: 8px;
}

.img-drop-inner span {
    display: block;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.55;
}

.img-drop-inner kbd {
    display: inline-block;
    padding: 1px 6px;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 5px;
    background: #fff;
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--text);
}

.img-drop-hint {
    margin-top: 10px !important;
    color: var(--accent-hover) !important;
    font-weight: 600;
    font-size: 0.86rem !important;
}

.img-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.img-item {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    gap: 16px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fafbfc;
}

.img-item-previews {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    min-width: 0;
}

.img-preview-col {
    min-width: 0;
}

.img-preview-col > span {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 6px;
}

.img-thumb {
    display: block;
    width: 100%;
    height: 140px;
    object-fit: contain;
    background:
        linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
        linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
        linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    background-color: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.img-thumb-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.86rem;
}

.img-item-meta {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.img-item-name {
    font-weight: 650;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.img-item-stats {
    color: var(--muted);
    font-size: 0.88rem;
    line-height: 1.45;
}

.img-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 650;
    vertical-align: middle;
}

.img-save-ok {
    color: var(--ok);
    background: var(--ok-soft);
}

.img-save-bad {
    color: var(--warn);
    background: rgba(217, 119, 6, 0.12);
}

.img-item-error {
    color: var(--danger);
    font-size: 0.86rem;
}

.img-item-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: auto;
    padding-top: 4px;
}

.img-fmt-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
    padding: 10px 10px 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

.img-fmt-title {
    font-size: 0.78rem;
    font-weight: 650;
    color: var(--muted);
    margin-bottom: 2px;
}

.img-fmt-row {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) minmax(0, 1.2fr) auto;
    gap: 8px;
    align-items: center;
    font-size: 0.86rem;
}

.img-fmt-row.img-fmt-disabled {
    opacity: 0.65;
}

.img-fmt-label {
    font-weight: 700;
    color: var(--text);
}

.img-fmt-size {
    color: var(--muted);
    min-width: 0;
}

.img-fmt-name {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 0.78rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.86rem;
}

.input-num-sm {
    width: 72px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 8px;
    outline: none;
    color: var(--text);
}

.input-num-sm:focus {
    border-color: rgba(59, 130, 246, 0.55);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.input-range-scale {
    width: 90px;
}

.img-summary {
    margin-top: 0;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--accent-hover);
    font-size: 0.92rem;
    line-height: 1.5;
}

.input-range {
    width: 110px;
    vertical-align: middle;
    accent-color: var(--accent);
}

.range-label {
    min-width: 2.6em;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--text);
}

.input-color {
    width: 36px;
    height: 32px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
}

@media (max-width: 860px) {
    .img-item {
        grid-template-columns: 1fr;
    }

    .img-thumb {
        height: 120px;
    }

    .img-fmt-row {
        grid-template-columns: 48px 1fr auto;
    }

    .img-fmt-name {
        display: none;
    }
}

/* UUID / 随机串：两块区域合计约占视口 90%，减少底部空白 */
.app-gen {
    min-height: 90vh;
    height: 90vh;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding-top: 16px;
    padding-bottom: 12px;
    box-sizing: border-box;
    overflow: hidden;
}

.app-gen .site-header {
    flex-shrink: 0;
    margin-bottom: 14px;
}

.app-gen .footer-note {
    flex-shrink: 0;
    margin-top: 12px;
}

.app-gen .gen-panel,
.app-gen .gen-panel.active {
    flex: 1 1 0;
    margin-bottom: 0;
    display: flex !important;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.app-gen .gen-panel-gap {
    margin-top: 12px;
}

.app-gen .gen-panel .panel-toolbar,
.app-gen .gen-panel .gen-options {
    flex-shrink: 0;
}

.app-gen .gen-body {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 12px 16px 16px;
}

.app-gen .gen-output {
    flex: 1 1 auto;
    width: 100%;
    min-height: 160px !important;
    height: 100% !important;
    max-height: none !important;
    resize: vertical;
    font-family: var(--mono);
    letter-spacing: 0.02em;
    word-break: break-all;
}

.panel-title {
    font-size: 0.95rem;
    font-weight: 650;
    color: var(--text);
    margin-right: 4px;
    padding: 0 4px 0 2px;
}

.gen-panel {
    margin-bottom: 0;
}

.gen-panel-gap {
    margin-top: 16px;
}

.gen-body {
    padding: 12px 16px 16px;
}

.gen-output {
    min-height: 120px !important;
    height: 140px !important;
    font-family: var(--mono);
    letter-spacing: 0.02em;
    word-break: break-all;
}

.input-num {
    width: 72px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 8px;
    outline: none;
    color: var(--text);
}

.input-num:focus {
    border-color: rgba(59, 130, 246, 0.55);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.gen-options {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 18px;
    padding: 4px 16px 8px;
    border-bottom: 1px solid var(--border-soft);
    background: #fafbfc;
}

.check-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 0.88rem;
    cursor: pointer;
    user-select: none;
}

.check-wrap input {
    width: 15px;
    height: 15px;
    accent-color: var(--accent);
    cursor: pointer;
}

.panel-toolbar .check-wrap {
    margin-left: 2px;
}

.tool-card {
    display: block;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 22px 18px;
    box-shadow: var(--shadow);
    color: inherit;
    text-decoration: none;
    transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.tool-card:hover {
    border-color: rgba(59, 130, 246, 0.45);
    background: #f8fafc;
    transform: translateY(-2px);
    text-decoration: none;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

.tool-card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
    height: 28px;
    padding: 0 10px;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent-hover);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    margin-bottom: 12px;
    font-family: var(--mono);
}

.tool-card h2 {
    font-size: 1.2rem;
    font-weight: 650;
    margin-bottom: 8px;
}

.tool-card p {
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.55;
    margin-bottom: 14px;
}

.tool-card-go {
    color: var(--accent-hover);
    font-size: 0.9rem;
    font-weight: 600;
}

/* 子页顶栏导航 */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.page-header .brand {
    margin-bottom: 0;
}

.brand-link {
    color: #fff;
    text-decoration: none;
}

.brand-link:visited {
    color: #fff;
}

.brand-link:hover {
    text-decoration: none;
    filter: brightness(1.08);
}

/* 导航注入前占位，避免布局跳动 */
[data-include-nav] {
    min-width: 180px;
    min-height: 44px;
}

.page-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px;
    position: relative;
}

/* 全屏时：导航并入工具页 toolbar 右侧靠屏幕边 */
.page-nav.page-nav-in-toolbar {
    flex-shrink: 0;
    margin-left: auto;
    margin-right: 0;
    order: 99;
    padding: 3px;
    gap: 2px;
    border-radius: 10px;
    background: #fff;
    box-shadow: inset 0 0 0 1px var(--border);
}

.page-nav.page-nav-in-toolbar .nav-link,
.page-nav.page-nav-in-toolbar .nav-dropdown-toggle {
    padding: 6px 10px;
    font-size: 0.85rem;
    border-radius: 8px;
}

/* 与左侧操作按钮之间的分隔感 */
.page-nav.page-nav-in-toolbar::before {
    content: "";
    display: inline-block;
    width: 1px;
    height: 22px;
    margin: 0 8px 0 2px;
    background: var(--border);
    flex-shrink: 0;
    align-self: center;
}

.page-nav .nav-link,
.page-nav .nav-dropdown-toggle {
    color: var(--muted);
    text-decoration: none;
    padding: 8px 14px;
    border-radius: 9px;
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.4;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.page-nav .nav-link:hover,
.page-nav .nav-dropdown-toggle:hover {
    color: var(--text);
    background: #f1f5f9;
    text-decoration: none;
}

.page-nav .nav-link.active,
.page-nav .nav-dropdown-toggle.active,
.page-nav .nav-dropdown.is-open .nav-dropdown-toggle {
    color: var(--accent-hover);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.25);
}

.nav-dropdown {
    position: relative;
}

.nav-dropdown-toggle .caret {
    font-size: 0.7rem;
    opacity: 0.75;
    transition: transform 0.15s ease;
}

.nav-dropdown.is-open .nav-dropdown-toggle .caret {
    transform: rotate(180deg);
}

.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 168px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.1);
    padding: 6px;
    z-index: 50;
}

.nav-dropdown.is-open .nav-dropdown-menu {
    display: block;
}

.nav-dropdown-menu a {
    display: block;
    color: var(--text);
    text-decoration: none;
    padding: 9px 12px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
}

.nav-dropdown-menu a:hover {
    background: #f1f5f9;
    color: var(--accent-hover);
    text-decoration: none;
}

.nav-dropdown-menu a.active {
    background: var(--accent-soft);
    color: var(--accent-hover);
}

/* 子页里 panel 默认展示 */
.panel.active {
    display: block;
}

/* Navigation */
.nav-tabs {
    display: flex;
    gap: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px;
    margin: 20px 0 16px;
    width: fit-content;
    max-width: 100%;
}

.nav-tab {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--muted);
    padding: 10px 18px;
    border-radius: 9px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: 0.15s ease;
    white-space: nowrap;
}

.nav-tab:hover {
    color: var(--text);
    background: #f1f5f9;
}

.nav-tab.active {
    color: var(--accent-hover);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.25);
}

/* Panels */
.panel {
    display: none;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    color: var(--text);
}

.panel.active {
    display: block;
}

.panel-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-soft);
    background: #f8fafc;
}

.toolbar-json {
    gap: 6px;
    padding: 10px 12px;
}

.toolbar-json .btn {
    padding: 7px 11px;
    font-size: 0.84rem;
    border-radius: 8px;
}

.panel-toolbar .spacer {
    flex: 1;
}

.panel-status-bar {
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-soft);
    background: #fafbfc;
}

.panel-status-bar .status {
    display: block;
    word-break: break-word;
}

.btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    border-radius: 9px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 550;
    transition: 0.15s ease;
}

.btn:hover {
    border-color: #cbd5e1;
    background: #f1f5f9;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: linear-gradient(180deg, #60a5fa, #3b82f6);
    border-color: transparent;
    color: #fff;
}

.btn-primary:hover {
    background: linear-gradient(180deg, #3b82f6, #2563eb);
    color: #fff;
}

.btn-ghost {
    background: transparent;
}

.btn-danger {
    color: #b91c1c;
    border-color: rgba(220, 38, 38, 0.28);
    background: var(--danger-soft);
}

.btn-danger:hover {
    border-color: rgba(220, 38, 38, 0.45);
    background: rgba(220, 38, 38, 0.14);
}

.status {
    font-size: 0.86rem;
    color: var(--muted);
    min-height: 1.2em;
}

.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }

.field-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 0.86rem;
}

.field-label strong {
    color: var(--text);
    font-weight: 600;
}

.field-label-left {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.field-hint {
    flex-shrink: 1;
    text-align: right;
}

.btn-collapse {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--muted);
    border-radius: 6px;
    padding: 2px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    line-height: 1.4;
    transition: 0.15s ease;
}

.btn-collapse:hover {
    color: var(--text);
    border-color: #cbd5e1;
    background: #f1f5f9;
}

/* 输入区收起：腾出更多空间给输出 */
.editor-col-input.is-collapsed .editor-input {
    display: none;
}

.editor-col-input.is-collapsed .field-hint {
    display: none;
}

.editor-col-input.is-collapsed {
    margin-bottom: 0;
}

.json-stack:has(.editor-col-input.is-collapsed) .editor-output {
    min-height: 620px;
    height: min(72vh, 780px);
}

.app.is-json-fullscreen .json-stack:has(.editor-col-input.is-collapsed) .editor-output {
    min-height: calc(100vh - 220px);
    height: calc(100vh - 220px);
}

textarea.editor {
    width: 100%;
    min-height: 280px;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-input);
    color: var(--text);
    padding: 14px;
    font-family: var(--mono);
    font-size: 0.9rem;
    line-height: 1.55;
    outline: none;
    transition: border-color 0.15s ease;
}

.editor-col {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.editor-col .editor {
    width: 100%;
}

textarea.editor:focus {
    border-color: rgba(59, 130, 246, 0.55);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

textarea.editor::placeholder {
    color: #94a3b8;
}

/* JSON：上输入（小）下输出（大），方便阅读格式化结果 */
.json-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px 16px 16px;
}

.editor-input {
    min-height: 110px;
    height: 120px;
    max-height: 200px;
    resize: vertical;
    font-size: 0.84rem;
    line-height: 1.45;
    color: #475569;
    background: #f8fafc;
}

.editor-output {
    min-height: 520px;
    height: min(62vh, 680px);
    resize: vertical;
    font-size: 0.92rem;
    line-height: 1.55;
    border-color: rgba(59, 130, 246, 0.28);
    background: #ffffff;
    color: var(--text);
}

.editor-col-output .field-label strong {
    color: var(--accent-hover);
}

/* 兼容旧类名 */
.json-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 16px;
}

textarea.editor-tall {
    min-height: 420px;
}

/* Text compare layout */
.diff-input-section {
    padding: 16px 16px 8px;
}

.compare-grid {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 10px;
    align-items: stretch;
}

.compare-pane {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.compare-pane .editor {
    flex: 1;
    min-height: 180px;
}

.compare-mid {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 28px 0 0;
}

.btn-collapse-mid {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 40px;
    padding: 10px 8px;
    writing-mode: horizontal-tb;
    border-radius: 10px;
    line-height: 1.2;
}

.btn-collapse-mid .collapse-icon {
    font-size: 0.85rem;
    line-height: 1;
    opacity: 0.85;
}

.btn-collapse-mid .collapse-text {
    font-size: 0.75rem;
    letter-spacing: 0.02em;
}

/* 收起输入区：隐藏两侧编辑框，中间按钮横条展示 */
.diff-input-section.is-collapsed {
    padding-bottom: 4px;
}

.diff-input-section.is-collapsed .compare-grid {
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
}

.diff-input-section.is-collapsed .compare-pane .editor {
    display: none;
}

.diff-input-section.is-collapsed .compare-pane .field-label span {
    display: none;
}

.diff-input-section.is-collapsed .compare-pane .field-label {
    margin-bottom: 0;
    justify-content: center;
}

.diff-input-section.is-collapsed .compare-mid {
    padding-top: 0;
}

.diff-input-section.is-collapsed .btn-collapse-mid {
    flex-direction: row;
    min-width: 88px;
    padding: 6px 14px;
}

.diff-input-section.is-collapsed .btn-collapse-mid .collapse-icon {
    transform: rotate(180deg);
}

/* 收起后结果区更高 */
.panel:has(.diff-input-section.is-collapsed) .diff-box {
    min-height: 380px;
    max-height: 620px;
}

.app.is-diff-fullscreen .panel:has(.diff-input-section.is-collapsed) .diff-box {
    min-height: calc(100vh - 220px);
    max-height: calc(100vh - 180px);
}

.app.is-diff-fullscreen .diff-input-section.is-collapsed .compare-pane .editor {
    display: none;
}

.diff-section {
    padding: 0 16px 16px;
}

.diff-side-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.diff-side {
    min-width: 0;
}

.diff-box {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-input);
    min-height: 280px;
    max-height: 520px;
    overflow: auto;
    font-family: var(--mono);
    font-size: 0.88rem;
    line-height: 1.5;
}

.diff-empty {
    color: var(--muted);
    padding: 24px 16px;
    text-align: center;
}

.diff-line {
    display: grid;
    grid-template-columns: 52px 28px 1fr;
    gap: 0;
    white-space: pre-wrap;
    word-break: break-word;
    border-bottom: 1px solid #f1f5f9;
    min-height: 1.5em;
}

.diff-line .ln {
    color: #94a3b8;
    text-align: right;
    padding: 2px 8px;
    user-select: none;
    border-right: 1px solid var(--border-soft);
    background: #f8fafc;
}

.diff-line .mark {
    text-align: center;
    padding: 2px 0;
    user-select: none;
    font-weight: 700;
}

.diff-line .code {
    padding: 2px 12px;
}

.diff-line.same .mark { color: #94a3b8; }
.diff-line.add {
    background: rgba(220, 38, 38, 0.06);
}
.diff-line.add .mark { color: var(--danger); }
.diff-line.del {
    background: rgba(220, 38, 38, 0.06);
}
.diff-line.del .mark { color: var(--danger); }
.diff-line.change {
    background: #fff;
}
.diff-line.change .mark { color: var(--warn); }
.diff-line.blank {
    background: #fafbfc;
    opacity: 0.7;
}
.diff-line.blank .code {
    color: transparent;
    user-select: none;
}

/* 行内字符级差异标红 */
.diff-hl {
    color: #991b1b;
    background: rgba(254, 202, 202, 0.9);
    border-radius: 2px;
    padding: 0 1px;
    box-shadow: inset 0 -1px 0 rgba(220, 38, 38, 0.35);
}

@media (max-width: 860px) {
    .diff-side-grid {
        grid-template-columns: 1fr;
    }

    .compare-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .compare-mid {
        order: 3;
        padding-top: 0;
        width: 100%;
    }

    .btn-collapse-mid {
        flex-direction: row;
        width: 100%;
        min-width: 0;
        padding: 8px 12px;
    }

    .compare-pane:first-child {
        order: 1;
    }

    .compare-pane:last-child {
        order: 2;
    }
}

.stats {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
    font-size: 0.85rem;
    color: var(--muted);
}

.stats span b {
    color: var(--text);
    font-weight: 600;
}

.stats .add-count b { color: var(--ok); }
.stats .del-count b { color: var(--danger); }

.footer-note {
    margin-top: 18px;
    color: var(--muted);
    font-size: 0.82rem;
    text-align: center;
}

/* Select */
.select-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 0.86rem;
}

.select-wrap select {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 8px;
    outline: none;
    color: var(--text);
}

@media (max-width: 860px) {
    .intro-cards,
    .tool-cards,
    .json-grid,
    .compare-grid {
        grid-template-columns: 1fr;
    }

    .page-header {
        flex-direction: column;
    }

    .page-nav {
        width: 100%;
    }

    .page-nav .nav-link,
    .nav-dropdown {
        flex: 1;
    }

    .page-nav .nav-link,
    .page-nav .nav-dropdown-toggle {
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    .nav-dropdown-menu {
        left: 0;
        right: 0;
        min-width: 0;
    }

    .editor-input {
        height: 100px;
        min-height: 90px;
    }

    .editor-output {
        min-height: 420px;
        height: 55vh;
    }

    .app-json .editor-input {
        height: 72px;
        min-height: 64px;
        max-height: 96px;
    }

    .app-json .editor-output {
        min-height: 0 !important;
        height: auto !important;
    }

    .nav-tabs {
        width: 100%;
    }

    .nav-tab {
        flex: 1;
        text-align: center;
    }

    .panel-toolbar {
        align-items: stretch;
    }
}
