/* ========== CSS Variables & Themes ========== */
:root {
    --bg: #0d1117;
    --bg2: #161b22;
    --bg3: #21262d;
    --fg: #e6edf3;
    --fg2: #8b949e;
    --fg3: #484f58;
    --accent: #58a6ff;
    --accent2: #1f6feb;
    --accent-glow: rgba(88, 166, 255, 0.15);
    --border: #30363d;
    --code-bg: #161b22;
    --success: #3fb950;
    --warn: #d29922;
    --err: #f85149;
    --radius: 8px;
    --transition: 0.25s ease;
    --font-size: 16px;
    --mono: 'SF Mono', 'Fira Code', 'Consolas', 'Monaco', monospace;
    /* JSON syntax colors (dark) */
    --json-key: #79c0ff;
    --json-str: #a5d6ff;
    --json-num: #3fb950;
    --json-bool: #ff7b72;
    --json-null: #8b949e;
    --json-punc: #e6edf3;
}

[data-theme="light"] {
    --bg: #ffffff;
    --bg2: #f6f8fa;
    --bg3: #eaeef2;
    --fg: #1f2328;
    --fg2: #656d76;
    --fg3: #afb8c1;
    --accent: #0969da;
    --accent2: #0550ae;
    --accent-glow: rgba(9, 105, 218, 0.1);
    --border: #d0d7de;
    --code-bg: #f6f8fa;
    /* JSON syntax colors (light) */
    --json-key: #0550ae;
    --json-str: #0a3069;
    --json-num: #116329;
    --json-bool: #cf222e;
    --json-null: #57606a;
    --json-punc: #1f2328;
}

/* ========== Reset & Base ========== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: var(--font-size);
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
    background: var(--bg);
    color: var(--fg);
    line-height: 1.7;
    transition: background var(--transition), color var(--transition);
    overflow-x: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========== Header ========== */
header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 12px 24px;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo span {
    opacity: 0.6;
    font-weight: 400;
    font-size: 0.85rem;
    color: var(--fg2);
}

.seal-container {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    cursor: pointer;
    border-radius: 4px;
    overflow: visible;
}

.seal-container canvas {
    display: block;
}

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

#btn-lang {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--fg);
    border-radius: var(--radius);
    padding: 5px 10px;
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
}

.controls button {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--fg);
    padding: 5px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all var(--transition);
    white-space: nowrap;
}

.controls button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ========== Main Layout ========== */
.app-container {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ========== Panels ========== */
.panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.panel-input {
    flex: 1;
    border-right: 1px solid var(--border);
}

.panel-output {
    flex: 1;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 40px;
}

.panel-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--fg2);
    display: flex;
    align-items: center;
    gap: 6px;
}

.panel-actions {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.panel-actions button {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--fg2);
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.82rem;
    transition: all var(--transition);
    white-space: nowrap;
}

.panel-actions button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.panel-actions button.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ========== Input Panel ========== */
.input-toolbar {
    display: flex;
    gap: 4px;
    padding: 6px 12px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.input-toolbar button {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--fg2);
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.78rem;
    transition: all var(--transition);
    white-space: nowrap;
}

.input-toolbar button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

#file-input {
    display: none;
}

.editor-wrap {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* Line numbers */
.line-numbers {
    padding: 10px 0;
    background: var(--bg2);
    color: var(--fg3);
    font-family: var(--mono);
    font-size: 0.85rem;
    text-align: right;
    user-select: none;
    overflow: hidden;
    line-height: 1.5;
    border-right: 1px solid var(--border);
    min-width: 40px;
    flex-shrink: 0;
}

.line-numbers div {
    padding: 0 8px 0 4px;
}

.editor-textarea {
    flex: 1;
    background: var(--bg);
    color: var(--fg);
    border: none;
    outline: none;
    font-family: var(--mono);
    font-size: 0.85rem;
    line-height: 1.5;
    padding: 10px 12px;
    resize: none;
    white-space: pre;
    overflow: auto;
    tab-size: 2;
}

.editor-textarea::placeholder {
    color: var(--fg3);
}

/* Drag overlay */
.drag-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 10;
    background: var(--accent-glow);
    border: 2px dashed var(--accent);
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    color: var(--accent);
    font-weight: 600;
    backdrop-filter: blur(4px);
}

