@font-face {
    font-family: Coolvetica;
    src: url('Coolvetica/coolvetica rg.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

:root {
    --subtitle-color: #000;
    --color-primary: #f07331;
    --color-primary-light: #eb6343;
    --color-secondary: #fec842;
    --color-accent: #2f43ca;
    --color-bg: #fff;
    --color-text: #000;
    --target-word-color: var(--color-accent);
    --bg-main: var(--color-bg);
    --bg-header: var(--color-bg);
    --bg-overlay: var(--color-bg);
    --border-color: var(--color-text);
    --text-primary: var(--color-text);
    --word-text: var(--color-text);
    --word-bg: var(--color-bg);
    --shadow-word: rgb(0 0 0 / 30%);
    --shadow-word-hover: rgb(0 0 0 / 40%);
    --button-radius: 24px;
    --level-a1: #fec842;
    --level-a2: #fec842;
    --level-b1: #f07331;
    --level-b2: #f07331;
    --level-c1: #2f43ca;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #1a1a1a;
        --color-text: #fff;
        --target-word-color: #fec842;
        --bg-main: #1a1a1a;
        --bg-header: #1a1a1a;
        --bg-overlay: #1a1a1a;
        --border-color: #444;
        --text-primary: #fff;
        --word-text: #fff;
        --word-bg: #2a2a2a;
        --shadow-word: rgb(255 255 255 / 10%);
        --shadow-word-hover: rgb(255 255 255 / 15%);
        --subtitle-color: #fff;
    }
}

[data-theme="dark"] {
    --color-bg: #1a1a1a;
    --color-text: #fff;
    --target-word-color: #fec842;
    --bg-main: #1a1a1a;
    --bg-header: #1a1a1a;
    --bg-overlay: #1a1a1a;
    --border-color: #444;
    --text-primary: #fff;
    --word-text: #fff;
    --word-bg: #2a2a2a;
    --shadow-word: rgb(255 255 255 / 10%);
    --shadow-word-hover: rgb(255 255 255 / 15%);
    --subtitle-color: #fff;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    background: var(--bg-main);
    font-family: Helvetica, Arial, sans-serif;
}

#header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--bg-header);
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    border-bottom: 2px solid var(--border-color);
    color: var(--text-primary);
    height: 70px;
}

#header .header-item {
    color: var(--text-primary) !important;
    font-size: 22px;
}

#header .timer-wrapper {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

#target-word {
    font-size: 28px;
    color: var(--target-word-color);
    font-weight: bold;
}

#score {
    font-size: 24px;
    color: var(--text-primary);
}

.theme-switch-wrapper {
    position: absolute;
    top: 20px;
    right: 20px;
}

.theme-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #ccc;
    transition: 0.4s;
    border-radius: 34px;
}

.slider::before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--color-primary);
}

input:checked+.slider::before {
    transform: translateX(24px);
}

#timer {
    font-size: 28px;
    color: var(--text-primary);
    min-width: 80px;
    text-align: center;
    opacity: 0;
    transition: opacity 0.3s;
}

#timer.visible {
    opacity: 1;
}

#start-screen,
#end-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 200;
    padding: 20px;
}

#end-screen {
    display: none;
}

h1 {
    color: var(--color-text);
    font-size: 48px;
    margin-bottom: 20px;
    text-align: center;
    font-family: Coolvetica, sans-serif;
}

button {
    background: var(--color-primary);
    color: #fff;
    border: none;
    padding: 15px 40px;
    font-size: 24px;
    cursor: pointer;
    border-radius: var(--button-radius);
    transition: background 0.3s;
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

button:hover {
    background: var(--color-primary-light);
}

#game-area {
    position: fixed;
    inset: 70px 0 0;
    overflow: hidden;
    pointer-events: none;
    background: var(--bg-main);
}

.word {
    position: absolute;
    font-size: 32px;
    font-weight: bold;
    color: var(--word-text);
    background: var(--word-bg);
    cursor: pointer;
    user-select: none;
    padding: 8px 15px;
    border-radius: var(--button-radius);
    box-shadow: 2px 2px 5px var(--shadow-word);
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    will-change: transform, left, top;
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000;
    white-space: nowrap;
    z-index: 10;
}

