/* ── KLTE Africa Academy — Free practice tools (typing + mouse) ──
   Loaded only on the /tools pages, on top of app.css, and reuses its tokens.
   Solid colours only, like the rest of the public site. */

:root {
    /* One tint per finger. The same colours paint the on-screen keyboard and
       its legend, so a learner can match a key to the finger that presses it. */
    --finger-little: #fbd9d9;
    --finger-ring:   #fdecc4;
    --finger-middle: #d6efdc;
    --finger-index:  #d3e4fb;
    --finger-index2: #cdeeee;
    --finger-thumb:  #e6dff5;
    --arena-bg:      #eaf2fb;
    --arena-tint:    #fff3e8;
}

/* ── Tools landing page ── */
.tool-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 24px; max-width: 900px; margin: 0 auto; }
.tool-card {
    display: flex; flex-direction: column; gap: 10px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: var(--shadow); padding: 28px; text-decoration: none; color: var(--text);
    transition: transform .15s, box-shadow .15s;
}
.tool-card:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0,0,0,.12); }
.tool-card-icon { font-size: 44px; line-height: 1; }
.tool-card h2 { font-size: 22px; color: var(--primary); }
.tool-card p { font-size: 15px; color: var(--text-muted); flex: 1; }
.tool-card ul { list-style: none; font-size: 14px; }
.tool-card li { padding: 5px 0 5px 24px; position: relative; }
.tool-card li::before { content: "\2714"; position: absolute; left: 0; color: var(--success); font-weight: 700; }
.tool-card .btn { align-self: flex-start; margin-top: 8px; }

/* ── Shared tool shell ── */
.tool-section { background: var(--bg); padding: 36px 0 56px; }
.tool {
    max-width: 980px; margin: 0 auto; padding: 22px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
    scroll-margin-top: calc(var(--nav-h) + 12px);
}
/* Set by KltePractice.setPlaying() while a lesson or game is running. */
.tool-playing .whatsapp-float { display: none; }
/* Several of these blocks set their own display, which would beat [hidden]. */
.tool [hidden] { display: none !important; }

