/* =====================================================================
   TYPING TEST  -  /typing/typing.css
   A quiet, minimal typing page in the spirit of the classic typing
   sites: one calm background colour for the whole page, the words in
   the middle, and a few soft sci-fi touches (corner brackets, a glow
   under the current line, words that "decode" in).
   The background colours are the THEMES below; pick one with the
   palette button on the page. The default is "midnight".
   ===================================================================== */

/* ---------------------------------------------------------------------
   THEMES  (the whole page takes these colours)
     --bg      page background        --panel   the little boxes
     --sub     labels, dim text       --dim     words not typed yet
     --text    words typed right      --accent  timer, cursor, glow
     --error   mistakes               --line    thin lines
   --------------------------------------------------------------------- */
:root, :root[data-ty-theme="midnight"] {
    --bg: #1b1c26; --panel: #222330; --sub: #6d7394; --dim: #4b5070; --text: #dfe3f5;
    --accent: #8fb3ff; --error: #ff6b81; --extra: #c94f63; --line: #2c2e3e; --shade: rgba(0, 0, 0, 0.35);
}
:root[data-ty-theme="charcoal"] {
    --bg: #2c2e31; --panel: #262829; --sub: #7a7c7f; --dim: #5d5f62; --text: #d1d0c5;
    --accent: #e2b714; --error: #ca4754; --extra: #7e2a33; --line: #3a3c40; --shade: rgba(0, 0, 0, 0.35);
}
:root[data-ty-theme="ocean"] {
    --bg: #0f1f2c; --panel: #142837; --sub: #5f7c93; --dim: #3d5a70; --text: #d6e6f2;
    --accent: #5ec4e8; --error: #ff7a6b; --extra: #c2564a; --line: #1d3445; --shade: rgba(0, 0, 0, 0.4);
}
:root[data-ty-theme="forest"] {
    --bg: #1d2721; --panel: #232f28; --sub: #6f8a77; --dim: #4c6354; --text: #e1eadb;
    --accent: #a6d58f; --error: #ff8a70; --extra: #c0634d; --line: #2c3a31; --shade: rgba(0, 0, 0, 0.35);
}
:root[data-ty-theme="rose"] {
    --bg: #271e25; --panel: #30252d; --sub: #8e7385; --dim: #644f5d; --text: #f3e2ea;
    --accent: #f29bb5; --error: #ff8a6b; --extra: #c75f4c; --line: #3a2d36; --shade: rgba(0, 0, 0, 0.35);
}
:root[data-ty-theme="terminal"] {
    --bg: #060c0b; --panel: #0c1513; --sub: #3f7465; --dim: #24463d; --text: #8ff7df;
    --accent: #8ff7df; --error: #ff8a5c; --extra: #c25b3a; --line: #13221e; --shade: rgba(0, 0, 0, 0.5);
}
:root[data-ty-theme="paper"] {
    --bg: #f6f3ec; --panel: #ece7dc; --sub: #8b8478; --dim: #bab2a3; --text: #1b1a17;
    --accent: #8a2b1d; --error: #c0392b; --extra: #8f2a1f; --line: #e1dbcf; --shade: rgba(60, 40, 10, 0.18);
}
:root[data-ty-theme="sepia"] {
    --bg: #efe4cf; --panel: #e5d7bb; --sub: #8c7a5e; --dim: #b29f80; --text: #3b2f22;
    --accent: #a0522d; --error: #b8402a; --extra: #8a3a22; --line: #dccdae; --shade: rgba(60, 40, 10, 0.2);
}

:root {
    --ty-ui: "TY IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --ty-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
    --ty-ease: cubic-bezier(.2, .7, .2, 1);
}

/* ---- the whole page in the theme's colours ---- */
body.ty-page {
    background: var(--bg);
    color: var(--text);
    transition: background-color 0.6s ease, color 0.6s ease;
}
body.ty-page h1, body.ty-page .site-title, body.ty-page .site-title:visited { color: var(--text); text-decoration: none; transition: color 0.6s ease; }
body.ty-page > header h2 { color: var(--sub); border-bottom-color: var(--line); transition: color 0.6s ease, border-color 0.6s ease; }
body.ty-page nav a, body.ty-page nav a:visited {
    background: transparent;
    border-color: var(--line);
    color: var(--sub);
}
body.ty-page nav a:hover, body.ty-page nav a:visited:hover {
    background: var(--text);
    border-color: var(--text);
    color: var(--bg);
    box-shadow: none;
}
body.ty-page > footer { color: var(--sub); border-top-color: var(--line); }
body.ty-page .lv-heart { color: var(--accent); }

