:root {
    --bg: #070d1c;
    --bg-elev: #0f172d;
    --panel: rgba(11, 20, 41, 0.88);
    --panel-border: rgba(146, 179, 255, 0.18);
    --text: #e6edf8;
    --text-muted: #9aa6c0;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --accent: #22c55e;
    --warning: #ef4444;
    --ring: rgba(59, 130, 246, 0.35);
    --shadow-lg: 0 24px 60px rgba(3, 8, 22, 0.45);
    --shadow-sm: 0 8px 20px rgba(3, 8, 22, 0.32);
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-sm: 9px;
    --transition: 180ms ease;
    --body-bg: radial-gradient(circle at 15% 15%, #1e3a8a 0%, rgba(30, 58, 138, 0) 40%),
        radial-gradient(circle at 85% 80%, #0ea5e9 0%, rgba(14, 165, 233, 0) 38%),
        linear-gradient(165deg, #040916 0%, #0b1429 45%, #050b1a 100%);
    --pill-bg: rgba(20, 33, 62, 0.8);
    --pill-border: rgba(148, 163, 184, 0.25);
    --editor-text: #d9e4f5;
    --placeholder: #6f85a8;
    --hint: #8ba0c2;
    --empty-surface: rgba(8, 18, 36, 0.92);
    --empty-border: rgba(148, 163, 184, 0.18);
    --empty-title: #e6edf8;
    --stat-strong: #f8fbff;
}

:root[data-theme="light"] {
    --bg: #f3f7ff;
    --bg-elev: #f8fbff;
    --panel: rgba(255, 255, 255, 0.92);
    --panel-border: rgba(37, 99, 235, 0.16);
    --text: #11203e;
    --text-muted: #4c5d7a;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --ring: rgba(37, 99, 235, 0.26);
    --shadow-lg: 0 20px 45px rgba(58, 88, 140, 0.16);
    --shadow-sm: 0 8px 20px rgba(58, 88, 140, 0.12);
    --body-bg: radial-gradient(circle at 15% 10%, #dbeafe 0%, rgba(219, 234, 254, 0) 48%),
        radial-gradient(circle at 90% 90%, #cffafe 0%, rgba(207, 250, 254, 0) 42%),
        linear-gradient(165deg, #f8fbff 0%, #eef4ff 55%, #f6f9ff 100%);
    --pill-bg: rgba(239, 246, 255, 0.95);
    --pill-border: rgba(147, 197, 253, 0.56);
    --editor-text: #1f3356;
    --placeholder: #7c8fad;
    --hint: #5b6e91;
    --empty-surface: rgba(245, 250, 255, 0.95);
    --empty-border: rgba(147, 197, 253, 0.5);
    --empty-title: #183154;
    --stat-strong: #1f3356;
}

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

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

body {
    position: relative;
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
    background: var(--body-bg);
    color: var(--text);
    padding: clamp(16px, 1vw, 36px);
}

.background-glow {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at 50% -10%, rgba(59, 130, 246, 0.22), transparent 48%);
    z-index: 0;
}

.app-shell {
    position: relative;
    z-index: 1;
    width: min(1640px, 100%);
    margin: 0 auto;
    display: grid;
    gap: 14px;
}

.hero {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    padding: clamp(8px, 1vw, 12px) clamp(10px, 1.2vw, 16px);
    border: 1px solid var(--panel-border);
    background: rgba(255, 255, 255, 0.72);
    box-shadow: 0 4px 16px rgba(12, 22, 44, 0.08);
    border-radius: 14px;
}

.hero-left {
    display: flex;
    justify-content: flex-start;
}

.hero-main {
    display: grid;
    gap: 3px;
    justify-items: center;
    text-align: center;
}

.hero h1 {
    font-family: "Space Grotesk", sans-serif;
    font-size: clamp(1.15rem, 1.8vw, 1.45rem);
    line-height: 1.08;
    letter-spacing: 0.01em;
    margin-bottom: 0;
}

.subtitle {
    color: var(--text-muted);
    font-size: clamp(0.76rem, 0.9vw, 0.88rem);
}

.hero-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.privacy-pill {
    color: var(--text-muted);
    background: var(--pill-bg);
    border: 1px solid var(--pill-border);
    border-radius: 999px;
    padding: 0 12px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.github-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 12px;
    height: 36px;
    padding: 0 12px;
    border: 1px solid rgba(148, 163, 184, 0.36);
    background: rgba(255, 255, 255, 0.86);
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    transition: background-color var(--transition), border-color var(--transition), transform var(--transition);
}

.github-link:hover {
    border-color: rgba(96, 165, 250, 0.6);
    background: rgba(244, 249, 255, 0.98);
    transform: translateY(-1px);
}

.github-link:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--ring);
}

.github-link svg {
    width: 15px;
    height: 15px;
}

.btn-theme {
    min-width: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    justify-content: center;
    border-radius: 12px;
    border-width: 1px;
}

.btn-icon-only .btn-label {
    display: none;
}

.theme-icon {
    display: inline-flex;
    width: 16px;
    height: 16px;
}

.theme-icon svg {
    width: 100%;
    height: 100%;
}

.moon-icon {
    display: none;
}

:root[data-theme="light"] .sun-icon {
    display: none;
}

:root[data-theme="light"] .moon-icon {
    display: inline-flex;
}

.workspace {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(8px);
    padding: clamp(14px, 1.6vw, 18px);
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
}

.btn {
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 8px 11px;
    min-height: 34px;
    background: transparent;
    color: var(--text);
    font-weight: 600;
    font-size: 0.82rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: transform var(--transition), background-color var(--transition), border-color var(--transition), box-shadow var(--transition);
}

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

.btn:active {
    transform: translateY(0);
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--ring);
}

.btn[disabled] {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none;
}

.btn-icon {
    width: 13px;
    height: 13px;
    display: inline-flex;
}

.btn-icon svg {
    width: 100%;
    height: 100%;
}

.btn-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    display: none;
}

.btn.is-loading .btn-spinner {
    display: inline-flex;
    animation: spin 600ms linear infinite;
}

.btn.is-loading .btn-icon {
    display: none;
}

.btn-primary {
    background: linear-gradient(165deg, var(--primary), #1d4ed8);
    color: #fff;
}

.btn-primary:hover {
    background: linear-gradient(165deg, #60a5fa, var(--primary));
}

.btn-secondary {
    background: linear-gradient(165deg, #475569, #334155);
    color: #f8fafc;
    border-color: rgba(148, 163, 184, 0.24);
}

.btn-secondary:hover {
    background: linear-gradient(165deg, #64748b, #475569);
}

.btn-ghost {
    border-color: rgba(148, 163, 184, 0.28);
    background: rgba(15, 23, 42, 0.55);
}

.btn-ghost:hover {
    background: rgba(30, 41, 59, 0.85);
}

.btn-theme {
    border-color: var(--pill-border);
    background: var(--pill-bg);
}

:root[data-theme="light"] .btn-secondary {
    background: linear-gradient(165deg, #e2ebff, #d7e5ff);
    color: #183154;
    border-color: rgba(96, 165, 250, 0.45);
}

:root[data-theme="light"] .btn-secondary:hover {
    background: linear-gradient(165deg, #dbe8ff, #cfe0ff);
}

:root[data-theme="light"] .btn-ghost {
    background: rgba(238, 246, 255, 0.9);
    border-color: rgba(96, 165, 250, 0.45);
}

:root[data-theme="light"] .btn-ghost:hover {
    background: rgba(227, 239, 255, 0.95);
}

:root[data-theme="light"] .github-link {
    background: rgba(238, 246, 255, 0.9);
    border-color: rgba(96, 165, 250, 0.45);
}

:root[data-theme="light"] .github-link:hover {
    background: rgba(227, 239, 255, 0.95);
}

:root[data-theme="light"] .hero {
    background: rgba(255, 255, 255, 0.82);
}

:root:not([data-theme="light"]) .hero {
    background: rgba(10, 18, 35, 0.7);
    box-shadow: 0 8px 28px rgba(3, 8, 22, 0.28);
}

.stat-pill {
    font-family: "JetBrains Mono", monospace;
    font-size: 0.69rem;
    color: var(--text-muted);
    background: var(--pill-bg);
    border: 1px solid var(--pill-border);
    border-radius: 999px;
    padding: 4px 8px;
    min-width: 84px;
    text-align: center;
}

.stat-pill strong {
    color: var(--stat-strong);
    margin-left: 4px;
}

.editor-frame {
    position: relative;
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-elev);
    min-height: clamp(460px, calc(100dvh - 260px), 760px);
}

#xmlInput {
    width: 100%;
    min-height: clamp(460px, calc(100dvh - 260px), 760px);
    border: none;
    resize: none;
    background: transparent;
    padding: clamp(10px, 1.2vw, 14px);
    color: var(--editor-text);
    font-family: "JetBrains Mono", Consolas, monospace;
    font-size: clamp(0.84rem, 1.1vw, 0.92rem);
    line-height: 1.6;
    tab-size: 4;
    overflow: hidden;
}

#xmlInput::placeholder {
    color: var(--placeholder);
}

#xmlInput:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 2px rgba(59, 130, 246, 0.5);
}

.status-row {
    margin-top: 12px;
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.error-message {
    color: #fecaca;
    font-size: 0.86rem;
}

.error-message:empty {
    display: none;
}

.hint {
    color: var(--hint);
    font-size: 0.8rem;
}

.empty-state {
    position: absolute;
    inset: 12px;
    border: 1px dashed var(--empty-border);
    border-radius: calc(var(--radius-md) - 2px);
    background: var(--empty-surface);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    gap: 10px;
    padding: clamp(14px, 2vw, 20px);
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px);
    transition: opacity var(--transition), transform var(--transition);
}

.editor-frame.is-empty .empty-state {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.empty-title {
    color: var(--empty-title);
    font-weight: 600;
}

.empty-desc {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.sample-preview {
    width: 100%;
    max-width: 520px;
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.22);
    border-radius: 10px;
    color: var(--editor-text);
    font-family: "JetBrains Mono", Consolas, monospace;
    font-size: 0.78rem;
    line-height: 1.45;
    padding: 10px 12px;
    white-space: pre-wrap;
}

.toast {
    position: fixed;
    top: 22px;
    right: 22px;
    z-index: 10;
    max-width: min(92vw, 360px);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: linear-gradient(160deg, rgba(34, 197, 94, 0.92), rgba(21, 128, 61, 0.95));
    color: #f0fdf4;
    padding: 10px 14px;
    font-size: 0.88rem;
    box-shadow: var(--shadow-sm);
    transform: translateY(-8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition), transform var(--transition);
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

@media (max-width: 800px) {
    .hero {
        grid-template-columns: 1fr;
        align-items: flex-start;
        gap: 8px;
        padding: 10px;
    }

    .hero h1 { font-size: 1.15rem; }
    .subtitle { font-size: 0.8rem; }

    .hero-main {
        justify-items: flex-start;
        text-align: left;
    }

    .hero-right {
        width: 100%;
        justify-content: flex-start;
    }

    .toolbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .toolbar-right {
        width: 100%;
        justify-content: space-between;
    }

    .status-row {
        flex-direction: column;
        align-items: flex-start;
    }

    #xmlInput {
        min-height: clamp(400px, calc(100dvh - 310px), 640px);
    }
}

@media (max-width: 560px) {
    body {
        padding: 10px;
    }

    .workspace {
        padding: 10px;
    }

    .hero-right {
        width: 100%;
    }

    .privacy-pill,
    .github-link {
        flex: 1;
        justify-content: center;
    }

    .hero .btn-theme {
        width: 36px;
        min-width: 36px;
        flex: 0 0 36px;
    }

    .toolbar-left {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr;
    }

    .toolbar-right {
        width: 100%;
        justify-content: space-between;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .stat-pill {
        flex: 1;
        text-align: center;
        min-width: 0;
    }

    #xmlInput {
        min-height: clamp(340px, calc(100dvh - 340px), 560px);
        padding: 10px;
        font-size: 0.84rem;
        line-height: 1.55;
    }

    .empty-state {
        inset: 8px;
        padding: 12px;
    }

    .sample-preview {
        font-size: 0.72rem;
    }

    .toast {
        left: 10px;
        right: 10px;
        max-width: none;
        top: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
