/* ==========================================================================
   JSON 在线解析工具 — 「工坊」视觉主题
   暖色纸感背景 + 墨绿强调色，避免紫渐变等典型 AI 审美
   ========================================================================== */

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

/* ---------- 设计令牌（浅色默认） ---------- */
:root {
    --font-ui: 'Source Sans 3', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    --font-display: 'Bricolage Grotesque', var(--font-ui);
    --font-mono: 'IBM Plex Mono', 'Menlo', 'Consolas', monospace;

    --page-bg: #e8e4dc;
    --surface: #faf8f5;
    --surface-raised: #ffffff;
    --surface-muted: #f0ece6;
    --surface-editor: #fdfcfa;

    --text: #2a2622;
    --text-muted: #6f6860;
    --text-faint: #9a9289;

    --border: #d8d2c8;
    --border-strong: #c4bcb0;

    --accent: #2f6b4f;
    --accent-hover: #245a42;
    --accent-soft: rgba(47, 107, 79, 0.12);
    --accent-text: #faf8f5;

    --warn: #b45309;
    --danger: #b54a3a;
    --danger-soft: rgba(181, 74, 58, 0.1);

    --syntax-key: #2f6b4f;
    --syntax-string: #5c7a2e;
    --syntax-number: #b45309;
    --syntax-bool: #2563eb;
    --syntax-null: #9a9289;

    --shadow-sm: 0 1px 2px rgba(42, 38, 34, 0.06);
    --shadow-md: 0 8px 24px rgba(42, 38, 34, 0.08);
    --shadow-lg: 0 20px 48px rgba(42, 38, 34, 0.12);

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --duration: 0.22s;
}

/* 深色主题令牌覆盖 */
[data-theme="dark"] {
    --page-bg: #121110;
    --surface: #1c1a18;
    --surface-raised: #242220;
    --surface-muted: #2a2826;
    --surface-editor: #1a1816;

    --text: #e8e4dc;
    --text-muted: #a8a29a;
    --text-faint: #78716c;

    --border: #3a3632;
    --border-strong: #4a4540;

    --accent: #6dbf8a;
    --accent-hover: #8ed4a8;
    --accent-soft: rgba(109, 191, 138, 0.15);
    --accent-text: #121110;

    --danger-soft: rgba(220, 120, 100, 0.12);

    --syntax-key: #8ed4a8;
    --syntax-string: #a3c97a;
    --syntax-number: #f0b86a;
    --syntax-bool: #7eb8ff;
    --syntax-null: #78716c;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 24px 56px rgba(0, 0, 0, 0.45);
}

/* ---------- 页面基底 ---------- */
html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-ui);
    background: var(--page-bg);
    min-height: 100vh;
    padding: clamp(12px, 2.5vw, 28px);
    color: var(--text);
    line-height: 1.5;
    transition: background-color var(--duration) var(--ease-out),
                color var(--duration) var(--ease-out);
}

/* 纸张噪点纹理层 */
.page-noise {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.35;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
    background-size: 180px;
}

[data-theme="dark"] .page-noise {
    opacity: 0.2;
}

/* ---------- 主容器 ---------- */
.container {
    position: relative;
    z-index: 1;
    max-width: 1560px;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: clamp(20px, 3vw, 36px);
    animation: container-in 0.55s var(--ease-out) both;
}

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

/* ---------- 页头 ---------- */
.site-header {
    margin-bottom: 28px;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

/* 花括号品牌标记 */
.brand-mark {
    flex-shrink: 0;
    margin-top: 4px;
    font-family: var(--font-mono);
    font-size: 1.25rem;
    font-weight: 500;
    letter-spacing: -0.04em;
    color: var(--accent);
    padding: 8px 10px;
    background: var(--accent-soft);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.brand-text h1 {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 3vw, 2rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
    line-height: 1.2;
}

.subtitle {
    margin-top: 6px;
    font-size: 0.95rem;
    color: var(--text-muted);
    max-width: 52ch;
}

.header-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.control-label {
    font-size: 0.8rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* 图标按钮 */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 10px;
    min-width: 38px;
    min-height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-raised);
    color: var(--text);
    cursor: pointer;
    transition: background var(--duration), border-color var(--duration), color var(--duration);
}

.btn-icon:hover {
    background: var(--surface-muted);
    border-color: var(--border-strong);
}

#langToggleText {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
}

/* 主题切换：浅色显示月亮，深色显示太阳 */
[data-theme="light"] .icon-sun,
[data-theme="dark"] .icon-moon {
    display: none;
}

.btn-theme svg {
    display: block;
}

/* ---------- 表单控件 ---------- */
.select-small,
.select-medium {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-raised);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: border-color var(--duration);
}

.select-small:focus,
.select-medium:focus {
    outline: 2px solid var(--accent-soft);
    outline-offset: 1px;
    border-color: var(--accent);
}

