:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --success-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --dark-bg: #0f0e17;
    --card-bg: #1a1825;
    --text-primary: #fffffe;
    --text-secondary: #a7a9be;
    --apple-1: #ff6b6b;
    --apple-2: #f06595;
    --apple-3: #cc5de8;
    --apple-4: #845ef7;
    --apple-5: #5c7cfa;
    --apple-6: #339af0;
    --apple-7: #22b8cf;
    --apple-8: #20c997;
    --apple-9: #51cf66;
    --selection-valid: rgba(245, 87, 108, 0.3);
    --selection-invalid: rgba(103, 126, 234, 0.2);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background: var(--dark-bg);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    user-select: none;
}

.game-container {
    max-width: 1100px;
    width: 100%;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 12px 20px;
    background: var(--card-bg);
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.header h1 {
    font-size: 1.8rem;
    font-weight: 800;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.volume-control {
    display: flex;
    align-items: center;
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    height: 6px;
    background: rgba(103, 126, 234, 0.2);
    border-radius: 5px;
    outline: none;
    transition: all 0.3s ease;
}

.volume-slider:hover {
    background: rgba(103, 126, 234, 0.3);
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary-gradient);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(103, 126, 234, 0.4);
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(103, 126, 234, 0.6);
}

.volume-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--primary-gradient);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(103, 126, 234, 0.4);
}

.volume-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(103, 126, 234, 0.6);
}

.bgm-toggle-btn {
    background: rgba(103, 126, 234, 0.2);
    border: none;
    border-radius: 999px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.5rem;
}

.bgm-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.bgm-toggle-btn:hover {
    background: rgba(103, 126, 234, 0.3);
    transform: scale(1.1);
}

.bgm-toggle-btn:active {
    transform: scale(0.95);
}

.score-display {
    text-align: right;
}

.score-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 3px;
}

