:root {
    --c-correct: #6aaa64;
    --c-present: #c9b458;
    --c-absent: #787c7e;
    --c-bg: #1a1a1c;
    --c-surface: #2c2c2e;
    --c-surface-light: #3a3a3c;
    --c-text: #ffffff;
    --c-text-secondary: #a1a1a3;
    --c-border: #3a3a3c;
    --c-border-active: #565758;
    --c-key-bg: #818384;
    --c-key-hover: #939598;
    --c-shadow: rgba(0, 0, 0, 0.5);
    --c-glow: rgba(255, 255, 255, 0.1);
    --font-main: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
    --animation-smooth: cubic-bezier(0.4, 0.0, 0.2, 1);
    --animation-bounce: cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

body {
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at top left, #2a2a2c, #0f0f11);
    color: var(--c-text);
    font-family: var(--font-main);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    touch-action: manipulation;
    position: relative;
}

body::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        45deg,
        transparent 0px,
        transparent 2px,
        rgba(255, 255, 255, 0.02) 2px,
        rgba(255, 255, 255, 0.02) 4px
    );
    pointer-events: none;
}

#game-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 100%;
    padding: 20px;
    max-width: 1400px;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border-radius: 32px;
    margin: 20px;
}

header {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 15px;
    margin-bottom: 15px;
    position: relative;
}

#changelog-btn {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(129, 131, 132, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: var(--c-text);
    padding: clamp(4px, 1vh, 8px) clamp(8px, 1.5vw, 15px);
    font-size: clamp(12px, 1.8vh, 16px);
    font-weight: 600;
    cursor: pointer;
    border-radius: 20px;
    transition: all 0.3s var(--animation-smooth);
    z-index: 10;
    backdrop-filter: blur(5px);
    letter-spacing: 0.5px;
}

#changelog-btn:hover {
    border-color: var(--c-correct);
    background: rgba(106, 170, 100, 0.2);
    transform: translateY(-50%) scale(1.05);
    box-shadow: 0 0 20px rgba(106, 170, 100, 0.3);
}

header > div:first-of-type {
    display: flex;
    align-items: center;
    gap: 15px;
    justify-content: center;
    margin-bottom: 8px;
}

header img {
    height: 40px;
    width: auto;
    filter: drop-shadow(0 0 20px rgba(106, 170, 100, 0.5));
    transition: transform 0.3s var(--animation-bounce);
}

header img:hover {
    transform: rotate(5deg) scale(1.1);
}

#game-title {
    font-weight: 900;
    font-size: clamp(24px, 5vh, 48px);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin: 0;
    text-align: center;
    line-height: 1;
    background: linear-gradient(135deg, #ffffff, #a8a8a8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 2px 20px rgba(255, 255, 255, 0.2);
    position: relative;
}

#game-title::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 50%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--c-correct), transparent);
}

#game-subtitle {
    font-size: clamp(10px, 1.4vh, 12px);
    color: var(--c-text-secondary);
    margin-top: 5px;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-align: center;
    font-weight: 500;
    opacity: 0.8;
}

#give-up-btn {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: white;
    border: none;
    margin-top: 12px;
    padding: 10px 30px;
    font-size: 14px;
    font-weight: bold;
    border-radius: 30px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.3s var(--animation-smooth);
    box-shadow: 0 8px 15px rgba(231, 76, 60, 0.3);
    width: fit-content;
    position: relative;
    overflow: hidden;
}

#give-up-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

#give-up-btn:hover::before {
    left: 100%;
}

#give-up-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 25px rgba(231, 76, 60, 0.5);
}

#give-up-btn:active {
    transform: translateY(0);
}

#board-container {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: clamp(4px, 1.5vh, 12px);
    flex-grow: 1;
    aspect-ratio: 5 / 6;
    width: 100%;
    max-width: min(70vh, 700px);
    margin: 0 auto 20px auto;
    position: relative;
    padding: clamp(8px, 2vh, 20px);
    background: rgba(0, 0, 0, 0.2);
    border-radius: 20px;
    backdrop-filter: blur(5px);
}

