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

/* === Accessibility === */
.skip-link {
    position: absolute; top: -100px; left: 16px;
    background: var(--accent); color: #fff; padding: 8px 16px;
    border-radius: 4px; font-size: 0.85rem; font-weight: 600;
    z-index: 999; text-decoration: none;
}
.skip-link:focus { top: 8px; }
*:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

:root {
    --bg: #1a1a2e; --surface: #16213e; --surface2: #0f3460;
    --accent: #e94560; --accent2: #533483; --text: #eee; --text-dim: #8892b0;
    --green: #64ffda; --yellow: #ffd369; --radius: 8px;
    --analysis-critical: #ef4444; --analysis-warning: #f59e0b;
    --analysis-info: #3b82f6; --analysis-pass: #22c55e;
    --mono: "SF Mono", "Fira Code", "Cascadia Code", Menlo, monospace;
}

/* === Light Theme === */
[data-theme="light"] {
    --bg: #f5f5f7; --surface: #ffffff; --surface2: #e5e5ea;
    --accent: #0071e3; --accent2: #7c3aed; --text: #1d1d1f; --text-dim: #6e6e73;
    --green: #059669; --yellow: #b45309;
    --analysis-critical: #dc2626; --analysis-warning: #d97706;
    --analysis-info: #2563eb; --analysis-pass: #16a34a;
}
[data-theme="light"] .radio-pill:checked + label { background: rgba(0,113,227,0.1); color: #0071e3; }
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg: #f5f5f7; --surface: #ffffff; --surface2: #e5e5ea;
        --accent: #0071e3; --accent2: #7c3aed; --text: #1d1d1f; --text-dim: #6e6e73;
        --green: #059669; --yellow: #b45309;
        --analysis-critical: #dc2626; --analysis-warning: #d97706;
        --analysis-info: #2563eb; --analysis-pass: #16a34a;
    }
    :root:not([data-theme="dark"]) .radio-pill:checked + label { background: rgba(0,113,227,0.1); color: #0071e3; }
}

.theme-toggle {
    margin-left: auto; background: none; border: 1px solid transparent;
    border-radius: 6px; color: var(--text-dim); font-size: 1.1rem;
    cursor: pointer; padding: 4px 8px; line-height: 1;
    transition: color 0.15s, background 0.15s;
}
.theme-toggle:hover { color: var(--yellow); background: rgba(128,128,128,0.1); }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg); color: var(--text);
    min-height: 100vh; display: flex; justify-content: center;
}
.app {
    width: 100%; max-width: 900px; padding: 60px 20px 160px;
    display: flex; flex-direction: column; gap: 24px;
}

/* === Site Nav === */
.site-nav {
    position: fixed; top: 0; left: 0; right: 0; height: 44px;
    background: var(--surface); border-bottom: 1px solid var(--surface2);
    display: flex; align-items: center; justify-content: center; z-index: 200;
}
.site-nav-inner {
    width: 100%; max-width: 900px; padding: 0 20px;
    display: flex; align-items: center; gap: 24px;
}
.nav-brand {
    font-size: 0.85rem; font-weight: 700; color: var(--text);
    text-decoration: none; letter-spacing: -0.02em; flex-shrink: 0;
    padding: 4px 10px; border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}
.nav-brand:hover { color: var(--green); background: rgba(100,255,218,0.08); }
.nav-links { display: flex; gap: 6px; list-style: none; }
.nav-links a {
    font-size: 0.75rem; font-weight: 500; color: var(--text-dim);
    text-decoration: none; padding: 4px 10px; border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}
.nav-links a:hover { color: var(--text); background: var(--surface2); }
.nav-links a.active { color: var(--green); background: rgba(100,255,218,0.08); }

/* === Hamburger Menu === */
.nav-hamburger {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    line-height: 1;
    transition: background 0.15s;
}
.nav-hamburger:hover {
    background: var(--surface2);
}

@media (max-width: 768px) {
    .nav-hamburger {
        display: block;
    }
    .nav-links {
        display: none;
        position: absolute;
        top: 44px;
        left: 0;
        right: 0;
        background: var(--surface);
        border-bottom: 1px solid var(--surface2);
        flex-direction: column;
        padding: 8px 20px 12px;
        gap: 2px;
        z-index: 199;
    }
    .nav-links.open {
        display: flex;
    }
    .nav-links a {
        display: block;
        padding: 8px 10px;
        font-size: 0.82rem;
    }
}

