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

:root {
    --color-background: #121213;
    --color-surface: #1a1a1b;
    --color-text-primary: #ffffff;
    --color-text-secondary: #818384;
    --color-border: #3a3a3c;
    --color-correct: #538d4e;
    --color-present: #b59f3b;
    --color-absent: #3a3a3c;
    --color-primary: #538d4e;
    --color-error: #d94e4e;
}

body {
    font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--color-background);
    color: var(--color-text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    touch-action: manipulation;
}

.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--color-background);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    pointer-events: none;
}

.loading-screen.active {
    display: flex;
    pointer-events: auto;
}

.loading-content {
    text-align: center;
    padding: 40px;
}

.loading-logo {
    width: 200px;
    height: auto;
    margin-bottom: 40px;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--color-border);
    border-top: 4px solid var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 30px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-content p {
    font-size: 16px;
    color: var(--color-text-secondary);
    margin-bottom: 20px;
}

.loading-bar {
    width: 300px;
    height: 6px;
    background-color: var(--color-border);
    border-radius: 3px;
    overflow: hidden;
    margin: 0 auto;
}

.loading-progress {
    height: 100%;
    background-color: var(--color-primary);
    width: 0%;
    transition: width 0.3s ease;
}

.container {
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
    position: relative;
    visibility: visible;
    opacity: 1;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
    position: relative;
    margin: -20px -20px 0 -20px;
}

.game-title {
    flex: 1;
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    color: var(--color-text-primary);
    letter-spacing: 0.1em;
    text-transform: none;
    padding-left: 40px; 
}

h1 {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: 0.2em;
}

.header-actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    transition: transform 0.1s;
}

.icon-btn:hover {
    transform: scale(1.1);
}

.screen {
    display: none !important;
}

.screen.active {
    display: block !important;
}

#pre-game.active {
    display: flex !important;
}

#game-screen {
    padding: 10px 20px 20px;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    height: calc(100vh - 76px);
}

/* Mobile: Scrollable game screen */
@media (max-width: 768px) {
    body.game-active > .container {
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    body.game-active #game-screen {
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 10px 10px 10px;
    }

    body.game-active .word-chain {
        flex: 1 1 auto;
        overflow-y: visible;
        overflow-x: hidden;
        min-height: 0;
    }

    body.game-active .keyboard {
        flex-shrink: 0;
    }
}

body.game-active > .container {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 500px;
    height: 100vh;
    background-color: var(--color-background);
    z-index: 1000;
    overflow: hidden;
}

body.game-active {
    overflow: hidden;
}

body.game-active #pre-game,
body.game-active #end-screen,
body.game-active #already-played {
    display: none !important;
}

body.game-active footer {
    display: none;
}

body.end-screen-active > .container {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 500px;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    background-color: var(--color-background);
    z-index: 1000;
}

body.end-screen-active {
    overflow: hidden;
}

body.end-screen-active #pre-game,
body.end-screen-active #game-screen {
    display: none !important;
}

body.end-screen-active footer {
    display: none;
}

#pre-game {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
}

.pre-game-content {
    text-align: center;
    max-width: 420px;
    width: 100%;
}

.logo-section {
    margin-bottom: 24px;
}

.main-logo {
    width: 120px;
    height: 120px;
}

.day-badge {
    margin-bottom: 24px;
}

.day-badge h2 {
    font-size: 32px;
    font-weight: 700;
    margin: 0;
    color: var(--color-primary);
    letter-spacing: 0.05em;
}

.game-goal {
    margin-bottom: 32px;
    padding: 20px;
    background-color: var(--color-surface);
    border-radius: 8px;
}

.goal-text {
    font-size: 18px;
    margin: 0 0 12px 0;
    color: var(--color-text-primary);
}

.time-text {
    font-size: 16px;
    margin: 0;
    color: var(--color-text-secondary);
}

.goal-text strong,
.time-text strong {
    color: var(--color-primary);
    font-weight: 700;
}

.hint {
    font-size: 14px;
    color: var(--color-text-secondary);
    opacity: 0.7;
}

.primary-btn {
    background-color: var(--color-primary);
    color: white;
    border: none;
    padding: 16px 48px;
    font-size: 18px;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.1em;
    width: 100%;
    margin-bottom: 12px;
}

.primary-btn:hover {
    background-color: #6aaa64;
    transform: translateY(-2px);
}

.secondary-btn {
    background-color: transparent;
    color: var(--color-text-primary);
    border: 2px solid var(--color-border);
    padding: 14px 48px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.05em;
    width: 100%;
}

.secondary-btn:hover {
    background-color: var(--color-surface);
    border-color: var(--color-text-secondary);
    transform: translateY(-2px);
}

.primary-btn:active {
    transform: scale(0.98);
}

.game-info {
    margin-bottom: 15px;
    flex-shrink: 0;
}

.timer-section {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background-color: var(--color-surface);
    border-radius: 8px;
    border: 2px solid var(--color-border);
}

.timer {
    font-size: 48px;
    font-weight: 700;
    color: var(--color-primary);
}

.timer.warning {
    color: #b59f3b;
    animation: pulse 1s infinite;
}

.timer.danger {
    color: var(--color-error);
    animation: pulse 0.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.stage {
    font-size: 18px;
    color: var(--color-text-secondary);
}

.stage span {
    color: var(--color-text-primary);
    font-weight: 700;
}

.word-chain {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    min-height: 60px;
    overflow-y: auto;
}

.starting-letters {
    display: inline-block;
    padding: 12px 24px;
    background-color: var(--color-surface);
    border: 2px solid var(--color-primary);
    border-radius: 4px;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 0.2em;
}

.word-item {
    display: inline-block;
    padding: 12px 24px;
    background-color: var(--color-primary);
    border-radius: 4px;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 0.1em;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.input-section {
    margin-bottom: 15px;
    flex-shrink: 0;
}

.current-letters {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--color-primary);
    letter-spacing: 0.2em;
}

#word-input {
    width: 100%;
    padding: 16px;
    font-size: 20px;
    background-color: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text-primary);
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 10px;
    cursor: default;
}

