/* Tähemäng — mänguala täidab nähtava kõrguse; suurused tulevad .tm-game konteinerist
   (cqh/cqw), et sama paigutus mahuks 1280×600 sülearvutisse, täisekraanile ja telefoni. */

.tm-app {
    --tm-accent: #7c3aed;
    --tm-accent-hover: #6d28d9;
    --tm-accent-soft: rgba(124, 58, 237, 0.10);
    --tm-on-accent: #ffffff;
    --tm-ok: #15803d;
    --tm-ok-soft: #dcfce7;
    --tm-bad: #dc2626;
    --tm-bad-soft: #fee2e2;
    --tm-hint: #d97706;
    --tm-hint-soft: #fef3c7;
    --tm-shadow-1: 0 1px 2px rgba(17, 17, 26, .06), 0 4px 12px rgba(17, 17, 26, .08);
    --tm-shadow-2: 0 2px 4px rgba(17, 17, 26, .08), 0 12px 24px rgba(17, 17, 26, .12);
    --tm-ease: cubic-bezier(0.4, 0, 0.2, 1);

    display: flex;
    flex-direction: column;
    height: calc(100vh - 3.25rem);
    height: calc(100svh - 3.25rem);
    min-height: 420px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: 'Nunito', sans-serif;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}
/* Täisekraanis on navi ruum vaba */
.tm-app:fullscreen { height: 100vh; height: 100svh; }
.tm-app:-webkit-full-screen { height: 100vh; }

[data-theme="dark"] .tm-app {
    --tm-accent: #a78bfa;
    --tm-accent-hover: #c4b5fd;
    --tm-accent-soft: rgba(167, 139, 250, 0.16);
    --tm-on-accent: #1c1433;
    --tm-ok: #4ade80;
    --tm-ok-soft: rgba(74, 222, 128, 0.16);
    --tm-bad: #f87171;
    --tm-bad-soft: rgba(248, 113, 113, 0.18);
    --tm-hint: #fbbf24;
    --tm-hint-soft: rgba(251, 191, 36, 0.18);
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .tm-app {
        --tm-accent: #a78bfa;
        --tm-accent-hover: #c4b5fd;
        --tm-accent-soft: rgba(167, 139, 250, 0.16);
        --tm-on-accent: #1c1433;
        --tm-ok: #4ade80;
        --tm-ok-soft: rgba(74, 222, 128, 0.16);
        --tm-bad: #f87171;
        --tm-bad-soft: rgba(248, 113, 113, 0.18);
        --tm-hint: #fbbf24;
        --tm-hint-soft: rgba(251, 191, 36, 0.18);
    }
}

.tm-app [hidden] { display: none !important; }
.tm-app button { font-family: inherit; }