.row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: clamp(4px, 1.5vh, 12px);
}

.tile {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(1.8rem, min(8vh, 8vw), 5rem);
    font-weight: bold;
    text-transform: uppercase;
    user-select: none;
    border: 2px solid var(--c-border);
    color: var(--c-text);
    background: transparent;
    transition: all 0.2s;
    position: relative;
    overflow: visible;
    border-radius: clamp(6px, 1.5vh, 12px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.1), transparent 70%);
    border-radius: clamp(5px, 1.2vh, 10px);
    pointer-events: none;
}

.tile-content {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2;
}

.tile[data-state='active'] {
    border-color: var(--c-border-active);
    animation: popIn 0.2s var(--animation-bounce);
    box-shadow: 0 0 20px var(--c-glow);
}

.tile[data-state='correct'] {
    background: linear-gradient(135deg, var(--c-correct), #4a7f46);
    border-color: var(--c-correct);
    box-shadow: 0 0 30px rgba(106, 170, 100, 0.5);
}

.tile[data-state='present'] {
    background: linear-gradient(135deg, var(--c-present), #9e8b40);
    border-color: var(--c-present);
    box-shadow: 0 0 30px rgba(201, 180, 88, 0.5);
}

.tile[data-state='absent'] {
    background: linear-gradient(135deg, var(--c-absent), #5c5e60);
    border-color: var(--c-absent);
}

.tile.flip {
    animation: flipIn 0.6s var(--animation-smooth);
    backface-visibility: hidden;
}

.tile-content.fall {
    animation: fallOff 1.5s cubic-bezier(0.3, 0.8, 0.4, 1) forwards;
    pointer-events: none;
}

@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0.5; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-2px); }
    20%, 40%, 60%, 80% { transform: translateX(2px); }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-30px); }
    60% { transform: translateY(-15px); }
}

@keyframes fallOff {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    30% { transform: translateY(-50px) rotate(-15deg); opacity: 1; }
    100% { transform: translateY(120vh) rotate(360deg); opacity: 0; }
}

.row.shake {
    animation: shake 0.4s var(--animation-smooth);
}

.tile.bounce {
    animation: bounce 1s var(--animation-bounce);
}

#keyboard {
    width: 100%;
    max-width: min(800px, 100%);
    display: flex;
    flex-direction: column;
    gap: clamp(4px, 1vh, 10px);
    margin-bottom: 5px;
    padding: clamp(8px, 1.5vh, 15px);
    background: rgba(0, 0, 0, 0.2);
    border-radius: 20px;
    backdrop-filter: blur(5px);
}

.keyboard-row {
    display: flex;
    width: 100%;
    justify-content: center;
    gap: clamp(3px, 0.8vw, 8px);
}

.key {
    font-family: inherit;
    font-weight: bold;
    border: none;
    height: clamp(35px, 7vh, 55px);
    border-radius: clamp(6px, 1.2vh, 10px);
    cursor: pointer;
    background: linear-gradient(135deg, var(--c-key-bg), #6b6d70);
    color: var(--c-text);
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    text-transform: uppercase;
    font-size: clamp(12px, 2.5vh, 18px);
    transition: all 0.2s var(--animation-smooth);
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3), inset 0 1px 2px rgba(255, 255, 255, 0.2);
    position: relative;
    overflow: hidden;
}

.key::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.key:hover::before {
    left: 100%;
}

