/* ============================================================
   Thai Typing Test — Temple Sunset theme
   Mirrors DooNoke's layout contract:
   - desktop: fullscreen game-container
   - mobile : game area on top, shared .fake-thai-keyboard below
   Uses the main site's design tokens (dark + light).
   ============================================================ */

:root {
    /* Temple Sunset tokens (mirrors main site) */
    --bg-base:      #1a1614;
    --bg-surface:   #2a2320;
    --bg-surface-2: #1f1a17;

    --accent:        #d85a30;
    --accent-strong: #c44a22;
    --accent-soft:   rgba(216, 90, 48, 0.15);
    --gold:          #e8b87a;
    --sage:          #6b8e7f;

    --text:          #f5e6d3;
    --text-muted:    #8a7866;
    --text-on-accent:#1a1614;

    --border-soft:   rgba(245, 230, 211, 0.08);
    --border-medium: rgba(245, 230, 211, 0.15);

    --font-display: 'Fraunces', Georgia, serif;
    --font-ui:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-thai:    'Sarabun', 'Noto Sans Thai', sans-serif;

    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 12px;

    /* internal roles, mapped onto the site palette */
    --bg:          var(--bg-base);     /* page / typing background  */
    --bg-soft:     var(--bg-surface);  /* config bar, hover chips   */
    --main:        var(--accent);      /* caret + active highlight  */
    --sub:         var(--text-muted);  /* untyped / upcoming        */
    /* --text inherited: correctly typed letters                    */
    --error:       var(--accent-strong);
    --error-extra: rgba(196, 74, 34, 0.5);
    --success:     var(--sage);
}

[data-theme="light"] {
    --bg-base:      #f5ede1;
    --bg-surface:   #ffffff;
    --bg-surface-2: #f0e5d3;

    --accent:        #c44a22;
    --accent-strong: #a83d1a;
    --accent-soft:   rgba(196, 74, 34, 0.12);
    --gold:          #b87c2a;
    --sage:          #3a5a4c;

    --text:          #3a1f12;
    --text-muted:    #8a6b52;
    --text-on-accent:#ffffff;

    --border-soft:   rgba(74, 27, 12, 0.06);
    --border-medium: rgba(74, 27, 12, 0.15);

    --error-extra:   rgba(168, 61, 26, 0.45);
}

*, body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.full-screen-container {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background-color: var(--bg);
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-ui);
}

.game-container {
    width: 95%;
    height: 90%;
    max-width: 1100px;
    background-color: var(--bg);
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 24px;
}

/* ---------- keyboard-language warning ---------- */
.kbd-warning {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    display: none;
    align-items: center;
    gap: 10px;
    max-width: 90%;
    padding: 10px 18px;
    border-radius: var(--radius-pill, 999px);
    background-color: var(--accent);
    color: var(--text-on-accent);
    font-family: var(--font-ui);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    z-index: 130;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.kbd-warning.visible {
    display: flex;
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.kbd-warning b { font-weight: 600; }

/* ---------- site logo ---------- */
.game-logo {
    height: 56px;
    width: auto;
    margin-bottom: 18px;
    user-select: none;
    -webkit-user-drag: none;
}
.results-logo { height: 64px; margin-bottom: 4px; }

/* ---------- top config bar ---------- */
.config-bar {
    display: flex;
    align-items: center;
    gap: 18px;
    background-color: var(--bg-soft);
    border: 1px solid var(--border-soft);
    padding: 8px 16px;
    border-radius: var(--radius-pill, 999px);
    margin-bottom: 14px;
    color: var(--sub);
    font-size: 0.85rem;
    user-select: none;
    flex-wrap: wrap;
    justify-content: center;
}

.config-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.config-divider {
    width: 1px;
    align-self: stretch;
    background-color: var(--border-medium);
}

.time-option {
    background: none;
    border: none;
    color: var(--sub);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 12px;
    border-radius: var(--radius-pill, 999px);
    transition: color 0.15s ease, background-color 0.15s ease;
}

.time-option:hover { color: var(--text); }
.time-option.active {
    color: var(--text-on-accent);
    background-color: var(--accent);
}

/* ---------- wordset label (the "globe + name" thing) ---------- */
.wordset-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--sub);
    font-size: 0.9rem;
    margin-bottom: 18px;
    user-select: none;
}
.wordset-label i { color: var(--gold); }

/* ---------- live timer ---------- */
.live-timer {
    color: var(--main);
    font-size: 1.6rem;
    height: 1.8rem;
    margin-bottom: 6px;
    opacity: 0;
    transition: opacity 0.2s ease;
    align-self: flex-start;
    padding-left: 4px;
}
.live-timer.visible { opacity: 1; }

/* ---------- typing area ---------- */
.typing-area {
    position: relative;
    width: 100%;
    max-width: 1000px;
    height: calc(3 * 2.9rem);          /* 3 visible lines */
    overflow: hidden;
    font-family: var(--font-thai);
    line-height: 2.9rem;
    font-size: 1.9rem;
}