/* ---------- ülariba ---------- */
.tm-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 16px;
    min-height: 60px;
}
.tm-bar-left, .tm-bar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tm-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    margin: 0;
    white-space: nowrap;
}
.tm-app[data-screen="tmGame"] .tm-title { display: none; }
.tm-ic-btn {
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    transition: box-shadow 150ms var(--tm-ease), color 150ms var(--tm-ease);
}
.tm-ic-btn[aria-pressed="false"] { color: var(--text-muted); }
.tm-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    font-size: 18px;
    font-variant-numeric: tabular-nums;
}
.tm-pill i { color: #f59e0b; font-size: 14px; }
.tm-dots { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tm-dot {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    border: 2px solid var(--border-color);
    background: var(--bg-card);
}
.tm-dot.is-done { background: var(--tm-accent); border-color: var(--tm-accent); }
.tm-dot.is-skip { background: var(--border-color); }
.tm-dot.is-now { border-color: var(--tm-accent); box-shadow: 0 0 0 3px var(--tm-accent-soft); }

/* ---------- ekraanid ---------- */
.tm-screen { flex: 1 1 auto; min-height: 0; }
.tm-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 16px;
    box-shadow: var(--tm-shadow-1);
    padding: 24px;
    width: 100%;
    max-width: 640px;
    margin: auto;
}

/* menüü */
.tm-menu { display: flex; overflow-y: auto; padding: 8px 16px 16px; }
.tm-menu-title {
    font-size: clamp(1.25rem, 2.4vw, 1.5rem);
    font-weight: 700;
    letter-spacing: -0.01em;
    text-align: center;
    margin: 0 0 8px;
    color: var(--text-primary);
}
.tm-field { margin-top: 16px; min-width: 0; }
.tm-field-row { display: grid; grid-template-columns: 1fr auto; gap: 16px; }
.tm-field-row .tm-field { margin-top: 16px; }
.tm-label { display: block; font-size: 14px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.tm-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tm-mode {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    min-height: 64px;
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-card);
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    transition: border-color 150ms var(--tm-ease), background 150ms var(--tm-ease);
}
.tm-mode > i { font-size: 24px; color: var(--tm-accent); width: 28px; text-align: center; }
.tm-mode strong { display: block; font-size: 16px; font-weight: 700; color: var(--text-primary); }
.tm-mode small { display: block; font-size: 14px; color: var(--text-secondary); }
.tm-mode[aria-pressed="true"] { border-color: var(--tm-accent); background: var(--tm-accent-soft); }
.tm-mode[aria-pressed="true"]::after {
    content: "\f00c";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    position: absolute;
    top: 8px;
    right: 12px;
    font-size: 14px;
    color: var(--tm-accent);
}
.tm-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.tm-chip {
    min-height: 40px;
    padding: 6px 16px;
    border: 1.5px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 150ms var(--tm-ease), background 150ms var(--tm-ease);
}
.tm-chip[aria-pressed="true"] { background: var(--tm-accent); border-color: var(--tm-accent); color: var(--tm-on-accent); }
.tm-start {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    min-height: 56px;
    margin-top: 24px;
    border: none;
    border-radius: 8px;
    background: var(--tm-accent);
    color: var(--tm-on-accent);
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    transition: background 150ms var(--tm-ease), box-shadow 150ms var(--tm-ease);
}
.tm-start:disabled { opacity: .5; cursor: not-allowed; }
.tm-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 8px 24px;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}
.tm-count { margin: 8px 0 0; font-size: 14px; color: var(--text-secondary); text-align: center; min-height: 20px; }
.tm-credit { margin: 12px 0 0; font-size: 12px; color: var(--text-muted); text-align: center; }
.tm-credit a { color: var(--text-link); }

