/* ── Typer container ─────────────────────────────────────── */
.typer {
    position: relative;
    width: 100%;
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
    padding: 28px 32px;
    overflow: visible;
    transition: background 0.5s ease, border-color 0.5s ease;
}

@keyframes typer-expand {
    0%   { transform: scale(1);     box-shadow: var(--shadow); }
    45%  { transform: scale(1.012); box-shadow: 0 36px 90px rgba(4, 14, 28, 0.80); }
    100% { transform: scale(1);     box-shadow: var(--shadow); }
}
@keyframes typer-contract {
    0%   { transform: scale(1); }
    40%  { transform: scale(0.996); }
    100% { transform: scale(1); }
}
.typer.is-expanding   { animation: typer-expand   0.6s cubic-bezier(0.22, 1, 0.36, 1); }
.typer.is-contracting { animation: typer-contract 0.4s ease-in; }

/* ── Typebox ─────────────────────────────────────────────── */
.typebox {
    position: relative;          /* contains the absolute-positioned cursor */
    height: calc(3 * 2.1rem + 44px);
    overflow: hidden;
    padding: 22px 22px;
    border-radius: 20px;
    background: rgba(10, 28, 55, 0.75);
    border: 1px solid rgba(255,255,255,0.06);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: var(--text);
    font-size: 1.5rem;
    line-height: 2.1rem;
    text-align: right;
    direction: rtl;
    unicode-bidi: bidi-override;
    overflow-wrap: normal;
    word-break: normal;
    white-space: pre-wrap;
}

.typebox-inner { transition: transform 0.48s cubic-bezier(0.4, 0, 0.2, 1); }
.word-group    { display: inline-block; white-space: nowrap; }

/* Space tokens — direct children of .typebox-inner (letter tokens are inside .word-group) */
.typebox-inner > .token { display: inline-block; min-width: 3em; }

@keyframes typebox-end-flash {
    0%   { background: var(--surface-strong); }
    25%  { background: rgba(6,182,212,0.18); box-shadow: inset 0 0 0 2px rgba(6,182,212,0.28); }
    100% { background: var(--surface-strong); box-shadow: none; }
}
.typebox--flash       { animation: typebox-end-flash 0.65s ease-out; }
.typebox .token       { position: relative; display: inline; }
.typebox .token.correct   { color: var(--success); }
.typebox .token.incorrect { color: var(--danger); }

/* Typebox end marker — hidden (cursor already shows position) */
.typebox-end-marker { display: none; }

/* Disqualified typebox (race mode) */
.typebox--disqualified {
    display: flex; align-items: center; justify-content: center;
    background: rgba(10, 14, 30, 0.70) !important;
    filter: grayscale(0.60);
}
.typebox-disq-notice  { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; direction: rtl; }
.typebox-disq-icon    { font-size: 2.2rem; line-height: 1; }
.typebox-disq-notice p     { font-size: 1.15rem; font-weight: 800; color: var(--danger); margin: 0; }
.typebox-disq-notice small { font-size: 0.80rem; color: var(--muted); }

/* ── Typing cursor — absolute, glides between character positions ─ */
.typing-cursor {
    position: absolute;
    width: 3px;
    height: 1.05em;
    background: var(--accent);
    border-radius: 2px;
    pointer-events: none;
    z-index: 10;
    box-shadow: 0 0 8px rgba(6, 182, 212, 0.55);
    transform-origin: center center;
    animation: cursor-blink 1s ease-in-out infinite;
    /* smooth float between character positions */
    transition: left 0.08s cubic-bezier(0.4, 0, 0.2, 1),
                top  0.12s cubic-bezier(0.4, 0, 0.2, 1),
                background 0.15s ease,
                box-shadow 0.15s ease;
}
/* Snap to new text start without sweeping across the box */
.typing-cursor.cursor-no-transition { transition: none !important; }

