/* ─── Reset & Custom Properties ───────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg:           #080810;
    --surface:      #0f0f1a;
    --card:         #13131f;
    --card-hover:   #181828;
    --border:       #252538;
    --border-hover: #3a3a58;
    --text:         #f0f0ff;
    --muted:        #5a5a7a;
    --accent:       #a78bfa;
    --accent-dim:   rgba(167, 139, 250, 0.12);
    --correct:      #22c55e;
    --correct-dim:  rgba(34, 197, 94, 0.12);
    --wrong:        #ef4444;
    --wrong-dim:    rgba(239, 68, 68, 0.12);
    --font: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ─── Base ─────────────────────────────────────────────────────────────────── */
html {
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
}

/* ─── Game Container ───────────────────────────────────────────────────────── */
#game {
    width: 100%;
    max-width: 480px;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 20px 16px 36px;
    position: relative;
}

/* ─── Header ───────────────────────────────────────────────────────────────── */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 36px;
    flex-shrink: 0;
}

#game-info {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

#game-info .brand {
    color: var(--accent);
    font-weight: 800;
}

#game-info .num {
    color: var(--text);
}

#game-info .sep {
    margin: 0 6px;
}

#header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

#streak {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 4px;
}

#about-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    font-family: var(--font);
    text-decoration: none;
    transition: border-color 0.18s ease, color 0.18s ease;
    flex-shrink: 0;
}

#about-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ─── Word Area ────────────────────────────────────────────────────────────── */
#word-area {
    text-align: center;
    margin-bottom: 36px;
    flex-shrink: 0;
}

#word {
    font-size: clamp(1.9rem, 9vw, 3.2rem);
    font-weight: 800;
    letter-spacing: 0.18em;
    color: var(--accent);
    line-height: 1.1;
    text-shadow: 0 0 40px rgba(167, 139, 250, 0.25);
    white-space: nowrap; /* JS fitWord() handles scaling — no mid-word breaks */
}

/* ─── Word Meta (speak button) ─────────────────────────────────────────────── */
#word-meta {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 10px;
    min-height: 28px;
}

#speak-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 1.05rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: color 0.18s ease, background 0.18s ease;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}

#speak-btn:hover {
    color: var(--accent);
    background: var(--accent-dim);
}

#speak-btn.speaking {
    color: var(--accent);
    animation: speakPulse 0.9s ease-in-out infinite;
}

@keyframes speakPulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.45; }
}

/* ─── Play Area ────────────────────────────────────────────────────────────── */
#play-area {
    display: flex;
    flex-direction: column;
    flex: 1;
}

/* ─── Definition Cards ─────────────────────────────────────────────────────── */
#definitions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 24px;
}

.def-card {
    width: 100%;
    min-height: 62px;
    background: var(--card);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 13px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    cursor: pointer;
    transition: border-color 0.18s ease, background 0.18s ease, transform 0.12s ease;
    text-align: left;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.45;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
}

.def-card:active:not(:disabled) {
    transform: scale(0.985);
}

@media (hover: hover) {
    .def-card:hover:not(:disabled):not(.wrong):not(.correct) {
        border-color: var(--accent);
        background: var(--accent-dim);
    }
}

.def-card:disabled {
    cursor: default;
}

/* Number badge */
.def-num {
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--muted);
    min-width: 18px;
    flex-shrink: 0;
    letter-spacing: 0.02em;
    transition: color 0.18s;
}

.def-text {
    flex: 1;
}

/* ─── Card States ──────────────────────────────────────────────────────────── */
.def-card.wrong {
    border-color: var(--wrong);
    background: var(--wrong-dim);
    color: var(--wrong);
}

.def-card.wrong .def-num {
    color: var(--wrong);
}

.def-card.correct {
    border-color: var(--correct);
    background: var(--correct-dim);
    color: var(--correct);
}

.def-card.correct .def-num {
    color: var(--correct);
}

/* ─── Animations ───────────────────────────────────────────────────────────── */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    15%       { transform: translateX(-7px); }
    30%       { transform: translateX(7px); }
    45%       { transform: translateX(-5px); }
    60%       { transform: translateX(5px); }
    75%       { transform: translateX(-2px); }
    90%       { transform: translateX(2px); }
}

.def-card.shake {
    animation: shake 0.48s ease;
}

@keyframes correctPop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.025); }
    100% { transform: scale(1); }
}

.def-card.correct {
    animation: correctPop 0.4s ease;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeUp 0.45s ease forwards;
}

/* ─── Attempt Dots ─────────────────────────────────────────────────────────── */
#attempts {
    display: flex;
    justify-content: center;
    gap: 9px;
    padding-top: 4px;
    margin-bottom: 8px;
}

.dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: transparent;
    transition: background 0.3s ease, border-color 0.3s ease;
}

.dot.used {
    background: var(--wrong);
    border-color: var(--wrong);
}

/* ─── Keyboard Hint ────────────────────────────────────────────────────────── */
#keyboard-hint {
    display: none;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    text-align: center;
    margin-top: 10px;
}

@media (hover: hover) {
    #keyboard-hint {
        display: block;
    }
}

/* ─── Result Screen ────────────────────────────────────────────────────────── */
#result {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 18px;
    flex: 1;
    padding-top: 8px;
}

#emoji-result {
    font-size: 2.2rem;
    letter-spacing: 6px;
    line-height: 1;
}

#correct-definition {
    font-size: 0.95rem;
    font-weight: 400;
    color: var(--muted);
    line-height: 1.65;
    max-width: 340px;
    padding: 16px 20px;
    background: var(--card);
    border-radius: 14px;
    border: 1.5px solid var(--border);
    width: 100%;
}

#share-btn {
    background: var(--accent);
    color: #06060f;
    border: none;
    border-radius: 14px;
    padding: 15px 32px;
    font-size: 0.9rem;
    font-weight: 800;
    font-family: var(--font);
    cursor: pointer;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    transition: opacity 0.18s ease, transform 0.12s ease;
    width: 100%;
    max-width: 280px;
}

#share-btn:hover {
    opacity: 0.88;
}

#share-btn:active {
    transform: scale(0.96);
}

#countdown-wrap {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--muted);
}

#timer {
    font-variant-numeric: tabular-nums;
    color: var(--text);
    font-weight: 700;
    font-size: 0.85rem;
}

#stats-btn {
    background: transparent;
    color: var(--muted);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 12px 28px;
    font-size: 0.82rem;
    font-weight: 700;
    font-family: var(--font);
    cursor: pointer;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    transition: border-color 0.18s ease, color 0.18s ease;
    width: 100%;
    max-width: 280px;
}

#stats-btn:hover {
    border-color: var(--muted);
    color: var(--text);
}

/* ─── Stats Modal ──────────────────────────────────────────────────────────── */
#stats-modal {
    position: fixed;
    inset: 0;
    background: rgba(8, 8, 16, 0.82);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
    padding: 0;
    animation: fadeUp 0.3s ease;
}

@media (min-width: 480px) {
    #stats-modal {
        align-items: center;
        padding: 20px;
    }
}

#stats-content {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 24px 24px 0 0;
    padding: 32px 24px 40px;
    width: 100%;
    max-width: 420px;
    position: relative;
}

@media (min-width: 480px) {
    #stats-content {
        border-radius: 20px;
        padding: 32px 28px;
    }
}

#close-stats {
    position: absolute;
    top: 16px;
    right: 16px;
    background: var(--card);
    border: 1.5px solid var(--border);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.9rem;
    cursor: pointer;
    transition: color 0.18s;
    font-family: var(--font);
}

#close-stats:hover {
    color: var(--text);
}

#stats-content h2 {
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    text-align: center;
    margin-bottom: 28px;
}

#stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 32px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.stat-val {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
}

.stat-label {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

#distribution h3 {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 14px;
}

.dist-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 9px;
}

.dist-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--muted);
    width: 14px;
    flex-shrink: 0;
    text-align: center;
}

.dist-bar-wrap {
    flex: 1;
}

.dist-bar {
    height: 26px;
    background: var(--accent);
    border-radius: 6px;
    min-width: 26px;
    display: flex;
    align-items: center;
    padding: 0 10px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #06060f;
    transition: width 0.5s ease;
    width: 0;
}

/* ─── Confetti Canvas ──────────────────────────────────────────────────────── */
#confetti-canvas {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 50;
    display: none;
}

/* ─── Utility ──────────────────────────────────────────────────────────────── */
.hidden {
    display: none !important;
}

/* ─── Tablet / Desktop ─────────────────────────────────────────────────────── */
@media (min-width: 640px) {
    #game {
        padding: 32px 28px 52px;
        min-height: 100dvh;
    }

    header {
        margin-bottom: 48px;
        padding-bottom: 24px;
    }

    #word-area {
        margin-bottom: 44px;
    }

    #word {
        font-size: 3.2rem;
        letter-spacing: 0.22em;
    }

    .def-card {
        font-size: 0.95rem;
        padding: 15px 20px;
        min-height: 66px;
    }

    #game-info {
        font-size: 0.78rem;
    }

    #emoji-result {
        font-size: 2.6rem;
    }
}