/* ---------- mäng ---------- */
.tm-game {
    container-type: size;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 4px 16px 16px;
}
.tm-play {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3cqh;
}
.tm-pic {
    position: relative;
    height: 50cqh;
    aspect-ratio: 4 / 3;
    max-width: 100%;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;   /* joonpildid on tumedate kontuuridega — pind jääb ka tumedas heledaks */
    border: 1px solid var(--border-light);
    border-radius: 16px;
    box-shadow: var(--tm-shadow-1);
}
.tm-app[data-mode="klaviatuur"] .tm-pic { height: 38cqh; }
.tm-pic img {
    max-width: 78%;
    max-height: 84%;
    object-fit: contain;
    pointer-events: none;
}
.tm-pic img.is-in { animation: tm-pic-in 250ms cubic-bezier(0, 0, 0.2, 1) backwards; }
@keyframes tm-pic-in { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: scale(1); } }
.tm-pic-btn {
    position: absolute;
    bottom: 8px;
    width: clamp(44px, 9cqh, 56px);
    height: clamp(44px, 9cqh, 56px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    border: 1px solid #e4e4e7;
    background: #ffffff;
    color: #5b21b6;
    font-size: clamp(18px, 3.6cqh, 24px);
    box-shadow: var(--tm-shadow-1);
    cursor: pointer;
}
.tm-listen { left: 8px; }
.tm-hint { right: 8px; color: #b45309; }

.tm-boxes {
    --box: min(13cqh, calc((100cqw - (var(--n, 4) - 1) * 8px) / var(--n, 4)), 88px);
    display: flex;
    justify-content: center;
    gap: 8px;
    flex: 0 0 auto;
}
.tm-app[data-mode="klaviatuur"] .tm-boxes { --box: min(11cqh, calc((100cqw - (var(--n, 4) - 1) * 8px) / var(--n, 4)), 80px); }
.tm-box {
    width: var(--box);
    height: calc(var(--box) * 1.12);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: calc(var(--box) * 0.62);
    font-weight: 700;
    line-height: 1;
    transition: border-color 150ms var(--tm-ease), background 150ms var(--tm-ease);
}
.tm-box.is-active { border-color: var(--tm-accent); background: var(--tm-accent-soft); }
.tm-box.is-filled { border-color: var(--tm-ok); background: var(--tm-ok-soft); animation: tm-pop 280ms cubic-bezier(0, 0, 0.2, 1); }
.tm-box.is-shake { animation: tm-shake 300ms var(--tm-ease); border-color: var(--tm-bad); }
.tm-box.is-hint { border-color: var(--tm-hint); background: var(--tm-hint-soft); }
.tm-boxes.is-done .tm-box { animation: tm-pop 320ms cubic-bezier(0, 0, 0.2, 1) backwards; }
.tm-boxes.is-done .tm-box:nth-child(2) { animation-delay: 40ms; }
.tm-boxes.is-done .tm-box:nth-child(3) { animation-delay: 80ms; }
.tm-boxes.is-done .tm-box:nth-child(4) { animation-delay: 120ms; }
.tm-boxes.is-done .tm-box:nth-child(5) { animation-delay: 160ms; }
.tm-boxes.is-done .tm-box:nth-child(n+6) { animation-delay: 200ms; }
@keyframes tm-pop { 0% { transform: scale(1); } 45% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes tm-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }

.tm-input { flex: 0 0 auto; display: flex; justify-content: center; }

/* „Tähed ette" — suured plaadid, murduvad vajadusel kahele reale */
.tm-tiles {
    --tile: max(44px, min(14cqh, calc((100cqw - (var(--n, 8) - 1) * 8px) / var(--n, 8)), 96px));
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    max-width: 100%;
}
.tm-tile {
    width: var(--tile);
    height: var(--tile);
    border: 1.5px solid var(--border-color);
    border-bottom-width: 4px;
    border-radius: 10px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: calc(var(--tile) * 0.55);
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: transform 150ms var(--tm-ease), opacity 150ms var(--tm-ease), box-shadow 150ms var(--tm-ease);
}
.tm-tile:active { transform: translateY(2px); }
.tm-tile.is-used { opacity: .25; transform: scale(.9); cursor: default; }
.tm-tile.is-bad { border-color: var(--tm-bad); background: var(--tm-bad-soft); animation: tm-shake 300ms var(--tm-ease); }
.tm-tile.is-hint { border-color: var(--tm-hint); background: var(--tm-hint-soft); box-shadow: 0 0 0 4px var(--tm-hint-soft); }

/* „Klaviatuur" — eesti paigutus, kuni 12 klahvi reas */
.tm-kb {
    --key-w: min(calc((100cqw - 11 * 6px) / 12), 76px);
    --key-h: min(11cqh, 68px, calc(var(--key-w) * 1.9));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
}
.tm-kb-row { display: flex; justify-content: center; gap: 6px; }
.tm-key {
    width: var(--key-w);
    height: var(--key-h);
    padding: 0;
    border: 1.5px solid var(--border-color);
    border-bottom-width: 3px;
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: min(calc(var(--key-h) * 0.48), calc(var(--key-w) * 0.62));
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: transform 150ms var(--tm-ease), background 150ms var(--tm-ease);
}
.tm-key.is-et { background: var(--tm-accent-soft); }
.tm-key:active { transform: translateY(2px); }
.tm-key.is-ok { background: var(--tm-ok-soft); border-color: var(--tm-ok); }
.tm-key.is-bad { background: var(--tm-bad-soft); border-color: var(--tm-bad); animation: tm-shake 300ms var(--tm-ease); }
.tm-key.is-hint { background: var(--tm-hint-soft); border-color: var(--tm-hint); box-shadow: 0 0 0 4px var(--tm-hint-soft); }

/* ---------- lõpp ---------- */
.tm-end { display: flex; overflow-y: auto; padding: 8px 16px 16px; }
.tm-end-panel { text-align: center; max-width: 560px; }
.tm-badge {
    width: 56px;
    height: 56px;
    margin: 0 auto 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    background: var(--tm-accent-soft);
    color: var(--tm-accent);
    font-size: 26px;
}
.tm-end-title { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; color: var(--text-primary); }
.tm-end-text { font-size: 16px; color: var(--text-secondary); margin: 0 0 16px; font-variant-numeric: tabular-nums; }
.tm-end-stars { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 8px; }
.tm-end-word {
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--tm-ok-soft);
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 700;
    animation: tm-pic-in 250ms cubic-bezier(0, 0, 0.2, 1) backwards;
    animation-delay: calc(var(--i, 0) * 90ms);
}
.tm-end-word.is-skip { background: transparent; border: 1.5px dashed var(--border-color); color: var(--text-muted); }
.tm-end-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 16px; }
.tm-end-actions .tm-start { width: auto; margin-top: 0; padding: 8px 24px; }