main.ty-main {
    --ty-font: "TY IBM Plex Mono", ui-monospace, monospace;
    --ty-size: 26px;
    display: block;
    width: 100%;
    max-width: 1100px;
    margin: 4px auto 0;
    font-family: var(--ty-ui);
    color: var(--text);
}
main.ty-main p { margin: 0; }
main.ty-main button { font-family: var(--ty-ui); }

/* ---------------------------------------------------------------------
   The little heading: name on the left, a note on the right
   --------------------------------------------------------------------- */
.ty-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 20px;
    padding: 2px 0 20px;
    transition: opacity 0.5s ease;
    animation: ty-fade 0.6s ease both;
}
main.ty-main .ty-title { display: inline-flex; align-items: center; gap: 9px; font-size: 1.05rem; color: var(--text); letter-spacing: 0.01em; }
.ty-title svg { width: 24px; height: 24px; fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; }
main.ty-main .ty-intro { font-size: 0.78rem; color: var(--sub); }

/* ---------------------------------------------------------------------
   The bar of choices
   --------------------------------------------------------------------- */
.ty-bar {
    position: relative;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin: 0 auto 34px;
    transition: opacity 0.5s ease;
    animation: ty-up 0.6s var(--ty-ease) 0.05s both;
}
.ty-box { position: relative; display: flex; align-items: center; gap: 4px; padding: 4px 6px; border-radius: 10px; background: var(--panel); transition: background-color 0.6s ease; }
.ty-box .ty-group:not([hidden]) ~ .ty-group:not([hidden]) { border-left: 1px solid var(--line); padding-left: 4px; margin-left: 2px; }
.ty-box:not(.ty-tools):not(:has(.ty-group:not([hidden]))) { display: none; }
.ty-group { display: flex; flex-wrap: wrap; }
.ty-group[hidden] { display: none; }
.ty-pill, .ty-tool {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 9px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--sub);
    font: 0.8rem/1.2 var(--ty-ui);
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease;
}
.ty-pill svg, .ty-tool svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ty-tool svg { width: 17px; height: 17px; }
.ty-pill:hover, .ty-tool:hover { color: var(--text); }
.ty-pill.on { color: var(--accent); }
.ty-pill:focus-visible, .ty-tool:focus-visible, .ty-btn:focus-visible, .ty-font:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ty-tool[aria-expanded="true"] { color: var(--accent); }
.ty-tool#ty-open-settings svg { transition: transform 0.6s var(--ty-ease); }
.ty-tool#ty-open-settings:hover svg { transform: rotate(90deg); }

/* the colour picker under the palette button */
.ty-palette {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    width: 330px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: 0 18px 40px -16px var(--shade);
    animation: ty-up 0.25s var(--ty-ease);
}
.ty-palette[hidden] { display: none; }
.ty-swatch-btn {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 9px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--sub);
    font: 0.78rem var(--ty-ui);
    text-align: left;
    cursor: pointer;
}
.ty-swatch-btn:hover { color: var(--text); background: rgba(127, 127, 127, 0.08); }
.ty-swatch-btn.on { color: var(--text); border-color: var(--line); }
.ty-swatch { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; flex: none; }
.ty-swatch i { width: 8px; height: 8px; border-radius: 50%; }

/* ---------------------------------------------------------------------
   The typing area
   --------------------------------------------------------------------- */
.ty-stage { position: relative; padding: 0 clamp(4px, 2vw, 24px); animation: ty-up 0.6s var(--ty-ease) 0.1s both; }