.typebox.is-typing .typing-cursor { animation: cursor-pump 1.6s ease-in-out infinite; }
.typing-cursor.cursor-error {
    background: var(--danger);
    box-shadow: 0 0 8px rgba(248, 113, 113, 0.55);
}
@keyframes cursor-blink {
    0%, 40%   { opacity: 1; }
    60%, 100% { opacity: 0; }
}
@keyframes cursor-pump {
    0%, 100% { transform: scaleY(1);    opacity: 1; }
    50%      { transform: scaleY(1.06); opacity: 0.8; }
}

/* ── Typing panel ────────────────────────────────────────── */
.typing-panel { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 14px; }

.typing-panel input {
    width: 100%;
    padding: 16px 18px;
    border-radius: 20px;
    border: 1px solid rgba(8,100,120,0.20);
    background: var(--surface-strong);
    font-size: 1.05rem;
    color: var(--text);
}
.typing-panel input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(6,182,212,0.16);
}

.status-row { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; margin: 6px 0; }

/* Capslock warning */
.capslock-warning {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 9px 20px; border-radius: 999px;
    font-size: 0.92rem; font-weight: 800; letter-spacing: 0.05em;
    color: #fff; background: #b45309;
    border: 2px solid rgba(255, 200, 100, 0.35);
    box-shadow: 0 4px 24px rgba(120, 60, 0, 0.55), 0 0 0 4px rgba(180, 83, 9, 0.18);
    animation: warn-pop 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.capslock-warning[hidden] { display: none; }

/* Language indicator */
.lang-indicator { display: none; }
.lang-indicator.lang-en {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 20px; border-radius: 999px;
    font-size: 0.92rem; font-weight: 800; letter-spacing: 0.05em;
    color: #fff; background: var(--danger);
    border: 2px solid rgba(255, 160, 160, 0.35);
    box-shadow: 0 4px 24px rgba(180, 40, 40, 0.55), 0 0 0 4px rgba(220, 38, 38, 0.18);
    animation: warn-pop 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.lang-dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, 0.9); flex-shrink: 0; }

@keyframes warn-pop {
    from { transform: translateY(-6px) scale(0.88); opacity: 0; }
    to   { transform: translateY(0)    scale(1);    opacity: 1; }
}

/* ── Exercise label ─────────────────────────────────────── */
.exercise-label {
    direction: rtl; text-align: right;
    padding: 0 2px 6px; min-height: 1.2em;
    display: flex; flex-direction: column; gap: 2px;
}
/* Mode label: show only desc, hide short name */
.mode-label-name { display: none !important; }
.mode-label-desc { color: var(--coral) !important; opacity: 1 !important; font-size: 0.72rem !important; font-weight: 600 !important; }

/* Quote attribution */
.quote-attrib {
    text-align: left; direction: rtl;
    color: var(--muted); font-size: 0.88rem; font-style: italic;
    padding: 6px 4px 0; letter-spacing: 0.01em;
}

/* ── Action panel ────────────────────────────────────────── */
.action-panel {
    display: flex; flex-wrap: wrap;
    align-items: center; justify-content: flex-end;
    gap: 14px; margin: 8px 0 4px; padding: 6px 0;
    background: transparent; border: none;
    opacity: 0.30;
    transition: opacity 0.25s ease;
}
.action-panel:hover,
.action-panel:focus-within { opacity: 1; }
.action-panel-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.controls { display: flex; gap: 8px; align-items: center; }
.action-panel .controls button:not(.kb-toggle) {
    background: transparent; border: none; border-radius: 8px;
    min-width: unset; padding: 5px 10px;
    font-size: 0.78rem; font-weight: 600;
    color: var(--muted); letter-spacing: 0.02em;
}
.action-panel .controls button:not(.kb-toggle):hover {
    background: rgba(255,255,255,0.06); color: var(--text); transform: none; box-shadow: none;
}

/* kbd shortcut hint inside buttons */
.kbd-hint {
    display: inline-block;
    font-size: 0.60rem; padding: 1px 4px;
    border-radius: 4px; border: 1px solid rgba(255,255,255,0.15);
    color: var(--muted); margin-right: 4px; vertical-align: middle;
}

