/* === 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;
    --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;
}
[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;
    }
    :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; }

/* === 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; }

/* === 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;
}

/* === 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(--text-dim);
    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;
}

/* === Pre-Built EA Cards === */
.prebuilt-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    margin-top: 12px;
}
.prebuilt-card {
    background: var(--surface);
    border: 1px solid var(--surface2);
    border-radius: 10px;
    padding: 14px 16px;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
}
.prebuilt-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}
.prebuilt-card-name {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 4px;
}
.prebuilt-card-desc {
    font-size: 0.78rem;
    color: var(--text-dim);
    line-height: 1.4;
    margin-bottom: 8px;
}
.prebuilt-card-meta {
    display: flex;
    gap: 8px;
    align-items: center;
}
.data-type-badge {
    font-size: 0.68rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(100, 255, 218, 0.12);
    color: var(--green);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.prebuilt-use-btn {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    margin-left: auto;
    transition: opacity 0.15s;
}
.prebuilt-use-btn:hover {
    opacity: 0.85;
}

/* === Pattern Fields === */
.pattern-fields {
    margin-top: 12px;
    padding: 12px 16px;
    background: rgba(255,255,255,0.03);
    border-radius: 8px;
    border: 1px solid var(--surface2);
}

/* === Validation Hints === */
.ea-warning {
    color: var(--yellow);
    font-size: 0.78rem;
    margin-top: 6px;
}
.ea-hint {
    color: var(--text-dim);
    font-size: 0.75rem;
    margin-top: 4px;
    font-style: italic;
}

/* === DDM Warning === */
.ddm-warning {
    margin-top: 8px;
    padding: 8px 10px;
    background: rgba(255, 211, 105, 0.08);
    border: 1px solid rgba(255, 211, 105, 0.25);
    border-radius: 6px;
    font-size: 0.75rem;
    color: var(--yellow);
    cursor: pointer;
    transition: background 0.15s;
}
.ddm-warning:hover {
    background: rgba(255, 211, 105, 0.15);
}
.ddm-warning strong {
    display: block;
    margin-bottom: 3px;
    font-size: 0.78rem;
}
.ddm-warning p {
    margin: 0;
    line-height: 1.4;
    color: var(--text-dim);
}

/* === Script Preview === */
.script-preview {
    background: var(--bg);
    border: 1px solid var(--surface2);
    border-radius: 8px;
    padding: 14px 16px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.78rem;
    line-height: 1.5;
    color: var(--green);
    overflow-x: auto;
    white-space: pre;
    max-height: 300px;
    overflow-y: auto;
    margin-top: 8px;
}
.script-preview.expanded {
    min-height: 500px;
    max-height: none;
}

/* === Mode Toggle === */
.mode-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

/* === Responsive === */
@media (max-width: 500px) {
    .app { padding: 56px 10px 170px; }
    .prebuilt-grid { grid-template-columns: 1fr; }
}
