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

html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    background: linear-gradient(180deg,rgb(25, 87, 112) 0%, rgba(0, 0, 0, 1) 100%);
    color: #ffffff;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    display: flex;
    justify-content: center;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
body:has(.analytics-container), html:has(.analytics-container) {
    overflow: auto;
    height: auto;
    background-attachment: fixed;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 500px;
    height: 100%;
    height: 100dvh;
    padding: env(safe-area-inset-top, 0) 6px 0;
}

.game-header {
    width: 100%;
    text-align: center;
    padding: clamp(2px, 0.8vh, 8px) 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.game-header h1 {
    font-size: clamp(1rem, 3.5vw, 1.6rem);
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.board {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(2px, 0.5vh, 6px);
    flex: 1;
    min-height: 0;
    padding: clamp(2px, 0.5vh, 8px) 0;
}

.row {
    display: flex;
    gap: clamp(2px, 0.5vh, 6px);
}

.tile {
    width: clamp(32px, min(12vw, 7vh), 62px);
    height: clamp(32px, min(12vw, 7vh), 62px);
    border: 2px solid #a3a3a3;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1rem, min(4vw, 2.8vh), 2rem);
    font-weight: 700;
    text-transform: uppercase;
    color: #ffffff;
    transition: border-color 0.1s;
    transform-style: preserve-3d;
    perspective: 500px;
}

.tile.filled {
    border-color: #565758;
    animation: pop 0.1s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.tile.correct {
    background-color: #538d4e;
    border-color: #538d4e;
}

.tile.present {
    background-color: #b59f3b;
    border-color: #b59f3b;
}

.tile.absent {
    background-color: #66666b;
    border-color: #66666b;
}

@keyframes pop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.14); }
    100% { transform: scale(1); }
}

.tile.revealing {
    animation: flipIn 0.25s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

.tile.reveal-out {
    animation: flipOut 0.25s cubic-bezier(0, 0.55, 0.45, 1) forwards;
}

@keyframes flipIn {
    0%   { transform: rotateX(0deg); }
    100% { transform: rotateX(90deg); }
}

@keyframes flipOut {
    0%   { transform: rotateX(90deg); }
    100% { transform: rotateX(0deg); }
}

.row.shake {
    animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%      { transform: translateX(-6px); }
    30%      { transform: translateX(5px); }
    50%      { transform: translateX(-4px); }
    70%      { transform: translateX(3px); }
    90%      { transform: translateX(-1px); }
}

.tile.dance {
    animation: dance 0.5s ease;
}

@keyframes dance {
    0%, 100% { transform: translateY(0); }
    30%      { transform: translateY(-20px); }
    60%      { transform: translateY(4px); }
    80%      { transform: translateY(-6px); }
}

.countdown {
    flex-shrink: 0;
    text-align: center;
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.5s ease, opacity 0.5s ease, padding 0.5s ease;
    padding: 0;
}

.countdown.visible {
    max-height: 80px;
    opacity: 1;
    padding: clamp(2px, 0.5vh, 6px) 0 clamp(1px, 0.3vh, 2px);
}

.countdown-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.8;
    margin-bottom: 4px;
}

.countdown-time {
    display: inline-flex;
    align-items: baseline;
    gap: 2px;
}

.countdown-segment {
    display: inline-flex;
    align-items: baseline;
}

.countdown-number {
    font-size: clamp(1rem, 2vh, 1.4rem);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    min-width: 1.7em;
    text-align: center;
    display: inline-block;
}

.countdown-unit {
    font-size: 0.7rem;
    font-weight: 600;
    opacity: 0.7;
}

.countdown-separator {
    font-size: 1.2rem;
    font-weight: 700;
    opacity: 0.5;
    margin: 0 1px;
}

.keyboard {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(3px, 0.6vw, 6px);
    padding: clamp(6px, 1.5vh, 20px);
    padding-bottom: max(clamp(6px, 1.5vh, 20px), env(safe-area-inset-bottom));
    width: 100%;
    flex-shrink: 0;
    background-color: whitesmoke;
    border-radius: 10px;
    box-shadow: 0 0 5px black;
}

.keyboard-row {
    display: flex;
    gap: clamp(2px, 0.6vw, 6px);
    justify-content: center;
    width: 100%;
}

.key {
    height: clamp(32px, 5.5vh, 54px);
    padding: 0;
    border: none;
    border-radius: clamp(4px, 1vw, 6px);
    background-color: #000000;
    color: #ffffff;
    font-size: clamp(0.6rem, 2vw, 0.85rem);
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    max-width: 44px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: background-color 0.3s ease, transform 0.08s ease;
    box-shadow: 0 0 2px black;
    margin: 1px;
}

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

.key-wide {
    max-width: 65px;
    flex: 1.5;
    font-size: clamp(0.55rem, 1.6vw, 0.75rem);
}