.tool-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 18px; }
.tool-bar-title { font-size: 18px; font-weight: 700; color: var(--primary); }
.tool-tab, .tool-chip {
    font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
    padding: 9px 16px; border-radius: 999px;
    background: var(--bg); color: var(--primary); border: 1px solid var(--border);
}
.tool-tab:hover, .tool-chip:hover { border-color: var(--accent); }
.tool-tab.is-active, .tool-chip.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.tool-bar-end { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.tool-tab:focus-visible, .tool-chip:focus-visible, .lesson-btn:focus-visible, .game-btn:focus-visible {
    outline: 3px solid var(--accent); outline-offset: 2px;
}

.tool-intro { font-size: 15px; color: var(--text-muted); margin-bottom: 16px; }
.tool-note {
    font-size: 14px; color: var(--text); background: var(--arena-tint);
    border: 1px solid #f6d3b4; border-left: 3px solid var(--accent);
    border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px;
}
.tool-setup { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 8px; }
.tool-setup-label { font-size: 14px; font-weight: 600; color: var(--primary); }
.tool-setup .btn { margin-left: auto; }

.tool-hud { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.tool-hud--three { grid-template-columns: repeat(3, 1fr); }
.tool-stat { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 8px; text-align: center; }
.tool-stat strong { display: block; font-size: 22px; line-height: 1.15; color: var(--primary); font-variant-numeric: tabular-nums; }
.tool-stat span { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }

.tool-progress { height: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin: 10px 0; }
.tool-progress span { display: block; height: 100%; width: 0; background: var(--success); transition: width .15s linear; }

.tool-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

.tool-stars { font-size: 44px; line-height: 1; letter-spacing: 6px; color: var(--accent); }
.tool-stars-off { color: var(--border); }

/* ── Result card (typing) ── */
.tool-result { text-align: center; padding: 26px 16px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); }
.tool-result h2 { font-size: 26px; color: var(--primary); margin: 6px 0; }
.tool-result p { font-size: 15px; color: var(--text-muted); margin-bottom: 14px; }
.tool-result .tool-hud { max-width: 520px; margin: 0 auto 6px; }
.tool-result .tool-stat { background: var(--surface); }
.tool-result .tool-actions { justify-content: center; }

/* ── Typing: lesson picker ── */
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; }
.lesson-btn {
    display: flex; flex-direction: column; gap: 2px; text-align: left;
    font: inherit; cursor: pointer; padding: 12px 14px;
    background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
}
.lesson-btn:hover { border-color: var(--accent); }
.lesson-btn small { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.lesson-btn strong { font-size: 15px; color: var(--primary); }
.lesson-btn .lesson-stars { font-size: 15px; letter-spacing: 2px; color: var(--accent); }
.lesson-btn.is-suggested { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(232,93,4,.18); }

/* ── Typing: the line being typed ── */
.type-box { position: relative; cursor: text; }
.type-line, .type-next { font-family: Consolas, 'Courier New', monospace; white-space: pre-wrap; overflow-wrap: break-word; }
.type-line {
    min-height: 86px; padding: 18px 20px; font-size: 30px; line-height: 1.5;
    background: var(--bg); border: 2px solid var(--border); border-radius: var(--radius); color: var(--text);
}
.type-line span { border-radius: 4px; }
.type-line .is-done { color: var(--success); }
.type-line .is-slip { color: var(--warning); }
.type-line .is-current { background: var(--primary); color: #fff; }
.type-line .is-wrong { background: var(--danger); color: #fff; }
.type-next { min-height: 30px; padding: 6px 20px 0; font-size: 19px; color: var(--text-muted); opacity: .7; }
.type-hint { font-size: 16px; color: var(--text); min-height: 26px; }
.type-hint kbd {
    display: inline-block; min-width: 28px; padding: 1px 8px; text-align: center;
    font: 700 15px Consolas, 'Courier New', monospace; color: #fff; background: var(--accent); border-radius: 5px;
}
/* Catches soft-keyboard input on phones. Kept on screen (not display:none) so
   it can take focus; 16px stops iOS zooming the page when it does. */
.type-capture {
    position: absolute; left: 0; top: 0; width: 100%; height: 100%;
    opacity: 0; border: 0; padding: 0; font-size: 16px; cursor: text;
}

/* ── Typing: on-screen keyboard ── */
.kb { margin-top: 14px; padding: 12px; background: var(--primary-dark); border-radius: 12px; display: flex; flex-direction: column; gap: 6px; user-select: none; }
.kb-row { display: flex; gap: 6px; }
.kb-key {
    position: relative; flex: 1 1 0; min-width: 0; height: 42px; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 700; text-transform: uppercase; color: var(--text);
    background: #fff; border-radius: 6px; border-bottom: 3px solid rgba(0,0,0,.22);
}
.kb-key--wide { font-size: 11px; text-transform: none; font-weight: 600; }
/* The space bar sits centred under the letters, as on a real keyboard. */
.kb-row--space { justify-content: center; }
.kb-row--space .kb-key { flex: 0 0 48%; }
.kb-key[data-finger="lp"], .kb-key[data-finger="rp"] { background: var(--finger-little); }
.kb-key[data-finger="lr"], .kb-key[data-finger="rr"] { background: var(--finger-ring); }
.kb-key[data-finger="lm"], .kb-key[data-finger="rm"] { background: var(--finger-middle); }
.kb-key[data-finger="li"] { background: var(--finger-index); }
.kb-key[data-finger="ri"] { background: var(--finger-index2); }
.kb-key[data-finger="th"] { background: var(--finger-thumb); }
/* The raised bumps on F and J that the index fingers rest on. */
.kb-key[data-key="f"]::after, .kb-key[data-key="j"]::after {
    content: ""; position: absolute; left: 50%; bottom: 6px; width: 12px; height: 3px;
    margin-left: -6px; border-radius: 2px; background: rgba(0,0,0,.4);
}
.kb-key.is-next { background: var(--accent); color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.85); z-index: 1; }
.kb-key.is-next::after { background: rgba(255,255,255,.8); }
.kb-key.is-down { transform: translateY(2px); border-bottom-width: 1px; }
.kb-key.is-bad { background: var(--danger); color: #fff; }

.kb-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: 13px; color: var(--text-muted); }
.kb-legend span { display: inline-flex; align-items: center; gap: 6px; }
.kb-legend i { width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(0,0,0,.15); }

/* ── Typing: Letter Rain game ── */
.rain-arena { position: relative; height: 340px; overflow: hidden; background: var(--primary); border-radius: var(--radius); border-bottom: 6px solid var(--accent); cursor: text; }
.rain-arena.is-hurt { background: #6b2330; }
.rain-item { position: absolute; left: 0; top: 0; will-change: transform; }
.rain-chip {
    display: block; min-width: 46px; padding: 5px 13px; text-align: center; white-space: nowrap;
    font: 700 23px Consolas, 'Courier New', monospace; color: var(--primary);
    background: #fff; border-radius: 999px; border-bottom: 3px solid rgba(0,0,0,.25);
}
.rain-item.is-active .rain-chip { background: var(--accent); color: #fff; }
.rain-chip b { opacity: .45; font-weight: 700; }
.rain-item.is-pop .rain-chip { background: var(--success); color: #fff; transform: scale(1.5); opacity: 0; transition: transform .2s, opacity .2s; }
.rain-item.is-lost .rain-chip { background: var(--danger); color: #fff; opacity: 0; transition: opacity .3s; }
.rain-lives { letter-spacing: 2px; }

/* ── Mouse: game picker ── */
.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.game-btn {
    display: grid; grid-template-columns: 52px 1fr; gap: 2px 12px; align-items: center; text-align: left;
    font: inherit; cursor: pointer; padding: 16px;
    background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
    transition: transform .15s, box-shadow .15s;
}
.game-btn:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.game-btn-icon { grid-row: span 3; font-size: 40px; line-height: 1; text-align: center; }
.game-btn small { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.game-btn strong { font-size: 17px; color: var(--primary); }
.game-btn .game-stars { font-size: 15px; letter-spacing: 2px; color: var(--accent); }

/* ── Mouse: arena ── */
.mouse-how { font-size: 16px; color: var(--text); margin-bottom: 12px; }
.mouse-arena {
    /* As tall as the window allows once the header, title bar and score row
       are accounted for, so no target ever spawns below the fold. */
    position: relative; height: clamp(320px, calc(100vh - 330px), 460px); overflow: hidden;
    background: var(--arena-bg); border: 2px solid var(--border); border-radius: var(--radius);
    user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.mouse-target {
    position: absolute; display: flex; align-items: center; justify-content: center;
    line-height: 1; cursor: pointer; transition: transform .12s;
}
.mouse-target:hover { transform: scale(1.08); }
.mouse-target.is-hit { transform: scale(1.6); opacity: 0; pointer-events: none; transition: transform .22s, opacity .22s; }
.mouse-target.is-wobble { animation: tool-wobble .3s; }
.mouse-target--left, .mouse-target--right { color: #fff; font-size: 15px; font-weight: 700; border-bottom: 4px solid rgba(0,0,0,.25); }
.mouse-target--left  { background: #2f6fed; border-radius: 50%; }
.mouse-target--right { background: var(--accent); border-radius: 14px; }

.mouse-miss {
    position: absolute; width: 30px; height: 30px; margin: -15px 0 0 -15px; pointer-events: none;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 700; color: var(--danger); animation: tool-fade .6s forwards;
}
.arena-tip {
    position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 15; pointer-events: none;
    max-width: 90%; padding: 8px 16px; font-size: 14px; font-weight: 600; text-align: center;
    color: #fff; background: var(--primary-dark); border-radius: 999px;
}
.arena-overlay {
    position: absolute; inset: 0; z-index: 20; padding: 24px; overflow-y: auto;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
    text-align: center; color: #fff; background: var(--primary);
}
.arena-overlay-icon { font-size: 56px; line-height: 1; }
.arena-overlay h2 { font-size: 26px; }
.arena-overlay p { font-size: 16px; max-width: 460px; color: rgba(255,255,255,.88); }
.arena-overlay .tool-stars-off { color: rgba(255,255,255,.3); }
.arena-overlay .tool-actions { justify-content: center; margin-top: 8px; }
.arena-overlay-stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 22px; font-size: 15px; }
.arena-overlay-stats strong { font-size: 20px; }

/* Drag and drop */
.drag-item { position: absolute; width: 78px; text-align: center; cursor: grab; touch-action: none; transition: left .2s, top .2s; }
.drag-item.is-dragging { cursor: grabbing; z-index: 10; transition: none; }
.drag-item.is-hit { transform: scale(.3); opacity: 0; pointer-events: none; transition: transform .2s, opacity .2s; }
.drag-item-icon { display: block; font-size: 40px; line-height: 1.1; }
.drag-item small {
    display: block; padding: 1px 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 11px; color: var(--text); background: #fff; border: 1px solid var(--border); border-radius: 4px;
}
.drag-zones { position: absolute; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 10px; }
.drag-zone { height: 100px; padding: 8px 4px; text-align: center; background: #fff; border: 2px dashed var(--primary); border-radius: 10px; }
.drag-zone.is-over { background: var(--arena-tint); border-color: var(--accent); border-style: solid; }
.drag-zone-icon { display: block; font-size: 34px; line-height: 1.1; }
.drag-zone strong { display: block; font-size: 14px; color: var(--primary); }
.drag-zone small { font-size: 12px; color: var(--text-muted); }

/* Scrolling */
/* contain: reaching either end of the list must not start scrolling the page. */
.scroll-box { position: absolute; inset: 0; overflow-y: scroll; overscroll-behavior: contain; background: #fff; }
.scroll-hint {
    position: sticky; top: 0; z-index: 2; padding: 9px 16px; font-size: 14px; font-weight: 600;
    color: #fff; background: var(--primary);
}
.scroll-row { padding: 11px 16px; font-size: 15px; color: var(--text-muted); border-bottom: 1px solid var(--border); cursor: pointer; }
.scroll-row:hover { background: var(--bg); }
.scroll-row.is-key { font-weight: 700; color: var(--accent-dark); background: var(--arena-tint); }

@keyframes tool-wobble {
    0%, 100% { transform: rotate(0); }
    25% { transform: rotate(-10deg); }
    75% { transform: rotate(10deg); }
}
@keyframes tool-fade {
    from { opacity: 1; transform: scale(1); }
    to   { opacity: 0; transform: scale(1.8); }
}

/* ── Help copy under a tool ── */
.prose h3 { font-size: 19px; color: var(--primary); margin: 24px 0 8px; }
.prose ol, .prose ul { margin: 0 0 18px 22px; font-size: 16px; }
.prose li { margin-bottom: 8px; }

@media (prefers-reduced-motion: reduce) {
    .mouse-target, .mouse-target.is-hit, .drag-item, .rain-item .rain-chip, .tool-card, .game-btn { transition: none; }
    .mouse-target.is-wobble, .mouse-miss { animation: none; }
    .mouse-miss { opacity: 0; }
}

@media (max-width: 768px) {
    .tool-section { padding: 20px 0 40px; }
    .tool { padding: 14px; }
    .tool-bar { gap: 8px; margin-bottom: 12px; }
    .tool-bar-title { flex-basis: 100%; }
    .tool-bar-end { margin-left: 0; gap: 6px; }
    .tool-tab, .tool-chip { padding: 7px 11px; font-size: 13px; }
    .tool-setup .btn { margin-left: 0; }
    .tool-hud { grid-template-columns: repeat(2, 1fr); }
    .tool-hud--three { grid-template-columns: repeat(3, 1fr); }
    .tool-stat strong { font-size: 20px; }
    .type-line { font-size: 22px; padding: 14px; min-height: 70px; }
    .type-next { font-size: 15px; padding: 6px 14px 0; }
    .kb { padding: 6px; gap: 3px; }
    .kb-row { gap: 3px; }
    .kb-key { height: 34px; font-size: 12px; border-radius: 4px; border-bottom-width: 2px; }
    .kb-key--wide { font-size: 8px; }
    .kb-key[data-key="f"]::after, .kb-key[data-key="j"]::after { bottom: 3px; width: 8px; height: 2px; margin-left: -4px; }
    .rain-arena { height: 300px; }
    .mouse-arena { height: clamp(380px, calc(100vh - 380px), 440px); }
    .arena-overlay h2 { font-size: 22px; }
    .arena-overlay p { font-size: 15px; }
    .drag-item { width: 70px; }
}
