:root {
    --navy: #0f172a;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --border: #dbe3ee;
    --border-strong: #cbd5e1;
    --text: #172033;
    --muted: #64748b;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --success: #15803d;
    --danger: #b42318;
    --console: #111827;
    --console-text: #e5e7eb;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: #f4f7fb;
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system,
        BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, select, textarea { font: inherit; }

.python-header {
    background: var(--navy);
    color: white;
}

.python-header-inner {
    min-height: 76px;
    padding: 0 32px;
    display: flex;
    align-items: center;
    gap: 24px;
}

.python-brand {
    display: flex;
    align-items: center;
    padding-right: 24px;
    border-right: 1px solid rgba(255,255,255,.14);
}

.python-brand img {
    display: block;
    max-height: 42px;
    width: auto;
}

.python-product-title {
    min-width: 165px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.python-product-title strong {
    font-size: 1.05rem;
}

.python-product-title span {
    color: rgba(255,255,255,.68);
    font-size: .78rem;
}

.python-site-nav {
    margin-left: auto;
    display: flex;
    gap: 6px;
}

.python-site-nav a {
    min-height: 38px;
    padding: 8px 12px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    color: rgba(255,255,255,.78);
    text-decoration: none;
    font-size: .9rem;
    white-space: nowrap;
}

.python-site-nav a:hover,
.python-site-nav a:focus-visible,
.python-site-nav a[aria-current="page"] {
    color: white;
    background: rgba(255,255,255,.1);
}

.python-shell {
    width: min(1440px, calc(100% - 40px));
    margin: auto;
    padding: 34px 0 48px;
}

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

.eyebrow {
    display: block;
    margin-bottom: 7px;
    color: var(--accent);
    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .1em;
}

.python-intro h1 {
    margin: 0;
    font-size: clamp(1.75rem, 3vw, 2.45rem);
}

.python-intro p {
    max-width: 720px;
    margin: 10px 0 0;
    color: var(--muted);
    line-height: 1.6;
}

.runtime-badge {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: white;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: .84rem;
    font-weight: 600;
}

.runtime-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
}

.runtime-badge.ready .runtime-dot { background: var(--success); }
.runtime-badge.error .runtime-dot { background: var(--danger); }

.playground-card {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: white;
}

.playground-toolbar {
    min-height: 62px;
    padding: 10px 14px 10px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.file-label,
.toolbar-actions,
.example-control,
.output-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #3776ab;
}

.toolbar-actions { flex-wrap: wrap; }

.example-control {
    color: var(--muted);
    font-size: .82rem;
    font-weight: 600;
}

.example-control select {
    min-height: 38px;
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: white;
}

.run-button,
.stop-button,
.secondary-button {
    min-height: 38px;
    padding: 7px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
}

.run-button {
    border: 1px solid var(--accent);
    background: var(--accent);
    color: white;
}

.run-button:hover:not(:disabled) { background: var(--accent-hover); }
.run-button:disabled { cursor: wait; opacity: .55; }

.stop-button {
    border: 1px solid #fecaca;
    background: #fff1f2;
    color: var(--danger);
}

.secondary-button {
    border: 1px solid var(--border-strong);
    background: white;
    color: var(--text);
}

.workspace-grid {
    min-height: 510px;
    display: grid;
    grid-template-columns: minmax(0,1.12fr) minmax(360px,.88fr);
}

.editor-panel,
.output-panel {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.editor-panel { border-right: 1px solid var(--border); }

.panel-heading {
    min-height: 42px;
    padding: 0 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--muted);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .08em;
}

.keyboard-hint {
    font-weight: 500;
    letter-spacing: 0;
}

.editor-shell {
    flex: 1;
    min-height: 468px;
    display: grid;
    grid-template-columns: auto minmax(0,1fr);
}

.line-numbers {
    min-width: 48px;
    padding: 18px 12px;
    border-right: 1px solid #edf2f7;
    background: #f8fafc;
    color: #94a3b8;
    text-align: right;
    white-space: pre;
    user-select: none;
    font: 14px/1.65 Consolas, monospace;
}

.code-editor {
    width: 100%;
    min-height: 468px;
    padding: 18px;
    resize: none;
    border: 0;
    outline: 0;
    tab-size: 4;
    color: var(--text);
    font: 14px/1.65 Consolas, monospace;
}

.output-panel { background: var(--console); }

.output-panel .panel-heading {
    border-color: rgba(255,255,255,.1);
    background: #172033;
    color: #aab6c8;
}

.execution-status {
    color: #cbd5e1;
    font-size: .76rem;
    font-weight: 600;
    letter-spacing: 0;
}

.execution-status.running { color: #fde68a; }
.execution-status.success { color: #86efac; }
.execution-status.error { color: #fca5a5; }

.text-button {
    padding: 4px 0;
    border: 0;
    background: transparent;
    color: #cbd5e1;
    cursor: pointer;
}

.output-console {
    flex: 1;
    min-height: 410px;
    overflow: auto;
    padding: 18px;
    color: var(--console-text);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font: 13.5px/1.65 Consolas, monospace;
}

.console-placeholder { color: #778399; }
.console-line.error { color: #fca5a5; }
.console-line.system { color: #93c5fd; }

.playground-footer {
    min-height: 42px;
    padding: 9px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: .78rem;
}

.playground-help {
    margin-top: 18px;
    display: grid;
    grid-template-columns: repeat(3,minmax(0,1fr));
    gap: 12px;
}

.playground-help > div {
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: white;
}

.playground-help strong,
.playground-help span { display: block; }

.playground-help strong {
    margin-bottom: 4px;
    font-size: .9rem;
}

.playground-help span {
    color: var(--muted);
    font-size: .82rem;
    line-height: 1.45;
}

@media (max-width: 980px) {
    .python-header-inner {
        padding: 12px 20px;
        flex-wrap: wrap;
    }

    .python-site-nav {
        width: 100%;
        margin-left: 0;
        overflow-x: auto;
    }

    .workspace-grid { grid-template-columns: 1fr; }

    .editor-panel {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }
}

@media (max-width: 680px) {
    .python-shell { width: calc(100% - 24px); }

    .python-header-inner { padding: 10px 14px; }

    .python-product-title span { display: none; }

    .python-site-nav a {
        padding: 7px 9px;
        font-size: .82rem;
    }

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

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

    .toolbar-actions { justify-content: flex-start; }

    .keyboard-hint { display: none; }

    .playground-help { grid-template-columns: 1fr; }
}

/* ============================================================
   Phase 2C — workspace usability
   ============================================================ */

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.file-area,
.panel-heading-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.file-label strong {
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.compact-button {
    min-height: 34px;
    padding: 5px 10px;
    font-size: .8rem;
}

.panel-action-button {
    padding: 4px 8px;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    background: white;
    color: var(--muted);
    cursor: pointer;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: 0;
}

.panel-action-button:disabled {
    cursor: default;
    opacity: .45;
}

.panel-action-button:hover:not(:disabled),
.panel-action-button:focus-visible {
    color: var(--text);
    border-color: #94a3b8;
    background: #f1f5f9;
}

.panel-action-button.copied {
    color: var(--success);
    border-color: #86efac;
    background: #f0fdf4;
}

.output-action-button {
    border-color: rgba(255,255,255,.18);
    background: rgba(255,255,255,.06);
    color: #cbd5e1;
}

.output-action-button:hover:not(:disabled),
.output-action-button:focus-visible {
    border-color: rgba(255,255,255,.32);
    background: rgba(255,255,255,.11);
    color: white;
}

.output-action-button.copied {
    color: #86efac;
    border-color: rgba(134,239,172,.45);
    background: rgba(34,197,94,.08);
}

.workspace-grid {
    --editor-share: 56%;
    grid-template-columns:
        minmax(300px, var(--editor-share))
        9px
        minmax(300px, 1fr);
}

.editor-panel {
    border-right: 0;
}

.workspace-divider {
    position: relative;
    z-index: 3;
    width: 9px;
    min-width: 9px;
    cursor: col-resize;
    touch-action: none;
    background: #eef2f7;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    outline: none;
}

.workspace-divider::before {
    content: "";
    position: absolute;
    inset: 0 -4px;
}

.workspace-divider:hover,
.workspace-divider:focus-visible,
.workspace-divider.is-dragging {
    background: #dbeafe;
    border-color: #93c5fd;
}

.divider-grip {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 3px;
    height: 34px;
    border-radius: 999px;
    background: #94a3b8;
    transform: translate(-50%, -50%);
}

.workspace-divider:hover .divider-grip,
.workspace-divider:focus-visible .divider-grip,
.workspace-divider.is-dragging .divider-grip {
    background: var(--accent);
}

body.is-resizing-workspace,
body.is-resizing-workspace * {
    cursor: col-resize !important;
    user-select: none !important;
}

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

    .workspace-divider {
        display: none;
    }

    .editor-panel {
        border-bottom: 1px solid var(--border);
    }
}

@media (max-width: 680px) {
    .file-area {
        width: 100%;
        justify-content: space-between;
    }

    .panel-heading-actions {
        gap: 6px;
    }
}

/* ============================================================
   Python Playground — Phase 2D-1
   File saving + modified state
   ============================================================ */

.file-label {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.modified-indicator {
    color: #d97706;
    font-size: 1.15rem;
    line-height: 1;
    font-weight: 900;
}

.save-control {
    position: relative;
}

.save-menu {
    position: absolute;
    z-index: 20;
    top: calc(100% + 6px);
    right: 0;
    min-width: 154px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    box-shadow: 0 12px 28px rgba(15, 23, 42, .14);
}

.save-menu[hidden] {
    display: none;
}

.save-menu button {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    text-align: left;
    font: inherit;
    font-size: .82rem;
    cursor: pointer;
}

.save-menu button:hover,
.save-menu button:focus-visible {
    background: var(--surface-soft);
    outline: none;
}

@media (max-width: 680px) {
    .save-control {
        flex: 0 0 auto;
    }
}
/* ============================================================
   Python Playground — Phase 2D-2B / 2D-2C
   ============================================================ */

.editor-panel {
    position: relative;
}

.editor-find-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.editor-find-bar[hidden] {
    display: none;
}

.editor-find-bar input {
    width: min(280px, 55%);
    min-height: 32px;
    padding: 5px 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    color: var(--text);
    font: inherit;
    font-size: .82rem;
    outline: none;
}

.editor-find-bar input:focus {
    border-color: #64748b;
    box-shadow: 0 0 0 2px rgba(100,116,139,.12);
}

.find-count {
    min-width: 58px;
    color: var(--muted);
    font-size: .78rem;
    text-align: center;
}

.editor-code-layer {
    position: relative;
    min-width: 0;
    min-height: 468px;
    overflow: hidden;
    background: white;
}

.syntax-highlight,
.code-editor {
    box-sizing: border-box;
    width: 100%;
    min-height: 468px;
    margin: 0;
    padding: 18px;
    border: 0;
    tab-size: 4;
    font: 14px/1.65 Consolas, monospace;
    letter-spacing: normal;
    white-space: pre;
    overflow-wrap: normal;
    word-break: normal;
}

.syntax-highlight {
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    pointer-events: none;
    color: #334155;
    background: white;
}

.code-editor {
    position: relative;
    z-index: 2;
    resize: none;
    outline: 0;
    overflow: auto;
    color: transparent;
    caret-color: #0f172a;
    background: transparent;
    -webkit-text-fill-color: transparent;
}

.code-editor::selection {
    background: rgba(59,130,246,.24);
    -webkit-text-fill-color: transparent;
}

.syntax-keyword {
    color: #7c3aed;
    font-weight: 600;
}

.syntax-builtin {
    color: #0369a1;
}

.syntax-string {
    color: #047857;
}

.syntax-comment {
    color: #64748b;
    font-style: italic;
}

.syntax-number {
    color: #b45309;
}

.syntax-decorator {
    color: #be185d;
}

.syntax-constant {
    color: #9333ea;
}

.autocomplete-menu {
    position: absolute;
    z-index: 30;
    left: 62px;
    top: 118px;
    width: min(260px, calc(100% - 80px));
    max-height: 220px;
    overflow: auto;
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    box-shadow: 0 12px 30px rgba(15,23,42,.16);
}

.autocomplete-menu[hidden] {
    display: none;
}

.autocomplete-option {
    display: block;
    width: 100%;
    padding: 7px 9px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--text);
    text-align: left;
    font: 13px/1.3 Consolas, monospace;
    cursor: pointer;
}

.autocomplete-option:hover,
.autocomplete-option.is-selected {
    background: #eef2ff;
}

.output-action-button.is-active {
    background: rgba(255,255,255,.12);
    color: white;
}

.output-console.no-wrap {
    white-space: pre;
    overflow-wrap: normal;
    word-break: normal;
    overflow-x: auto;
}

.console-truncation {
    margin-top: 10px;
    padding: 8px 10px;
    border: 1px solid rgba(251,191,36,.28);
    border-radius: 6px;
    color: #fde68a;
    background: rgba(146,64,14,.18);
}

.history-drawer {
    max-height: 220px;
    overflow: auto;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255,255,255,.1);
    background: rgba(15,23,42,.58);
}

.history-drawer[hidden] {
    display: none;
}

.history-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
    color: #e2e8f0;
    font-size: .8rem;
}

.history-list {
    display: grid;
    gap: 6px;
}

.history-empty {
    padding: 8px 0;
    color: #94a3b8;
    font-size: .8rem;
}

.history-item {
    display: grid;
    grid-template-columns: minmax(0,1fr) auto;
    gap: 8px;
    align-items: center;
    padding: 8px;
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 7px;
    background: rgba(255,255,255,.035);
}

.history-item-code {
    min-width: 0;
    overflow: hidden;
    color: #cbd5e1;
    font: 12px/1.35 Consolas, monospace;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item button {
    padding: 4px 7px;
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 5px;
    background: transparent;
    color: #bfdbfe;
    font: inherit;
    font-size: .72rem;
    cursor: pointer;
}

@media (max-width: 680px) {
    .editor-find-bar {
        flex-wrap: wrap;
    }

    .editor-find-bar input {
        width: calc(100% - 76px);
    }

    .autocomplete-menu {
        left: 54px;
        width: calc(100% - 68px);
    }
}