/* ── Timer panel ─────────────────────────────────────────── */
.timer-panel {
    display: inline-flex; align-items: center; gap: 6px;
    background: transparent; border: none; padding: 0;
}
.timer-value { display: flex; flex-direction: column; align-items: center; min-width: 56px; }
#timer {
    font-size: 1.1rem; font-weight: 700; letter-spacing: 0.04em;
    color: var(--text); transition: color 0.4s ease;
    font-variant-numeric: tabular-nums;
}
.timer-value small { font-size: 0.58rem; color: var(--muted); letter-spacing: 0.06em; }

@keyframes timer-pulse {
    0%, 100% { transform: scale(1); }
    50%       { transform: scale(1.08); }
}
#timer.is-warning { color: #fb923c; }
#timer.is-urgent  { color: var(--danger); animation: timer-pulse 0.7s ease-in-out infinite; }

.duration-change {
    background: transparent; color: var(--muted); border: none;
    width: 28px; height: 28px; min-width: unset; padding: 0;
    border-radius: 50%; font-size: 1rem; font-weight: 700;
    display: grid; place-items: center;
    transition: background 0.15s, color 0.15s;
}
.duration-change:hover:not(:disabled) { background: rgba(255,255,255,0.08); color: var(--text); }
.duration-change:disabled              { opacity: 0.2; cursor: not-allowed; }

/* Timer strip (race mode) */
.timer-strip { display: flex; flex-direction: column; align-items: center; padding: 10px 0 2px; }
.timer-strip #timer { font-size: 2rem; font-weight: 800; letter-spacing: 0.02em; color: var(--text); transition: color 0.4s ease; }
.timer-strip #timer.is-urgent { color: var(--danger); animation: timer-pulse 0.7s ease-in-out infinite; }
.timer-strip small { font-size: 0.72rem; color: var(--muted); letter-spacing: 0.06em; margin-top: 2px; }

/* ── Info bar (post-test mini stats) ────────────────────── */
.info-bar {
    display: grid;
    grid-template-columns: repeat(4, minmax(110px, 1fr));
    gap: 16px;
    margin-top: 0; margin-bottom: 0;
    clip-path: inset(0 0 100% 0);
    opacity: 0;
    pointer-events: none;
}
.info-bar.is-open    { animation: results-slide-in 0.55s cubic-bezier(0.22, 1, 0.36, 1) forwards; pointer-events: auto; }
.info-bar.is-closing { animation: results-wipe-ltr 0.4s ease-in forwards; pointer-events: none; }

@keyframes results-slide-in {
    from { clip-path: inset(0 0 100% 0); opacity: 0; margin-top: 0; }
    to   { clip-path: inset(0 0 0% 0);   opacity: 1; margin-top: 18px; }
}
@keyframes results-wipe-ltr {
    from { clip-path: inset(0 0 0 0%);   opacity: 1; margin-top: 18px; }
    to   { clip-path: inset(0 0 0 100%); opacity: 0; margin-top: 0; }
}

.stat {
    background: rgba(6,182,212,0.05);
    border: none; border-radius: 20px;
    padding: 18px 16px; text-align: center;
}
.stat span  { display: block; font-size: 1.7rem; font-weight: 700; color: var(--accent); }
.stat small { display: block; margin-top: 6px; color: var(--muted); font-size: 0.86rem; }

