.scp-widget {
    margin: 1.5rem 0;
    padding: 1.25rem;
    border-radius: 24px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

.scp-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.scp-tab,
.scp-controls button {
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    padding: 0.65rem 1rem;
    background: white;
    color: #334155;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
    transition: all 0.2s ease;
}

.scp-tab:hover,
.scp-controls button:hover {
    transform: translateY(-2px);
    background: #0f172a;
    color: white;
    border-color: #0f172a;
}

.scp-tab.active {
    background: #5b5fa8;
    color: white;
    border-color: #5b5fa8;
}

.scp-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(340px, 0.95fr);
    gap: 1rem;
    align-items: stretch;
}

.scp-chart-card,
.scp-code-card,
.scp-explain-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 22px;
    padding: 1rem;
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.06);
}

.scp-mini-label {
    margin: 0 0 0.8rem;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 900;
    color: #64748b;
}

/* New readable chart layout */
.scp-chart {
    display: grid;
    grid-template-columns: repeat(3, minmax(130px, 1fr));
    grid-template-areas:
        "top top top"
        "arrow1 arrow2 arrow3"
        "input choose output"
        "param1 param2 param3"
        "param4 param4 param4";
    gap: 0.85rem;
    align-items: stretch;

    min-height: auto;
    padding: 1.25rem;
    border-radius: 20px;
    background:
        radial-gradient(circle at top left, rgba(91, 95, 168, 0.08), transparent 35%),
        linear-gradient(180deg, #ffffff, #eef2ff);
    border: 1px solid #e0e7ff;
    overflow: visible;
}

/* The old SVG lines are hidden because they caused overlap */
.scp-lines {
    display: none !important;
}

.scp-module-row {
    display: contents;
}

.scp-module {
    position: static;
    z-index: auto;

    display: flex;
    align-items: center;
    justify-content: center;

    min-width: 0;
    min-height: 78px;
    padding: 0.9rem 1rem;

    border-radius: 18px;
    background: #ffffff;
    border: 2px solid #c7d2fe;
    color: #312e81;

    font-weight: 900;
    text-align: center;
    line-height: 1.25;

    box-shadow: 0 10px 22px rgba(49, 46, 129, 0.08);
    transition: all 0.25s ease;
}

.scp-top {
    grid-area: top;
    width: min(100%, 360px);
    justify-self: center;
    margin: 0;

    min-height: 86px;
    background: #eef2ff;
    border-color: #818cf8;
    font-size: 1.1rem;
}

.scp-module-row .scp-module:nth-child(1) {
    grid-area: input;
}

.scp-module-row .scp-module:nth-child(2) {
    grid-area: choose;
}

.scp-module-row .scp-module:nth-child(3) {
    grid-area: output;
}

/* Simple visual arrows that cannot overlap */
.scp-chart::before,
.scp-chart::after {
    display: none;
}

.scp-module-row::before,
.scp-module-row::after {
    display: none;
}

.scp-param {
    position: static;
    z-index: auto;

    display: flex;
    align-items: center;
    justify-content: center;

    min-height: 52px;
    padding: 0.65rem 0.75rem;

    border-radius: 16px;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    color: #7c2d12;

    font-size: 0.82rem;
    font-weight: 900;
    text-align: center;
    line-height: 1.25;

    box-shadow: 0 6px 16px rgba(124, 45, 18, 0.06);
    transition: all 0.25s ease;
}

.scp-param-a {
    grid-area: param1;
}

.scp-param-b {
    grid-area: param2;
    transform: none;
}

.scp-param-c {
    grid-area: param3;
}

.scp-param-d {
    grid-area: param4;
    justify-self: center;
    width: min(100%, 420px);
}

/* Add non-overlapping arrow cards */
.scp-chart .scp-top::after {
    content: "calls lower-level modules";
    display: block;
    margin-top: 0.45rem;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    background: rgba(91, 95, 168, 0.10);
    color: #4b4f9c;
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.03em;
}

.scp-chart-card .scp-chart > .scp-param-a::before,
.scp-chart-card .scp-chart > .scp-param-b::before,
.scp-chart-card .scp-chart > .scp-param-c::before,
.scp-chart-card .scp-chart > .scp-param-d::before {
    display: block;
    margin-right: 0.35rem;
    color: #9a3412;
}

.scp-param-a::before {
    content: "Input:";
}

.scp-param-b::before {
    content: "Uses:";
}

.scp-param-c::before {
    content: "Returns:";
}

.scp-param-d::before {
    content: "Output:";
}

/* Code panel */
.scp-code-card pre,
.scp-widget pre {
    margin: 0;
    white-space: pre-wrap;
    background: #0f172a;
    color: #e5e7eb;
    padding: 1rem;
    border-radius: 18px;
    min-height: 260px;
    overflow: auto;
    font-size: 0.92rem;
    line-height: 1.55;
}

.scp-code-card code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

/* Explanation panel */
.scp-explain-card {
    margin-top: 1rem;
}

.scp-step-counter {
    margin: 0;
    color: #64748b;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.78rem;
}

.scp-explain-card h3 {
    margin: 0.25rem 0 0.4rem;
    color: #0f172a;
}

.scp-explain-card p {
    margin-bottom: 0;
}

.scp-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 1rem;
}

/* Stage highlighting */
.scp-widget.stage-module [data-node="main"],
.scp-widget.stage-procedures .scp-module,
.scp-widget.stage-parameters .scp-param {
    transform: translateY(-2px);
    filter: saturate(1.15);
}

.scp-widget.stage-module [data-node="main"],
.scp-widget.stage-procedures .scp-module {
    border-color: #e6004f;
    box-shadow:
        0 0 0 4px rgba(230, 0, 79, 0.08),
        0 12px 28px rgba(230, 0, 79, 0.14);
}

.scp-widget.stage-calls .scp-module {
    border-color: #5b5fa8;
    background: #f5f3ff;
}

.scp-widget.stage-calls .scp-top {
    border-color: #5b5fa8;
}

.scp-widget.stage-parameters .scp-param {
    background: #f0fdf4;
    border-color: #bbf7d0;
    color: #14532d;
    box-shadow:
        0 0 0 4px rgba(34, 197, 94, 0.08),
        0 12px 26px rgba(21, 128, 61, 0.10);
}

.scp-widget.stage-chart .scp-chart {
    border-color: #c7d2fe;
}

.scp-widget.stage-chart .scp-module,
.scp-widget.stage-chart .scp-param {
    box-shadow: 0 10px 22px rgba(49, 46, 129, 0.08);
}

/* Medium screens */
@media (max-width: 1100px) {
    .scp-layout {
        grid-template-columns: 1fr;
    }
}

/* Tablet */
@media (max-width: 760px) {
    .scp-chart {
        grid-template-columns: 1fr;
        grid-template-areas:
            "top"
            "input"
            "param1"
            "choose"
            "param2"
            "param3"
            "output"
            "param4";
    }

    .scp-top,
    .scp-param-d {
        width: 100%;
        max-width: none;
    }
}

/* Mobile */
@media (max-width: 560px) {
    .scp-widget {
        padding: 0.9rem;
    }

    .scp-toolbar,
    .scp-controls {
        gap: 0.5rem;
    }

    .scp-tab,
    .scp-controls button {
        width: 100%;
        justify-content: center;
    }

    .scp-code-card pre,
    .scp-widget pre {
        font-size: 0.82rem;
        min-height: 220px;
    }
}