.ty-live {
    display: flex;
    align-items: baseline;
    gap: 22px;
    min-height: 2em;
    margin: 0 0 6px 18px;
    color: var(--sub);
    font-size: 0.9rem;
}
.ty-live-main { min-width: 2.4em; font-size: 1.55rem; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.ty-live-stat b { font-weight: normal; color: var(--text); font-variant-numeric: tabular-nums; }
.ty-live-stat { opacity: 0; transition: opacity 0.4s ease; }
.is-started .ty-live-stat { opacity: 1; }
.no-live-wpm #ty-live-wpm, .no-live-acc #ty-live-acc { display: none; }
.no-timer .ty-progress, .no-timer .ty-live-main { visibility: hidden; }
.ty-caps { margin-left: auto; padding: 2px 10px; border-radius: 6px; background: var(--error); color: var(--bg); font-size: 0.75rem; }

/* the frame: four soft corner brackets, a faint dot grid and a glow
   under the line you're on. They "lock on" when you start typing. */
.ty-frame { position: relative; padding: 16px 18px; }
.ty-frame::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(color-mix(in srgb, var(--sub) 22%, transparent) 0.8px, transparent 1.2px) 0 0 / 18px 18px;
    -webkit-mask: radial-gradient(ellipse at center, #000 30%, transparent 75%);
    mask: radial-gradient(ellipse at center, #000 30%, transparent 75%);
    opacity: 0.55;
    pointer-events: none;
    transition: opacity 0.8s ease;
}
.is-started .ty-frame::before { opacity: 0.25; }
.ty-corner {
    position: absolute;
    width: 16px;
    height: 16px;
    border: 0 solid var(--accent);
    opacity: 0.35;
    pointer-events: none;
    transition: transform 0.6s var(--ty-ease), opacity 0.6s ease;
    animation: ty-corner-in 0.9s var(--ty-ease) 0.2s both;
}
.ty-corner.tl { left: 0; top: 0; border-width: 1.5px 0 0 1.5px; border-top-left-radius: 4px; --mx: -8px; --my: -8px; }
.ty-corner.tr { right: 0; top: 0; border-width: 1.5px 1.5px 0 0; border-top-right-radius: 4px; --mx: 8px; --my: -8px; }
.ty-corner.bl { left: 0; bottom: 0; border-width: 0 0 1.5px 1.5px; border-bottom-left-radius: 4px; --mx: -8px; --my: 8px; }
.ty-corner.br { right: 0; bottom: 0; border-width: 0 1.5px 1.5px 0; border-bottom-right-radius: 4px; --mx: 8px; --my: 8px; }
@keyframes ty-corner-in { from { opacity: 0; transform: translate(calc(var(--mx) * 3), calc(var(--my) * 3)); } }
main:not(.is-started) .ty-corner { animation: ty-corner-in 0.9s var(--ty-ease) 0.2s both, ty-breathe 4s ease-in-out 1.2s infinite; }
@keyframes ty-breathe { 50% { opacity: 0.15; } }
.is-started .ty-corner { opacity: 0.7; transform: translate(calc(var(--mx) * -0.5), calc(var(--my) * -0.5)); }
.ty-frame.tick .ty-corner { opacity: 1; transition-duration: 0.05s; }

/* three lines of words, the current one in the middle */
.ty-words-wrap {
    position: relative;
    height: calc(var(--ty-size) * 1.75 * 3);
    overflow: hidden;
    cursor: text;
}
.ty-line {
    position: absolute;
    left: -10px;
    right: -10px;
    top: 0;
    height: calc(var(--ty-size) * 1.5);
    border-radius: 8px;
    background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent) 7%, transparent) 12%, color-mix(in srgb, var(--accent) 7%, transparent) 88%, transparent);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s var(--ty-ease), opacity 0.5s ease;
}
.is-started .ty-line { opacity: 1; }
.ty-words {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    font-family: var(--ty-font);
    font-size: var(--ty-size);
    line-height: 1.5;
    color: var(--dim);
    transition: transform 0.3s var(--ty-ease), opacity 0.25s ease;
    user-select: none;
    -webkit-user-select: none;
}
.ty-words:not(.is-in) { opacity: 0; }
.ty-words.is-in { animation: ty-fade 0.3s ease; }
.ty-w { display: inline-block; box-sizing: border-box; height: 1.5em; margin: 0 0.42em 0.25em 0; border-bottom: 2px solid transparent; transition: border-color 0.3s ease; white-space: pre; }
.ty-w.err { border-bottom-color: color-mix(in srgb, var(--error) 60%, transparent); }
.ty-w .l { display: inline-block; transition: color 0.12s ease; }
.ty-w .l.dec { color: color-mix(in srgb, var(--accent) 70%, var(--dim)); }
.ty-w .l.ok, .ty-w .l.t { color: var(--text); }
.ty-w .l.no { color: var(--error); }
.ty-w .l.x { color: var(--extra); }
.ty-w .l.pop { animation: ty-pop 0.16s ease-out; }
.ty-w .l.shake { animation: ty-shake 0.22s ease-out; }
@keyframes ty-pop { from { transform: translateY(-1.5px); text-shadow: 0 0 10px var(--accent); } }
@keyframes ty-shake { 25% { transform: translateX(-1.5px); } 75% { transform: translateX(1.5px); } }