.select-small {
    min-width: 72px;
    min-height: 28px;
}

.select-small:disabled,
.select-medium:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.checkbox-label,
.checkbox-label-inline {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

.checkbox-label-inline input[type="checkbox"] {
    accent-color: var(--accent);
    cursor: pointer;
}

/* ---------- 按钮体系 ---------- */
.btn {
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    background: var(--surface-raised);
    color: var(--text);
    white-space: nowrap;
    transition: background var(--duration), border-color var(--duration), color var(--duration);
}

.btn:hover {
    background: var(--surface-muted);
    border-color: var(--border-strong);
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface-muted);
    border-color: var(--border-strong);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-soft);
}

/* 强调操作（原 btn-info） */
.btn-accent,
.btn-info {
    background: transparent;
    border-color: var(--accent);
    color: var(--accent);
}

.btn-accent:hover,
.btn-info:hover {
    background: var(--accent-soft);
}

.btn-small {
    padding: 5px 10px;
    font-size: 0.75rem;
    /* 与 select-small 统一高度，保证工具栏行对齐 */
    min-height: 28px;
    line-height: 1.2;
}

/* ---------- 双栏主工作区 ---------- */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

@media (max-width: 1100px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

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

/* 面板工具栏区 */
.section-header {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 10px;
    padding: 12px 14px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

/* 标题行：徽章 + 副标题，左右面板统一高度 */
.panel-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    min-height: 1.625rem;
}

.panel-badge {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 2px;
    border: 1px solid var(--border);
}

.panel-badge--input {
    color: var(--accent);
    background: var(--accent-soft);
    border-color: transparent;
}

.panel-badge--output {
    color: var(--text-muted);
    background: var(--surface-raised);
}

.panel-heading {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    margin: 0;
}

/* 工具栏：纵向两行，与对侧面板等高对齐 */
.section-toolbar {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: stretch;
    flex: 1;
    min-width: 0;
}

/* 单行按钮组：横向排列，固定最小高度与按钮一致 */
.toolbar-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px 8px;
    min-height: 30px;
    width: 100%;
}

.toolbar-group-inline {
    display: flex;
    gap: 5px;
    align-items: center;
    flex-wrap: wrap;
}

/* 双栏布局时，左右 section-header 固定等高，工具栏双行对齐 */
@media (min-width: 1101px) {
    .main-content {
        align-items: start;
    }

    .input-section .section-header,
    .output-section .section-header {
        height: 126px;
        box-sizing: border-box;
    }

    .section-toolbar {
        height: 66px;
        box-sizing: border-box;
        justify-content: space-between;
    }

    .toolbar-row {
        flex: 0 0 30px;
    }
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    flex-shrink: 0;
}

.toolbar-label-small {
    font-size: 0.75rem;
    color: var(--text-faint);
    white-space: nowrap;
}

/* ---------- 代码编辑器 ---------- */
.editor-wrapper {
    position: relative;
    display: flex;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--surface-editor);
    min-height: 420px;
    box-shadow: var(--shadow-sm) inset;
}

.line-numbers {
    padding: 14px 6px 14px 10px;
    background: var(--surface-muted);
    color: var(--text-faint);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.65;
    text-align: right;
    user-select: none;
    min-width: 48px;
    max-width: 48px;
    width: 48px;
    border-right: 1px solid var(--border);
    display: none;
    overflow: hidden;
    white-space: pre;
    flex-shrink: 0;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1;
    pointer-events: none;
}

.line-numbers.show {
    display: block;
    pointer-events: auto;
}

.json-editor {
    flex: 1;
    width: 100%;
    min-height: 420px;
    padding: 14px 16px;
    border: none;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.65;
    resize: vertical;
    background: var(--surface-editor);
    color: var(--text);
    overflow: auto;
    tab-size: 2;
    transition: background var(--duration);
}

.json-editor:focus {
    outline: none;
    box-shadow: inset 0 0 0 2px var(--accent-soft);
}

.json-editor[readonly] {
    background: var(--surface-muted);
    color: var(--text);
}

/* ---------- 错误提示 ---------- */
.error-message {
    margin-top: 10px;
    padding: 10px 14px;
    background: var(--danger-soft);
    border-left: 3px solid var(--danger);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--danger);
    font-size: 0.8125rem;
    font-family: var(--font-mono);
    display: none;
}

.error-message.show {
    display: block;
}

/* ---------- 树形视图 ---------- */
.tree-view {
    position: absolute;
    inset: 0;
    min-height: 420px;
    padding: 14px 16px;
    background: var(--surface-editor);
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.65;
    overflow: auto;
    color: var(--text);
    z-index: 10;
}

.tree-item {
    padding: 3px 0;
    cursor: pointer;
    user-select: none;
    border-radius: 2px;
}

