.stack-widget {
    margin: 1.5rem 0;
    padding: 1.25rem;
    border: 1px solid #dbe4f0;
    border-radius: 24px;
    background: #ffffff;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

.stack-widget-toolbar,
.stack-preset-row,
.stack-widget-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 0.75rem;
}

.stack-widget-toolbar {
    justify-content: space-between;
}

.stack-value-field {
    display: grid;
    gap: 0.35rem;
    flex: 1 1 220px;
}

.stack-value-field span,
.stack-label {
    color: #64748b;
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.stack-value-field input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #cbd5e1;
    border-radius: 14px;
    background: #ffffff;
    color: #0f172a;
    font: inherit;
    padding: 0.7rem 0.8rem;
}

.stack-widget-actions button,
.stack-preset-btn {
    appearance: none;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    background: #f8fafc;
    color: #334155;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    padding: 0.65rem 1rem;
    transition:
        transform 0.18s ease,
        border-color 0.18s ease,
        background 0.18s ease,
        box-shadow 0.18s ease;
}

.stack-widget-actions button:hover,
.stack-preset-btn:hover {
    transform: translateY(-1px);
    border-color: #64748b;
}

.stack-preset-row {
    margin-top: 1rem;
}

.stack-preset-btn.is-active {
    border-color: #6366f1;
    background: #eef2ff;
    color: #312e81;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.10);
}

.stack-widget-layout {
    display: grid;
    grid-template-columns:
        minmax(240px, 0.9fr)
        minmax(280px, 1.1fr)
        minmax(220px, 0.85fr);
    gap: 1rem;
    margin-top: 1rem;
}

.stack-visual-card,
.stack-status-card,
.stack-history-card {
    min-width: 0;
    padding: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    background: #f8fafc;
}

.stack-visual-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.8rem;
}

.stack-visual {
    min-height: 330px;
    display: flex;
    flex-direction: column-reverse;
    justify-content: flex-start;
    gap: 0.45rem;
    padding: 1rem 1rem 0;
    border-right: 4px solid #94a3b8;
    border-left: 4px solid #94a3b8;
    background: #ffffff;
}

.stack-visual-item,
.stack-visual-empty-slot {
    min-height: 48px;
    display: grid;
    place-items: center;
    border-radius: 12px;
}

.stack-visual-item {
    border: 1px solid #c7d2fe;
    background: #eef2ff;
    color: #312e81;
    font-weight: 800;
    animation: stackPushIn 0.34s ease both;
}

.stack-visual-item.is-top {
    border-color: #6366f1;
    background: #e0e7ff;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.stack-visual-empty-slot {
    border: 1px dashed #dbe4f0;
    color: #94a3b8;
    font-size: 0.8rem;
}

.stack-base-line {
    padding-top: 0.45rem;
    border-top: 4px solid #475569;
    color: #475569;
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-align: center;
    text-transform: uppercase;
}

.stack-status-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.7rem;
    margin-top: 0.75rem;
}

.stack-status-grid > div {
    padding: 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    background: #ffffff;
}

.stack-status-grid span {
    display: block;
    color: #64748b;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.035em;
    text-transform: uppercase;
}

.stack-status-grid strong {
    display: block;
    margin-top: 0.25rem;
    color: #0f172a;
    overflow-wrap: anywhere;
}

.stack-message-box {
    margin-top: 0.85rem;
    padding: 0.85rem;
    border-left: 4px solid #6366f1;
    border-radius: 0 14px 14px 0;
    background: #eef2ff;
    color: #312e81;
}

.stack-message-box.is-error {
    border-left-color: #dc2626;
    background: #fef2f2;
    color: #7f1d1d;
}

.stack-message-box.is-success {
    border-left-color: #16a34a;
    background: #f0fdf4;
    color: #14532d;
}

.stack-history {
    max-height: 320px;
    margin: 0.75rem 0 0;
    padding-left: 1.4rem;
    overflow-y: auto;
}

.stack-history li {
    margin-bottom: 0.5rem;
    color: #334155;
}

.stack-history li:first-child {
    font-weight: 800;
}

.stack-concept-diagram {
    width: min(320px, 100%);
    margin: 1.25rem auto;
}

.stack-concept-top,
.stack-concept-base {
    color: #64748b;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-align: center;
    text-transform: uppercase;
}

.stack-concept-item {
    margin: 0.35rem 0;
    padding: 0.7rem;
    border: 1px solid #c7d2fe;
    border-radius: 12px;
    background: #eef2ff;
    color: #312e81;
    font-weight: 800;
    text-align: center;
}

.stack-concept-newest {
    border-color: #6366f1;
    background: #e0e7ff;
}

@keyframes stackPushIn {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

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

    .stack-history-card {
        grid-column: 1 / -1;
    }
}

@media (max-width: 680px) {
    .stack-widget-layout {
        grid-template-columns: 1fr;
    }

    .stack-history-card {
        grid-column: auto;
    }

    .stack-status-grid {
        grid-template-columns: 1fr;
    }

    .stack-widget-toolbar {
        align-items: stretch;
    }
}

@media (max-width: 440px) {
    .stack-widget {
        padding: 1rem;
        border-radius: 20px;
    }

    .stack-widget-actions button,
    .stack-preset-btn {
        flex: 1 1 auto;
    }
}