/* the cursor */
.ty-caret {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 2;
    width: 2px;
    height: var(--ch, 1.2em);
    border-radius: 2px;
    background: var(--accent);
    box-shadow: 0 0 8px color-mix(in srgb, var(--accent) 70%, transparent);
    pointer-events: none;
    transition: transform 0.1s ease-out, width 0.1s ease;
}
.ty-caret.no-glide { transition: none; }
.ty-caret.idle { animation: ty-blink 1.05s ease-in-out infinite; }
@keyframes ty-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
[data-caret="block"] .ty-caret { width: var(--cw, 0.6em); opacity: 0.3; border-radius: 3px; box-shadow: none; }
[data-caret="block"] .ty-caret.idle { animation-name: ty-blink-soft; }
@keyframes ty-blink-soft { 0%, 100% { opacity: 0.3; } 50% { opacity: 0.08; } }
[data-caret="under"] .ty-caret { width: var(--cw, 0.6em); height: 2.5px; margin-top: calc(var(--ch, 1.2em) - 3px); }
[data-caret="off"] .ty-caret { display: none; }

.ty-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    opacity: 0;
    font-size: 16px;
    color: transparent;
    background: transparent;
    caret-color: transparent;
    cursor: text;
    z-index: 1;
}
.ty-blur {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: grid;
    place-items: center;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    background: color-mix(in srgb, var(--bg) 45%, transparent);
    color: var(--text);
    font-size: 0.95rem;
    cursor: pointer;
    animation: ty-fade 0.3s ease;
}
.ty-blur span::before { content: "⌖ "; color: var(--accent); }
.ty-blur[hidden] { display: none; }

/* progress: a thin line with a glowing head */
.ty-progress { position: relative; height: 2px; margin: 0 18px; border-radius: 2px; background: var(--line); overflow: visible; }
.ty-progress i {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    border-radius: 2px;
    background: linear-gradient(90deg, transparent, var(--accent));
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.15s linear;
}
main.ty-main .ty-by { margin: 12px 18px 0; font-size: 0.8rem; color: var(--sub); text-align: right; }
.ty-by[hidden] { display: none; }

.ty-foot { display: flex; flex-direction: column; align-items: center; gap: 22px; margin-top: 30px; transition: opacity 0.5s ease; }
.ty-restart {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--sub);
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease;
}
.ty-restart svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.6s var(--ty-ease); }
.ty-restart:hover { color: var(--text); background: var(--panel); }
.ty-restart:hover svg { transform: rotate(-200deg); }
.ty-restart:focus-visible { outline: 2px solid var(--accent); }
main.ty-main .ty-hint { font-size: 0.75rem; color: var(--sub); }
.ty-page kbd {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--sub);
    color: var(--bg);
    font: 0.72rem/1.4 var(--ty-ui);
}

/* the keyboard on screen */
.ty-kb { display: grid; gap: 5px; justify-content: center; margin: 26px auto 0; font-family: var(--ty-ui); }
.ty-kb[hidden] { display: none; }
.ty-kb-row { display: flex; gap: 5px; padding-left: calc(var(--o, 0) * 34px); }
.ty-kb-row span {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 7px;
    background: var(--panel);
    color: var(--sub);
    font-size: 0.8rem;
    transition: background-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease, transform 0.12s ease;
}
.ty-kb-row .ty-kb-space { width: 240px; margin-left: 100px; font-size: 0.68rem; letter-spacing: 0.2em; }
.ty-kb-row span.next { color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent), 0 0 12px -4px var(--accent); }
.ty-kb-row span.hit { animation: ty-hit 0.25s ease-out; }
.ty-kb-row span.miss { animation: ty-miss 0.35s ease-out; }
@keyframes ty-hit { from { transform: translateY(2px); background: color-mix(in srgb, var(--accent) 30%, var(--panel)); } }
@keyframes ty-miss { from { transform: translateY(2px); background: color-mix(in srgb, var(--error) 50%, var(--panel)); } }

