/* D/BASIC Playground visual system */
*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    color-scheme: dark;
    --bg: #0a0a0f;
    --bg-elevated: #12121a;
    --bg-card: #16161f;
    --bg-card-hover: #1c1c28;
    --border: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.12);
    --text: #e4e4ed;
    --text-muted: #8888a0;
    --text-dim: #55556a;
    --accent: #f59e0b;
    --accent-light: #fbbf24;
    --accent-glow: rgba(245, 158, 11, 0.15);
    --red: #ef4444;
    --violet: #8b5cf6;
    --success: #4ade80;
    --danger: #fb7185;
    --radius: 12px;
    --radius-lg: 20px;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
    --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html {
    min-height: 100%;
    background: var(--bg);
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 18% -20%, rgba(245, 158, 11, 0.11), transparent 32rem),
        radial-gradient(circle at 88% 2%, rgba(139, 92, 246, 0.08), transparent 28rem),
        var(--bg);
    font-family: var(--sans);
}

button, select, textarea {
    font: inherit;
}

button, a, select, textarea, canvas {
    -webkit-tap-highlight-color: transparent;
}

a {
    color: inherit;
}

.app-bar {
    position: sticky;
    z-index: 20;
    top: 0;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    min-height: 64px;
    padding: 0 28px;
    border-bottom: 1px solid var(--border);
    background: rgba(10, 10, 15, 0.82);
    backdrop-filter: blur(22px);
}

.brand {
    display: inline-flex;
    align-items: baseline;
    justify-self: start;
    gap: 2px;
    text-decoration: none;
}

.brand-mark {
    font-size: 1.12rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    color: var(--accent-light);
}

.brand-name {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.02em;
}

.brand-product {
    margin-left: 8px;
    color: var(--text-muted);
    font-size: 0.84rem;
    font-weight: 500;
}

.runtime-state {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 11px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.025);
    font-size: 0.74rem;
}

.status-light {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-dim);
}

.status-light.is-loading {
    background: var(--accent);
    box-shadow: 0 0 0 5px rgba(245, 158, 11, 0.1);
    animation: breathe 1.6s ease-in-out infinite;
}

.status-light.is-ready {
    background: var(--success);
    box-shadow: 0 0 0 5px rgba(74, 222, 128, 0.1);
}

.status-light.is-error {
    background: var(--danger);
    box-shadow: 0 0 0 5px rgba(251, 113, 133, 0.1);
}

.runtime-label {
    color: var(--text);
    font-weight: 600;
}

.runtime-value {
    color: var(--text-muted);
}

.app-links {
    display: flex;
    justify-self: end;
    gap: 24px;
}

.app-links a {
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 500;
    text-decoration: none;
    transition: color 160ms ease;
}

.app-links a:hover {
    color: var(--accent-light);
}

.workbench {
    width: min(1500px, 100%);
    margin: 0 auto;
    padding: 42px 28px 30px;
}

.workbench-intro {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 32px;
    margin-bottom: 24px;
}

.eyebrow,
.panel-kicker {
    margin: 0;
    color: var(--accent);
    font-family: var(--mono);
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

h1 {
    margin: 7px 0 9px;
    color: #fff;
    font-size: clamp(1.8rem, 3vw, 2.7rem);
    line-height: 1.07;
    letter-spacing: -0.04em;
}

h1 span {
    background: linear-gradient(110deg, var(--accent-light), var(--red), var(--violet));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.intro-copy {
    max-width: 760px;
    margin: 0;
    color: var(--text-muted);
    font-size: 0.92rem;
    line-height: 1.65;
}

.runtime-facts {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.runtime-facts span {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.02);
    font-size: 0.69rem;
    white-space: nowrap;
}

.command-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 12px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(18, 18, 26, 0.76);
}

.sample-picker {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: min(340px, 48vw);
}

.sample-picker > span {
    padding-left: 4px;
    color: var(--text-dim);
    font-family: var(--mono);
    font-size: 0.67rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

select {
    min-width: 0;
    flex: 1;
    height: 36px;
    padding: 0 34px 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    outline: none;
    color: var(--text);
    background: var(--bg-card);
    font-size: 0.78rem;
}

select:focus-visible,
button:focus-visible,
textarea:focus-visible,
canvas:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

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

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    gap: 8px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    font-size: 0.76rem;
    font-weight: 650;
    transition: transform 150ms ease, border-color 150ms ease, background 150ms ease, opacity 150ms ease;
}

.button svg {
    width: 15px;
    height: 15px;
    fill: currentColor;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.button-primary {
    background: linear-gradient(135deg, var(--accent), var(--red));
    box-shadow: 0 5px 22px rgba(245, 158, 11, 0.16);
}

.button-secondary,
.button-icon {
    border-color: var(--border);
    background: rgba(255, 255, 255, 0.035);
}

.button-icon {
    width: 36px;
    padding: 0;
}

.button:not(:disabled):hover {
    transform: translateY(-1px);
    border-color: var(--border-strong);
}

.button:disabled,
select:disabled {
    cursor: wait;
    opacity: 0.52;
}

kbd {
    display: inline-flex;
    min-width: 20px;
    min-height: 18px;
    align-items: center;
    justify-content: center;
    padding: 1px 5px;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 4px;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.18);
    font-family: var(--mono);
    font-size: 0.62rem;
    font-weight: 500;
}

.button-primary kbd {
    color: rgba(255, 255, 255, 0.8);
    border-color: rgba(255, 255, 255, 0.22);
}

.workbench-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.12fr) minmax(390px, 0.88fr);
    gap: 12px;
    height: clamp(610px, calc(100vh - 260px), 760px);
    min-height: 610px;
}

