/* Typing practice page. Colours come from theme.css. */

kbd {
    font: 600 11px ui-monospace, Consolas, monospace; padding: 1px 5px; margin-left: 4px;
    border: 1px solid var(--control-border); border-bottom-width: 2px; border-radius: 4px; color: var(--muted);
}
.btn-primary kbd { color: var(--on-yellow); border-color: rgba(20, 34, 47, .4); }

.typing-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.typing-controls .spacer { flex: 1; }
.segmented { display: inline-flex; border: 1px solid var(--control-border); border-radius: 8px; overflow: hidden; }
.segmented button {
    background: var(--panel); color: var(--muted); border: 0; padding: 7px 14px; cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--control-border); }
.segmented button:hover { color: var(--text); background: var(--raised); }
.segmented button[aria-pressed="true"] { background: var(--py-blue-dark); color: #fff; font-weight: 600; }

/* --- The test -------------------------------------------------------------- */
.typing-card {
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
    border-top: 4px solid var(--py-yellow); padding: 16px 20px 12px;
}
.typing-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.snippet-title { margin: 0; font-size: 18px; color: #fff; }
.live { margin-left: auto; display: flex; gap: 18px; color: var(--muted); font-size: 14px; }
.live strong { color: var(--py-yellow); font-size: 20px; font-variant-numeric: tabular-nums; }

.typing-area {
    position: relative; background: var(--panel-2); border-radius: 8px; padding: 18px 20px;
    cursor: text; overflow: auto; max-height: 60vh;
}
.typing-area:focus-within { box-shadow: 0 0 0 2px var(--py-blue); }
.typing-code {
    margin: 0; font: 20px/1.6 ui-monospace, "Cascadia Code", Consolas, "Courier New", monospace;
    white-space: pre; color: var(--text); tab-size: 4;
}
/* The textarea sits over the code (so tablets open a keyboard) but is invisible. */
.typing-input {
    position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; resize: none;
    border: 0; padding: 0; caret-color: transparent; cursor: text;
}
.focus-hint {
    position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
    background: rgba(10, 22, 34, .78); color: var(--py-yellow-light); font-weight: 600; border-radius: 8px;
}
.typing-help { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

/* Characters: syntax colour, dimmed until typed. */
.typing-code span { opacity: .4; border-radius: 2px; }
.typing-code span.done { opacity: 1; }
.typing-code span.auto { opacity: .4; }
.typing-code span.wrong {
    opacity: 1; color: #ffd0d0; background: rgba(255, 143, 143, .35);
    text-decoration: underline wavy var(--error); text-underline-offset: 4px;
}
.typing-code span.nl { opacity: .22; font-size: .75em; padding: 0 2px; }
.typing-code span.nl.done { opacity: .35; }
.typing-code span.cursor { opacity: .9; box-shadow: -2px 0 0 var(--py-yellow); animation: caret 1s steps(1) infinite; }
@keyframes caret { 50% { box-shadow: -2px 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .typing-code span.cursor { animation: none; } }

.t-keyword { color: var(--py-yellow); font-weight: 700; }
.t-string { color: #9cc8eb; }
.t-number { color: var(--py-yellow-light); }
.t-comment { color: #8ea3b7; font-style: italic; }
.t-builtin { color: #6ea8da; }
.t-defname { color: #ffffff; font-weight: 700; }
.t-call { color: #cfe0ef; }
.t-punct { color: #b8c7d6; }

/* --- Results --------------------------------------------------------------- */
.results {
    margin-top: 16px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
    padding: 18px 20px; display: grid; grid-template-columns: auto 1fr; gap: 6px 32px; align-items: center;
}
.results-hero { grid-row: span 3; text-align: center; }
.hero-number { font-size: 64px; font-weight: 800; color: var(--py-yellow); line-height: 1; font-variant-numeric: tabular-nums; }
.hero-number small { display: block; font-size: 14px; font-weight: 600; color: var(--muted); letter-spacing: .08em; margin-top: 4px; }
.badge {
    margin-top: 10px; display: inline-block; background: var(--py-yellow); color: var(--on-yellow);
    font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 999px;
}
.results-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 0; }
.results-grid div { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; }
.results-grid dt { color: var(--muted); font-size: 12px; }
.results-grid dd { margin: 2px 0 0; font-size: 22px; font-weight: 700; color: #fff; font-variant-numeric: tabular-nums; }
.results-save { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.results-actions { display: flex; gap: 10px; flex-wrap: wrap; }
@media (max-width: 700px) { .results { grid-template-columns: 1fr; } .results-hero { grid-row: auto; } }

/* --- Progress ------------------------------------------------------------- */
.typing-stats { margin-top: 32px; }
.typing-stats h2 { font-size: 20px; color: #fff; margin: 0 0 12px; }
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-tile {
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
    display: flex; flex-direction: column; gap: 2px;
}
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 28px; font-weight: 700; color: #fff; font-variant-numeric: tabular-nums; }
.stat-note { color: var(--muted); font-size: 12px; }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; margin-bottom: 16px; }
.chart-card { margin: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px 6px; }
.chart-card figcaption { font-weight: 600; margin-bottom: 4px; }
.chart-card .unit { color: var(--muted); font-weight: 400; }
.line-chart { display: block; max-width: 100%; }
.line-chart:focus-visible { outline: 2px solid var(--py-yellow); outline-offset: 2px; border-radius: 4px; }
.chart-tip {
    position: absolute; pointer-events: none; background: var(--bg); border: 1px solid var(--control-border);
    border-radius: 6px; padding: 6px 9px; font-size: 12px; white-space: nowrap; display: flex; flex-direction: column;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
}
.chart-tip strong { font-size: 15px; color: #fff; }
.chart-tip-detail { color: var(--muted); }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.history { width: 100%; border-collapse: collapse; font-size: 14px; }
.history caption { text-align: left; font-weight: 600; padding: 12px 14px 4px; }
.history th, .history td { padding: 8px 14px; border-top: 1px solid var(--border); text-align: left; }
.history th { color: var(--muted); font-weight: 600; font-size: 12px; }
.history .num { text-align: right; font-variant-numeric: tabular-nums; }

.scoring { margin-top: 24px; color: var(--muted); }
.scoring summary { cursor: pointer; color: var(--text); font-weight: 600; }
.scoring li { margin: 6px 0; }
