#time-control,
.preview-time-control {
    width: 530px;
    max-width: calc(100vw - 40px);
    height: var(--widget-bar-height, 56px);
    padding: 0 10px;
    box-sizing: border-box;

    display: flex;
    align-items: center;
    gap: 10px;

    background: var(--widget-bar-bg, #FFFDF5);
    border: var(--widget-bar-border, 2px solid #1A1A1A);
    border-radius: var(--widget-bar-radius, 6px);
    box-shadow: var(--widget-bar-shadow, 4px 4px 0 rgba(26, 26, 26, 0.18));
    color: var(--widget-bar-color, #1A1A1A);
    pointer-events: auto;
}

#time-control {
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;

    --tc-side-reserve: 200px;
    max-width: calc(100vw - var(--tc-side-reserve) * 2);

    --tc-snap-zone: 4%;
}

#time-control[hidden] { display: none; }

#time-control.is-locked .tc-pause,
#time-control.is-locked .tc-scrubber {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

#time-control.is-back-locked .tc-back-btn {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

#time-control.is-calculating .tc-back-btn,
#time-control.is-calculating .tc-pause,
#time-control.is-calculating .tc-scrubber,
#time-control.is-calculating .tc-readout,
.preview-time-control.is-calculating .tc-back-btn,
.preview-time-control.is-calculating .tc-pause,
.preview-time-control.is-calculating .tc-scrubber,
.preview-time-control.is-calculating .tc-readout {
    display: none;
}

.tc-busy {
    display: none;
}

#time-control.is-calculating .tc-busy,
.preview-time-control.is-calculating .tc-busy {
    flex: 1 0 0;
    min-width: 1px;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.tc-busy__spinner {
    width: 18px;
    height: 18px;
    flex-shrink: 0;

    border: 2px solid var(--color-border, rgba(26, 26, 26, 0.15));
    border-top-color: var(--color-text, #1A1A1A);
    border-radius: 50%;
    animation: tc-busy-spin 0.8s linear infinite;
}

@keyframes tc-busy-spin {
    to { transform: rotate(360deg); }
}

.tc-busy__label {
    min-width: 0;
    font-family: var(--font-family);
    font-size: 12.5px;
    font-weight: 500;
    color: var(--color-text-secondary, #43423D);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (prefers-reduced-motion: reduce) {
    .tc-busy__spinner { animation-duration: 1.6s; }
}

.tc-speed-dial {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    width: 54px;
    padding: 0 10px 0 12px;
    gap: 4px;

    border: 1px solid var(--color-border-strong, rgba(26, 26, 26, 0.20));
    border-radius: 5px;
    background: var(--color-surface, #FFFDF5);
    color: var(--color-text-secondary, #43423D);

    font-family: var(--font-family);
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    flex-shrink: 0;

    transition: background 120ms ease-out, color 120ms ease-out, border-color 120ms ease-out;
}

.tc-speed-dial:hover {
    background: var(--color-surface-hover, #EDE9D9);
    color: var(--color-text, #1A1A1A);
}

.tc-speed-dial.engaged {
    background: var(--color-success, #1F8F4E);
    border-color: var(--color-success-border, #0F5C4A);
    color: var(--color-white, #FFFDF5);
}

.tc-speed-dial.engaged:hover {
    background: var(--color-success-hover, #177A40);
}

.tc-speed-dial .tc-speed-chev {
    width: 12px;
    height: 12px;
    transition: transform 120ms ease-out;
}

.tc-speed-dial.engaged .tc-speed-chev {
    transform: rotate(180deg);
}

.tc-pause {
    width: 44px;
    height: 32px;
    padding: 0;

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

    border: 1px solid var(--color-success-border, #0F5C4A);
    border-radius: 5px;
    background: var(--color-success, #1F8F4E);
    color: var(--color-white, #FFFDF5);

    cursor: pointer;
    flex-shrink: 0;
    transition: background 120ms ease-out, transform 80ms;
}

.tc-pause:hover { background: var(--color-success-hover, #177A40); }
.tc-pause:active { transform: scale(0.96); }

.tc-pause svg { width: 16px; height: 16px; pointer-events: none; }

.tc-pause.paused {
    background: var(--color-surface, #FFFDF5);
    border-color: var(--color-border-strong, rgba(26, 26, 26, 0.40));
    color: var(--color-text, #1A1A1A);
}
.tc-pause.paused:hover { background: var(--color-surface-hover, #EDE9D9); }

.tc-scrubber {
    flex: 1 0 0;
    min-width: 1px;
    height: 5px;
    background: rgba(26, 26, 26, 0.10);
    border-radius: 3px;
    position: relative;
    cursor: pointer;
    align-self: center;

    margin: 14px 4px;
}
.tc-scrubber::before {
    content: "";
    position: absolute;
    inset: -14px 0;
}

.tc-scrubber-fill {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 0%;
    background: var(--color-success, #1F8F4E);
    border-radius: 3px;
    pointer-events: none;
}

.tc-scrubber-handle {
    position: absolute;
    width: 13px;
    height: 13px;
    top: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: var(--color-text, #1A1A1A);
    border: 2px solid var(--color-surface, #FFFDF5);
    box-shadow: 0 0 0 1px var(--color-text, #1A1A1A);
    pointer-events: none;
    will-change: left;
}

.tc-scrubber.dragging .tc-scrubber-handle {
    transform: translate(-50%, -50%) scale(1.1);
}

.tc-readout {
    display: inline-grid;
    justify-items: end;
    flex-shrink: 0;
    font-family: var(--font-display, 'Space Grotesk', system-ui, sans-serif);
    font-size: 13px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--color-text, #1A1A1A);
    white-space: nowrap;
}

.tc-readout > * { grid-area: 1 / 1; }
.tc-readout__ghost { visibility: hidden; }

.tc-back-btn {
    width: 88px;
    height: 32px;
    padding: 0 8px;
    gap: 6px;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;

    border: 1px solid var(--color-border-strong, rgba(26, 26, 26, 0.20));
    border-radius: 5px;
    background: var(--color-surface, #FFFDF5);
    color: var(--color-text-secondary, #43423D);
    cursor: pointer;

    transition: background 120ms ease-out, color 120ms ease-out, transform 80ms;
}

.tc-back-btn:hover {
    background: var(--color-surface-hover, #EDE9D9);
    color: var(--color-text, #1A1A1A);
}
.tc-back-btn:active { transform: scale(0.96); }

.tc-back-btn svg { width: 12px; height: 12px; flex-shrink: 0; }

.tc-back-btn-label {
    font-family: var(--font-family);
    font-size: 11.5px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
}

.tc-speed-popover {
    position: fixed;
    z-index: 61;

    box-sizing: border-box;
    padding: 14px 18px 12px;

    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 5px;

    background: var(--color-surface, #FFFDF5);
    border: 1.5px solid var(--color-text, #1A1A1A);
    border-radius: 12px;
    box-shadow: 3px 3px 0 rgba(26, 26, 26, 0.18);
    pointer-events: auto;
}

.tc-speed-popover[hidden] { display: none; }

.tc-speed-popover .tc-speed-cell {
    width: 54px;
    height: 32px;
    padding: 0 10px;

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

    border: 1px solid var(--color-border-strong, rgba(26, 26, 26, 0.20));
    border-radius: 5px;
    background: var(--color-surface, #FFFDF5);
    color: var(--color-text-secondary, #43423D);

    font-family: var(--font-family);
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background 120ms ease-out, color 120ms ease-out, border-color 120ms ease-out;
}

.tc-speed-popover .tc-speed-cell:hover {
    background: var(--color-surface-hover, #EDE9D9);
    color: var(--color-text, #1A1A1A);
}

.tc-speed-popover .tc-speed-cell.active {
    background: var(--color-success, #1F8F4E);
    color: var(--color-white, #FFFDF5);
    border-color: var(--color-success-border, #0F5C4A);
}

.tc-speed-popover .tc-speed-cell.active:hover {
    background: var(--color-success-hover, #177A40);
}

.preview-with-popover {
    position: relative;
    display: inline-block;
}
.preview-with-popover .tc-speed-popover {
    position: absolute;
    right: -1.5px;
    bottom: calc(100% + 6px);
    margin: 0;
}

@media (max-width: 600px) {
    #time-control {
        width: calc(100vw - 24px);
        gap: 6px;
        padding: 6px 8px;
    }
    .tc-readout { font-size: 12px; }
    .tc-speed-dial { width: 48px; padding: 0 6px 0 8px; }
    .tc-pause { width: 36px; }
    .tc-back-btn { width: 36px; padding: 0; justify-content: center; gap: 0; }
    .tc-back-btn-label { display: none; }
}
