:root {
    --bg: #121213;
    --bg-secondary: #1a1a1b;
    --text: #ffffff;
    --text-dim: #818384;
    --tile-border: #3a3a3c;
    --tile-empty: #121213;
    --correct: #538d4e;
    --present: #b59f3b;
    --absent: #3a3a3c;
    --key-bg: #818384;
    --key-text: #ffffff;
}

/* Loading overlay */
#loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s;
}
#loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}
.loading-content {
    text-align: center;
    color: var(--text);
}
.loading-content h1 {
    font-size: 2rem;
    margin-bottom: 1.5rem;
}
.loading-content p {
    margin-top: 1rem;
    color: var(--text-dim);
    font-size: 0.9rem;
}
.spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto;
    border: 3px solid var(--tile-border);
    border-top-color: var(--correct);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
}

#app {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 8px;
}

/* --- Header --- */
header {
    text-align: center;
    padding: 12px 0 8px;
    border-bottom: 1px solid var(--tile-border);
    width: 100%;
    margin-bottom: 12px;
}

.header-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.header-spacer {
    width: 36px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--tile-border);
    background: transparent;
    color: var(--text);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: var(--bg-secondary);
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.1em;
}

#subtitle {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-top: 2px;
}

/* --- Message --- */
.message {
    padding: 8px 16px;
    border-radius: 6px;
    background: var(--bg-secondary);
    font-size: 0.9rem;
    text-align: center;
    margin-bottom: 8px;
    transition: opacity 0.3s;
}

.message.hidden {
    opacity: 0;
    pointer-events: none;
}

.message.error {
    background: #6e2020;
}

/* --- Board --- */
#board {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 16px;
}

.row {
    display: flex;
    gap: 5px;
    justify-content: center;
}

.tile {
    width: 58px;
    height: 58px;
    border: 2px solid var(--tile-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 700;
    text-transform: uppercase;
    background: var(--tile-empty);
    transition: transform 0.1s;
}

.tile.filled {
    border-color: #565758;
    animation: pop 0.1s ease-in-out;
}

.tile.reveal {
    animation: flip 0.5s ease forwards;
}

.tile.correct {
    background: var(--correct);
    border-color: var(--correct);
}

.tile.present {
    background: var(--present);
    border-color: var(--present);
}

.tile.absent {
    background: var(--absent);
    border-color: var(--absent);
}

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

@keyframes flip {
    0% { transform: rotateX(0); }
    45% { transform: rotateX(90deg); }
    55% { transform: rotateX(90deg); }
    100% { transform: rotateX(0); }
}

/* --- Keyboard --- */
#keyboard {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-bottom: 16px;
}

.kb-row {
    display: flex;
    gap: 4px;
    justify-content: center;
}

.kb-row button {
    height: 52px;
    min-width: 32px;
    padding: 0 6px;
    border: none;
    border-radius: 4px;
    background: var(--key-bg);
    color: var(--key-text);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    flex: 1;
    max-width: 44px;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.kb-row button.wide {
    max-width: 65px;
    font-size: 0.85rem;
}

.kb-row button:active {
    opacity: 0.8;
}

.kb-row button.correct {
    background: var(--correct);
}

.kb-row button.present {
    background: var(--present);
}

.kb-row button.absent {
    background: var(--absent);
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: opacity 0.3s;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 24px;
    max-width: 360px;
    width: 90%;
    text-align: center;
}

.modal h2 {
    margin-bottom: 8px;
    font-size: 1.4rem;
}

.modal p {
    color: var(--text-dim);
    margin-bottom: 16px;
    font-size: 0.95rem;
}

.share-preview {
    font-family: monospace;
    font-size: 1.3rem;
    line-height: 1.5;
    margin-bottom: 16px;
    white-space: pre-line;
}

.btn-share {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: var(--correct);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 8px;
}

.btn-share:active {
    opacity: 0.8;
}

.btn-close {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--tile-border);
    border-radius: 8px;
    background: transparent;
    color: var(--text-dim);
    font-size: 0.9rem;
    cursor: pointer;
}

/* --- Help modal --- */
.help-text {
    color: var(--text-dim);
    margin-bottom: 12px;
    font-size: 0.92rem;
    text-align: left;
    line-height: 1.5;
}

.help-rules {
    text-align: left;
    color: var(--text);
    margin: 0 0 16px 16px;
    font-size: 0.92rem;
    line-height: 1.8;
}

.help-examples {
    margin-bottom: 16px;
}

.help-example {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 0.88rem;
    color: var(--text-dim);
}

.mini-tile {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    border-radius: 3px;
    flex-shrink: 0;
}

.mini-tile.correct {
    background: var(--correct);
    color: white;
}

.mini-tile.present {
    background: var(--present);
    color: white;
}

.mini-tile.absent {
    background: var(--absent);
    color: white;
}

/* --- Responsive --- */
@media (max-width: 400px) {
    .tile {
        width: 48px;
        height: 48px;
        font-size: 1.5rem;
    }

    .kb-row button {
        height: 46px;
        font-size: 0.85rem;
    }

    header h1 {
        font-size: 1.6rem;
    }
}

@media (max-width: 340px) {
    .tile {
        width: 40px;
        height: 40px;
        font-size: 1.3rem;
    }
}
