:root {
    --bg: #0f172a;
    --panel: #1f2937;
    --panel-2: #111827;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --green: #22c55e;
    --yellow: #eab308;
    --colorWrong: #1e293b;
    --square-size: 56px;
    --bold-weight: 800;
    --key: #374151;
    --key-border: #4b5563;
}

* { box-sizing: border-box; }

html {
    overflow-x: hidden;
}

#loadingOverlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: oklch(20.8% .042 265.755);
    z-index: 9999;
    transition: opacity 0.3s;
}

.loading-spinner {
    width: 80px;
    height: 80px;
    border-radius: 16px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

body {
    margin: 0;
    min-height: 100vh;
    background: oklch(20.8% .042 265.755);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    display: grid;
    place-items: center;
}

.game-shell {
    width: min(920px, 100%);
    margin: 0 auto;
    padding: 20px 14px 28px;
}

.game-header h1 {
    margin: 0;
    font-size: 2rem;
    text-align: center;
}

.game-header p {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 0.92rem;
    text-align: center;
}

.day-number {
    color: #94a3b8;
    font-weight: 700;
    font-size: 1.25rem;
}

.mode-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.mode-link {
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 600;
}

.mode-link.active {
    color: #f8fafc;
}

.mode-link:hover {
    color: #f8fafc;
}

.mode-sep {
    color: #64748b;
}

.board {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.typing-line {
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #f8fafc;
    text-transform: uppercase;
}

.typing-line.shake {
    animation: typingShake 0.3s ease;
}

@keyframes typingShake {
    0% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(6px); }
    100% { transform: translateX(0); }
}

.typing-text {
    white-space: pre;
}

.typing-caret {
    display: inline-block;
    width: 2px;
    height: 1.3em;
    margin-left: 4px;
    background: #f8fafc;
    vertical-align: text-bottom;
    animation: caretBlink 1s steps(1) infinite;
}

@keyframes caretBlink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

.guess-row {
    display: flex;
    flex-wrap: nowrap;
    gap: 0;
    align-items: center;
    justify-content: center;
}

.tile {
    width: var(--square-size);
    height: var(--square-size);
    text-transform: uppercase;
    user-select: none;
    transition: background-color 0.15s ease, border-color 0.15s ease, filter 0.15s ease;
}

.tile.pending {
    background: #0b1220;
    border-color: #223047;
    color: #cbd5e1;
}

.letter {
    align-items: center;
    border-radius: 5%;
    display: flex;
    font-size: calc(var(--square-size) * 0.62);
    font-weight: var(--bold-weight);
    justify-content: center;
    margin: calc(var(--square-size) * 0.1) calc(var(--square-size) * 0.06);
    padding-top: calc(var(--square-size) * 0.03);
    position: relative;
    border: 1px solid #334155;
    background: var(--panel-2);
    line-height: 1;
}

.letter.absent {
    background-color: var(--colorWrong);
    border: none;
    color: #fff;
}

.letter.present {
    background-color: var(--yellow);
    border: none;
    color: #fff;
}

.letter.head,
.letter.one-present,
.letter.tail {
    background-color: var(--green);
    border: none;
    color: #fff;
}

.letter.head,
.letter.tail {
    border-radius: 0;
}

.letter.tail:before {
    background-color: var(--green);
    bottom: 0;
    content: "";
    display: block;
    left: 0;
    position: absolute;
    top: 0;
    transform: translate(-75%);
    width: calc(var(--square-size) * 0.26);
    z-index: -10;
}

.letter.start {
    border-radius: 50% 0 0 50%;
}

.letter.end {
    border-radius: 0 50% 50% 0;
}

.letter.start:after {
    border-radius: 50% 0 0 50%;
    right: 25%;
}

.letter.end:after,
.letter.start:after {
    background-color: var(--green);
    bottom: 0;
    content: "";
    display: block;
    height: var(--square-size);
    position: absolute;
    top: 0;
    width: var(--square-size);
    z-index: -10;
}

.letter.end:after {
    border-radius: 0 50% 50% 0;
    left: 25%;
}

.letter.flip-in {
    transform: rotateY(90deg);
    animation: tileFlipIn 0.38s ease forwards;
    transform-style: preserve-3d;
}

@keyframes tileFlipIn {
    from {
        transform: rotateY(90deg);
    }
    to {
        transform: rotateY(0deg);
    }
}


.keyboard {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 7px;
    align-items: center;
}

.kb-row {
    width: min(760px, 100%);
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 6px;
}

.kb-key {
    width: 100%;
    height: 44px;
    border-radius: 8px;
    border: 1px solid var(--key-border);
    background: var(--key);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    padding: 0 6px;
}

.kb-spacer {
    width: 100%;
    height: 44px;
}

.kb-key.wide { grid-column: span 2; }
.kb-key.half { grid-column: span 5; }
.kb-key.game-end-btn { grid-column: span 10; background: var(--green); border-color: #15803d; }
.kb-key.mobile-enter { grid-column: span 10; }
.kb-key:hover { filter: brightness(1.1); }
.kb-key:active { transform: translateY(1px); }

.kb-key.present {
    background: var(--yellow);
    border-color: #ca8a04;
}

.kb-key.absent {
    background: var(--colorWrong);
    border-color: #374151;
}

.kb-key.right {
    background: var(--green);
    border-color: #15803d;
}


.help-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid #94a3b8;
    background: none;
    color: #94a3b8;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    margin-left: 8px;
    vertical-align: middle;
    line-height: 1;
    padding: 0;
    transition: border-color 0.15s, color 0.15s;
}

.help-btn:hover {
    border-color: #f8fafc;
    color: #f8fafc;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 8000;
    padding: 16px;
}

.modal-backdrop.hidden {
    display: none;
}

.modal-card {
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 12px;
    width: min(480px, 100%);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #374151;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.modal-close:hover {
    color: #f8fafc;
}

.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    font-size: 0.95rem;
    line-height: 1.5;
    color: #e5e7eb;
}

.modal-body p { margin: 0; }

.modal-body ul {
    margin: 0;
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.modal-examples {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 14px 0;
}

.modal-ex-board {
    --square-size: 36px;
    /* isolation: isolate creates a new stacking context with no background,
       so z-index: -10 on connector pseudo-elements is relative to this board
       (transparent) rather than sinking behind the card's background. */
    isolation: isolate;
}

.ex-caption {
    font-size: 0.85rem;
    color: #cbd5e1;
    margin: 0 0 10px 0;
    padding-left: 2px;
}

.modal-footer-note {
    color: #94a3b8;
    font-size: 0.88rem;
}

@media (max-width: 640px) {
    :root {
        --square-size: 42px;
    }

    .tile {
        width: var(--square-size);
        height: var(--square-size);
        font-size: calc(var(--square-size) * 0.62);
        border-radius: 8px;
    }

    .typing-line {
        min-height: 46px;
        font-size: 1.2rem;
    }

    .kb-key {
        width: 100%;
        height: 40px;
        padding: 0 6px;
        font-size: 0.85rem;
    }

    .kb-key.wide {
        grid-column: span 2;
    }

    .kb-key.half {
        grid-column: span 5;
    }

    .kb-spacer {
        height: 40px;
    }
}
