/* Typing Test playfield (Phase 6, inside the shared game shell).
   The passage is a fixed number of lines that scrolls inside its own box, so the input is always
   directly below it. .ty-compact is set by the script when an on-screen keyboard leaves too little
   room: a slim timer line appears in the stage and the passage shows two lines. */
.ty-stage { --ty-lines: 3; --ty-font: 1.0625rem; --ty-leading: 1.65; display: flex; flex-direction: column; gap: var(--rb-space-3); }

.ty-meter { display: none; justify-content: space-between; gap: var(--rb-space-3); margin: 0; padding: .375rem .75rem; border-radius: var(--rb-radius-sm); background: var(--rb-surface-soft); color: var(--rb-text); font-size: var(--rb-fs-sm); font-weight: var(--rb-fw-extrabold); font-variant-numeric: tabular-nums; }
.ty-meter span:first-child { color: var(--rb-primary); }

.ty-passage {
    padding: .75rem 1rem;
    border: 1px solid var(--rb-border); border-radius: var(--rb-radius-md);
    background: var(--rb-surface-soft);
}
/* Scroll window of exactly N lines, so a line is never cut in half. */
.ty-passage__view { position: relative; overflow: hidden; height: calc(var(--ty-lines) * var(--ty-font) * var(--ty-leading)); }
.ty-passage__text {
    margin: 0; color: var(--rb-text-secondary);
    font-size: var(--ty-font); line-height: var(--ty-leading); letter-spacing: .01em;
    white-space: pre-wrap; overflow-wrap: break-word;
    user-select: none; -webkit-user-select: none;
}
.ty-passage__text .is-correct { color: var(--rb-text); }
.ty-passage__text .is-incorrect { border-radius: 3px; background: var(--rb-danger-bg); color: var(--rb-danger); text-decoration: underline 2px; text-underline-offset: 3px; }
.ty-passage__text .is-current { border-radius: 2px; background: var(--rb-primary-soft); box-shadow: inset 2px 0 0 var(--rb-primary); }

/* Setting (start) and input (playing) share one slot of fixed height. */
.ty-slot { display: grid; height: 104px; }
.ty-setup, .ty-entry { grid-area: 1 / 1; min-width: 0; }
.rb-game:not([data-state="start"]) .ty-setup { display: none; }
.rb-game[data-state="start"] .ty-entry { display: none; }
.ty-setup { position: relative; margin: 0; padding: 0; border: 0; overflow: hidden; }
/* Header row: legend left, shuffle button right, both absolutely placed. Not floated: Chrome can
   render a floated legend at full width, which pushed the options out of the clipped 104px slot. */
.ty-setup__legend { position: absolute; top: 0; left: 0; width: max-content; max-width: calc(100% - 8.5rem); float: none; margin: 0; padding: 0; color: var(--rb-text); font-size: var(--rb-fs-sm); font-weight: var(--rb-fw-semibold); line-height: 44px; }
.ty-setup__shuffle { position: absolute; top: 0; right: 0; min-height: 44px; margin: 0; }
.ty-setup__options { margin-top: calc(44px + var(--rb-space-2)); display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--rb-space-2); }
.ty-option { position: relative; display: block; cursor: pointer; }
.ty-option input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.ty-option span { display: flex; align-items: center; justify-content: center; min-height: 48px; border: 1px solid var(--rb-border-strong); border-radius: var(--rb-radius-sm); background: var(--rb-surface); color: var(--rb-text); font-weight: var(--rb-fw-bold); }
.ty-option input:checked + span { border: 2px solid var(--rb-primary); background: var(--rb-primary-soft); color: var(--rb-primary); }
.ty-option input:focus-visible + span { outline: 3px solid var(--rb-focus-ring); outline-offset: 2px; }

.ty-input {
    display: block; width: 100%; height: 100%; min-height: 76px; resize: none;
    padding: .625rem .875rem;
    border: 2px solid var(--rb-border-strong); border-radius: var(--rb-radius-md);
    background: var(--rb-surface); color: var(--rb-text);
    font: inherit; font-size: 1.0625rem; line-height: 1.5; /* ≥ 16px: no zoom on iOS focus */
}
.ty-input::placeholder { color: var(--rb-text-muted); }
.ty-input:focus { border-color: var(--rb-primary); outline: 3px solid color-mix(in srgb, var(--rb-focus-ring) 35%, transparent); outline-offset: 1px; }
.ty-input:disabled { opacity: .7; }
.ty-feedback { min-height: 2.9em; margin: 0; color: var(--rb-text-secondary); font-size: var(--rb-fs-sm); line-height: 1.45; text-align: center; }

/* Compact mode (on-screen keyboard, short visible area). */
.ty-compact .ty-stage { --ty-lines: 2; gap: var(--rb-space-2); }
.ty-compact .ty-meter { display: flex; }
.ty-compact .ty-feedback { display: none; }
.ty-compact .ty-slot { height: auto; }
.ty-compact .ty-input { min-height: 64px; }

@media (min-width: 576px) { .ty-stage { --ty-lines: 4; --ty-font: 1.1875rem; } }
@media (min-width: 992px) { .ty-stage { --ty-lines: 5; --ty-font: 1.25rem; } }