.drag-overlay.visible {
    display: flex;
}

/* ========== Output Panel ========== */
.output-tabs {
    display: flex;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.output-tab {
    padding: 6px 14px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--fg2);
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}

.output-tab:hover {
    color: var(--fg);
}

.output-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.output-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Output view containers (tab switching) */
.output-view {
    display: none;
    height: 100%;
    overflow: auto;
}

.output-view.active {
    display: flex;
}

.output-view-formatted.active {
    overflow: hidden;
}

.output-view-tree.active,
.output-view-raw.active {
    display: block;
}

/* Output line numbers */
.output-line-numbers {
    padding: 10px 0;
    background: var(--bg2);
    color: var(--fg3);
    font-family: var(--mono);
    font-size: 0.85rem;
    text-align: right;
    user-select: none;
    overflow: hidden;
    line-height: 1.5;
    border-right: 1px solid var(--border);
    min-width: 40px;
    flex-shrink: 0;
}

.output-line-numbers div {
    padding: 0 8px 0 4px;
}

/* Formatted view */
.output-formatted {
    flex: 1;
    padding: 10px 12px;
    font-family: var(--mono);
    font-size: 0.85rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    overflow: auto;
}

/* Tree view */
.output-tree {
    padding: 10px 12px;
    font-family: var(--mono);
    font-size: 0.82rem;
    overflow: auto;
    height: 100%;
}

.tree-toolbar {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.tree-toolbar button {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--fg2);
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all var(--transition);
}

.tree-toolbar button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.tree-node {
    padding-left: 20px;
}

.tree-node-root {
    padding-left: 0;
}

.tree-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 1px 0;
    cursor: default;
    border-radius: 3px;
    transition: background 0.15s;
}

.tree-row:hover {
    background: var(--bg3);
}

.tree-toggle {
    cursor: pointer;
    width: 16px;
    text-align: center;
    color: var(--fg3);
    user-select: none;
    flex-shrink: 0;
    font-size: 0.7rem;
}

.tree-toggle:hover {
    color: var(--accent);
}

.tree-key {
    color: var(--json-key);
}

.tree-colon {
    color: var(--fg3);
    margin: 0 2px;
}

.tree-value-str {
    color: var(--json-str);
}

.tree-value-num {
    color: var(--json-num);
}

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

.tree-value-null {
    color: var(--json-null);
    font-style: italic;
}

.tree-type {
    font-size: 0.65rem;
    padding: 0 4px;
    border-radius: 3px;
    background: var(--bg3);
    color: var(--fg3);
    margin-left: 4px;
    flex-shrink: 0;
}

.tree-count {
    color: var(--fg3);
    font-size: 0.75rem;
    margin-left: 2px;
}

.tree-children {
    overflow: hidden;
}

.tree-children.collapsed {
    display: none;
}

/* Raw view */
.output-raw {
    padding: 10px 12px;
    font-family: var(--mono);
    font-size: 0.85rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    overflow: auto;
    height: 100%;
    color: var(--fg2);
}

/* ========== Status Bar ========== */
.status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 36px;
}

.status-info {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--fg2);
    flex-wrap: wrap;
}

.status-icon {
    font-weight: 600;
}

.status-icon.valid {
    color: var(--success);
}

.status-icon.invalid {
    color: var(--err);
}

.status-icon.empty {
    color: var(--fg3);
}

.status-actions {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.status-actions button {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--fg2);
    padding: 5px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.82rem;
    transition: all var(--transition);
    white-space: nowrap;
}

