:root {
    --red:          #e11d48;
    --red-hover:    #be123c;
    --red-light:    #fff1f2;
    --red-dim:      rgba(225, 29, 72, 0.12);
    --green:        #16a34a;
    --bg:           #f1f5f9;
    --surface:      #ffffff;
    --border:       #e2e8f0;
    --text:         #0f172a;
    --text-muted:   #64748b;
    --radius-lg:    24px;
    --radius-md:    16px;
    --shadow-card:  0 4px 24px rgba(0,0,0,0.07);
    --shadow-btn:   0 4px 12px rgba(225, 29, 72, 0.3);
    --font-display: 'Syne', sans-serif;
    --font-body:    'DM Sans', sans-serif;

    /* All three overwritten immediately by JS */
    --gap:            8px;
    --card-pad:       20px;
    --cell-size:      100px;
    --cell-font:      calc(var(--cell-size) * 0.13);
    --cell-font-free: calc(var(--cell-size) * 0.42);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-body);
    background-color: var(--bg);
    background-image: radial-gradient(circle, #cbd5e1 1px, transparent 1px);
    background-size: 24px 24px;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: clamp(12px, 3vw, 40px) 16px 40px;
}

/* Card width is derived from the same variables JS sets */
.app-wrapper {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    align-items: center;
    width: calc(var(--cell-size) * 5 + var(--gap) * 4 + var(--card-pad) * 2);
    padding: var(--card-pad);
}

.app-header {
    text-align: center;
    margin-bottom: clamp(10px, 2vw, 20px);
    width: 100%;
}

.app-header h1 {
    font-family: var(--font-display);
    font-size: clamp(1.6rem, 5vw, 3.5rem);
    font-weight: 800;
    letter-spacing: -2px;
    line-height: 1;
    color: var(--text);
}

.app-header h1 span { color: var(--red); }

#live-timer {
    display: inline-block;
    margin-top: 10px;
    font-size: clamp(0.8rem, 2vw, 1.05rem);
    font-weight: 600;
    color: var(--red);
    background: var(--red-dim);
    padding: 4px 14px;
    border-radius: 99px;
    border: 1px solid rgba(225, 29, 72, 0.2);
}

.main-content { width: 100%; }

.grid {
    display: grid;
    grid-template-columns: repeat(5, var(--cell-size));
    gap: var(--gap);
    margin-bottom: clamp(14px, 2vw, 24px);
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: calc(var(--cell-size) * 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(var(--cell-size) * 0.07);
    font-family: var(--font-body);
    font-size: var(--cell-font);
    font-weight: 600;
    line-height: 1.25;
    text-align: center;
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.1s, color 0.15s;
    word-break: break-word;
    hyphens: auto;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.cell:active { transform: scale(0.94); }

@media (hover: hover) {
    .cell:hover {
        border-color: var(--red);
        background: var(--red-light);
        color: var(--red);
    }
}

.cell.marked {
    background: var(--red-light) !important;
    border-color: var(--red) !important;
    color: var(--red) !important;
    box-shadow: inset 0 0 0 1px var(--red);
}

.cell.free {
    font-size: var(--cell-font-free) !important;
    cursor: default;
    background: var(--red-dim) !important;
    border-color: var(--red) !important;
}

.controls-bottom {
    width: 100%;
    display: flex;
    justify-content: center;
}

.btn-main {
    background: var(--red);
    color: white;
    border: none;
    padding: clamp(11px, 1.5vw, 15px) 0;
    border-radius: var(--radius-md);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(0.9rem, 1.5vw, 1.1rem);
    cursor: pointer;
    width: 100%;
    box-shadow: var(--shadow-btn);
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn-main:active { transform: scale(0.97); box-shadow: none; }
@media (hover: hover) { .btn-main:hover { background: var(--red-hover); } }

.btn-success {
    background: var(--green);
    color: white;
    border: none;
    padding: 14px;
    border-radius: var(--radius-md);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    width: 100%;
    transition: opacity 0.2s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.btn-success:active { transform: scale(0.97); opacity: 0.9; }

.popup-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.88);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    justify-content: center;
    align-items: center;
    z-index: 9999;
    padding: 20px;
}

.popup-content {
    background: var(--surface);
    padding: 36px 28px 28px;
    border-radius: var(--radius-lg);
    text-align: center;
    width: 100%;
    max-width: 340px;
    animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes popIn {
    from { transform: scale(0.8); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

.icon-win {
    font-size: clamp(3rem, 12vw, 5rem);
    color: var(--red);
    margin-bottom: 8px;
    display: block;
}

.popup-content h2 {
    font-family: var(--font-display);
    font-size: clamp(2rem, 8vw, 3rem);
    font-weight: 800;
    color: var(--text);
    letter-spacing: -1px;
    margin-bottom: 8px;
}

.popup-content p { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 4px; }

.timer-final {
    font-size: 1.2rem !important;
    font-weight: 700 !important;
    color: var(--red) !important;
    margin: 16px 0 !important;
    display: block;
}

.grid.frozen {
    pointer-events: none;
    opacity: 0.55;
    filter: blur(1.5px);
    transition: opacity 0.3s, filter 0.3s;
}