@media (hover: hover) {
    .word:hover {
        transform: scale(1.15);
        box-shadow: 4px 4px 10px var(--shadow-word-hover);
        z-index: 20;
    }
}

.target {
    background: var(--color-primary) !important;
    color: var(--color-bg) !important;
}

.level-selector {
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.level-btn {
    background: var(--bg-header);
    border: 2px solid var(--border-color);
    padding: 10px 20px;
    font-size: 18px;
    cursor: pointer;
    border-radius: var(--button-radius);
    color: var(--text-primary);
    transition: all 0.3s;
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
    outline: none;
}

.level-btn[data-level="A1"]:hover,
.level-btn[data-level="A1"].active {
    background: var(--level-a1);
    color: #000;
    border-color: var(--level-a1);
}

.level-btn[data-level="A2"]:hover,
.level-btn[data-level="A2"].active {
    background: var(--level-a2);
    color: #000;
    border-color: var(--level-a2);
}

.level-btn[data-level="B1"]:hover,
.level-btn[data-level="B1"].active {
    background: var(--level-b1);
    color: #fff;
    border-color: var(--level-b1);
}

.level-btn[data-level="B2"]:hover,
.level-btn[data-level="B2"].active {
    background: var(--level-b2);
    color: #fff;
    border-color: var(--level-b2);
}

.level-btn[data-level="C1"]:hover,
.level-btn[data-level="C1"].active {
    background: var(--level-c1);
    color: #fff;
    border-color: var(--level-c1);
}

.subtitle {
    color: #000;
    font-size: 20px;
    margin-bottom: 30px;
    text-align: center;
}

#start-screen .subtitle,
#end-screen .subtitle {
    color: var(--subtitle-color);
    font-size: 24px;
    font-weight: normal;
    margin-bottom: 30px;
    text-align: center;
    width: 100%;
    display: block;
}

#final-score {
    font-size: 36px;
    color: var(--text-primary);
    margin-bottom: 10px;
    text-align: center;
}

#final-rank {
    font-size: 28px;
    color: var(--color-accent);
    margin-bottom: 20px;
    font-weight: bold;
    text-align: center;
}

#guessed-words {
    max-height: 200px;
    overflow-y: auto;
    background: rgb(240 115 49 / 15%);
    padding: 15px;
    border-radius: var(--button-radius);
    margin-bottom: 20px;
    text-align: left;
    width: 90%;
    max-width: 400px;
    -webkit-overflow-scrolling: touch;
}

.guessed-word {
    padding: 8px 0;
    border-bottom: 1px solid rgb(240 115 49 / 30%);
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.4;
}

.guessed-word:last-child {
    border-bottom: none;
}

.hamburger-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    width: 44px;
    height: 44px;
    background: var(--bg-header);
    border: none;
    border-radius: var(--button-radius);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 0;
    z-index: 300;
    min-width: 44px;
}

.hamburger-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--color-text);
    border-radius: 1px;
}

.menu-overlay {
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / 50%);
    z-index: 400;
    display: none;
    justify-content: flex-start;
    align-items: flex-start;
}

.menu-overlay.active {
    display: flex;
}

.menu-content {
    background: var(--bg-header);
    width: 280px;
    max-width: 80%;
    height: 100%;
    padding: 20px;
    box-shadow: 4px 0 15px rgb(0 0 0 / 30%);
    overflow-y: auto;
    position: relative;
}

.menu-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--color-text);
    padding: 0;
    min-width: 36px;
}

.menu-description {
    margin-top: 30px;
    margin-bottom: 25px;
}

.menu-description h3 {
    color: var(--color-primary);
    font-size: 22px;
    margin-bottom: 12px;
}

.menu-description p {
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.5;
}

.menu-link {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--color-text);
    text-decoration: none;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: var(--button-radius);
    font-size: 16px;
    margin-bottom: 12px;
    transition: background 0.3s, border-color 0.3s;
}