.panel {
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(18, 18, 26, 0.9);
    box-shadow: var(--shadow);
}

.panel-header {
    display: flex;
    min-height: 58px;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 10px 15px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.016);
}

.panel-header-compact {
    min-height: 48px;
}

.panel-heading h2 {
    margin: 3px 0 0;
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.77rem;
    font-weight: 500;
}

.panel-heading-inline {
    display: flex;
    align-items: center;
    gap: 12px;
}

.panel-heading-inline h2 {
    margin: 0;
}

.dirty-state,
.surface-size {
    color: var(--text-dim);
    font-family: var(--mono);
    font-size: 0.65rem;
}

.editor-panel {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: 0;
}

.editor {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr;
    min-height: 0;
    overflow: hidden;
    background: #0d0d14;
}

.line-numbers {
    min-width: 48px;
    height: 100%;
    margin: 0;
    padding: 18px 12px 18px 8px;
    overflow: hidden;
    border-right: 1px solid var(--border);
    color: #414152;
    background: rgba(255, 255, 255, 0.012);
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.65;
    text-align: right;
    user-select: none;
}

textarea {
    width: 100%;
    height: 100%;
    min-height: 0;
    resize: none;
    padding: 18px;
    overflow: auto;
    border: 0;
    outline: 0;
    color: #d8d8e4;
    background: transparent;
    caret-color: var(--accent-light);
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.65;
    tab-size: 2;
    white-space: pre;
}

textarea:disabled {
    opacity: 1;
    -webkit-text-fill-color: #d8d8e4;
}

.panel-footer {
    display: flex;
    min-height: 34px;
    align-items: center;
    gap: 18px;
    padding: 7px 13px;
    border-top: 1px solid var(--border);
    color: var(--text-dim);
    background: rgba(255, 255, 255, 0.012);
    font-family: var(--mono);
    font-size: 0.61rem;
}

.editor-status span:first-child {
    margin-right: auto;
}

.dirty-state.is-dirty {
    color: var(--accent-light);
}

.output-column {
    display: grid;
    grid-template-rows: minmax(390px, 1fr) minmax(150px, 0.34fr);
    gap: 12px;
    min-width: 0;
    min-height: 0;
}

.preview-panel,
.console-panel {
    display: grid;
    grid-template-rows: auto 1fr auto;
}

.console-panel {
    grid-template-rows: auto 1fr;
}

.canvas-stage {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 0;
    padding: 28px;
    overflow: hidden;
    background:
        linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
        #0d0d14;
    background-size: 24px 24px;
}

.canvas-stage::after {
    position: absolute;
    inset: 0;
    content: "";
    pointer-events: none;
    background: radial-gradient(circle at center, transparent 35%, rgba(10, 10, 15, 0.44));
}

#surface {
    z-index: 1;
    display: block;
    width: min(100%, 640px);
    height: auto;
    aspect-ratio: 5 / 3;
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 5px;
    background: #08080c;
    box-shadow: 0 22px 55px rgba(0, 0, 0, 0.55);
    image-rendering: auto;
}

.canvas-empty {
    position: absolute;
    z-index: 2;
    display: flex;
    align-items: center;
    flex-direction: column;
    gap: 7px;
    padding: 22px;
    color: var(--text-muted);
    text-align: center;
    pointer-events: none;
}