/* focus mode: everything else fades away while you type */
body.ty-typing > header, body.ty-typing > nav, body.ty-typing > footer,
body.ty-typing .ty-hero, body.ty-typing .ty-bar, body.ty-typing .ty-history, body.ty-typing .ty-foot,
body.ty-typing .lv-hearts { opacity: 0; pointer-events: none; }
body.ty-page > header, body.ty-page > nav, body.ty-page > footer, .ty-history { transition: opacity 0.6s ease; }

/* ---------------------------------------------------------------------
   History
   --------------------------------------------------------------------- */
.ty-history { margin: 70px 0 10px; animation: ty-fade 0.8s ease 0.3s both; }
.ty-h-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
main.ty-main .ty-label { margin: 0; font: 0.75rem var(--ty-ui); letter-spacing: 0.08em; color: var(--sub); }
main.ty-main .ty-note { font-size: 0.75rem; color: var(--sub); }
.ty-link { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.ty-h-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.ty-card { padding: 16px 18px; border-radius: 12px; background: var(--panel); transition: background-color 0.6s ease; }
.ty-card-wide { grid-column: 1 / -1; }
.ty-card h4 { margin: 0 0 12px; font: 0.8rem var(--ty-ui); font-weight: normal; color: var(--sub); }
main.ty-main .ty-card-note, .ty-card-note { margin: -6px 0 12px; font-size: 0.75rem; color: var(--sub); opacity: 0.8; }
main.ty-main .ty-empty, .ty-empty { font-size: 0.8rem; color: var(--sub); list-style: none; }
.ty-pbs p { display: grid; grid-template-columns: 1fr auto 3.4em; gap: 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 0.82rem; }
.ty-pbs p:last-child { border-bottom: 0; }
.ty-pbs span { color: var(--sub); }
.ty-pbs b { font-weight: normal; font-size: 1.15rem; color: var(--accent); }
.ty-pbs small { font-size: 0.7rem; color: var(--sub); }
.ty-pbs i { font-style: normal; text-align: right; color: var(--sub); }
.ty-spark svg { display: block; width: 100%; height: 64px; overflow: visible; }
.ty-spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.ty-spark circle { fill: var(--panel); stroke: var(--accent); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.ty-recent { margin: 12px 0 0; padding: 0; list-style: none; }
.ty-recent li { display: grid; grid-template-columns: auto auto 1fr auto; gap: 12px; align-items: baseline; padding: 4px 0; font-size: 0.78rem; color: var(--sub); }
.ty-recent li b { font-size: 1rem; font-weight: normal; color: var(--text); white-space: nowrap; }
.ty-recent li small { font-size: 0.7rem; color: var(--sub); }
.ty-recent li em { font-style: normal; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ty-recent li.ty-empty { display: block; }
.ty-heat { display: grid; gap: 5px; justify-content: center; margin: 4px 0 16px; }
.ty-heat-row { display: flex; gap: 5px; padding-left: calc(var(--o, 0) * 36px); }
.ty-key {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 7px;
    background: color-mix(in srgb, var(--error) calc(var(--heat, 0) * 85%), var(--bg));
    color: var(--text);
    font: 0.85rem var(--ty-ui);
}
.ty-key.none { color: var(--dim); }
.ty-practice { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.ty-practice .ty-btn { background: var(--bg); }

/* ---------------------------------------------------------------------
   Pop-ups: the result, settings and your own text
   --------------------------------------------------------------------- */
.ty-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 20px 14px;
    overflow-y: auto;
    background: color-mix(in srgb, var(--bg) 70%, transparent);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.ty-modal[hidden] { display: none; }
.ty-modal.is-in { animation: ty-fade 0.25s ease; }
.ty-modal.is-in .ty-sheet { animation: ty-sheet 0.45s var(--ty-ease); }
.ty-modal.is-out { opacity: 0; transition: opacity 0.2s ease; }
@keyframes ty-sheet { from { opacity: 0; transform: translateY(16px) scale(0.98); } }
.ty-sheet {
    position: relative;
    width: min(780px, 100%);
    padding: 26px clamp(18px, 4vw, 34px) 24px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--bg);
    box-shadow: 0 30px 70px -30px var(--shade);
    font-family: var(--ty-ui);
    color: var(--text);
}
.ty-sheet p { margin: 0; }
.ty-x { position: absolute; top: 12px; right: 14px; width: 34px; height: 34px; border: 0; border-radius: 8px; background: none; color: var(--sub); font-size: 1.4rem; line-height: 1; cursor: pointer; }
.ty-x:hover { color: var(--text); background: var(--panel); }
.ty-r-kicker { font-size: 0.75rem; letter-spacing: 0.1em; color: var(--sub); }

.ty-r-top { display: grid; grid-template-columns: auto 1fr; gap: 10px 44px; align-items: end; margin-bottom: 18px; }
.ty-r-big { position: relative; }
.ty-r-wpm { display: flex; align-items: baseline; gap: 8px; line-height: 1; margin-top: 8px !important; }
.ty-r-wpm b { font-size: clamp(3.4rem, 9vw, 5rem); font-weight: normal; color: var(--accent); font-variant-numeric: tabular-nums; letter-spacing: -0.03em; text-shadow: 0 0 30px color-mix(in srgb, var(--accent) 35%, transparent); }
.ty-r-wpm span { font-size: 1rem; color: var(--sub); }
.ty-r-pb { display: inline-block; margin-top: 10px !important; padding: 2px 10px; border-radius: 6px; background: var(--accent); color: var(--bg); font-size: 0.75rem; animation: ty-pb 0.6s var(--ty-ease) 0.6s both; }
@keyframes ty-pb { from { opacity: 0; transform: scale(0.7); } }
.ty-r-pb[hidden] { display: none; }
.ty-r-side { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 26px; }
.ty-r-side p { display: flex; flex-direction: column; gap: 2px; }
.ty-r-side span, .ty-r-label { font-size: 0.7rem; letter-spacing: 0.06em; color: var(--sub); }
.ty-r-side b { font-size: 1.7rem; font-weight: normal; color: var(--text); font-variant-numeric: tabular-nums; }

.ty-chart { position: relative; margin: 4px 0 10px; }
.ty-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.ty-c-grid line { stroke: var(--line); stroke-width: 1; }
.ty-c-grid text, .ty-c-ticks text { fill: var(--sub); font: 10px var(--ty-ui); }
.ty-c-wpm { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; filter: drop-shadow(0 0 4px color-mix(in srgb, var(--accent) 50%, transparent)); }
.ty-c-raw { fill: none; stroke: var(--sub); stroke-width: 1.4; stroke-linejoin: round; stroke-dasharray: 3 3; }
.ty-c-err path { stroke: var(--error); stroke-width: 1.8; stroke-linecap: round; }
.ty-c-err { animation: ty-fade 0.4s ease 1s both; }
.ty-c-guide { stroke: var(--sub); stroke-width: 1; stroke-dasharray: 2 3; transition: opacity 0.2s ease; }
.ty-c-key { display: flex; gap: 16px; justify-content: flex-end; font-size: 0.7rem; color: var(--sub); }
.ty-c-key span::before { content: ""; display: inline-block; width: 14px; height: 0; margin-right: 6px; vertical-align: 3px; border-top: 2px solid var(--accent); }
.ty-c-key .k-raw::before { border-top: 1.5px dashed var(--sub); }
.ty-c-key .k-err::before { width: 8px; border: 0; content: "×"; color: var(--error); height: auto; vertical-align: 0; font-size: 1rem; line-height: 0; margin-right: 4px; }
.ty-c-tip { position: absolute; top: 4px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-size: 0.75rem; line-height: 1.4; pointer-events: none; white-space: nowrap; }
.ty-c-tip b { color: var(--accent); font-weight: normal; }
.ty-c-tip i { color: var(--error); font-style: normal; }

.ty-r-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 18px; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.ty-r-grid > div { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ty-r-grid b { font-weight: normal; font-size: 0.88rem; }
.c-ok { color: var(--text); font-style: normal; }
.c-no { color: var(--error); font-style: normal; }
.c-x { color: var(--extra); font-style: normal; }
.c-miss { color: var(--sub); font-style: normal; }
.ty-r-by { margin-top: 12px !important; font-size: 0.8rem; color: var(--sub); text-align: right; }
.ty-r-by[hidden] { display: none; }
.ty-r-more { display: grid; gap: 12px; margin-top: 14px; }
.ty-r-more:empty { display: none; }
.ty-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px !important; }
.ty-chips span { padding: 3px 10px; border-radius: 6px; background: var(--panel); color: var(--error); font-size: 0.8rem; }
.ty-chips-keys span { color: var(--sub); }
.ty-chips-keys kbd { margin-right: 4px; }
.ty-r-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.ty-btn {
    padding: 8px 14px;
    border: 0;
    border-radius: 8px;
    background: var(--panel);
    color: var(--sub);
    font: 0.8rem/1.3 var(--ty-ui);
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
.ty-btn:hover { background: var(--text); color: var(--bg); }
.ty-btn[hidden] { display: none; }
.ty-btn-main { background: var(--accent); color: var(--bg); }
.ty-btn-main:hover { background: var(--text); }
.ty-btn kbd { margin-left: 6px; background: color-mix(in srgb, var(--bg) 25%, transparent); color: inherit; }

/* hearts for a new personal best */
.ty-heart { position: absolute; left: 60px; top: 50%; width: 16px; height: 16px; color: var(--accent); pointer-events: none; animation: ty-heart 1.8s cubic-bezier(.2,.6,.3,1) both; }
.ty-heart svg { width: 100%; height: 100%; fill: currentColor; }
@keyframes ty-heart {
    0% { opacity: 0; transform: translate(0, 0) scale(0.3); }
    15% { opacity: 1; }
    100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--r)) scale(var(--s)); }
}

/* settings */
.ty-s-body { margin-top: 6px; }
.ty-s-h { margin: 20px 0 6px; font: 0.8rem var(--ty-ui); font-weight: normal; letter-spacing: 0.08em; color: var(--accent); }
.ty-s-row { display: flex; justify-content: space-between; align-items: center; gap: 10px 20px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.ty-s-label { font-size: 0.85rem; }
.ty-s-help { margin-top: 3px !important; max-width: 28em; font-size: 0.72rem; color: var(--sub); }
.ty-seg { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 2px; padding: 3px; border-radius: 8px; background: var(--panel); }
.ty-seg .ty-pill { padding: 4px 10px; font-size: 0.75rem; }
.ty-seg .ty-pill.on { background: var(--accent); color: var(--bg); }
.ty-s-fonts { flex-direction: column; align-items: stretch; }
.ty-fonts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.ty-font {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: var(--panel);
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease;
}
.ty-font span { font-size: 1rem; }
.ty-font small { font: 0.68rem var(--ty-ui); color: var(--sub); }
.ty-font:hover { transform: translateY(-1px); }
.ty-font.on { border-color: var(--accent); }
.ty-s-themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }

/* your own text */
.ty-custom textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
    color: var(--text);
    font: 0.95rem/1.5 var(--ty-ui);
    resize: vertical;
}
.ty-custom textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