.score-value {
    font-size: 2rem;
    font-weight: 800;
    background: var(--success-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.high-score-display .score-value {
    font-size: 2rem;
    background: linear-gradient(135deg, #ffd43b 0%, #f59f00 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 15px;
}

.game-board-wrapper {
    position: relative;
    background: var(--card-bg);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.game-board {
    display: grid;
    grid-template-columns: repeat(17, 1fr);
    grid-template-rows: repeat(10, 1fr);
    gap: 6px;
    width: 100%;
    aspect-ratio: 17 / 10;
    position: relative;
}

.apple {
    aspect-ratio: 1;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    position: relative;
}


.apple:hover {
    box-shadow: 0 6px 15px rgba(255, 255, 255, 0.3);
}

.apple[data-value="1"] {
    background: var(--apple-1);
}

.apple[data-value="2"] {
    background: var(--apple-2);
}

.apple[data-value="3"] {
    background: var(--apple-3);
}

.apple[data-value="4"] {
    background: var(--apple-4);
}

.apple[data-value="5"] {
    background: var(--apple-5);
}

.apple[data-value="6"] {
    background: var(--apple-6);
}

.apple[data-value="7"] {
    background: var(--apple-7);
}

.apple[data-value="8"] {
    background: var(--apple-8);
}

.apple[data-value="9"] {
    background: var(--apple-9);
}

.apple.removing {
    animation: pop-out 0.4s ease forwards;
}

.apple.highlighted {
    outline: 3px solid rgba(255, 255, 255, 0.9);
    outline-offset: -3px;
    transform: scale(1.05);
    z-index: 2;
}

.apple.highlighted.valid {
    outline-color: #f5576c;
    box-shadow: 0 0 20px rgba(245, 87, 108, 0.6);
}

@keyframes pop-out {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.3);
        opacity: 0.8;
    }

    100% {
        transform: scale(0);
        opacity: 0;
    }
}

.apple.falling {
    animation: fall 0.3s ease;
}

@keyframes fall {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.selection-box {
    position: absolute;
    border: 3px solid;
    border-radius: 8px;
    pointer-events: none;
    display: none;
    z-index: 10;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.selection-box.active {
    display: block;
}

.selection-box.valid {
    background: var(--selection-valid);
    border-color: #f5576c;
    box-shadow: 0 0 20px rgba(245, 87, 108, 0.5);
}

.selection-box.invalid {
    background: var(--selection-invalid);
    border-color: #667eea;
}

.selection-sum-wrapper {
    position: absolute;
    transform: translate(8px, -8px);
    pointer-events: none;
    z-index: 11;
}

.selection-sum {
    min-width: calc(3ch + 12px);
    text-align: center;
    font-variant-numeric: tabular-nums;
    padding: 6px 12px;
    font-size: 0.9rem;
    font-weight: 700;
    border-radius: 999px;
    background: rgba(15, 14, 23, 0.9);
    color: white;
    display: none;
    white-space: nowrap;
}

.selection-sum.active {
    display: block;
}

.selection-sum.valid {
    background: #f5576c;
    box-shadow: 0 0 15px rgba(245, 87, 108, 0.6);
    animation: pulse 0.2s ease;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.15);
    }

    100% {
        transform: scale(1);
    }
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.timer-container,
.info-panel,
.combo-guide {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 25px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.timer-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-align: center;
}

.timer-display {
    font-size: 3rem;
    font-weight: 800;
    text-align: center;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 20px;
}

.timer-bar-bg {
    width: 100%;
    height: 12px;
    background: rgba(103, 126, 234, 0.2);
    border-radius: 10px;
    overflow: hidden;
}

.timer-bar {
    height: 100%;
    background: var(--primary-gradient);
    border-radius: 10px;
    transition: width 0.3s linear;
    width: 100%;
}

.info-panel h3,
.combo-guide h3 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.info-panel ul {
    list-style: none;
}

.info-panel li {
    padding: 10px 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    border-bottom: 1px solid rgba(167, 169, 190, 0.1);
}

.info-panel li:last-child {
    border-bottom: none;
}

.info-panel li::before {
    content: '✓';
    margin-right: 10px;
    color: #51cf66;
    font-weight: bold;
}

.combo-guide {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.combo-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: rgba(103, 126, 234, 0.1);
    border-radius: 10px;
    transition: transform 0.2s ease;
}

.combo-item:hover {
    transform: translateX(5px);
}

.combo-count {
    font-weight: 600;
    color: var(--text-primary);
}

.combo-freq {
    color: #ffd43b;
    font-size: 1.1rem;
}

.game-over-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 14, 23, 0.95);
    backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    z-index: 100;
}

.game-over-overlay.active {
    display: flex;
    animation: fade-in 0.3s ease;
}

@keyframes fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

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

.game-over-content h2 {
    font-size: 3rem;
    margin-bottom: 20px;
    background: var(--success-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

.final-score {
    font-size: 5rem;
    font-weight: 800;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 30px;
}

.restart-btn {
    padding: 15px 40px;
    font-size: 1.2rem;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    background: var(--primary-gradient);
    color: var(--text-primary);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    font-family: 'Outfit', sans-serif;
}

.restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(103, 126, 234, 0.4);
}

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

/* Start Screen */
.start-screen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--dark-bg);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.start-screen-overlay.active {
    display: flex;
}

.start-screen-content {
    text-align: center;
    padding: 60px;
    background: var(--card-bg);
    border-radius: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.start-screen-content h1 {
    font-size: 4rem;
    font-weight: 800;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 20px;
}

.start-description {
    font-size: 1.3rem;
    color: var(--text-secondary);
    margin-bottom: 40px;
}

.start-btn {
    padding: 20px 60px;
    font-size: 1.5rem;
    font-weight: 700;
    border: none;
    border-radius: 15px;
    background: var(--success-gradient);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Outfit', sans-serif;
    box-shadow: 0 10px 30px rgba(245, 87, 108, 0.4);
}

.start-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 40px rgba(245, 87, 108, 0.6);
}

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

/* Footer License */
.footer {
    margin-top: 20px;
    padding: 15px 20px;
    background: var(--card-bg);
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.license-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.license-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.license-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.license-text a {
    color: #667eea;
    text-decoration: none;
}

.license-text a:hover {
    text-decoration: underline;
}

/* Mobile Top Bar */
.mobile-top-bar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    padding: 8px 12px;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    z-index: 100;
    gap: 10px;
}

.mobile-logo {
    font-size: 1.2rem;
}

.mobile-timer {
    font-size: 0.9rem;
    font-weight: 700;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    min-width: 3ch;
}

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

.mobile-score-value {
    font-size: 0.9rem;
    font-weight: 700;
    background: var(--success-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.mobile-settings-btn {
    background: rgba(103, 126, 234, 0.2);
    border: none;
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.3s ease;
}

.mobile-settings-btn:active {
    background: rgba(103, 126, 234, 0.4);
    transform: scale(0.95);
}

/* Settings Popup */
.settings-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 14, 23, 0.9);
    backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.settings-popup-overlay.active {
    display: flex;
}

.settings-popup {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 20px;
    max-width: 400px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.settings-header h2 {
    font-size: 1.5rem;
    margin: 0;
    color: var(--text-primary);
}

.settings-close-btn {
    background: rgba(103, 126, 234, 0.2);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-close-btn:hover,
.settings-close-btn:active {
    background: rgba(103, 126, 234, 0.4);
    transform: scale(0.95);
}

.settings-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.settings-section {
    background: rgba(103, 126, 234, 0.1);
    padding: 15px;
    border-radius: 12px;
}

.settings-section h3 {
    font-size: 1.1rem;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.settings-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
}

.settings-item label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.settings-item .volume-slider {
    width: 150px;
}

.settings-item .bgm-toggle-btn {
    margin: 0;
}

.settings-license {
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.6;
}

.settings-license p {
    margin: 8px 0;
}

.settings-license a {
    color: #667eea;
    text-decoration: none;
}

.settings-license a:hover {
    text-decoration: underline;
}

@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
    }
}

@media (max-width: 768px) {

    /* Hide desktop UI elements */
    .header,
    .sidebar,
    .footer {
        display: none !important;
    }

    /* Show mobile top bar */
    .mobile-top-bar {
        display: flex;
    }

    /* Adjust body and container for mobile */
    body {
        padding: 0;
        align-items: flex-start;
        overflow: hidden;
        height: 100vh;
    }

    .game-container {
        padding-top: 45px;
        height: 100vh;
        display: flex;
        flex-direction: column;
    }

    /* Make main content fill the viewport */
    .main-content {
        flex: 1;
        display: flex;
        padding: 0;
        margin: 0;
        min-height: 0;
    }

    .game-board-wrapper {
        flex: 1;
        margin: 10px;
        padding: 10px;
        display: flex;
        flex-direction: column;
        border-radius: 15px;
        touch-action: none;
        overflow: hidden;
    }

    .game-board {
        aspect-ratio: 10 / 17;
        max-height: calc(100vh - 65px);
        max-width: calc(100vw - 40px);
        width: 100%;
        touch-action: none;
    }

    .apple {
        font-size: 0.9rem;
        touch-action: none;
    }

    /* Adjust selection box for mobile padding */
    .selection-box,
    .selection-sum-wrapper {
        touch-action: none;
    }
}

/* High Score Styles */
.high-score-label {
    font-size: 1.5rem;
    font-weight: 700;
    color: #ffd43b;
    margin: 20px 0;
    animation: bounce 0.6s ease infinite;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.final-high-score-label {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-top: 20px;
    margin-bottom: 10px;
}

.final-high-score {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #ffd43b 0%, #f59f00 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 30px;
}