#word-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

#word-input[readonly] {
    cursor: default;
    user-select: none;
}

#word-input:not([readonly]) {
    cursor: text;
}

.switcharo-btn {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    background-color: var(--color-surface);
    border: 2px solid var(--color-present);
    border-radius: 4px;
    color: var(--color-text-primary);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.1em;
}

.switcharo-btn:hover {
    background-color: var(--color-present);
}

.switcharo-btn:active {
    transform: scale(0.98);
}

.switcharo-btn.used {
    animation: switchAnim 0.3s ease-out;
}

.switcharo-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--color-surface);
    border-color: var(--color-border);
}

.switcharo-btn:disabled:hover {
    background-color: var(--color-surface);
}

@keyframes switchAnim {
    0% { transform: rotate(0deg); }
    50% { transform: rotate(180deg); }
    100% { transform: rotate(360deg); }
}

.error-message {
    min-height: 30px;
    padding: 10px;
    text-align: center;
    color: var(--color-error);
    font-weight: 600;
    animation: shake 0.3s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

.keyboard {
    margin-top: auto;
    padding: 10px 5px;
    flex-shrink: 0;
    display: block;
    width: 100%;
}

/* Keep on-screen keyboard visible on all devices */

.keyboard-row {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-bottom: 4px;
}

.key {
    min-width: 40px;
    height: 54px;
    background-color: var(--color-absent);
    border: none;
    border-radius: 4px;
    color: var(--color-text-primary);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

.key:hover {
    background-color: #4a4a4c;
}

.key:active {
    transform: scale(0.95);
}

.key-large {
    min-width: 60px;
    font-size: 11px;
}

.results {
    text-align: center;
    padding: 20px;
}

.results h2 {
    font-size: 28px;
    margin-bottom: 30px;
}

.final-score {
    margin-bottom: 30px;
}

.score-label {
    font-size: 16px;
    color: var(--color-text-secondary);
    margin-bottom: 10px;
}

.score-value {
    font-size: 72px;
    font-weight: 700;
    color: var(--color-primary);
}

.score-subtext {
    font-size: 18px;
    color: var(--color-text-secondary);
    margin-top: 10px;
}

.word-list {
    margin: 30px 0;
    padding: 20px;
    background-color: var(--color-surface);
    border-radius: 8px;
}

.word-list h3 {
    font-size: 18px;
    margin-bottom: 15px;
    color: var(--color-text-secondary);
}

#final-word-chain, #played-word-chain {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.chain-word {
    padding: 8px 16px;
    background-color: var(--color-primary);
    border-radius: 4px;
    font-weight: 600;
    letter-spacing: 0.05em;
}

.next-game {
    margin-top: 20px;
    color: var(--color-text-secondary);
    font-size: 14px;
}

.next-game span {
    color: var(--color-text-primary);
    font-weight: 600;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: var(--color-surface);
    padding: 30px;
    border-radius: 8px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: var(--color-text-primary);
    font-size: 32px;
    cursor: pointer;
    line-height: 1;
}

.close-btn:hover {
    color: var(--color-primary);
}

.modal-content h2 {
    margin-bottom: 20px;
    font-size: 24px;
}

.instructions p {
    margin-bottom: 15px;
    line-height: 1.6;
}

.instructions ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.instructions li {
    margin-bottom: 8px;
    line-height: 1.6;
}

.example {
    background-color: var(--color-background);
    padding: 15px;
    border-radius: 4px;
    margin: 15px 0;
    border-left: 3px solid var(--color-primary);
}

.example p {
    margin-bottom: 5px;
}

.example-text {
    font-style: italic;
    color: var(--color-text-secondary);
}

.stats-content {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-top: 20px;
}

.stat-item {
    text-align: center;
    padding: 20px;
    background-color: var(--color-background);
    border-radius: 4px;
}

.stat-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 8px;
}

.stat-label {
    font-size: 14px;
    color: var(--color-text-secondary);
}

.error-screen {
    text-align: center;
    padding: 40px 20px;
}

.error-screen h2 {
    font-size: 24px;
    color: var(--color-error);
    margin-bottom: 20px;
}

.error-screen p {
    color: var(--color-text-secondary);
    line-height: 1.6;
    margin-bottom: 20px;
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
    }

    h1 {
        font-size: 24px;
    }

    .header-logo {
        height: 60px;
    }

    .timer {
        font-size: 36px;
    }

    .score-value {
        font-size: 56px;
    }

    .loading-logo {
        width: 150px;
    }

    .loading-bar {
        width: 250px;
    }

    #game-screen {
        padding: 10px;
    }

    .key {
        min-width: 32px;
        height: 52px;
        font-size: 12px;
        padding: 0 4px;
    }

    .key-large {
        min-width: 50px;
        font-size: 10px;
    }

    .keyboard-row {
        gap: 4px;
    }

    .keyboard {
        padding: 10px 4px 15px;
    }

    body.game-active > .container {
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    body.game-active #game-screen {
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
        overflow-x: hidden;
        display: flex;
        flex-direction: column;
    }

    body.game-active .word-chain {
        flex: 1 1 auto;
        overflow-y: visible;
        overflow-x: hidden;
        min-height: 0;
    }

    body.game-active .keyboard {
        flex-shrink: 0;
        flex-grow: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

