.tts-page {
    --tts-soft: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.tts-admin-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 1.25rem 0 -0.5rem;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 750;
}

.tts-admin-toolbar form {
    margin: 0;
}

.tts-admin-toolbar .button {
    min-height: 2.4rem;
    padding: 0.45rem 0.7rem;
    font-size: 0.78rem;
}

.tts-upload-card {
    margin-bottom: 1.25rem;
}

.tts-upload-card > p {
    color: var(--muted);
    line-height: 1.5;
}

.admin-upload-form {
    display: grid;
    gap: 0.75rem;
}

.admin-upload-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 1rem;
}

.admin-upload-row input[type="file"] {
    width: 100%;
    min-height: 3rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--input-border);
    border-radius: 0.65rem;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
}

.admin-upload-help {
    color: var(--muted);
    line-height: 1.45;
}

.admin-upload-message {
    margin: 1rem 0 0;
    color: var(--accent-dark);
    font-size: 0.85rem;
}

.admin-upload-message.is-error,
.admin-login-error {
    color: var(--danger, #b91c1c);
}

.admin-login-page {
    max-width: 42rem;
}

.admin-login-card {
    max-width: 36rem;
    margin: 2rem auto 3rem;
}

.admin-login-card h1 {
    margin-bottom: 0.75rem;
}

.admin-login-form {
    display: grid;
    gap: 1rem;
    margin-top: 1.5rem;
}

.admin-login-form .button {
    justify-self: start;
    margin-top: 0.25rem;
}

.admin-login-error {
    margin: 1rem 0 0;
    font-size: 0.9rem;
}

.tts-hero {
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    gap: 2rem;
    margin: 1.5rem 0 1.75rem;
}

.tts-hero .utility-page-heading {
    gap: 0.7rem;
}

.tts-hero .utility-page-heading h1 {
    margin-bottom: 0;
}

.tts-card {
    max-width: 920px;
    padding: clamp(1rem, 3vw, 1.8rem);
    border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
    border-radius: 1rem;
    background: var(--surface);
    box-shadow: 0 1rem 2.5rem color-mix(in srgb, var(--ink) 8%, transparent);
}

.tts-card-heading,
.tts-result-heading,
.tts-progress-heading,
.tts-field-meta,
.tts-actions,
.tts-result-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.tts-card-heading {
    align-items: flex-start;
    margin-bottom: 1.35rem;
}

.tts-card-heading h2,
.tts-result-heading h2 {
    margin-bottom: 0;
}

.tts-field {
    display: grid;
    gap: 0.45rem;
}

.tts-field label,
.tts-queue-label {
    color: var(--ink);
    font-size: 0.9rem;
    font-weight: 750;
}

.tts-field input[type="text"],
.tts-field input[type="password"],
.tts-field textarea,
.tts-field select {
    width: 100%;
    border: 1px solid var(--input-border);
    border-radius: 0.65rem;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
}

.tts-field input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

.tts-range-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.tts-range-label output {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.tts-checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.tts-checkbox-label input[type="checkbox"] {
    width: auto;
    margin: 0;
    accent-color: var(--accent);
}

.tts-field input[type="text"],
.tts-field input[type="password"] {
    min-height: 3rem;
    padding: 0.7rem 0.9rem;
}

.tts-field textarea {
    min-height: 15rem;
    padding: 0.8rem 0.9rem;
    line-height: 1.55;
    resize: vertical;
}

.tts-field select {
    min-height: 3rem;
    padding: 0.65rem 0.75rem;
}

.tts-voice-picker {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.65rem;
}

.tts-voice-picker select {
    min-width: 0;
    word-spacing: 0.15em;
}

.tts-voice-picker select option {
    word-spacing: normal;
}

.tts-voice-preview {
    width: 3rem;
    height: 3rem;
    min-width: 3rem;
    padding: 0;
    border-radius: 50%;
    justify-content: center;
}

.tts-voice-preview:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.tts-field input[type="text"]:focus,
.tts-field input[type="password"]:focus,
.tts-field textarea:focus,
.tts-field select:focus {
    border-color: var(--accent);
    outline: 3px solid color-mix(in srgb, var(--accent) 25%, transparent);
}

.tts-field textarea[aria-invalid="true"] {
    border-color: var(--danger, #b91c1c);
}

.tts-field-meta {
    align-items: flex-start;
    color: var(--muted);
    font-size: 0.8rem;
}

.tts-field-meta small {
    max-width: 72%;
}

.tts-field-meta span {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.tts-field-meta span.is-over {
    color: var(--danger, #b91c1c);
    font-weight: 750;
}

.tts-processing-estimate {
    display: block;
    margin-top: 0.35rem;
    color: var(--muted);
    font-size: 0.8rem;
    line-height: 1.4;
}

.tts-controls {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(8rem, 0.55fr) minmax(10rem, 0.75fr) minmax(10rem, 0.75fr) minmax(13rem, 0.8fr);
    gap: 1rem;
    margin-top: 1rem;
}

.tts-field small,
.tts-queue-copy p {
    color: var(--muted);
    font-size: 0.8rem;
    line-height: 1.4;
}

.tts-queue-copy {
    align-self: end;
    min-height: 3rem;
    padding: 0.7rem 0.8rem;
    border-left: 3px solid var(--accent);
    background: var(--surface-alt);
}

.tts-queue-copy p {
    margin: 0;
}

.tts-queue-copy .tts-queue-label {
    margin-bottom: 0.25rem;
    color: var(--ink);
}

.tts-actions {
    align-items: flex-start;
    margin-top: 1.25rem;
}

.tts-submit {
    min-width: 11rem;
}

.tts-submit-action {
    display: grid;
    gap: 0.35rem;
    min-width: 11rem;
}

.tts-generation-count {
    color: var(--muted);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    text-align: center;
}

.tts-submit:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.tts-form-status {
    flex: 1;
    min-height: 1.5rem;
    margin: 0.55rem 0 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.tts-form-status.is-error {
    color: var(--danger, #b91c1c);
}

.tts-progress {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--line);
}

.tts-phase-progress {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.4rem;
    margin: 0 0 1rem;
    padding: 0;
    list-style: none;
}

.tts-phase-segment {
    min-width: 0;
    padding: 0.55rem 0.4rem;
    border: 1px solid var(--line);
    border-radius: 0.55rem;
    background: var(--surface-alt);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 750;
    text-align: center;
    transition: border-color 160ms ease, background-color 160ms ease, color 160ms ease;
}

.tts-phase-segment.is-complete {
    border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
    background: color-mix(in srgb, var(--accent) 12%, var(--surface));
    color: var(--accent-dark);
}

.tts-phase-segment.is-active {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--on-accent, #fff);
}

.tts-progress-heading {
    margin-bottom: 0.45rem;
    color: var(--muted);
    font-size: 0.85rem;
}

.tts-progress-status {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    white-space: nowrap;
}

.tts-progress-spinner {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
}

.tts-progress-spinner[hidden] {
    display: none;
}

.tts-progress-spinner-processing {
    color: var(--accent-dark);
}

.tts-progress-heading strong {
    color: var(--ink);
}

.tts-progress progress {
    width: 100%;
    height: 0.7rem;
    accent-color: var(--accent);
}

.tts-progress-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.85rem;
}

.tts-cancel {
    min-width: 9.5rem;
}

.tts-result {
    margin-top: 1.5rem;
    padding: 1.1rem;
    border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
    border-radius: 0.8rem;
    background: var(--tts-soft);
}

.tts-result-heading {
    align-items: flex-start;
    margin-bottom: 1rem;
}

.tts-result-heading > i {
    color: var(--accent-dark);
    font-size: 1.4rem;
}

.tts-waveform-player {
    --tts-waveform-accent: var(--accent, #3973b9);
    --tts-waveform-muted: color-mix(in srgb, var(--accent, #3973b9) 28%, var(--line));
    --tts-waveform-track: color-mix(in srgb, var(--accent, #3973b9) 8%, var(--surface));
    display: grid;
    gap: 0.4rem;
    padding: 0.5rem;
    border: 1px solid color-mix(in srgb, var(--accent) 18%, var(--line));
    border-radius: 0.7rem;
    background: color-mix(in srgb, var(--accent) 4%, var(--surface));
}

.tts-waveform-player[hidden] {
    display: none;
}

.tts-waveform-play {
    min-width: 0;
}

.tts-waveform-track {
    position: relative;
    min-height: 3.25rem;
    overflow: hidden;
    border-radius: 0.45rem;
    background: var(--tts-waveform-track);
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.tts-waveform-track.is-dragging {
    cursor: grabbing;
}

.tts-waveform-track:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent);
    outline-offset: 2px;
}

.tts-waveform-canvas {
    display: block;
    width: 100%;
    height: 3.25rem;
    pointer-events: none;
}

.tts-waveform-controls {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.4rem;
    justify-content: flex-start;
}

.tts-waveform-controls .button {
    flex: 0 0 2.35rem;
    width: 2.35rem;
    min-width: 2.35rem;
    min-height: 2.35rem;
    height: 2.35rem;
    padding: 0.3rem;
    border-radius: 0.5rem;
    font-size: 0.82rem;
}

.tts-waveform-play:disabled,
.tts-waveform-controls .button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.tts-waveform-time {
    color: var(--muted);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.tts-result audio {
    width: 100%;
}

.tts-result-actions {
    justify-content: flex-start;
    margin-top: 0.9rem;
}

.tts-audio-status,
.tts-share-status {
    color: var(--muted);
    font-size: 0.82rem;
}

.tts-share-status.is-error {
    color: var(--danger, #b91c1c);
}

.tts-ad {
    display: flex;
    align-items: center;
    justify-content: center;
    width: min(100%, 728px);
    min-height: 50px;
    margin: 1.25rem auto;
    overflow: hidden;
}

.tts-intro-ad {
    margin-top: 0;
}

.tts-ad iframe {
    display: block;
    flex: 0 0 auto;
    width: 320px;
    height: 50px;
    border: 0;
}

.tts-processing {
    max-width: 920px;
    margin: 1.8rem 0 0;
}

.tts-processing[hidden] {
    display: none;
}

.tts-processing-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.9rem;
}

.tts-processing-heading h2 {
    margin-bottom: 0;
}

.tts-processing-count {
    color: var(--muted);
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.tts-processing-list {
    display: grid;
    gap: 0.65rem;
}

.tts-processing-item {
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
    border-radius: 0.75rem;
    background: var(--surface);
}

.tts-processing-item-heading {
    display: flex;
    align-items: stretch;
}

.tts-processing-toggle {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 1rem;
    min-width: 0;
    padding: 0.85rem 0.95rem;
    border: 0;
    background: transparent;
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.tts-processing-toggle:hover {
    background: var(--surface-alt);
    color: var(--ink);
}

.tts-processing-toggle:focus-visible,
.tts-processing-toggle:active {
    color: var(--ink);
}

.tts-processing-toggle:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 25%, transparent);
    outline-offset: -3px;
}

.tts-processing-title-content {
    display: grid;
    flex: 1;
    gap: 0.2rem;
    min-width: 0;
}

.tts-processing-title {
    overflow: hidden;
    font-weight: 750;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tts-processing-details {
    color: var(--muted);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

.tts-processing-activity {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 0.45rem;
    color: var(--accent-dark);
    font-size: 0.78rem;
    font-weight: 750;
    white-space: nowrap;
}

.tts-processing-toggle > i {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 0.8rem;
}

.tts-processing-actions {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.85rem 0.95rem;
    border-top: 1px solid var(--line);
    background: var(--surface-alt);
}

.tts-processing-actions[hidden] {
    display: none;
}

.tts-processing-cancel {
    min-width: 9.5rem;
    color: var(--danger, #b91c1c);
}

.tts-history {
    max-width: 920px;
    margin: 1.25rem 0 3rem;
}

.tts-history-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.9rem;
}

.tts-history-heading h2 {
    margin-bottom: 0;
}

.tts-history-count {
    color: var(--muted);
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.tts-history-empty {
    margin: 0;
    padding: 1rem;
    border: 1px dashed var(--line);
    border-radius: 0.75rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.tts-history-list {
    display: grid;
    gap: 0.65rem;
}

.tts-history-item {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 0.75rem;
    background: var(--surface);
}

.tts-history-item-failed {
    border-color: var(--danger, #b91c1c);
}

.tts-history-item-failed .tts-history-generated {
    color: var(--danger, #b91c1c);
}

.tts-history-terminal-error {
    flex: 1 1 100%;
    min-width: 0;
    margin: 0;
    color: var(--danger, #b91c1c);
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.tts-history-item-heading {
    display: flex;
    align-items: stretch;
    gap: 0.4rem;
}

.tts-history-toggle {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-width: 0;
    padding: 0.85rem 0.95rem;
    border: 0;
    background: transparent;
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.tts-history-toggle:hover {
    background: var(--surface-alt);
    color: var(--ink);
}

.tts-history-toggle:focus-visible,
.tts-history-toggle:active {
    color: var(--ink);
}

.tts-history-toggle:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 25%, transparent);
    outline-offset: -3px;
}

.tts-history-title-content {
    display: grid;
    flex: 1;
    gap: 0.2rem;
    min-width: 0;
}

.tts-history-title {
    overflow: hidden;
    font-weight: 750;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tts-history-generated {
    color: var(--muted);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

.tts-history-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem 0.85rem;
    color: var(--muted);
    font-size: 0.74rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.4;
}

.tts-history-stat {
    white-space: nowrap;
}

.tts-history-stat-label {
    font-weight: 750;
}

.tts-history-stat-value {
    color: var(--ink);
}

.tts-history-toggle > i {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 0.8rem;
}

.tts-history-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.65rem;
    padding: 0.85rem 0.95rem;
    border-top: 1px solid var(--line);
    background: var(--surface-alt);
}

.tts-history-actions[hidden] {
    display: none;
}

.tts-history-actions .button {
    min-height: 2.5rem;
}

.tts-history-actions audio {
    flex: 1 1 100%;
    width: 100%;
    min-width: 16rem;
}

.tts-history-actions .tts-waveform-player {
    flex: 1 1 100%;
    min-width: 16rem;
}

.tts-history-actions .tts-waveform-controls .button {
    min-height: 2.35rem;
    height: 2.35rem;
}

.tts-history-delete {
    color: var(--danger, #b91c1c);
}

.tts-history-status {
    min-height: 1.4rem;
    margin: 0.65rem 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.tts-history-status.is-error {
    color: var(--danger, #b91c1c);
}

.tts-share-page .tts-hero {
    margin-bottom: 1rem;
}

.tts-share-card {
    max-width: 760px;
}

.tts-share-card p {
    color: var(--muted);
    line-height: 1.55;
}

.tts-share-card audio {
    width: 100%;
    margin: 0.75rem 0 0.5rem;
}

.tts-share-card .tts-waveform-player {
    margin: 0.75rem 0 0.5rem;
}

.tts-share-card .button {
    margin-top: 0.5rem;
}

.tts-share-card .tts-waveform-controls .button {
    margin-top: 0;
}

.tts-share-error {
    color: var(--danger, #b91c1c) !important;
}

@media (max-width: 700px) {
    .tts-admin-toolbar,
    .admin-upload-row {
        align-items: stretch;
        grid-template-columns: 1fr;
        flex-direction: column;
    }

    .tts-hero {
        align-items: flex-start;
        flex-direction: column;
        gap: 1rem;
    }

    .tts-controls {
        grid-template-columns: 1fr;
    }

    .tts-actions,
    .tts-result-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .tts-progress-actions {
        align-items: stretch;
    }

    .tts-progress-actions .button {
        width: 100%;
        justify-content: center;
    }

    .tts-submit-action,
    .tts-submit,
    .tts-result-actions .button,
    .admin-upload-row .button {
        width: 100%;
        justify-content: center;
    }

    .tts-form-status {
        margin-top: 0;
    }

    .tts-history-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.35rem;
    }

    .tts-processing-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.35rem;
    }

    .tts-processing-toggle {
        align-items: flex-start;
    }

    .tts-processing-activity {
        align-self: center;
    }

    .tts-history-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .tts-history-actions .button {
        width: 100%;
        justify-content: center;
    }

    .tts-processing-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .tts-processing-actions .button {
        width: 100%;
        justify-content: center;
    }

    .tts-history-actions audio {
        min-width: 0;
    }

    .tts-history-actions .tts-waveform-player {
        min-width: 0;
    }

    .tts-history-actions .tts-waveform-controls {
        flex-direction: row;
    }

    .tts-history-actions .tts-waveform-controls .button {
        width: 2.35rem;
        min-width: 2.35rem;
    }
}

@media (min-width: 768px) {
    .tts-ad {
        min-height: 90px;
    }

    .tts-ad iframe {
        width: 728px;
        height: 90px;
    }
}

@media (max-width: 480px) {
    .tts-waveform-player {
        gap: 0.3rem;
        padding: 0.4rem;
    }

    .tts-waveform-track,
    .tts-waveform-canvas {
        min-height: 3rem;
        height: 3rem;
    }

    .tts-card-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .tts-field-meta {
        flex-direction: column;
        gap: 0.3rem;
    }

    .tts-field-meta small {
        max-width: none;
    }
}
