* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

:root {
    --bg-color: #f7ede2;
    --header-bg: #ffffff;
    --text-main: #2f3542;
    --text-muted: #8892b0;
    --accent-red: #ff4757;
    --accent-hover: #fff1f2;
}

body {
    background-color: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    touch-action: none;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#app-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    padding: 10px;
}

/* Fluid game board: calculated to fit header + canvas + footer within 100dvh without scrolling */
#game-board {
    container-type: inline-size;
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
    width: min(calc((100dvh - 130px) * (380 / 620)), calc(100vw - 20px));
}

#game-header {
    width: 100%;
    height: clamp(50px, 11cqw, 76px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--header-bg);
    padding: 0 clamp(10px, 3cqw, 22px);
    border-radius: clamp(14px, 3cqw, 22px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.05);
    margin-bottom: clamp(6px, 1.8cqw, 14px);
    border: 1px solid rgba(0, 0, 0, 0.04);
    flex-shrink: 0;
}

.game-title {
    font-size: clamp(13px, 3.4cqw, 22px);
    font-weight: 800;
    color: var(--accent-red);
    letter-spacing: -0.3px;
    text-transform: uppercase;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: clamp(9px, 2cqw, 13px);
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.stat-value {
    font-size: clamp(18px, 4.8cqw, 32px);
    font-weight: 900;
    color: var(--text-main);
    line-height: 1.1;
}

.header-right {
    display: flex;
    align-items: center;
    gap: clamp(6px, 1.6cqw, 12px);
}

.canvas-holder {
    width: clamp(28px, 6.5cqw, 44px);
    height: clamp(28px, 6.5cqw, 44px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.canvas-holder canvas {
    width: 100%;
    height: 100%;
}

/* Custom Language Dropdown */
.custom-dropdown {
    position: relative;
}

.dropdown-trigger {
    background: #f1f2f6;
    border: none;
    outline: none;
    height: clamp(32px, 7.5cqw, 46px);
    padding: 0 clamp(8px, 2cqw, 14px);
    border-radius: clamp(10px, 2.2cqw, 16px);
    color: var(--text-main);
    font-size: clamp(11px, 2.4cqw, 15px);
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
}

.dropdown-trigger:hover,
.custom-dropdown.open .dropdown-trigger {
    background: #e4e7eb;
}

.dropdown-chevron {
    transition: transform 0.2s ease;
    color: #747d8c;
}

.custom-dropdown.open .dropdown-chevron {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.06);
    padding: 6px;
    list-style: none;
    display: none;
    flex-direction: column;
    gap: 4px;
    min-width: 125px;
    z-index: 100;
    animation: dropdownPop 0.15s ease-out;
}

.custom-dropdown.open .dropdown-menu {
    display: flex;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.dropdown-item:hover {
    background: #f8f9fa;
}

.dropdown-item.active {
    background: var(--accent-hover);
}

.dropdown-item .item-code {
    font-size: 11px;
    font-weight: 900;
    padding: 2px 6px;
    border-radius: 6px;
    background: #f1f2f6;
    color: var(--text-main);
}

.dropdown-item.active .item-code {
    background: var(--accent-red);
    color: #ffffff;
}

.dropdown-item .item-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
}

.dropdown-item.active .item-label {
    color: var(--accent-red);
}

#header-restart-btn {
    background: #f1f2f6;
    border: none;
    width: clamp(32px, 7.5cqw, 46px);
    height: clamp(32px, 7.5cqw, 46px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #57606f;
    cursor: pointer;
    transition: all 0.2s ease;
}

#header-restart-btn svg {
    width: clamp(16px, 3.5cqw, 22px);
    height: clamp(16px, 3.5cqw, 22px);
}

#header-restart-btn:hover {
    background: #e4e7eb;
    color: var(--text-main);
}

#header-restart-btn:active {
    transform: scale(0.92);
}

#game-container {
    position: relative;
    width: 100%;
    aspect-ratio: 380 / 620;
    border-radius: clamp(16px, 3.5cqw, 28px);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    background-color: #ffffff;
}

canvas#matter-canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

/* Footer link styling */
#game-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: clamp(6px, 1.8cqw, 12px);
    flex-shrink: 0;
}

