/* ------------------------------------------------------------------
   C# Playground - themeable shell
   URL / iframe parameters:
     theme   = dark | light | auto
     accent  = indigo | blue | emerald | amber | rose | violet | cyan | orange | RRGGBB
     layout  = split | stacked
     chrome  = full | minimal | none
     density = comfortable | compact
     radius  = 0..32
     fontsize= 11..22
   ------------------------------------------------------------------ */

html,
body {
    margin: 0;
    padding: 0;
    overflow: hidden;
}

#app {
    min-height: 100vh;
    min-height: 100dvh;
}

.compiler-container.app-shell {
    --bg: #090d18;
    --bg-glow: rgba(99, 102, 241, .12);
    --surface: #111827;
    --surface-2: #0f172a;
    --surface-3: #1e293b;
    --border: rgba(148, 163, 184, .16);
    --border-strong: rgba(148, 163, 184, .26);
    --text: #e5edf8;
    --muted: #8da0b9;
    --editor-bg: #0b1220;
    --editor-text: #d8e4f4;
    --editor-selection: rgba(99, 102, 241, .32);
    --console-bg: #060a13;
    --console-text: #c9f7df;
    --console-muted: #6f839d;
    --shadow: 0 24px 70px rgba(0, 0, 0, .38);
    --accent: #6366f1;
    --accent-rgb: 99, 102, 241;
    --radius: 16px;
    --editor-font-size: 14px;
    --gap: 14px;
    --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    --success: #34d399;
    --error: #fb7185;
    --warning: #fbbf24;
    --info: #67e8f9;

    box-sizing: border-box;
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(0, .92fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
        "header header"
        "editor output"
        "compile compile";
    gap: var(--gap);
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    padding: clamp(10px, 1.5vw, 20px);
    overflow: hidden;
    background:
        radial-gradient(900px 460px at 12% -10%, var(--bg-glow), transparent 62%),
        radial-gradient(700px 420px at 100% 0%, rgba(6, 182, 212, .07), transparent 58%),
        var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    color-scheme: dark;
    transition: background .25s ease, color .25s ease;
}

.compiler-container.app-shell.theme-light {
    --bg: #f1f4fa;
    --bg-glow: rgba(99, 102, 241, .15);
    --surface: #ffffff;
    --surface-2: #f7f9fd;
    --surface-3: #eef2f9;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --muted: #64748b;
    --editor-bg: #f8fafc;
    --editor-text: #0f172a;
    --editor-selection: rgba(99, 102, 241, .18);
    --console-bg: #f1f5f9;
    --console-text: #14532d;
    --console-muted: #64748b;
    --success: #047857;
    --error: #be123c;
    --warning: #b45309;
    --info: #0e7490;
    --shadow: 0 18px 45px rgba(30, 41, 59, .10);
    color-scheme: light;
}

@media (prefers-color-scheme: light) {
    .compiler-container.app-shell.theme-auto {
        --bg: #f1f4fa;
        --bg-glow: rgba(99, 102, 241, .15);
        --surface: #ffffff;
        --surface-2: #f7f9fd;
        --surface-3: #eef2f9;
        --border: #e2e8f0;
        --border-strong: #cbd5e1;
        --text: #0f172a;
        --muted: #64748b;
        --editor-bg: #f8fafc;
        --editor-text: #0f172a;
        --editor-selection: rgba(99, 102, 241, .18);
        --console-bg: #f1f5f9;
        --console-text: #14532d;
        --console-muted: #64748b;
        --success: #047857;
        --error: #be123c;
        --warning: #b45309;
        --info: #0e7490;
        --shadow: 0 18px 45px rgba(30, 41, 59, .10);
        color-scheme: light;
    }
}

/* ---------- App header ---------- */

.compiler-container.app-shell .header {
    grid-area: header;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 54px;
    padding: 0 4px;
    background: transparent;
    color: var(--text);
    border: 0;
    box-shadow: none;
}

.compiler-container.app-shell .header-content {
    display: flex;
    align-items: center;
    gap: 13px;
    text-align: left;
}

.compiler-container.app-shell .header h1 {
    position: relative;
    margin: 0;
    padding-left: 44px;
    font-size: clamp(17px, 1.55vw, 21px);
    line-height: 1.15;
    font-weight: 700;
    letter-spacing: -.025em;
    color: var(--text);
}

.compiler-container.app-shell .header h1::before {
    content: "C#";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 58%, #111827));
    color: #fff;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: -.08em;
    box-shadow: 0 7px 20px rgba(var(--accent-rgb), .28);
}

.compiler-container.app-shell .subheading {
    margin: 2px 0 0 44px;
    font-size: 12px;
    font-weight: 400;
    font-style: normal;
    line-height: 1.3;
    color: var(--muted);
}

.compiler-container.app-shell .header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.compiler-container.app-shell .header-actions .target-picker {
    padding: 5px 8px;
}

.compiler-container.app-shell .header::after {
    content: attr(data-runtime);
    flex: 0 0 auto;
    padding: 6px 11px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: .02em;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04);
}

