/*
 * Trim levels, the faded preview and the status card (issue #15, spec R-8.3
 * to R-8.5). Consumes public/css/tokens.css only; nothing is hard-coded
 * except the shadow (as in lab.css and selection-menu.css).
 *
 * The preview uses the ghost treatment (R-5.1: the fade on the text colour,
 * `--te-ghost-opacity`) under its own class, `te-trim-faded`, so a trim
 * preview is never confused with a user ghost (`te-ghost`) in the DOM or in
 * the model. The card's signature is a one-line meter: the document as a
 * bar, the part that would go drawn with the same fade as the faded words.
 */

/* ---- Faded preview (R-8.4) ---- */

.te-trim-faded {
    color: color-mix(in srgb, currentColor calc(var(--te-ghost-opacity) * 100%), transparent);
}

@supports not (color: color-mix(in srgb, red 50%, transparent)) {
    .te-trim-faded {
        opacity: var(--te-ghost-opacity);
    }
}

/* Clickable to keep only while the card is shown. */
[data-te-trimming] .te-trim-faded {
    cursor: pointer;
}

[data-te-trimming] .te-trim-faded:hover {
    text-decoration: underline dotted var(--te-color-accent-soft) 1px;
    text-underline-offset: 0.22em;
}

/* The walk-through cursor: still faded, outlined in the accent. */
.te-trim-current {
    border-radius: 2px;
    box-shadow: 0 0 0 1px var(--te-color-accent);
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
}

/* ---- Level buttons in the Lab popover (R-8.3) ---- */

.te-lab-trim {
    align-items: center;
    padding-top: 0.625rem;
    border-top: 1px solid var(--te-color-panel-border);
}

/* The radio group's name ("Trim"), for assistive technology only: the video
   shows the five buttons with no label above them (4:56 to 5:30). */
.te-trim-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* One row of five equal buttons, the target under the name, as in the
   video; only a window too narrow for the popover's full width wraps it. */
.te-trim-levels {
    display: flex;
    flex: 1 1 100%;
    flex-wrap: nowrap;
    gap: 0.25rem;
    min-width: 0;
}

@media (max-width: 34rem) {
    .te-trim-levels {
        flex-wrap: wrap;
    }
}

.te-lab .te-trim-level {
    display: inline-flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    gap: 0.125rem;
    min-width: 0;
    padding: 0.375rem 0.125rem;
    border: 1px solid var(--te-color-panel-border);
    border-radius: calc(var(--te-radius-popover) - 2px);
    color: var(--te-color-text);
    font-size: 0.6875rem;
    white-space: nowrap;
}

.te-lab .te-trim-level:hover {
    background: var(--te-color-popover-hover);
}

.te-lab .te-trim-level[aria-checked="true"] {
    border-color: var(--te-color-accent);
    color: var(--te-color-accent);
}

.te-trim-level-target {
    color: var(--te-color-text-dim);
    font-size: 0.625rem;
    font-variant-numeric: tabular-nums;
}

/* ---- Status card (R-8.4), bottom-centre ---- */

.te-trim-card {
    position: fixed;
    left: 50%;
    bottom: 4rem;
    z-index: 30;
    box-sizing: border-box;
    width: min(28rem, calc(100vw - 2rem));
    padding: 0.875rem 1rem 0.75rem;
    transform: translateX(-50%);
    border: 1px solid var(--te-color-panel-border);
    border-radius: var(--te-radius-popover);
    background: var(--te-color-popover);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
    color: var(--te-color-text);
    font-family: var(--te-font-mono);
    font-size: 0.8125rem;
    line-height: 1.5;
    text-align: left;
    outline: none;
}

.te-trim-card[hidden],
.te-trim-walk[hidden] {
    display: none;
}

.te-trim-card:focus-visible {
    box-shadow: 0 0 0 2px var(--te-color-accent), 0 18px 48px rgba(0, 0, 0, 0.55);
}

@media (prefers-reduced-motion: no-preference) {
    .te-trim-card:not([hidden]) {
        animation: te-trim-rise 160ms ease-out;
    }
}

@keyframes te-trim-rise {
    from { opacity: 0; transform: translate(-50%, 6px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

.te-trim-card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.25rem 1rem;
}

.te-trim-card-level {
    font-weight: 700;
}

.te-trim-card-count {
    color: var(--te-color-accent);
    font-variant-numeric: tabular-nums;
}

.te-trim-meter {
    position: relative;
    height: 3px;
    margin: 0.5rem 0 0.625rem;
    border-radius: 2px;
    background: color-mix(in srgb, var(--te-color-text) calc(var(--te-ghost-opacity) * 100%), transparent);
    overflow: hidden;
}

.te-trim-meter-keep {
    position: absolute;
    inset: 0 auto 0 0;
    width: 100%;
    background: var(--te-color-text);
}

@media (prefers-reduced-motion: no-preference) {
    .te-trim-meter-keep {
        transition: width 220ms ease-out;
    }
}

.te-trim-card-hint,
.te-trim-walk-text {
    margin: 0 0 0.625rem;
    color: var(--te-color-text-dim);
    font-size: 0.75rem;
}

.te-trim-walk-text {
    color: var(--te-color-text);
    overflow-wrap: anywhere;
}

.te-trim-actions,
.te-trim-walk-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.te-trim-walk-buttons {
    margin-bottom: 0.625rem;
}

.te-trim-card button {
    display: inline-flex;
    align-items: center;
    gap: 0.5ch;
    margin: 0;
    padding: 0.25rem 0.75rem;
    border: 1px solid var(--te-color-panel-border);
    border-radius: 999px;
    background: none;
    color: var(--te-color-text);
    font: inherit;
    font-size: 0.75rem;
    cursor: pointer;
}

.te-trim-card button i {
    color: var(--te-color-text-dim);
    font-size: 0.6875rem;
}

.te-trim-card button:hover:not(:disabled) {
    background: var(--te-color-popover-hover);
}

.te-trim-card button:focus-visible {
    outline: 2px solid var(--te-color-accent);
    outline-offset: 1px;
}

.te-trim-card button:disabled {
    color: var(--te-color-text-dim);
    cursor: default;
}

.te-trim-card .te-trim-cut {
    border-color: var(--te-color-accent);
    color: var(--te-color-accent);
}

.te-trim-card .te-trim-cut i {
    color: var(--te-color-accent);
}

.te-trim-card .te-trim-done {
    margin-left: auto;
}

/* Visually hidden live region for messages while the card is hidden. */
.te-trim-live {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}