.tree-item:hover {
    background: var(--accent-soft);
}

.tree-key {
    color: var(--syntax-key);
    font-weight: 500;
}

.tree-value.string {
    color: var(--syntax-string);
}

.tree-value.number {
    color: var(--syntax-number);
}

.tree-value.boolean {
    color: var(--syntax-bool);
}

.tree-value.null {
    color: var(--syntax-null);
}

.tree-toggle {
    display: inline-block;
    width: 14px;
    text-align: center;
    margin-right: 4px;
    color: var(--text-faint);
}

.tree-children {
    margin-left: 18px;
    display: none;
    border-left: 1px solid var(--border);
    padding-left: 8px;
}

.tree-children.expanded {
    display: block;
}

/* ---------- 底部统计条 ---------- */
.info-panel {
    display: flex;
    gap: 0;
    padding: 0;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 28px;
    overflow: hidden;
}

.info-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 20px;
    border-right: 1px solid var(--border);
}

.info-item:last-child {
    border-right: none;
}

.info-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
}

.info-value {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text);
}

#status {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 2px;
    width: fit-content;
}

.status-valid {
    background: var(--accent-soft);
    color: var(--accent);
}

.status-invalid {
    background: var(--danger-soft);
    color: var(--danger);
}

/* ---------- 功能说明（SEO 次要区块） ---------- */
.features-section {
    margin-top: 8px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.features-title {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* SEO 引导段落：可读性优先，避免隐藏堆砌关键词 */
.features-intro {
    font-size: 0.875rem;
    line-height: 1.65;
    color: var(--text-muted);
    max-width: 72ch;
    margin-bottom: 18px;
}

/* 页脚：版权与站内链接，增强站点可信度 */
.site-footer {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.site-footer__copy {
    font-size: 0.75rem;
    color: var(--text-faint);
    text-align: center;
}

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

.site-footer__copy a:hover {
    text-decoration: underline;
}

.site-footer__icp {
    color: var(--text-faint);
    text-decoration: none;
}

.site-footer__icp:hover {
    color: var(--text-muted);
    text-decoration: underline;
}

.features {
    padding: 0;
}

.features h3 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    margin-bottom: 14px;
}

.features ul {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px 24px;
}

.features li {
    position: relative;
    padding-left: 14px;
    font-size: 0.8125rem;
    color: var(--text-muted);
    line-height: 1.55;
}

/* 列表项前的短横线标记，替代 ✅ emoji */
.features li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.55em;
    width: 6px;
    height: 1px;
    background: var(--accent);
}

.features li strong {
    color: var(--text);
    font-weight: 600;
}

/* ---------- 历史记录弹层 ---------- */
.history-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(18, 17, 16, 0.45);
    z-index: 999;
    backdrop-filter: blur(3px);
    animation: fade-in 0.2s var(--ease-out);
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.history-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
    max-width: 560px;
    width: calc(100% - 32px);
    max-height: 72vh;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: modal-in 0.28s var(--ease-out);
}

@keyframes modal-in {
    from {
        opacity: 0;
        transform: translate(-50%, -48%) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.history-header h3 {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.btn-close {
    min-width: 32px;
    min-height: 32px;
    padding: 6px;
}

.history-list {
    max-height: 52vh;
    overflow-y: auto;
}

.history-item {
    padding: 12px 14px;
    margin-bottom: 8px;
    background: var(--surface-muted);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color var(--duration), background var(--duration);
}

.history-item:hover {
    background: var(--surface-raised);
    border-color: var(--accent);
}

.history-time {
    font-size: 0.7rem;
    color: var(--text-faint);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.history-content {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: pre-wrap;
    max-height: 88px;
    overflow: hidden;
}

/* ---------- 滚动条 ---------- */
.json-editor::-webkit-scrollbar,
.tree-view::-webkit-scrollbar,
.history-list::-webkit-scrollbar {
    width: 7px;
    height: 7px;
}

.json-editor::-webkit-scrollbar-track,
.tree-view::-webkit-scrollbar-track,
.history-list::-webkit-scrollbar-track {
    background: transparent;
}

.json-editor::-webkit-scrollbar-thumb,
.tree-view::-webkit-scrollbar-thumb,
.history-list::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}

.json-editor::-webkit-scrollbar-thumb:hover,
.tree-view::-webkit-scrollbar-thumb:hover,
.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-faint);
}

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
    .header-top {
        flex-direction: column;
    }

    .brand {
        width: 100%;
    }

    .header-controls {
        width: 100%;
        justify-content: flex-end;
    }

    .container {
        padding: 16px;
    }

    .toolbar-divider {
        display: none;
    }

    .info-panel {
        flex-direction: column;
    }

    .info-item {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .info-item:last-child {
        border-bottom: none;
    }
}

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