@keyframes panel-enter {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Panes ---------- */

.compiler-container.app-shell .editor-section,
.compiler-container.app-shell .output-section {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.compiler-container.app-shell .editor-section {
    grid-area: editor;
    animation: panel-enter .32s ease both;
}

.compiler-container.app-shell .output-section {
    grid-area: output;
    animation: panel-enter .38s ease both;
    animation-delay: .04s;
}

.compiler-container.app-shell .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 46px;
    padding: 8px 12px;
    background: var(--surface-2);
    border: 0;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-weight: 600;
}

.compiler-container.app-shell .section-header h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    margin: 0;
    font-size: 11px;
    line-height: 1;
    font-weight: 700;
    letter-spacing: .10em;
    text-transform: uppercase;
    color: var(--muted);
}

.compiler-container.app-shell .section-header h3::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 4px rgba(var(--accent-rgb), .12);
}

.compiler-container.app-shell .output-section .section-header h3::before {
    background: #34d399;
    box-shadow: 0 0 0 4px rgba(52, 211, 153, .12);
}

.compiler-container.app-shell .editor-controls,
.compiler-container.app-shell .console-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.compiler-container.app-shell .editor-settings {
    position: relative;
}

.compiler-container.app-shell .editor-settings > summary {
    list-style: none;
    cursor: pointer;
}

.compiler-container.app-shell .editor-settings > summary::-webkit-details-marker {
    display: none;
}

.compiler-container.app-shell .settings-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 1000;
    width: 240px;
    padding: 12px;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.compiler-container.app-shell .settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 12px;
}

.compiler-container.app-shell .settings-row:last-child {
    margin-bottom: 0;
}

.compiler-container.app-shell .settings-row select {
    max-width: 120px;
    padding: 4px 8px;
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    background: var(--surface-2);
    color: var(--text);
}

.compiler-container.app-shell .settings-check {
    justify-content: flex-start;
}

.compiler-container.app-shell .settings-check input {
    accent-color: var(--accent);
}


/* ---------- Code completion ---------- */