/* === Header === */
.header { text-align: center; padding: 20px 0 8px; }
.header h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.version { font-size: 0.8rem; color: var(--text-dim); font-family: var(--mono); }
.beta-badge {
    font-size: 0.55rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.08em; background: var(--yellow); color: var(--bg);
    padding: 2px 8px; border-radius: 10px; vertical-align: middle;
    position: relative; top: -2px;
}
.alpha-badge {
    font-size: 0.55rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.08em; background: var(--accent); color: #fff;
    padding: 2px 8px; border-radius: 10px; vertical-align: middle;
    position: relative; top: -2px;
}
.badge {
    font-size: 0.55rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 2px 8px;
    border-radius: 10px;
    vertical-align: middle;
    position: relative;
    top: -2px;
}
.badge-beta {
    background: var(--yellow);
    color: var(--bg);
}
.badge-alpha {
    background: var(--accent);
    color: #fff;
}
.header-sub { font-size: 0.85rem; color: var(--text-dim); margin-top: 6px; }

/* === Workspace === */
.workspace {
    background: var(--surface); border-radius: var(--radius);
    padding: 24px; min-height: 200px;
}

/* === Form Elements === */
.form-section { margin-bottom: 16px; }
.form-section:last-child { margin-bottom: 0; }
.form-label {
    display: block; font-size: 0.78rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-dim); margin-bottom: 6px;
}
.radio-group { display: flex; flex-wrap: wrap; gap: 6px; }
.radio-pill { display: none; }
.radio-pill + label {
    background: var(--bg); border: 1px solid transparent;
    border-radius: 20px; padding: 5px 12px; font-size: 0.82rem;
    cursor: pointer; transition: border-color 0.15s, background 0.15s;
    white-space: nowrap;
}
.radio-pill + label:hover { border-color: var(--accent); }
.radio-pill:checked + label {
    border-color: var(--accent); background: rgba(233,69,96,0.15); color: #fff;
}
.text-input, select.text-input {
    width: 100%; background: var(--bg); border: 1px solid var(--surface2);
    border-radius: var(--radius); padding: 8px 12px; color: var(--text);
    font-size: 0.85rem; font-family: var(--mono); outline: none;
    transition: border-color 0.15s;
}
select.text-input { cursor: pointer; appearance: auto; }
.text-input:focus, select.text-input:focus { border-color: var(--accent); }
.text-input:focus-visible, select.text-input:focus-visible { outline: none; }
.text-input::placeholder { color: var(--text-dim); opacity: 0.6; }
.checkbox-row {
    display: flex; align-items: center; gap: 8px; margin-top: 0;
}
.checkbox-row input[type="checkbox"] {
    accent-color: var(--accent); width: 14px; height: 14px;
}
.checkbox-row label { font-size: 0.78rem; cursor: pointer; }
.hint { font-size: 0.75rem; color: var(--text-dim); margin-top: 4px; }
.warning { font-size: 0.75rem; color: var(--accent); margin-top: 4px; font-weight: 500; }
.form-divider { border: none; border-top: 1px solid var(--surface2); margin: 16px 0; }

