/* CCT (PASAT-style serial addition) stage layout. Original Cerevana CSS -
   chrome/controls reuse the shared design system in styles.css
   (.nback__answer / .nback__start), mechanics adapted from tim22dev22/CCT
   (MIT, see js/cct/PROVENANCE.md). */

#cct-stage {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    user-select: none;
}

.cct-hud {
    position: absolute;
    top: 4.2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 40;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.35rem 1rem;
    align-items: center;
    padding: 0.35rem 1.25rem;
    background-color: var(--label-background-color);
    font-family: Oxanium, sans-serif;
    letter-spacing: 0.05em;
    white-space: nowrap;
    user-select: none;
}

.cct-frame {
    --cct-digit-size: clamp(4rem, 18svh, 9rem);

    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin: 0 3rem;
    padding: 1.5rem 3rem;
    min-width: 14rem;
    /* idle height must match the running game, so the frame doesn't resize
       when a session starts: vertical padding (1.5rem × 2) + digit (1.2em of
       --cct-digit-size) + gap (1rem) + verdict line (1.5rem) + gap (1rem) +
       answer input (4.25rem) */
    min-height: calc(3rem + var(--cct-digit-size) * 1.2 + 1rem + 1.5rem + 1rem + 4.25rem);
}

.cct-digit {
    font-family: Oxanium, sans-serif;
    font-weight: bold;
    font-size: var(--cct-digit-size);
    color: var(--accent-color);
    min-height: 1.2em;
    line-height: 1.2em;
}

/* per-answer verdict under the digit (✓ 8 / ✗ was 8) - colors come from the
   shared .nback__answer--right/--wrong classes in styles.css */
.cct-verdict {
    min-height: 1.5rem;
    line-height: 1.5rem;
}

.cct-answer-input {
    font-family: Oxanium, sans-serif;
    font-size: var(--step-2);
    text-align: center;
    width: 6ch;
    height: 4.25rem;
    background-color: var(--single-input-bg);
    color: var(--text-color);
    border: 1px solid var(--switch-border-color);
    border-radius: 0.25rem;
    padding: 0.5rem;
}

/* audio-only + physical keyboard: the input is alone between the frame
   brackets, so it takes over the hidden digit's space */
.cct-answer-input--hero {
    font-size: calc(var(--cct-digit-size) * 0.55);
    height: calc(var(--cct-digit-size) * 1.2);
    width: 4.5ch;
}

.cct-answer-input.cct-flash-right { border-color: var(--correct-color); }
.cct-answer-input.cct-flash-wrong { border-color: var(--wrong-color); }

/* the browser's default focus ring fights the bracket aesthetic */
.cct-answer-input:focus-visible {
    border-color: var(--accent-color);
    outline: none;
}

/* each new digit lands with a small pop */
@keyframes cct-digit-pop {
    from {
        transform: scale(1.07);
        opacity: 0.75;
    }
}

.cct-digit--pop {
    animation: cct-digit-pop 120ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
    .cct-digit--pop {
        animation: none;
    }
}

/* end-of-session summary card, inline in the frame where the digit was */
.cct-result {
    display: grid;
    gap: 0.75rem;
    text-align: center;
}

.cct-result-status {
    font-family: Oxanium, sans-serif;
    font-size: var(--step-0);
    letter-spacing: 0.05em;
}

.cct-result-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr));
    gap: 0.75rem;
}

.cct-result-value {
    font-family: Oxanium, sans-serif;
    font-size: var(--step-1);
    color: var(--accent-color);
    white-space: nowrap;
}

.cct-result-label {
    font-size: var(--step--2);
    color: var(--preamble-color);
}

.cct-result-interval {
    font-size: var(--step--1);
    color: var(--preamble-color);
}

.cct-actions {
    position: absolute;
    bottom: 2rem;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    z-index: 10;
}

.cct-actions button {
    touch-action: manipulation;
}

/* history panel: stacked per-session cards (.hqli shell from styles.css,
   same tier-color chip idiom as N-Back's .qb-hist-card/.qb-chip) */
.cct-hist-card {
    display: grid;
    gap: 0.35rem;
    padding: 0.6rem 0.75rem;
    font-size: var(--step--1);
}