.status-actions button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.status-actions button.copied {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

/* ========== Error Display ========== */
.error-detail {
    display: none;
    padding: 8px 16px;
    background: rgba(248, 81, 73, 0.08);
    border-top: 1px solid var(--err);
    font-size: 0.8rem;
    color: var(--err);
    flex-shrink: 0;
}

.error-detail.visible {
    display: block;
}

.error-msg-text {
    font-family: var(--mono);
    margin-bottom: 4px;
}

.error-suggestion {
    color: var(--warn);
    font-style: italic;
}

/* ========== Inscription ID Input ========== */
.inscription-bar {
    display: none;
    padding: 6px 12px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 6px;
    align-items: center;
}

.inscription-bar.visible {
    display: flex;
}

.inscription-bar input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--fg);
    padding: 4px 8px;
    font-family: var(--mono);
    font-size: 0.8rem;
    outline: none;
}

.inscription-bar input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.inscription-bar input::placeholder {
    color: var(--fg3);
}

.inscription-bar button {
    background: var(--accent2);
    color: #fff;
    border: none;
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all var(--transition);
}

.inscription-bar button:hover {
    background: var(--accent);
}

/* ========== Search Bar ========== */
.search-bar {
    display: none;
    padding: 6px 12px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 6px;
    align-items: center;
}

.search-bar.visible {
    display: flex;
}

.search-bar input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--fg);
    padding: 4px 8px;
    font-size: 0.82rem;
    outline: none;
    min-width: 120px;
}

.search-bar input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.search-bar input::placeholder {
    color: var(--fg3);
}

.search-info {
    font-size: 0.78rem;
    color: var(--fg2);
    white-space: nowrap;
    min-width: 45px;
    text-align: center;
}

.search-bar button {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--fg2);
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    transition: all var(--transition);
}

.search-bar button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Search highlights */
mark.search-hl {
    background: rgba(210, 153, 34, 0.35);
    color: inherit;
    border-radius: 2px;
    padding: 1px 2px;
}

mark.search-hl.current {
    background: rgba(210, 153, 34, 0.75);
    outline: 1px solid var(--warn);
}

/* ========== Path Query Bar ========== */
.path-bar {
    display: none;
    padding: 6px 12px;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    flex-direction: column;
    gap: 6px;
}

.path-bar.visible {
    display: flex;
}

.path-bar-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.path-bar input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--fg);
    padding: 5px 10px;
    font-family: var(--mono);
    font-size: 0.82rem;
    outline: none;
}

.path-bar input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.path-bar input::placeholder {
    color: var(--fg3);
}

.path-bar-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.path-bar-actions button {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--fg2);
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all var(--transition);
    white-space: nowrap;
}