/* Results grid cell styles (used inside results modal) */
.result-value                                     { color: #ffffff !important; }
.results-grid > div:nth-child(1) .result-value    { font-size: 3.4rem; letter-spacing: -0.03em; text-shadow: 0 0 36px rgba(6,182,212,0.55); }
.results-grid > div:nth-child(1) small            { font-size: 0.78rem; }
.results-grid > div:nth-child(2) .result-value    { font-size: 2rem; color: var(--success) !important; text-shadow: 0 0 20px rgba(74,222,128,0.35); }
.results-grid > div:nth-child(3) .result-value,
.results-grid > div:nth-child(4) .result-value    { font-size: 1.3rem; color: var(--muted) !important; text-shadow: none; }

/* ── Mode info bar chips ─────────────────────────────────── */
.mode-info-bar { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 8px; direction: rtl; }

.mib-chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: 999px;
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em;
    background: rgba(6,182,212,0.08); border: 1px solid rgba(6,182,212,0.22);
    color: var(--muted); white-space: nowrap;
}
.mib-chip i  { font-size: 0.62rem; }
.mib-mode    { color: var(--accent);  border-color: rgba(6,182,212,0.35);      background: rgba(6,182,212,0.10); }
.mib-easy    { color: #4ade80;        border-color: rgba(74,222,128,0.35);      background: rgba(74,222,128,0.08); }
.mib-medium  { color: #fb923c;        border-color: rgba(251,146,60,0.35);      background: rgba(251,146,60,0.08); }
.mib-hard    { color: var(--danger);  border-color: rgba(248,113,113,0.38);     background: rgba(248,113,113,0.09); }
.mib-row     { color: #c4b5fd;        border-color: rgba(196,181,253,0.32);     background: rgba(196,181,253,0.07); }
.mib-letter  { color: #facc15;        border-color: rgba(250,204,21,0.35);      background: rgba(250,204,21,0.08); font-size: 0.88rem; padding: 2px 9px; }

/* ── Finite mode progress bar ────────────────────────────── */
#finiteProgress {
    width: 100%; height: 3px;
    background: rgba(6,182,212,0.10);
    border-radius: 999px; overflow: hidden;
    margin-top: -8px;
}
#finiteProgressFill {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, var(--accent), #34d399);
    border-radius: 999px;
    transition: width 0.2s linear;
}

/* ── Replay mode ─────────────────────────────────────────── */
.replay-blocker { position: fixed; inset: 0; z-index: 450; background: rgba(4, 12, 24, 0.38); }
.typer.is-replaying { z-index: 451; }
.typer.is-replaying .action-panel     { pointer-events: none; opacity: 0.30; }
.typer.is-replaying .action-indicators { pointer-events: none; opacity: 0.30; }

.replay-bar {
    position: fixed; bottom: 36px; left: 50%; transform: translateX(-50%);
    z-index: 460;
    background: linear-gradient(130deg, #e4f4ff 0%, #b8dcf8 52%, #cce8ff 100%);
    border: 1px solid rgba(60, 150, 230, 0.42);
    border-radius: 20px; padding: 12px 20px;
    display: flex; align-items: center; gap: 12px;
    box-shadow: 0 10px 32px rgba(10, 60, 160, 0.30), 0 2px 8px rgba(0,0,0,0.14);
    direction: rtl; white-space: nowrap;
    animation: replay-bar-in 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes replay-bar-in {
    from { opacity: 0; transform: translateX(-50%) translateY(14px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.replay-bar-title          { font-size: 0.88rem; font-weight: 800; color: #1a5c94; display: flex; align-items: center; gap: 5px; }
.replay-bar-progress-track { width: 100px; height: 5px; background: rgba(60,150,230,0.22); border-radius: 999px; overflow: hidden; flex-shrink: 0; }
.replay-bar-progress-fill  { height: 100%; background: linear-gradient(90deg, #4db8ff, #1880cc); border-radius: 999px; width: 0%; transition: width 0.15s linear; }
.replay-bar-timer          { font-size: 0.82rem; font-weight: 700; color: #1a5c94; font-variant-numeric: tabular-nums; letter-spacing: 0.03em; min-width: 38px; text-align: center; }
.replay-bar-stop {
    min-width: unset; padding: 6px 14px; border-radius: 999px;
    background: rgba(60,150,230,0.16); color: #1a5c94;
    border: 1px solid rgba(60,150,230,0.34);
    font-size: 0.80rem; font-weight: 700;
    display: flex; align-items: center; gap: 5px;
}
.replay-bar-stop:hover { background: rgba(180,30,30,0.10); color: var(--danger); border-color: rgba(180,30,30,0.28); transform: none; box-shadow: none; }