.menu-link:hover {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.boosty-link {
    color: #ee7829;
    border-color: #ee7829;
}

.boosty-link svg {
    fill: #ee7829;
}

.boosty-link:hover {
    background: #ee7829;
    color: #fff;
}

.boosty-link:hover svg {
    fill: #fff;
}

.rules-modal {
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / 70%);
    z-index: 500;
    display: none;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.rules-modal.active {
    display: flex;
}

.rules-content {
    background: var(--bg-header);
    border-radius: 16px;
    padding: 30px;
    max-width: 400px;
    width: 100%;
    position: relative;
    box-shadow: 0 10px 40px rgb(0 0 0 / 40%);
}

.rules-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: transparent;
    border: none;
    font-size: 32px;
    cursor: pointer;
    color: var(--color-text);
    padding: 0;
    min-width: 40px;
    height: 40px;
}

.rules-content h2 {
    color: var(--color-primary);
    font-size: 28px;
    margin-bottom: 20px;
    text-align: center;
}

.rules-content p {
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.6;
    margin-bottom: 15px;
}

.rules-content strong {
    color: var(--color-primary);
}

.rules-good-luck {
    text-align: center;
    font-weight: bold;
    margin-top: 25px !important;
    color: #000 !important;
}

@media (width <=768px) {
    .hamburger-btn {
        top: 12px;
        left: 12px;
        width: 40px;
        height: 40px;
    }

    .hamburger-btn span {
        width: 18px;
        height: 2px;
    }

    #header {
        padding: 8px 12px;
        padding-top: max(8px, env(safe-area-inset-top));
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        height: 70px;
    }

    #header .header-item {
        font-size: 16px !important;
        margin-top: -10px;
    }

    #header .timer-wrapper {
        position: absolute;
        top: 55px;
        left: 50%;
        transform: translateX(-50%);
    }

    #target-word {
        font-size: 20px;
        max-width: 35vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #timer {
        font-size: 18px;
        min-width: 60px;
    }

    #score {
        font-size: 18px;
    }

    #game-area {
        top: 90px;
    }

    h1 {
        font-size: 32px;
    }

    .subtitle {
        font-size: 20px;
    }

    button {
        padding: 12px 30px;
        font-size: 18px;
        min-width: 180px;
    }

    .level-selector {
        gap: 8px;
    }

    .level-btn {
        padding: 8px 16px;
        font-size: 14px;
        min-width: 50px;
    }

    .word {
        font-size: 18px;
        padding: 6px 12px;
        border-width: 2px;
        -webkit-font-smoothing: antialiased;
        font-weight: 600;
    }

    .word::after {
        content: '';
        position: absolute;
        inset: -8px;
        background: transparent;
    }

    .word:active {
        transform: scale(1.05);
        opacity: 0.9;
    }

    button:active {
        background: var(--color-primary-light);
        transform: scale(0.98);
    }

    #final-score {
        font-size: 28px;
    }

    #final-rank {
        font-size: 22px;
    }

    #guessed-words {
        max-height: 150px;
        font-size: 14px;
    }

    .guessed-word {
        font-size: 14px;
        padding: 6px 0;
    }

    .rules-content {
        padding: 20px;
    }

    .rules-content h2 {
        font-size: 22px;
    }

    .rules-content p {
        font-size: 14px;
    }
}

@media (width <=380px) {
    #header .header-item {
        font-size: 14px !important;
    }

    #target-word {
        font-size: 16px;
        max-width: 30vw;
    }

    #timer {
        font-size: 16px;
        min-width: 50px;
    }

    #score {
        font-size: 16px;
    }

    .word {
        font-size: 16px;
        padding: 5px 10px;
    }

    .level-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
}

@media (width >=769px) and (width <=1024px) {
    #header {
        height: 80px;
        padding: 15px 20px;
    }

    #game-area {
        top: 80px;
    }

    .word {
        font-size: 28px;
        padding: 10px 18px;
    }

    .word:active {
        transform: scale(1.1);
    }
}