/* small live-status pill (sits above the timer) */
.type-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    align-self: center;
    margin-bottom: 8px;
    padding: 4px 12px;
    border-radius: var(--radius-pill, 999px);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-soft);
    color: var(--text-muted);
    font-family: var(--font-ui);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: text;
    transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}
.type-status .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-muted);
    transition: background-color 0.2s ease;
}

/* when the window is live, highlight it */
.game-container.is-focused .type-status {
    color: var(--accent);
    border-color: var(--accent);
}
.game-container.is-focused .type-status .dot {
    background-color: var(--accent);
    animation: status-pulse 1.4s ease-in-out infinite;
}

@keyframes status-pulse {
    0%, 100% { opacity: 1;   }
    50%      { opacity: 0.4; }
}

.words {
    position: relative;
    transition: transform 0.18s ease;
    will-change: transform;
}

.word {
    display: inline-block;
    margin: 0 0.5rem 0.1rem 0;
    color: var(--sub);
    border-bottom: 2px solid transparent;
}

/* completed words */
.word.typed.right  { color: var(--text); }
.word.typed.error  {
    color: var(--text);
    border-bottom: 2px solid var(--error);
}

/* active word letters */
.word .letter            { color: var(--sub); }
.word .letter.correct    { color: var(--text); }
.word .letter.incorrect  { color: var(--error); }
.word .letter.extra      { color: var(--error-extra); }

/* stacked-letter (cluster): neutral background + prefix-substring colour overlays */
.word .cluster        { position: relative; display: inline-block; }
.word .cp-bg          { color: var(--sub); }
.word .cp-ov          { position: absolute; left: 0; top: 0; }
.word .cp-ov.correct  { color: var(--text); }
.word .cp-ov.incorrect { color: var(--error); }

/* ---------- caret ---------- */
.caret {
    position: absolute;
    width: 2px;
    background-color: var(--main);
    border-radius: 2px;
    transition: left 0.08s ease, top 0.08s ease;
    animation: caret-blink 1s steps(1) infinite;
}
@keyframes caret-blink {
    0%, 40%   { opacity: 1; }
    60%, 100% { opacity: 0; }
}
.caret.typing { animation: none; opacity: 1; }

/* ---------- restart button ---------- */
.restart-btn {
    margin-top: 26px;
    background: none;
    border: none;
    color: var(--sub);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    transition: color 0.15s ease, background-color 0.15s ease;
}
.restart-btn:hover { color: var(--text); background-color: var(--bg-soft); }

/* ---------- results ---------- */
.results-screen {
    position: absolute;
    inset: 0;
    background-color: var(--bg);
    z-index: 150;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 28px;
    font-family: var(--font-ui);
}
.results-screen.visible { display: flex; }

.results-stats {
    display: flex;
    gap: 56px;
    align-items: flex-end;
}
.stat-block { text-align: left; }
.stat-label { color: var(--sub); font-size: 1.1rem; }
.stat-value {
    color: var(--main);
    font-family: var(--font-display);
    font-size: 3.6rem;
    line-height: 1.1;
}
.stat-value small { font-size: 1.4rem; }

.results-sub {
    color: var(--sub);
    font-size: 0.95rem;
}
.results-sub b { color: var(--text); font-weight: 500; }

/* ---------- results action buttons ---------- */
.results-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}
.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-ui);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    padding: 12px 22px;
    border-radius: var(--radius-pill, 999px);
    background-color: var(--bg-surface);
    color: var(--text);
    border: 1px solid var(--border-medium);
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.action-btn:hover { background-color: var(--bg-surface-2); }
.action-btn:active { transform: translateY(1px); }
.action-btn.primary {
    background-color: var(--accent);
    color: var(--text-on-accent);
    border-color: transparent;
}
.action-btn.primary:hover { background-color: var(--accent-strong); }
.action-btn.is-busy { opacity: 0.6; pointer-events: none; }

.results-hint {
    color: var(--sub);
    font-size: 0.8rem;
    margin-top: 8px;
}

/* ---------- back button (matches DooNoke) ---------- */
.back-button {
    position: fixed;
    top: 6px;
    left: 6px;
    z-index: 200;
    background-color: rgba(0, 0, 0, 0.5);
    color: var(--text);
    padding: 10px 15px;
    border-radius: var(--radius-lg);
    text-decoration: none;
    font-size: 20px;
    transition: background-color 0.3s ease;
}
.back-button:hover { background-color: rgba(0, 0, 0, 0.8); }

/* ---------- mobile ---------- */
@media (max-width: 768px) {
    .full-screen-container {
        justify-content: flex-start;
        align-items: stretch;
        flex-direction: column;
    }
    .game-container {
        width: 100%;
        flex: 1;
        min-height: 0;
        border-radius: 0;
        padding: 12px;
        justify-content: flex-start;
        padding-top: 56px;
    }
    .typing-area {
        font-size: 1.5rem;
        line-height: 2.4rem;
        height: calc(3 * 2.4rem);
    }
    .results-stats { gap: 32px; }
    .stat-value { font-size: 2.6rem; }
    .live-timer { align-self: center; }
    .config-bar { font-size: 0.8rem; gap: 12px; }
}