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

body {
    background: #faf8ef;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-family: 'Arial', 'PingFang SC', sans-serif;
    overflow: hidden;
    touch-action: none;
}

.game-wrapper {
    width: 100%;
    max-width: 500px;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
}

.game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.game-title {
    font-size: 36px;
    font-weight: 700;
    color: #776e65;
}

.game-title-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
}

.more-modes-dropdown {
    position: relative;
}

.more-modes-btn {
    background: #bbada0;
    border: none;
    color: #fff;
    height: 28px;
    padding: 0 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.more-modes-btn:active {
    transform: scale(0.9);
    background: #a8998a;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) scaleY(0);
    transform-origin: top center;
    margin-top: 6px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    min-width: 110px;
    z-index: 50;
    overflow: hidden;
    opacity: 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
    pointer-events: none;
}

.dropdown-menu.show {
    transform: translateX(-50%) scaleY(1);
    opacity: 1;
    pointer-events: auto;
}

.dropdown-item {
    padding: 10px 16px;
    font-size: 14px;
    color: #776e65;
    cursor: pointer;
    transition: background 0.15s;
    text-align: center;
}

.dropdown-item:not(.disabled):active {
    background: #ede4d3;
}

.dropdown-item.active-mode {
    color: #8f7a66;
    font-weight: 700;
    background: #e0d5c3;
}



.dropdown-item.disabled {
    color: #ccc0b3;
    cursor: default;
}

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

.back-btn {
    background: #8f7a66;
    border: none;
    color: #fff;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.back-btn:active {
    transform: scale(0.95);
    background: #7a6a58;
}

.new-game-header-btn {
    background: #776e65;
}

.new-game-header-btn:active {
    background: #6b6259;
}

.game-info-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.score-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #bbada0;
    padding: 6px 0;
    border-radius: 6px;
    flex: 1;
    margin: 0 4px;
}

.score-label {
    font-size: 12px;
    color: #eee4da;
    text-transform: uppercase;
}

.score-value {
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    min-height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.best-score-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.best-player-name {
    font-size: 10px;
    font-weight: 400;
    color: #eee4da;
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.new-game-btn-inline {
    background: transparent;
    border: none;
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    padding: 0;
    margin: 0;
    line-height: 1;
    min-height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.new-game-btn-inline:active {
    transform: scale(0.9);
}

.new-game-btn-inline.disabled {
    color: #ccc0b3;
    cursor: not-allowed;
    pointer-events: none;
}

.new-game-btn-inline.timed-countdown {
    color: #fff;
    font-size: 18px;
    cursor: default;
}

.new-game-btn-inline.timed-urgent {
    color: #ff6b6b;
    animation: timedPulse 0.5s ease-in-out infinite alternate;
}

@keyframes timedPulse {
    from { transform: scale(1); }
    to { transform: scale(1.15); }
}

.board-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

#grid-container {
    max-width: 400px;
    max-height: 400px;
    padding: 10px;
    background: #bbada0;
    border-radius: 8px;
    position: relative;
    margin: 0 auto;
}

.grid-cell {
    border-radius: 4px;
    background: #ccc0b3;
    position: absolute;
}

.number-cell {
    border-radius: 4px;
    font-family: Arial;
    font-weight: bold;
    text-align: center;
    position: absolute;
    transition: all 0.18s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform, top, left;
}

.game-tips {
    margin-top: 15px;
    font-size: 14px;
    color: #776e65;
}

.toast-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: center;
    z-index: 200;
    pointer-events: none;
}

.toast-overlay.show {
    display: flex;
}

.toast-box {
    background: rgba(119, 110, 101, 0.92);
    color: #fff;
    padding: 14px 28px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    animation: toastFadeIn 0.2s ease, toastFadeOut 0.3s ease 0.7s forwards;
}

@keyframes toastFadeIn {
    from { opacity: 0; transform: scale(0.85); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes toastFadeOut {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.9); }
}

.game-over-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(238, 228, 218, 0.95);
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 20px;
    z-index: 100;
}

.game-over-overlay.show {
    display: flex;
}

.game-over-title {
    font-size: 36px;
    font-weight: 700;
    color: #776e65;
}

.final-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.final-score-label {
    font-size: 14px;
    color: #776e65;
}

.final-score-value {
    font-size: 32px;
    font-weight: 700;
    color: #8f7a66;
}

.retry-btn {
    background: #8f7a66;
    border: none;
    color: #fff;
    padding: 12px 30px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.retry-btn:active {
    transform: scale(0.95);
    background: #7a6a58;
}