.code-completion {
    display: none;
    position: fixed;
    z-index: 9999;
    max-height: 180px;
    overflow-y: auto;
    padding: 5px;
    border: 1px solid var(--completion-border, rgba(255, 255, 255, .16));
    border-radius: 10px;
    background: var(--completion-bg, #1b2030);
    color: var(--completion-text, #e8ecf5);
    box-shadow: var(--completion-shadow, 0 14px 38px rgba(0, 0, 0, .38));
}

@keyframes completion-pop {
    from { opacity: 0; transform: translateY(4px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.code-completion.is-visible {
    display: block;
    animation: completion-pop .14s ease-out;
    transform-origin: top left;
}

.code-completion-item {
    padding: 5px 9px;
    border-radius: 6px;
    color: var(--completion-text, #e8ecf5);
    font-family: var(--font-mono, "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace);
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

.code-completion-item.active,
.code-completion-item:hover {
    background: var(--completion-active-bg, rgba(99, 102, 241, .28));
    color: var(--completion-active-text, #c7d2fe);
}

/* ---------- Editor / console bodies ---------- */

.compiler-container.app-shell .editor-container,
.compiler-container.app-shell .output-container {
    position: relative;
    flex: 1;
    min-height: 0;
}

.compiler-container.app-shell .code-editor {
    display: block;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 16px 18px 24px;
    border: 0;
    outline: none;
    resize: none;
    background: var(--editor-bg);
    color: var(--editor-text);
    caret-color: var(--accent);
    font-family: var(--font-mono);
    font-size: var(--editor-font-size);
    line-height: 1.68;
    tab-size: 4;
    scrollbar-color: var(--surface-3) transparent;
}

.compiler-container.app-shell .code-editor::selection,
.compiler-container.app-shell .output-content::selection {
    background: var(--editor-selection);
}

.compiler-container.app-shell .code-editor::placeholder {
    color: var(--console-muted);
    font-style: normal;
}

.compiler-container.app-shell .output-content {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    padding: 15px 16px 24px;
    background: var(--console-bg);
    color: var(--console-text);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.58;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    scrollbar-color: var(--surface-3) transparent;
}

.compiler-container.app-shell .output-content:empty::before {
    content: "运行结果会显示在这里…";
    color: var(--console-muted);
    opacity: .72;
}

/* ---------- Target framework picker ---------- */

.compiler-container.app-shell .target-picker {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 7px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface-3);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.compiler-container.app-shell .target-picker-label {
    color: var(--muted);
}

.compiler-container.app-shell .target-picker select {
    padding: 1px 2px;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.compiler-container.app-shell .target-picker select option {
    background: var(--surface);
    color: var(--text);
}

.compiler-container.app-shell .target-picker:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(var(--accent-rgb), .16);
}

/* ---------- Buttons / toggles ---------- */

.compiler-container.app-shell .btn,
.compiler-container.app-shell .compile-btn {
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface-3);
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    box-shadow: none;
    transition: background .18s ease, border-color .18s ease, transform .18s ease;
}

.compiler-container.app-shell .btn {
    padding: 8px 11px;
}

.compiler-container.app-shell .btn:hover:not(:disabled) {
    background: color-mix(in srgb, var(--surface-3) 72%, var(--accent));
    border-color: var(--border-strong);
}

.compiler-container.app-shell .btn:active:not(:disabled),
.compiler-container.app-shell .compile-btn:active:not(:disabled) {
    transform: translateY(1px);
}

.compiler-container.app-shell .btn:focus-visible,
.compiler-container.app-shell .compile-btn:focus-visible,
.compiler-container.app-shell .code-editor:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Toggle switch */
.compiler-container.app-shell .toggle-switch {
    gap: 7px;
    color: var(--muted);
    font-size: 12px;
}

.compiler-container.app-shell .toggle-slider {
    width: 36px;
    height: 20px;
    background: var(--surface-3);
    border: 1px solid var(--border);
}

.compiler-container.app-shell .toggle-slider::before {
    width: 14px;
    height: 14px;
    left: 2px;
    bottom: 2px;
    background: var(--muted);
    box-shadow: none;
}

.compiler-container.app-shell .toggle-switch input:checked + .toggle-slider {
    background: rgba(var(--accent-rgb), .28);
    border-color: rgba(var(--accent-rgb), .55);
}

.compiler-container.app-shell .toggle-switch input:checked + .toggle-slider::before {
    background: var(--accent);
    transform: translateX(16px);
}

.compiler-container.app-shell .toggle-label {
    color: var(--muted);
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 10px;
    font-weight: 700;
}

/* ---------- Run bar ---------- */

.compiler-container.app-shell .compile-section {
    grid-area: compile;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    min-height: 50px;
    padding: 0 2px;
    background: transparent;
    border: 0;
}

.compiler-container.app-shell .compile-section::before {
    content: "Ctrl + Enter 运行";
    margin-right: auto;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: .01em;
}

.compiler-container.app-shell .compile-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: auto;
    min-width: 146px;
    height: 42px;
    padding: 0 20px;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 62%, #111827));
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .01em;
    box-shadow: 0 9px 26px rgba(var(--accent-rgb), .34);
}

.compiler-container.app-shell .compile-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 82%, white), var(--accent));
    box-shadow: 0 12px 30px rgba(var(--accent-rgb), .42);
    transform: translateY(-1px);
}

.compiler-container.app-shell .compile-btn:disabled {
    opacity: .68;
    cursor: not-allowed;
    box-shadow: 0 5px 18px rgba(var(--accent-rgb), .20);
}

.compiler-container.app-shell .run-label {
    white-space: nowrap;
}

.compiler-container.app-shell .spinner-border {
    width: 14px;
    height: 14px;
    border-width: 2px;
}

.compiler-container.app-shell .editor-controls .btn.is-busy {
    animation: busy-pulse 1s ease-in-out infinite;
}

@keyframes busy-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0); }
    50% { box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .14); }
}

.compiler-container.app-shell .compile-btn {
    transition: transform .12s ease, filter .18s ease, box-shadow .18s ease;
}

.compiler-container.app-shell .compile-btn:not(:disabled):active {
    transform: scale(.975);
}

.compiler-container.app-shell .compile-btn.is-waiting {
    position: relative;
    overflow: hidden;
}

.compiler-container.app-shell .compile-btn.is-waiting::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, .28) 50%, transparent 80%);
    transform: translateX(-100%);
    animation: run-shimmer 1.05s ease-in-out infinite;
    pointer-events: none;
}