/* ---------- hover ainult hiirega ---------- */
@media (hover: hover) {
    .tm-ic-btn:hover, .tm-secondary:hover { box-shadow: var(--tm-shadow-2); color: var(--text-primary); }
    .tm-mode:hover, .tm-chip:hover { border-color: var(--tm-accent); }
    .tm-chip[aria-pressed="true"]:hover { border-color: var(--tm-accent-hover); }
    .tm-start:not(:disabled):hover { background: var(--tm-accent-hover); box-shadow: var(--tm-shadow-2); }
    .tm-tile:not(.is-used):hover, .tm-key:hover { box-shadow: var(--tm-shadow-2); }
    .tm-pic-btn:hover { box-shadow: var(--tm-shadow-2); }
}

/* ---------- madal ekraan ja mobiil ---------- */
/* „Alusta" jääb nähtavaks ka siis, kui menüü madalal ekraanil kerib */
.tm-menu .tm-start { position: sticky; bottom: 0; box-shadow: 0 -8px 16px var(--bg-card); }

@media (max-height: 720px) {
    .tm-bar { min-height: 52px; padding: 4px 16px; }
    .tm-menu { padding-top: 0; }
    .tm-panel { padding: 16px 24px; }
    .tm-menu-title { margin-bottom: 4px; }
    .tm-field, .tm-field-row .tm-field { margin-top: 12px; }
    .tm-label { margin-bottom: 4px; }
    .tm-chip { min-height: 36px; padding: 4px 16px; }
    .tm-mode { min-height: 56px; padding: 8px 16px; }
    .tm-start { margin-top: 16px; min-height: 48px; }
    .tm-credit { margin-top: 8px; }
}
@media (max-width: 560px) {
    .tm-bar { padding: 8px 12px; gap: 8px; }
    .tm-bar-left, .tm-bar-right { gap: 4px; }
    .tm-ic-btn { width: 40px; height: 40px; font-size: 16px; }
    .tm-dot { width: 8px; height: 8px; border-width: 1.5px; }
    .tm-dots { gap: 3px; flex-wrap: nowrap; }
    .tm-app[data-screen="tmGame"] .tm-pill { display: none; }   /* tähed näeb lõpus; kitsal ribal on nupud tähtsamad */
    .tm-panel { padding: 16px; }
    .tm-menu-title { font-size: 18px; }
    .tm-modes { gap: 8px; }
    .tm-mode { flex-direction: column; align-items: flex-start; gap: 4px; padding: 8px 12px; }
    .tm-mode > i { font-size: 20px; width: auto; }
    .tm-mode small { font-size: 12px; }
    .tm-chip { min-height: 36px; padding: 4px 12px; font-size: 14px; }
    .tm-field-row { grid-template-columns: 1fr; gap: 0; }
    .tm-game { padding: 4px 8px 12px; }
    .tm-kb { --key-w: min(calc((100cqw - 11 * 4px) / 12), 76px); gap: 6px; }
    .tm-kb-row { gap: 4px; }
}
@media (max-width: 400px) {
    .tm-pill { padding: 4px 8px; font-size: 16px; }
    .tm-title { font-size: 18px; }
}