/* === Criterion Rows === */
.criteria-list {
    display: flex; flex-direction: column; gap: 8px;
    margin: 8px 0;
}
.criterion-row {
    background: var(--bg); border-radius: var(--radius);
    padding: 12px; display: flex; flex-direction: column; gap: 8px;
    border: 1px solid var(--surface2);
}
.criterion-top {
    display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.criterion-top select { flex: 1; min-width: 120px; max-width: 220px; }
.criterion-top .text-input { flex: 1; min-width: 100px; }
.criterion-logic {
    display: flex; align-items: center; gap: 6px;
    margin-bottom: 4px;
}
.criterion-logic .logic-label {
    font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
    color: var(--green); font-family: var(--mono); min-width: 30px;
}
.criterion-parens {
    display: flex; gap: 12px; align-items: center;
}
.criterion-controls {
    display: flex; gap: 2px; flex-shrink: 0; margin-left: auto;
}
.btn-icon {
    background: none; border: none; color: var(--text-dim);
    cursor: pointer; font-size: 0.85rem; padding: 2px 6px;
    border-radius: 4px; transition: color 0.15s, background 0.15s;
}
.btn-icon:hover { color: var(--accent); background: rgba(233,69,96,0.1); }

.btn-add {
    background: var(--surface2); border: 1px solid var(--accent);
    border-radius: var(--radius); color: var(--text);
    padding: 8px 16px; cursor: pointer; font-size: 0.82rem;
    white-space: nowrap; transition: background 0.15s; margin-top: 8px;
}
.btn-add:hover { background: rgba(233,69,96,0.2); }

/* === Output Bar === */
.output-bar {
    position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
    width: 100%; max-width: 900px; background: var(--surface);
    border-top: 2px solid var(--accent); padding: 10px 20px 14px; z-index: 100;
}
.output-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 6px; gap: 10px;
}
.output-label {
    font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.06em; color: var(--green);
}
.output-toggle { display: flex; gap: 4px; }
.toggle-btn {
    background: var(--bg); border: 1px solid transparent;
    border-radius: 14px; padding: 3px 12px; font-size: 0.72rem;
    font-weight: 600; color: var(--text-dim); cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.toggle-btn:hover { border-color: var(--accent); }
.toggle-btn.active {
    border-color: var(--accent); color: #fff;
    background: rgba(233,69,96,0.15);
}
[data-theme="light"] .toggle-btn.active { color: var(--accent); }
.output-row { display: flex; gap: 10px; align-items: center; }
.output-cmd {
    flex: 1; background: var(--bg); border-radius: var(--radius);
    padding: 8px 12px; font-family: var(--mono); font-size: 0.78rem;
    color: var(--yellow); overflow-x: auto; white-space: pre;
    line-height: 1.5; max-height: 180px; overflow-y: auto;
}
.output-cmd.empty-state {
    color: var(--text-dim); font-style: italic; font-family: var(--sans, system-ui, sans-serif);
}
.copy-btn {
    background: var(--accent); border: none; border-radius: var(--radius);
    color: #fff; padding: 6px 16px; cursor: pointer; font-weight: 600;
    font-size: 0.78rem; transition: opacity 0.15s; flex-shrink: 0;
}
.copy-btn:hover { opacity: 0.85; }
.copy-toast {
    position: absolute; top: -30px; right: 20px;
    background: var(--green); color: var(--bg); font-size: 0.78rem;
    font-weight: 700; padding: 4px 12px; border-radius: 4px;
    opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.copy-toast.show { opacity: 1; }

/* === Breadcrumb === */
.breadcrumb {
    font-size: 0.78rem;
    color: var(--text-dim);
    padding: 8px 0 0;
}
.breadcrumb a {
    color: var(--green);
    text-decoration: none;
}
.breadcrumb a:hover {
    text-decoration: underline;
}

/* === Related Tools === */
.related-tools {
    font-size: 0.82rem;
    color: var(--text-dim);
    text-align: center;
    padding: 16px;
    margin-top: 8px;
}
.related-tools a {
    color: var(--green);
    text-decoration: none;
}
.related-tools a:hover {
    text-decoration: underline;
}

/* === Footer === */
.site-footer {
    text-align: center; padding: 24px 16px; font-size: 0.78rem;
    color: var(--text-dim); line-height: 1.7;
    border-top: 1px solid var(--surface2); margin-top: 8px;
}
.footer-copy { margin-top: 8px; font-size: 0.72rem; color: var(--text-dim); opacity: 0.7; }

/* === Analyze Button === */
.analyze-btn {
    background: var(--surface2); border: 1px solid var(--green);
    border-radius: var(--radius); color: var(--green);
    padding: 6px 14px; cursor: pointer; font-weight: 600;
    font-size: 0.78rem; transition: background 0.15s, opacity 0.15s;
    flex-shrink: 0; white-space: nowrap;
}
.analyze-btn:hover { background: rgba(100,255,218,0.1); }
[data-theme="light"] .analyze-btn:hover { background: rgba(5,150,105,0.1); }

/* === Analysis Panel === */
.analysis-panel {
    background: var(--surface); border-radius: var(--radius);
    border: 1px solid var(--surface2); padding: 16px;
    animation: analysisSlideIn 0.25s ease-out;
}
.analysis-panel[hidden] { display: none; }
@keyframes analysisSlideIn {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
}
.analysis-header {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 12px; padding-bottom: 8px;
    border-bottom: 1px solid var(--surface2);
}
.analysis-title {
    font-size: 0.78rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.05em; color: var(--green);
}
.analysis-summary {
    font-size: 0.75rem; color: var(--text-dim); margin-left: auto;
}
.analysis-close { margin-left: 8px; }
.analysis-findings {
    display: flex; flex-direction: column; gap: 8px;
}
.analysis-card {
    display: flex; gap: 10px; align-items: flex-start;
    padding: 10px 12px; border-radius: var(--radius);
    background: var(--bg); border-left: 3px solid var(--text-dim);
}
.analysis-card[data-severity="critical"] { border-left-color: var(--analysis-critical); }
.analysis-card[data-severity="warning"]  { border-left-color: var(--analysis-warning); }
.analysis-card[data-severity="info"]     { border-left-color: var(--analysis-info); }
.analysis-card[data-severity="pass"]     { border-left-color: var(--analysis-pass); }
.analysis-icon { font-size: 1rem; flex-shrink: 0; line-height: 1.3; }
.analysis-card-body { flex: 1; min-width: 0; }
.analysis-card-title {
    font-size: 0.82rem; font-weight: 600; color: var(--text);
    margin-bottom: 2px;
}
.analysis-card-detail {
    font-size: 0.75rem; color: var(--text-dim); line-height: 1.5;
}

/* === Changelog === */
.changelog {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--surface2);
    margin-top: 8px;
}
.changelog summary {
    padding: 12px 16px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    cursor: pointer;
    list-style: none;
}
.changelog summary::-webkit-details-marker { display: none; }
.changelog summary::before {
    content: "\25B6";
    display: inline-block;
    margin-right: 8px;
    font-size: 0.6rem;
    transition: transform 0.15s;
}
.changelog[open] summary::before { transform: rotate(90deg); }
.changelog-content {
    padding: 0 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.changelog-entry h3 {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--green);
    font-family: var(--mono);
    margin-bottom: 4px;
}
.changelog-entry ul {
    list-style: disc;
    padding-left: 20px;
    font-size: 0.78rem;
    color: var(--text-dim);
    line-height: 1.7;
}

/* === Import XML Modal === */
.import-modal-overlay[hidden] {
    display: none !important;
}
.import-modal-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.import-modal {
    background: var(--surface); color: var(--text);
    border: 1px solid var(--surface2); border-radius: var(--radius);
    width: 100%; max-width: 640px;
    padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.import-modal-title {
    font-size: 1rem; font-weight: 700; margin-bottom: 12px;
    color: var(--green);
}
.import-modal-textarea {
    width: 100%; resize: vertical;
    background: var(--bg); color: var(--text);
    border: 1px solid var(--surface2); border-radius: var(--radius);
    padding: 12px; font-family: var(--mono); font-size: 0.8rem;
    line-height: 1.5;
}
.import-modal-textarea:focus { outline: 2px solid var(--green); outline-offset: 1px; }
.import-modal-error {
    color: var(--analysis-critical); font-size: 0.8rem;
    margin-top: 8px; font-weight: 600;
}
.import-modal-success {
    color: var(--analysis-pass); font-size: 0.8rem;
    margin-top: 8px; font-weight: 600;
}
.import-modal-actions {
    display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end;
}
.btn-import {
    background: var(--green); color: var(--bg);
    border: none; border-radius: var(--radius);
    padding: 8px 20px; font-weight: 700; font-size: 0.82rem;
    cursor: pointer; transition: opacity 0.15s;
}
.btn-import:hover { opacity: 0.85; }
.btn-cancel {
    background: transparent; color: var(--text-dim);
    border: 1px solid var(--surface2); border-radius: var(--radius);
    padding: 8px 20px; font-weight: 600; font-size: 0.82rem;
    cursor: pointer; transition: background 0.15s;
}
.btn-cancel:hover { background: rgba(128,128,128,0.1); }
.btn-import-xml {
    background: none; border: 1px solid var(--green); color: var(--green);
    border-radius: var(--radius); padding: 6px 14px;
    font-size: 0.78rem; font-weight: 600; cursor: pointer;
    margin-left: 8px; transition: background 0.15s;
}
.btn-import-xml:hover { background: rgba(100,255,218,0.1); }
[data-theme="light"] .btn-import-xml:hover { background: rgba(5,150,105,0.1); }

/* === Responsive === */
@media (max-width: 500px) {
    .app { padding: 56px 10px 170px; }
    .criterion-top { flex-direction: column; }
    .criterion-top select, .criterion-top .text-input { max-width: 100%; }
    .analysis-header { flex-wrap: wrap; }
    .analysis-summary { margin-left: 0; width: 100%; }
}

/* === Shareable Link Box === */
.share-link-box {
    margin: 16px auto 12px;
    max-width: 760px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--surface2);
    border-radius: 10px;
}
.share-link-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 6px;
}
.share-link-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.share-link-input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--surface2);
    border-radius: 6px;
    color: var(--text);
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.78rem;
    padding: 6px 10px;
    outline: none;
    overflow: hidden;
    text-overflow: ellipsis;
}
.share-link-input:focus {
    border-color: var(--accent);
}
.share-link-copy {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.15s;
}
.share-link-copy:hover {
    opacity: 0.85;
}