@keyframes ty-up { from { opacity: 0; transform: translateY(8px); } }
@keyframes ty-fade { from { opacity: 0; } }

/* ---------------------------------------------------------------------
   Small screens
   --------------------------------------------------------------------- */
@media (max-width: 760px) {
    .ty-h-grid { grid-template-columns: 1fr; }
    .ty-r-top { grid-template-columns: 1fr; }
    .ty-r-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ty-s-row { flex-direction: column; align-items: flex-start; }
    .ty-seg { justify-content: flex-start; }
    .ty-kb { display: none !important; }
    .ty-heat-row { padding-left: calc(var(--o, 0) * 14px); gap: 3px; }
    .ty-heat { gap: 3px; }
    .ty-key { width: 26px; height: 30px; font-size: 0.75rem; }
    main.ty-main .ty-hint { display: none; }
    .ty-bar { margin-bottom: 22px; }
    .ty-frame { padding: 12px 10px; }
    .ty-palette { width: 240px; }
}
@media (max-width: 560px) {
    main.ty-main { --ty-size: 20px !important; }
    main.ty-main .ty-intro { display: none; }
    .ty-hero { padding-bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
    .ty-hero, .ty-bar, .ty-stage, .ty-history, .ty-words.is-in, .ty-modal.is-in, .ty-modal.is-in .ty-sheet,
    .ty-r-pb, .ty-c-err, .ty-caret.idle, .ty-w .l, .ty-corner, .ty-palette { animation: none !important; }
    .ty-words, .ty-caret, .ty-line, .ty-corner { transition: none !important; }
}