.key.correct {
    background-color: #538d4e;
    transition: background-color 0.5s ease;
}

.key.present {
    background-color: #b59f3b;
    transition: background-color 0.5s ease;
}

.key.absent {
    background-color: #66666b;
    transition: background-color 0.5s ease;
}

.spacer-half {
    flex: 0.5;
}

.toast {
    position: fixed;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #ffffff;
    color: #121213;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    transition: top 0.35s cubic-bezier(0.22, 0.61, 0.36, 1), opacity 0.3s ease;
    opacity: 0;
    pointer-events: none;
    z-index: 100;
    white-space: nowrap;
}

.toast.show {
    top: 60px;
    opacity: 1;
}

.consent-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(18, 18, 19, 0.95);
    padding: 14px 20px;
    z-index: 200;
    transform: translateY(100%);
    transition: transform 0.35s ease;
    text-align: center;
}
.consent-banner.visible {
    transform: translateY(0);
}
.consent-banner p {
    font-size: 0.85rem; color: #ccc; margin-bottom: 10px;
}
.consent-buttons {
    display: flex; gap: 10px; justify-content: center;
}
.consent-btn {
    padding: 8px 20px; border: none; border-radius: 6px; font-size: 0.85rem; font-weight: 700; cursor: pointer;
}
.consent-accept {
    background: #538d4e; color: #fff;
}
.consent-decline {
    background: #3a3a3c; color: #fff;
}

.analytics-container {
    max-width: 800px; margin: 0 auto; padding: 20px 16px 40px;
    -webkit-user-select: text; user-select: text;
}
.analytics-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px; padding-bottom: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.3);
}
.analytics-header h1 {
    font-size: 1.5rem;
}
.analytics-header a {
    color: #fff; text-decoration: none; font-size: 0.85rem; opacity: 0.8;
}
.stats-overview {
    display: flex; gap: 16px; margin-bottom: 24px;
}
.stat-card {
    flex: 1; background: rgba(255,255,255,0.1); border-radius: 10px; padding: 16px; text-align: center;
}
.stat-number {
    display: block; font-size: 2rem; font-weight: 700;
}
.stat-label {
    font-size: 0.75rem; opacity: 0.7; text-transform: uppercase;
}
.analytics-section {
    margin-bottom: 24px;
}
.analytics-section h2 {
    font-size: 1rem; margin-bottom: 8px; opacity: 0.9;
}
.analytics-table {
    width: 100%; border-collapse: collapse; font-size: 0.9rem;
}
.analytics-table th, .analytics-table td {
    padding: 7px 10px; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.15);
}
.analytics-table th {
    font-size: 0.75rem; text-transform: uppercase; opacity: 0.7;
}
.no-data {
    font-size: 0.85rem; opacity: 0.5; font-style: italic;
}

body:has(.analytics-container), html:has(.analytics-container) {
    overflow: auto; height: auto;
}

@media (max-height: 600px) {
    .game-header { padding: 4px 0; }
    .board { padding: 4px 0; }

    .tile {
        width: clamp(36px, 10vw, 50px);
        height: clamp(36px, 10vw, 50px);
        font-size: clamp(1rem, 3.5vw, 1.6rem);
    }

    .key {
        height: clamp(34px, 6vh, 48px);
    }
}

@media (max-width: 400px) {
    .tile {
        width: clamp(36px, 15vw, 48px);
        height: clamp(36px, 15vw, 48px);
        font-size: clamp(1rem, 4vw, 1.4rem);
    }

    .row, .board {
        gap: 3px;
    }

    .keyboard-row, .keyboard {
        gap: 2px;
    }

    .keyboard {
        padding: 10px 4px;
    }

    .key {
        font-size: 0.65rem;
        border-radius: 4px;
        margin: 0.5px;
    }

    .key-wide {
        max-width: 55px;
        font-size: 0.55rem;
    }
}

@media (max-width: 340px) {
    .tile {
        width: 34px;
        height: 34px;
        font-size: 1rem;
        border-width: 1.5px;
    }

    .row, .board {
        gap: 2px;
    }

    .keyboard-row, .keyboard {
        gap: 2px;
    }

    .key {
        font-size: 0.6rem;
        height: 36px;
    }

    .key-wide {
        max-width: 48px;
    }
}

@media (max-height: 440px) and (orientation: landscape) {
    .tile {
        width: clamp(28px, 8vh, 42px);
        height: clamp(28px, 8vh, 42px);
    }

    .row, .board {
        gap: 2px;
    }

    .key {
        height: clamp(28px, 6vh, 40px);
    }

    .keyboard-row, .keyboard {
        gap: 2px;
    }

    .keyboard {
        padding: 6px 4px;
    }

    .game-header { padding: 2px 0; }
    .game-header h1 { font-size: 1rem; }
    .board { padding: 2px 0; }
}