* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #121213;
    color: #fff;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
}

.wordle-header {
    width: 100%;
    max-width: 600px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid #3a3a3c;
}

.wordle-header h1 {
    margin: 0;
    font-size: 1.7rem;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.wordle-header h1 span { font-size: 0.6rem; color: #818384; font-weight: 600; }

.header-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.wordle-main {
    flex: 1;
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
}

/* ----- Board ----- */
.wordle-board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: 5px;
    padding: 10px;
    flex: 1;
    align-content: center;
}

.wordle-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }

.wordle-tile {
    width: 58px;
    height: 58px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    text-transform: uppercase;
    border: 2px solid #3a3a3c;
    color: #fff;
    user-select: none;
}

.wordle-tile.filled { border-color: #565758; animation: pop 0.1s ease; }
.wordle-tile.correct { background: #538d4e; border-color: #538d4e; }
.wordle-tile.present { background: #b59f3b; border-color: #b59f3b; }
.wordle-tile.absent { background: #3a3a3c; border-color: #3a3a3c; }

@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.08); } 100% { transform: scale(1); } }

.wordle-row.shake { animation: shake 0.45s ease; }
@keyframes shake {
    10%, 90% { transform: translateX(-2px); }
    20%, 80% { transform: translateX(4px); }
    30%, 50%, 70% { transform: translateX(-7px); }
    40%, 60% { transform: translateX(7px); }
}

/* ----- Keyboard ----- */
.wordle-keyboard { width: 100%; max-width: 500px; display: flex; flex-direction: column; gap: 6px; padding-bottom: 8px; }
.kb-row { display: flex; gap: 5px; justify-content: center; }

.kb-key {
    flex: 1;
    min-width: 0;
    height: 52px;
    border: none;
    border-radius: 4px;
    background: #818384;
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
}
.kb-key.kb-wide { flex: 1.5; font-size: 0.7rem; }
.kb-key.correct { background: #538d4e; }
.kb-key.present { background: #b59f3b; }
.kb-key.absent { background: #3a3a3c; }
.kb-key:active { filter: brightness(1.2); }

/* ----- Message toast ----- */
.wordle-message {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    color: #121213;
    padding: 12px 20px;
    border-radius: 6px;
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 100;
}
.wordle-message.show { opacity: 1; }

/* ----- Stats modal ----- */
.stats-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.stats-modal.open { display: flex; }

.stats-box {
    background: #1a1a1b;
    border: 1px solid #3a3a3c;
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 360px;
    position: relative;
}
.stats-box h2 { margin: 0 0 16px; text-align: center; font-size: 1.1rem; text-transform: uppercase; letter-spacing: 0.05em; }
.stats-box h3 { margin: 18px 0 8px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: #818384; }

.stats-close {
    position: absolute;
    top: 8px; right: 12px;
    background: none; border: none; color: #818384;
    font-size: 26px; cursor: pointer;
}

.stats-numbers { display: flex; justify-content: space-around; text-align: center; }
.stats-numbers > div { display: flex; flex-direction: column; }
.stat-n { font-size: 1.8rem; font-weight: 700; }
.stat-l { font-size: 0.7rem; color: #818384; }

.stat-dist { display: flex; flex-direction: column; gap: 4px; }
.dist-row { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; }
.dist-label { width: 12px; text-align: right; }
.dist-bar {
    background: #3a3a3c;
    color: #fff;
    text-align: right;
    padding: 2px 6px;
    min-width: 22px;
    border-radius: 2px;
    font-weight: 700;
    font-size: 0.8rem;
}

.stats-foot { font-size: 0.78rem; color: #818384; text-align: center; margin: 16px 0 0; }

.version-info { position: fixed; bottom: 6px; right: 8px; font-size: 0.65rem; color: #555; }

@media (max-width: 420px) {
    .wordle-tile { width: 52px; height: 52px; font-size: 1.7rem; }
    .kb-key { height: 48px; }
}