.canvas-empty-mark {
    margin-bottom: 3px;
    color: var(--accent);
    font-family: var(--mono);
    font-size: 1.8rem;
    font-weight: 700;
}

.canvas-empty strong {
    color: var(--text);
    font-size: 0.85rem;
}

.canvas-empty span:last-child {
    font-size: 0.72rem;
}

.canvas-empty.is-hidden {
    display: none;
}

.preview-help {
    justify-content: space-between;
    flex-wrap: wrap;
}

.preview-help span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.console {
    min-height: 100px;
    padding: 14px 15px 18px;
    overflow: auto;
    color: #c7c7d6;
    background: #0d0d14;
    font-family: var(--mono);
    font-size: 0.7rem;
    line-height: 1.65;
    white-space: pre-wrap;
}

.console-prompt {
    margin-right: 9px;
    color: var(--accent);
}

.console-muted {
    color: var(--text-dim);
}

.console-line {
    display: block;
    width: 100%;
    margin: 0 0 5px;
    color: inherit;
    font: inherit;
    line-height: inherit;
    text-align: left;
    white-space: pre-wrap;
}

.console-line:last-child {
    margin-bottom: 0;
}

.console-diagnostic {
    padding: 5px 7px;
    border: 1px solid rgba(251, 113, 133, 0.18);
    border-radius: 5px;
    color: #fda4af;
    background: rgba(251, 113, 133, 0.06);
    cursor: pointer;
    user-select: text;
}

.console-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.console-diagnostic:hover {
    border-color: rgba(251, 113, 133, 0.38);
    background: rgba(251, 113, 133, 0.1);
}

.console-transcript {
    color: #e4e4ed;
}

.console-error {
    color: var(--danger);
}

.console-success {
    color: var(--success);
}

.console-meta {
    color: var(--text-dim);
    font-size: 0.64rem;
}

.button.is-running svg {
    animation: spin 900ms linear infinite;
}

.text-button {
    padding: 6px;
    border: 0;
    color: var(--text-dim);
    background: transparent;
    cursor: pointer;
    font-size: 0.68rem;
}

.text-button:not(:disabled):hover {
    color: var(--accent-light);
}

.text-button:disabled {
    cursor: wait;
    opacity: 0.55;
}

.workbench-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 17px 4px 0;
    color: var(--text-dim);
    font-size: 0.69rem;
}

.workbench-footer p {
    margin: 0;
}

.footer-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-right: 7px;
    border-radius: 50%;
    background: var(--success);
}

.workbench-footer a {
    color: var(--text-muted);
    font-weight: 600;
    text-decoration: none;
}

.workbench-footer a:hover {
    color: var(--accent-light);
}

@keyframes breathe {
    50% { opacity: 0.55; }
}

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

@media (max-width: 980px) {
    .app-bar {
        grid-template-columns: 1fr auto;
    }

    .runtime-state {
        display: none;
    }

    .workbench-intro {
        align-items: start;
        flex-direction: column;
        gap: 18px;
    }

    .runtime-facts {
        justify-content: flex-start;
    }

    .workbench-grid {
        grid-template-columns: 1fr;
        height: auto;
        min-height: 0;
    }

    .editor-panel {
        height: 560px;
        min-height: 560px;
    }

    .output-column {
        grid-template-rows: minmax(460px, auto) minmax(160px, auto);
    }
}

@media (max-width: 640px) {
    .app-bar {
        min-height: 58px;
        padding: 0 16px;
    }

    .brand-product,
    .app-links a:last-child {
        display: none;
    }

    .app-links {
        gap: 14px;
    }

    .workbench {
        padding: 28px 12px 22px;
    }

    .command-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .sample-picker {
        width: 100%;
        min-width: 0;
    }

    .command-actions {
        display: grid;
        grid-template-columns: 1fr 1fr auto;
    }

    .button-primary kbd {
        display: none;
    }

    .editor-panel {
        height: 510px;
        min-height: 510px;
    }

    .line-numbers {
        min-width: 40px;
        padding-right: 8px;
        font-size: 12px;
    }

    textarea {
        padding: 16px 12px;
        font-size: 12px;
    }

    .canvas-stage {
        padding: 18px 10px;
    }

    .output-column {
        grid-template-rows: minmax(330px, auto) minmax(160px, auto);
    }

    .preview-help span:last-child {
        width: 100%;
    }

    .workbench-footer {
        align-items: start;
        flex-direction: column;
        gap: 8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
