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

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

.fsm-input-btn,
.fsm-reset-btn {
    border: none;
    border-radius: 999px;
    padding: 0.65rem 1rem;
    font-weight: 700;
    cursor: pointer;
    background: #0f172a;
    color: white;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.fsm-input-btn:hover,
.fsm-reset-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.18);
}

.fsm-reset-btn {
    background: #5b5fa8;
}

.fsm-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.75fr);
    gap: 1rem;
    align-items: stretch;
}

.fsm-diagram-card,
.fsm-info-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 22px;
    padding: 1rem;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.05);
}

.fsm-mini-label,
.fsm-label {
    display: inline-block;
    margin: 0 0 0.75rem;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 800;
    color: #64748b;
}

/* New readable diagram layout */
.fsm-diagram {
    display: grid;
    grid-template-columns: repeat(4, minmax(130px, 1fr));
    gap: 1rem;
    align-items: stretch;

    height: auto;
    min-height: auto;
    overflow: visible;

    padding: 1.25rem;
    border-radius: 18px;
    background:
        radial-gradient(circle at 10% 20%, rgba(91, 95, 168, 0.08), transparent 30%),
        radial-gradient(circle at 90% 80%, rgba(230, 0, 79, 0.06), transparent 30%),
        #ffffff;
    border: 1px solid #e2e8f0;
}

/* Hide the old SVG arrows because they are the source of the overlap */
.fsm-svg {
    display: none !important;
}

.fsm-state {
    position: static;

    width: 100%;
    height: auto;
    min-height: 150px;

    border-radius: 24px;

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

    text-align: center;
    padding: 1rem;
    box-sizing: border-box;

    background: #eff6ff;
    border: 3px solid #bfdbfe;
    color: #1e3a8a;

    font-weight: 850;
    line-height: 1.2;

    box-shadow: 0 12px 26px rgba(37, 99, 235, 0.08);
    transition: transform 0.25s ease, border-color 0.25s ease, background 0.25s ease;
}

.fsm-state::before {
    display: block;
    margin-bottom: 0.55rem;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;

    background: rgba(91, 95, 168, 0.10);
    color: #4b4f9c;

    font-size: 0.72rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.fsm-state::after {
    display: block;
    margin-top: 0.65rem;

    color: #475569;
    font-size: 0.78rem;
    font-weight: 800;
    line-height: 1.35;
}

.fsm-state-waiting::before {
    content: "Start state";
}

.fsm-state-waiting::after {
    content: "validCard → Card accepted\A invalidCard → Waiting";
    white-space: pre-line;
}

.fsm-state-card::before {
    content: "After valid card";
}

.fsm-state-card::after {
    content: "scanBook → Borrowing item\A finish → Finished";
    white-space: pre-line;
}

.fsm-state-borrowing::before {
    content: "Items being scanned";
}

.fsm-state-borrowing::after {
    content: "scanBook → stay here\A finish → Finished";
    white-space: pre-line;
}

.fsm-state-finished::before {
    content: "Final state";
}

.fsm-state-finished::after {
    content: "Session complete";
}

.fsm-state.active {
    transform: translateY(-3px);
    background: #fff7ed;
    border-color: #fb923c;
    color: #7c2d12;
    box-shadow:
        0 0 0 4px rgba(251, 146, 60, 0.12),
        0 14px 30px rgba(251, 146, 60, 0.14);
}

.fsm-state.final {
    border-style: double;
    border-width: 6px;
}

.fsm-info-card h3 {
    margin: 0.2rem 0 0.7rem;
    color: #0f172a;
    font-size: clamp(1.6rem, 3vw, 2.1rem);
    line-height: 1.15;
}

.fsm-info-card p {
    line-height: 1.55;
}

.fsm-output-box {
    margin-top: 1rem;
    padding: 0.85rem 1rem;
    border-radius: 16px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #14532d;
    font-weight: 700;
}

.fsm-output-box strong {
    display: block;
    margin-top: 0.25rem;
    font-size: 1.15rem;
}

.fsm-table {
    margin-top: 1rem;
    margin-bottom: 0;
}

.fsm-table tr.active td {
    background: #fff7ed !important;
    color: #7c2d12;
    font-weight: 800;
}

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

/* Tablet */
@media (max-width: 820px) {
    .fsm-diagram {
        grid-template-columns: repeat(2, minmax(130px, 1fr));
    }

    .fsm-state {
        min-height: 140px;
    }
}

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

    .fsm-toolbar {
        gap: 0.5rem;
    }

    .fsm-input-btn,
    .fsm-reset-btn {
        width: 100%;
    }

    .fsm-diagram {
        grid-template-columns: 1fr;
    }

    .fsm-state {
        min-height: 130px;
    }
}