.compiler-container.app-shell .run-waiting {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 1em;
}

.compiler-container.app-shell .run-waiting span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #fff;
    animation: run-dot 1s ease-in-out infinite;
}

.compiler-container.app-shell .run-waiting span:nth-child(2) { animation-delay: .14s; }
.compiler-container.app-shell .run-waiting span:nth-child(3) { animation-delay: .28s; }

@keyframes run-shimmer {
    to { transform: translateX(100%); }
}

@keyframes run-dot {
    0%, 80%, 100% { opacity: .35; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Output and console input ---------- */

.compiler-container.app-shell .success { color: var(--success); }
.compiler-container.app-shell .error { color: var(--error); }
.compiler-container.app-shell .warning { color: var(--warning); }
.compiler-container.app-shell .info { color: var(--info); }

.compiler-container.app-shell .interactive-output {
    display: flex;
    align-items: center;
    width: 100%;
    margin: 2px 0;
}

.compiler-container.app-shell .console-prompt {
    margin-right: 8px;
    color: var(--accent);
    font-weight: 800;
}

.compiler-container.app-shell .console-input {
    flex: 1;
    min-width: 0;
    padding: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--console-text);
    font: inherit;
    caret-color: var(--accent);
}

/* ---------- Layout variants ---------- */

.compiler-container.app-shell.layout-stacked {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(240px, 1.12fr) minmax(180px, .88fr) auto;
    grid-template-areas:
        "header"
        "editor"
        "output"
        "compile";
}

/* ---------- Chrome variants ---------- */

.compiler-container.app-shell.chrome-minimal,
.compiler-container.app-shell.chrome-none {
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas:
        "editor output"
        "compile compile";
}

.compiler-container.app-shell.chrome-minimal .header,
.compiler-container.app-shell.chrome-none .header {
    display: none;
}

.compiler-container.app-shell.chrome-minimal.layout-stacked,
.compiler-container.app-shell.chrome-none.layout-stacked {
    grid-template-rows: minmax(240px, 1.12fr) minmax(180px, .88fr) auto;
    grid-template-areas:
        "editor"
        "output"
        "compile";
}

.compiler-container.app-shell.chrome-none .section-header {
    min-height: 37px;
    padding: 6px 10px;
    background: transparent;
}

.compiler-container.app-shell.chrome-none .compile-section::before {
    display: none;
}

/* Compact density */
.compiler-container.app-shell.density-compact {
    --gap: 8px;
    padding: 9px;
}

.compiler-container.app-shell.density-compact .header {
    min-height: 40px;
}

.compiler-container.app-shell.density-compact .section-header {
    min-height: 36px;
    padding: 6px 10px;
}

.compiler-container.app-shell.density-compact .code-editor,
.compiler-container.app-shell.density-compact .output-content {
    padding: 10px 12px 16px;
}

.compiler-container.app-shell.density-compact .compile-section {
    min-height: 42px;
}

.compiler-container.app-shell.density-compact .compile-btn {
    height: 36px;
    min-width: 126px;
    padding: 0 16px;
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
    .compiler-container.app-shell {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(240px, 1.1fr) minmax(180px, .9fr) auto;
        grid-template-areas:
            "header"
            "editor"
            "output"
            "compile";
    }

    .compiler-container.app-shell.chrome-minimal,
    .compiler-container.app-shell.chrome-none {
        grid-template-rows: minmax(240px, 1.1fr) minmax(180px, .9fr) auto;
        grid-template-areas:
            "editor"
            "output"
            "compile";
    }

    .compiler-container.app-shell .header {
        min-height: 44px;
    }

    .compiler-container.app-shell .header::after {
        display: none;
    }

    .compiler-container.app-shell .section-header {
        min-height: 40px;
        padding: 7px 10px;
    }

    .compiler-container.app-shell .compile-section::before {
        content: "Ctrl + Enter";
    }
}

@media (max-width: 520px) {
    .compiler-container.app-shell {
        --gap: 8px;
        padding: 8px;
    }

    .compiler-container.app-shell .subheading {
        display: none;
    }

    .compiler-container.app-shell .header h1 {
        font-size: 16px;
    }

    .compiler-container.app-shell .compile-btn {
        width: 100%;
    }

    .compiler-container.app-shell .compile-section::before {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .compiler-container.app-shell *,
    .compiler-container.app-shell *::before,
    .compiler-container.app-shell *::after {
        transition: none !important;
        animation: none !important;
    }
}