.key:hover {
    transform: translateY(-2px);
    background: linear-gradient(135deg, var(--c-key-hover), #7f8185);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

.key:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.key.big {
    flex: 1.5;
    font-size: clamp(10px, 2vh, 14px);
}

.key[data-state='correct'] {
    background: linear-gradient(135deg, var(--c-correct), #4a7f46);
    box-shadow: 0 0 20px rgba(106, 170, 100, 0.5);
}

.key[data-state='present'] {
    background: linear-gradient(135deg, var(--c-present), #9e8b40);
    box-shadow: 0 0 20px rgba(201, 180, 88, 0.5);
}

.key[data-state='absent'] {
    background: linear-gradient(135deg, var(--c-absent), #5c5e60);
    opacity: 0.8;
}

#toast-container {
    position: fixed;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
    width: max-content;
}

.toast {
    background: rgba(238, 238, 238, 0.95);
    color: #111;
    padding: clamp(10px, 1.5vh, 15px) clamp(20px, 3vh, 30px);
    border-radius: 30px;
    font-weight: bold;
    font-size: clamp(14px, 2.5vh, 20px);
    opacity: 1;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3), 0 0 20px var(--c-correct);
    text-align: center;
    animation: toastIn 0.4s var(--animation-bounce);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(15px);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: linear-gradient(135deg, #1e1e20, #151517);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: clamp(25px, 5vh, 40px);
    width: clamp(300px, 80vw, 800px);
    max-height: 90vh;
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    position: relative;
    animation: modalIn 0.4s var(--animation-bounce);
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    font-size: clamp(28px, 6vh, 48px);
    font-weight: 900;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 2px;
    background: linear-gradient(135deg, #fff, #ccc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 2px 10px rgba(255, 255, 255, 0.1);
}

.modal-header.win {
    background: linear-gradient(135deg, #6aaa64, #4a7f46);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.modal-header.loss {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.modal-header.giveup {
    color: var(--c-text-secondary);
}

#result-word {
    font-size: clamp(20px, 3.5vh, 32px);
    margin: 10px 0;
    letter-spacing: 4px;
    text-transform: uppercase;
    color: #aaa;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#result-word span {
    color: #fff;
    font-weight: bold;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

.stat-grid {
    display: flex;
    justify-content: center;
    gap: clamp(20px, 4vw, 50px);
    margin: 20px 0;
    width: 100%;
    padding: 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 16px;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.stat-box::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--c-correct), transparent);
}

.stat-number {
    font-size: clamp(32px, 7vh, 56px);
    font-weight: bold;
    line-height: 1;
    background: linear-gradient(135deg, #fff, #ccc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stat-label {
    font-size: clamp(11px, 1.8vh, 18px);
    color: var(--c-text-secondary);
    margin-top: 8px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 1px;
}

.play-btn {
    background: linear-gradient(135deg, var(--c-correct), #4a7f46);
    color: white;
    border: none;
    padding: 15px 0;
    width: 100%;
    border-radius: 50px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    margin-top: 10px;
    text-transform: uppercase;
    transition: all 0.3s var(--animation-smooth);
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 15px rgba(106, 170, 100, 0.4);
}

.play-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 25px rgba(106, 170, 100, 0.6);
}

.play-btn:active {
    transform: translateY(0);
}

.reset-btn {
    background: transparent;
    color: #ffffff;
    border: 2px solid rgba(255, 255, 255, 0.2);
    padding: 15px 0;
    width: 100%;
    border-radius: 50px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    margin-top: 12px;
    text-transform: uppercase;
    transition: all 0.3s var(--animation-smooth);
}

.reset-btn:hover {
    border-color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
    transform: scale(1.02);
}

#close-changelog {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    transition: all 0.3s;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

#close-changelog:hover {
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.2);
    transform: rotate(90deg);
}

.changelog-list {
    text-align: left;
    width: 100%;
    font-size: clamp(15px, 2.2vh, 20px);
    line-height: 1.6;
    color: #ccc;
    margin-top: 15px;
    padding-left: 25px;
}

.changelog-list li {
    margin-bottom: 10px;
    position: relative;
}

.changelog-list li::before {
    content: '→';
    position: absolute;
    left: -20px;
    color: var(--c-correct);
    font-weight: bold;
}

/* Ultra-wide screens (larger than 1400px) */
@media (min-width: 1400px) {
    #board-container {
        max-width: min(80vh, 800px);
    }
    
    .tile {
        font-size: clamp(3rem, 10vh, 6rem);
    }
}

/* Large screens (1200px - 1400px) */
@media (min-width: 1200px) and (max-width: 1399px) {
    #board-container {
        max-width: min(75vh, 700px);
    }
    
    .tile {
        font-size: clamp(2.5rem, 9vh, 5.5rem);
    }
}

/* Medium screens (900px - 1199px) */
@media (min-width: 900px) and (max-width: 1199px) {
    #board-container {
        max-width: min(70vh, 600px);
    }
    
    .tile {
        font-size: clamp(2.2rem, 8vh, 5rem);
    }
}

