/* =========================================================
   Streaming Buffer Simulator
   Topic: 2.07 Applications that Make Use of the Internet
   ========================================================= */

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

.streaming-control-grid {
    display: grid;
    grid-template-columns: 1fr 1.15fr 1.15fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.streaming-control-card {
    display: grid;
    gap: 0.55rem;
    padding: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    background: white;
}

.streaming-control-card label {
    color: #334155;
    font-weight: 700;
}

.streaming-control-card select {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: white;
    color: #0f172a;
    font: inherit;
}

.streaming-range-row {
    display: grid;
    gap: 0.45rem;
}

.streaming-range-row input[type="range"] {
    width: 100%;
}

.streaming-range-row strong {
    color: #0f172a;
    font-size: 0.95rem;
}

.streaming-action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin: 1rem 0 1.25rem;
}

.streaming-secondary-btn {
    background: white;
    color: #334155;
    border: 1px solid #cbd5e1;
}

.streaming-secondary-btn:hover {
    background: #f8fafc;
    color: #0f172a;
    border-color: #94a3b8;
}

.streaming-main-grid {
    display: grid;
    grid-template-columns: minmax(270px, 0.8fr) minmax(300px, 1.2fr);
    gap: 1rem;
    align-items: stretch;
}

.streaming-buffer-card,
.streaming-status-card {
    padding: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    background: white;
}

.streaming-buffer-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    margin-bottom: 0.8rem;
}

.streaming-buffer-header h3,
.streaming-status-card h3 {
    margin: 0;
}

.streaming-buffer-header span {
    color: #475569;
    font-weight: 700;
}

.buffer-tank {
    position: relative;
    height: 300px;
    overflow: hidden;
    border: 2px solid #cbd5e1;
    border-radius: 22px;
    background:
        linear-gradient(to top, rgba(226, 232, 240, 0.55), rgba(248, 250, 252, 0.75));
}

.buffer-fill {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: 9.765625%;
    border-radius: 0 0 18px 18px;
    background: linear-gradient(180deg, #38bdf8, #2563eb);
    transition: height 0.5s ease;
}

.buffer-mark {
    position: absolute;
    right: 0;
    left: 0;
    z-index: 3;
    border-top: 2px dashed;
}

.buffer-mark span {
    position: absolute;
    right: 0.65rem;
    top: -1.8rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    font-size: 0.78rem;
    font-weight: 700;
}

.high-mark {
    bottom: 87.890625%;
    border-color: #16a34a;
}

.high-mark span {
    color: #166534;
}

.low-mark {
    bottom: 9.765625%;
    border-color: #ea580c;
}

.low-mark span {
    color: #9a3412;
}

.streaming-status-card {
    display: grid;
    align-content: start;
    gap: 0.9rem;
}

.streaming-status-card p {
    margin: 0;
}

.streaming-stat-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.streaming-stat-grid div {
    display: grid;
    gap: 0.2rem;
    padding: 0.8rem;
    border-radius: 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.streaming-stat-grid span {
    color: #64748b;
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.streaming-stat-grid strong {
    color: #0f172a;
    font-size: 1.12rem;
}

.streaming-flow-strip {
    display: grid;
    grid-template-columns: auto minmax(90px, 1fr) auto minmax(90px, 1fr) auto;
    align-items: center;
    gap: 0.6rem;
    margin-top: 1rem;
}

.flow-node {
    padding: 0.7rem 0.9rem;
    border-radius: 999px;
    background: white;
    border: 1px solid #cbd5e1;
    color: #334155;
    font-weight: 700;
    text-align: center;
}

.flow-arrow {
    position: relative;
    height: 4px;
    border-radius: 999px;
    background: #94a3b8;
}

.flow-arrow::after {
    content: "";
    position: absolute;
    right: -2px;
    top: 50%;
    width: 0;
    height: 0;
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
    border-left: 10px solid #94a3b8;
    transform: translateY(-50%);
}

.flow-arrow span {
    position: absolute;
    left: 50%;
    top: -1.9rem;
    transform: translateX(-50%);
    padding: 0.18rem 0.48rem;
    border-radius: 999px;
    background: white;
    border: 1px solid #e2e8f0;
    color: #475569;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}

.streaming-widget.is-running .flow-arrow {
    background:
        repeating-linear-gradient(
            90deg,
            #2563eb 0 18px,
            #bfdbfe 18px 32px
        );
    background-size: 64px 100%;
    animation: streamingFlow 0.8s linear infinite;
}

.streaming-widget.is-running .flow-arrow::after {
    border-left-color: #2563eb;
}

.streaming-widget.is-input-paused .flow-arrow:first-of-type {
    background: #cbd5e1;
    animation: none;
}

.streaming-widget.is-input-paused .flow-arrow:first-of-type::after {
    border-left-color: #cbd5e1;
}

@keyframes streamingFlow {
    from {
        background-position: 0 0;
    }

    to {
        background-position: 64px 0;
    }
}

@media (max-width: 850px) {
    .streaming-control-grid,
    .streaming-main-grid {
        grid-template-columns: 1fr;
    }

    .streaming-flow-strip {
        grid-template-columns: 1fr;
        gap: 0.85rem;
    }

    .flow-arrow {
        width: 4px;
        height: 42px;
        justify-self: center;
    }

    .flow-arrow::after {
        right: auto;
        left: 50%;
        top: auto;
        bottom: -2px;
        border-top: 10px solid #94a3b8;
        border-right: 7px solid transparent;
        border-left: 7px solid transparent;
        border-bottom: 0;
        transform: translateX(-50%);
    }

    .streaming-widget.is-running .flow-arrow::after {
        border-top-color: #2563eb;
        border-left-color: transparent;
    }

    .streaming-widget.is-input-paused .flow-arrow:first-of-type::after {
        border-top-color: #cbd5e1;
        border-left-color: transparent;
    }

    .flow-arrow span {
        left: calc(50% + 2.7rem);
        top: 50%;
        transform: translateY(-50%);
    }
}

@media (max-width: 520px) {
    .streaming-stat-grid {
        grid-template-columns: 1fr;
    }

    .streaming-buffer-header {
        display: grid;
        gap: 0.3rem;
    }

    .buffer-tank {
        height: 250px;
    }
}