.path-bar-actions button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.path-bar-actions button.copied {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

.path-result {
    display: none;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    max-height: 150px;
    overflow: auto;
    animation: fadeIn 0.2s ease;
}

.path-result.visible {
    display: block;
}

.path-result pre {
    margin: 0;
    padding: 8px 10px;
    font-family: var(--mono);
    font-size: 0.8rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
}

.path-result .path-result-info {
    padding: 4px 10px;
    font-size: 0.72rem;
    color: var(--fg3);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
}

.path-result .path-type {
    color: var(--accent);
}

.path-result-error {
    color: var(--err);
    padding: 6px 10px;
    font-size: 0.78rem;
}

/* ========== highlight.js overrides for JSON ========== */
.output-formatted .hljs {
    background: transparent;
    padding: 0;
}

.hljs-attr {
    color: var(--json-key);
}

.hljs-string {
    color: var(--json-str);
}

.hljs-number {
    color: var(--json-num);
}

.hljs-literal {
    color: var(--json-bool);
}

.hljs-punctuation {
    color: var(--json-punc);
}

/* ========== Animations ========== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

/* ========== Responsive ========== */

/* Use dvh for mobile viewport (handles Safari address bar) */
@supports (height: 100dvh) {
    body {
        height: 100dvh;
    }
}

@media (max-width: 768px) {
    body {
        height: 100vh;
        height: 100dvh;
    }

    header {
        padding: 6px 10px;
    }

    .header-top {
        flex-wrap: wrap;
        gap: 6px;
    }

    .logo {
        font-size: 1rem;
        gap: 6px;
    }

    .logo span {
        display: none;
    }

    .seal-container {
        width: 32px;
        height: 32px;
    }

    .controls {
        gap: 3px;
        flex-wrap: wrap;
    }

    .controls button,
    #btn-lang {
        padding: 3px 6px;
        font-size: 0.72rem;
    }

    /* Stacked layout */
    .app-container {
        flex-direction: column;
        flex: 1;
        min-height: 0;
    }

    .panel-input {
        border-right: none;
        border-bottom: 1px solid var(--border);
        flex: 0 0 45%;
        max-height: 45%;
    }

    .panel-output {
        flex: 1;
        min-height: 0;
    }

    .panel-header {
        padding: 5px 8px;
        min-height: 34px;
        flex-wrap: wrap;
        gap: 4px;
    }

    .panel-title {
        font-size: 0.78rem;
    }

    .panel-actions {
        gap: 3px;
    }

    .panel-actions button {
        padding: 2px 6px;
        font-size: 0.7rem;
    }

    .output-tabs {
        gap: 0;
    }

    .output-tab {
        padding: 4px 8px;
        font-size: 0.72rem;
    }

    .line-numbers,
    .output-line-numbers {
        min-width: 30px;
        font-size: 0.75rem;
    }

    .line-numbers div,
    .output-line-numbers div {
        padding: 0 4px 0 2px;
    }

    .editor-textarea {
        font-size: 0.78rem;
        padding: 8px;
    }

    .output-formatted,
    .output-tree,
    .output-raw {
        padding: 8px;
        font-size: 0.78rem;
    }

    /* Status bar */
    .status-bar {
        padding: 4px 8px;
        gap: 4px;
        min-height: 30px;
        flex-direction: column;
        align-items: flex-start;
    }

    .status-info {
        gap: 6px;
        font-size: 0.72rem;
    }

    .status-actions {
        gap: 3px;
        width: 100%;
        justify-content: flex-start;
    }

    .status-actions button {
        padding: 2px 6px;
        font-size: 0.68rem;
    }

    /* Error detail */
    .error-detail {
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    /* Inscription bar */
    .inscription-bar {
        padding: 4px 8px;
    }

    .inscription-bar input {
        font-size: 0.75rem;
    }

    /* Search bar */
    .search-bar {
        padding: 4px 8px;
        gap: 4px;
    }

    .search-bar input {
        min-width: 80px;
        font-size: 0.75rem;
    }

    .search-bar button {
        width: 26px;
        height: 26px;
    }

    /* Path query bar */
    .path-bar {
        padding: 4px 8px;
        gap: 4px;
    }

    .path-bar input {
        font-size: 0.75rem;
        padding: 4px 6px;
    }

    .path-bar-actions button {
        font-size: 0.68rem;
        padding: 3px 6px;
    }

    .path-result {
        max-height: 120px;
    }

    .path-result pre {
        font-size: 0.72rem;
        padding: 6px 8px;
    }

    /* Tree */
    .tree-node {
        padding-left: 14px;
    }

    .tree-toolbar button {
        font-size: 0.68rem;
        padding: 2px 6px;
    }

    /* Drag overlay */
    .drag-overlay {
        font-size: 0.85rem;
    }
}

/* Extra small screens */
@media (max-width: 400px) {

    .controls button,
    #btn-lang {
        padding: 2px 4px;
        font-size: 0.68rem;
    }

    .panel-actions button {
        font-size: 0.65rem;
        padding: 2px 4px;
    }

    .status-actions button {
        font-size: 0.65rem;
        padding: 2px 4px;
    }
}