.footer-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    font-size: clamp(11px, 2.5cqw, 14px);
    font-weight: 600;
    color: var(--text-muted);
    transition: color 0.2s ease;
    padding: 4px 8px;
}

.footer-link:hover {
    color: var(--text-main);
}

.domain-tag {
    color: var(--accent-red);
    font-weight: 800;
    background: rgba(255, 71, 87, 0.08);
    padding: 2px 8px;
    border-radius: 8px;
    transition: background 0.2s ease, transform 0.15s ease;
}

.footer-link:hover .domain-tag {
    background: rgba(255, 71, 87, 0.16);
    transform: translateY(-1px);
}

/* Modal Game Over */
#game-over-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(47, 53, 66, 0.65);
    backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
    padding: 20px;
}

#game-over-modal.hidden {
    display: none;
}

.modal-content {
    background: #ffffff;
    padding: clamp(20px, 6cqw, 40px) clamp(24px, 8cqw, 50px);
    border-radius: clamp(16px, 4cqw, 28px);
    text-align: center;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.25);
    animation: popUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-content h2 {
    color: var(--accent-red);
    font-size: clamp(22px, 6cqw, 36px);
    font-weight: 900;
    margin-bottom: 6px;
}

.modal-content p {
    color: #747d8c;
    font-size: clamp(12px, 3cqw, 18px);
}

#final-score {
    display: block;
    font-size: clamp(32px, 9cqw, 56px);
    font-weight: 900;
    color: #2ed573;
    margin: 10px 0 20px 0;
}

#restart-btn {
    background: linear-gradient(135deg, #ff6b81, #ff4757);
    color: #ffffff;
    border: none;
    padding: clamp(10px, 2.8cqw, 16px) clamp(24px, 6cqw, 40px);
    border-radius: 40px;
    font-size: clamp(13px, 3.2cqw, 20px);
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(255, 71, 87, 0.35);
    transition: transform 0.1s ease;
}

#restart-btn:active {
    transform: scale(0.96);
}

#pwa-install-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.05);
    padding: clamp(6px, 1.8cqw, 10px) clamp(10px, 2.5cqw, 16px);
    border-radius: clamp(12px, 2.8cqw, 18px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    margin-bottom: clamp(6px, 1.8cqw, 12px);
    animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    flex-shrink: 0;
}

#pwa-install-banner.hidden {
    display: none !important;
}

.banner-content {
    display: flex;
    align-items: center;
    gap: clamp(8px, 2cqw, 12px);
}

.banner-icon {
    width: clamp(26px, 6cqw, 36px);
    height: clamp(26px, 6cqw, 36px);
    border-radius: clamp(6px, 1.5cqw, 10px);
}

.banner-text {
    display: flex;
    flex-direction: column;
}

.banner-text strong {
    font-size: clamp(11px, 2.6cqw, 15px);
    font-weight: 800;
    color: var(--text-main);
    line-height: 1.2;
}

.banner-text span {
    font-size: clamp(9px, 2.1cqw, 12px);
    color: var(--text-muted);
    font-weight: 600;
}

.banner-actions {
    display: flex;
    align-items: center;
    gap: clamp(6px, 1.5cqw, 10px);
}

#pwa-install-btn {
    background: #20bf6b;
    color: #ffffff;
    border: none;
    padding: clamp(4px, 1.2cqw, 8px) clamp(10px, 2.5cqw, 18px);
    border-radius: 20px;
    font-size: clamp(10px, 2.4cqw, 13px);
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(32, 191, 107, 0.3);
    transition: transform 0.1s ease, background 0.2s ease;
}

#pwa-install-btn:hover {
    background: #1cb062;
}

#pwa-install-btn:active {
    transform: scale(0.94);
}

#pwa-dismiss-btn {
    background: transparent;
    border: none;
    width: clamp(24px, 5.5cqw, 32px);
    height: clamp(24px, 5.5cqw, 32px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

#pwa-dismiss-btn:hover {
    background: #f1f2f6;
    color: var(--text-main);
}

@keyframes dropdownPop {
    0% {
        opacity: 0;
        transform: translateY(-6px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes popUp {
    0% {
        transform: scale(0.75);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}