/* Small screens (600px - 899px) */
@media (min-width: 600px) and (max-width: 899px) {
    #game-layout {
        padding: 15px;
    }
    
    #board-container {
        max-width: min(65vh, 500px);
    }
    
    .tile {
        font-size: clamp(1.8rem, 7vh, 4rem);
    }
    
    header > div:first-of-type {
        gap: 10px;
    }
    
    header img {
        height: 30px;
    }
    
    #game-title {
        font-size: 22px;
    }
    
    .key {
        height: 40px;
        font-size: 14px;
    }
}

/* Very small screens (under 600px) */
@media (max-width: 599px) {
    #game-layout {
        padding: 10px;
        margin: 10px;
        border-radius: 20px;
    }
    
    #board-container {
        max-width: min(85vw, 450px);
        gap: clamp(3px, 1vh, 8px);
    }
    
    .row {
        gap: clamp(3px, 1vh, 8px);
    }
    
    .tile {
        font-size: clamp(1.5rem, 6vh, 2.5rem);
        border-radius: clamp(4px, 1vh, 8px);
    }
    
    header > div:first-of-type {
        gap: 8px;
    }
    
    header img {
        height: 25px;
    }
    
    #game-title {
        font-size: 18px;
    }
    
    .key {
        height: 38px;
        font-size: 13px;
    }
    
    .key.big {
        font-size: 11px;
    }
}

/* Extra small screens (under 400px) */
@media (max-width: 399px) {
    #board-container {
        max-width: 95vw;
        gap: 2px;
    }
    
    .row {
        gap: 2px;
    }
    
    .tile {
        font-size: clamp(1.2rem, 5vh, 2rem);
        border-radius: 4px;
        border-width: 1px;
    }
    
    .key {
        height: 35px;
        font-size: 11px;
    }
    
    .key.big {
        font-size: 9px;
    }
    
    #changelog-btn {
        padding: 3px 8px;
        font-size: 10px;
    }
}

/* Landscape mode on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    #game-layout {
        flex-direction: row;
        flex-wrap: wrap;
        padding: 8px;
    }
    
    header {
        width: 25%;
        border-bottom: none;
        border-right: 2px solid rgba(255, 255, 255, 0.1);
        padding-right: 15px;
        margin-right: 15px;
    }
    
    #board-container {
        width: 50%;
        max-width: 50vh;
        margin: 0;
    }
    
    #keyboard {
        width: 25%;
        margin: 0;
    }
    
    .keyboard-row {
        flex-direction: column;
    }
    
    .key {
        height: auto;
        min-height: 40px;
        width: 100%;
    }
}

/* Short screens (netbooks, etc) */
@media (max-height: 700px) and (min-width: 800px) {
    #board-container {
        max-width: min(60vh, 600px);
    }
    
    .tile {
        font-size: clamp(1.8rem, 6vh, 4rem);
    }
    
    .key {
        height: 40px;
    }
}

/* Tall screens (very high resolution) */
@media (min-height: 1200px) {
    #board-container {
        max-width: min(60vh, 800px);
    }
    
    .tile {
        font-size: clamp(3rem, 8vh, 6rem);
    }
    
    .key {
        height: 60px;
        font-size: 20px;
    }
}