/* mode label left, accuracy chip pinned right - same head row as N-Back's */
.cct-hist-card__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.cct-hist-card .hqli-footer {
    margin-right: 0;
    color: var(--text-color);
    opacity: 0.55;
}

/* keep the date on one line - the longer stats span wraps instead */
.cct-hist-card .hqli-footer span:first-child {
    white-space: nowrap;
}

.cct-chip {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    border-radius: 0.25rem;
    color: #fffffd;
}

/* on-screen keypad (Input method setting) - one button per possible answer,
   wrapping rows below the frame; visuals come from the shared .nback__match
   class. Button count varies by operation (9 difference / 17 addition,
   subtraction / 36 multiplication). Only rendered in keypad mode (physical
   is typing-only), so the grid is always the sole input and sizes for it. */
.cct-keypad {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.65rem;
    max-width: 36rem;
}

.cct-keypad button {
    min-width: 4.5rem;
    padding: 1.1rem 0.75rem;
    font-family: Oxanium, sans-serif;
    font-size: var(--step-1);
    /* reaction-time game: no double-tap-zoom delay on touch */
    touch-action: manipulation;
}

/* audio-only + keypad: no digit above it, so the grid takes the digit's room */
.cct-keypad--hero {
    max-width: 46rem;
    gap: 0.75rem;
}

.cct-keypad--hero button {
    min-width: 5.75rem;
    padding: 1.5rem 1rem;
    font-size: var(--step-2);
}

/* paused: the stimulus area visibly sleeps until RESUME */
.cct-stage--paused .cct-digit,
.cct-stage--paused .cct-keypad,
.cct-stage--paused .cct-answer-input {
    opacity: 0.35;
    transition: opacity 0.15s;
}

/* Phones and short (landscape-phone) viewports: the desktop layout's
   absolute overlays (HUD over the stage, actions pinned to the bottom)
   collide with the content once the keypad grows - the HUD covered the
   digit and the multiplication keypad ran under STOP/PAUSE and off the
   viewport with no way to scroll. Rebuild the stage as a plain
   top-to-bottom column that scrolls as a last resort, and collapse the
   keypad size variants into one compact touch grid. */
@media (width <= 500px), (height <= 500px) {
    #cct-stage {
        justify-content: flex-start;
        overflow: hidden auto;
        padding: 3.5rem 0.5rem calc(0.75rem + env(safe-area-inset-bottom));
        gap: 0.75rem;
    }

    /* flex spacers: center the game column in the leftover space when it
       fits, collapse to nothing when it overflows - unlike
       justify-content: center, which would clip the top off a scrolling
       overflow */
    #cct-stage::before,
    #cct-stage::after {
        content: '';
        flex: 1;
    }

    .cct-hud {
        position: static;
        transform: none;
        font-size: var(--step--2);
        padding: 0.3rem 0.75rem;
        max-width: 100%;
    }

    .cct-frame {
        --cct-digit-size: clamp(2.5rem, 10svh, 5rem);

        margin: 0;
        padding: 0.75rem;
        min-width: 0;
        /* desktop reserves idle space so the frame doesn't resize when a
           session starts; the mobile column recenters on start anyway, so
           the reservation just parks START below center */
        min-height: 0;
        gap: 0.75rem;
    }

    /* full-width frame: the bracket chrome reads as stray marks at the
       screen edges and the lips (offset -1rem) overflow the viewport -
       same treatment as RRT's .display-inner at this width */
    .cct-frame .border-left,
    .cct-frame .border-right,
    .cct-frame .bracket-lip-top-left,
    .cct-frame .bracket-lip-top-right,
    .cct-frame .bracket-lip-bottom-left,
    .cct-frame .bracket-lip-bottom-right {
        display: none;
    }

    .cct-actions {
        position: static;
    }

    .cct-keypad,
    .cct-keypad--hero {
        max-width: 100%;
        gap: 0.4rem;
    }

    .cct-keypad button,
    .cct-keypad--hero button {
        min-width: 48px;
        min-height: 48px;
        padding: 0.5rem;
        font-size: var(--step-0);
    }
}

/* landscape phones: the corner-tab columns overlay the left/right edges
   the wide keypad rows would otherwise reach */
@media (height <= 500px) {
    #cct-stage {
        padding-left: 3rem;
        padding-right: 3rem;
    }
}
