/* ==========================================================================
   CSS Design System: Coprime Block Puzzle
   Theme: Modern Dark Neon Glassmorphism
   ========================================================================== */

/* 1. Global Variables & Reset */
:root {
    --bg-primary: #0a0b10;
    --panel-bg: rgba(20, 22, 37, 0.45);
    --panel-border: rgba(255, 255, 255, 0.08);
    --panel-shadow: rgba(0, 0, 0, 0.4);

    --color-text-main: #f3f4f6;
    --color-text-muted: #9ca3af;

    --color-accent-blue: #3b82f6;
    --color-accent-purple: #8b5cf6;
    --color-accent-emerald: #10b981;
    --color-accent-rose: #f43f5e;
    --color-accent-yellow: #f59e0b;

    --font-main: 'Inter', sans-serif;
    --font-display: 'Outfit', sans-serif;

    --transition-smooth: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --radius-lg: 16px;
    --radius-md: 10px;
    --radius-sm: 6px;
}

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

.hidden {
    display: none !important;
}

body {
    background-color: var(--bg-primary);
    color: var(--color-text-main);
    font-family: var(--font-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    position: relative;
}

/* 2. Background Neon Glows */
.glass-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    background: radial-gradient(circle at 10% 20%, rgba(88, 28, 135, 0.2) 0%, transparent 45%),
        radial-gradient(circle at 90% 80%, rgba(59, 130, 246, 0.15) 0%, transparent 50%),
        var(--bg-primary);
}

/* 3. Base Glassmorphism Utility */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--panel-border);
    box-shadow: 0 8px 32px 0 var(--panel-shadow);
    border-radius: var(--radius-lg);
    transition: var(--transition-smooth);
}

/* 4. App Container & Layout */
.app-container {
    width: 100%;
    max-width: 1100px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* 5. Header Styles */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.logo-area {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.logo-badge {
    align-self: flex-start;
    font-family: var(--font-display);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.15em;
    background: linear-gradient(135deg, var(--color-accent-blue), var(--color-accent-purple));
    color: #fff;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
}

header h1 {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(to right, #ffffff, #d1d5db);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

header h1 span {
    font-size: 1rem;
    font-weight: 400;
    color: var(--color-text-muted);
    margin-left: 8px;
    display: inline-block;
}

.control-panel {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    gap: 20px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.control-group label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.control-group select {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-main);
    padding: 6px 12px;
    font-family: var(--font-main);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.control-group select:focus {
    border-color: var(--color-accent-blue);
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.3);
}

.control-group select:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

/* Buttons */
.btn {
    font-family: var(--font-display);
    font-weight: 600;
    border: none;
    outline: none;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: var(--transition-smooth);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-accent-blue), var(--color-accent-purple));
    color: #fff;
    padding: 10px 20px;
    font-size: 0.95rem;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.6);
}

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

.btn-secondary {
    padding: 10px 16px;
    border: 1px solid rgba(139, 92, 246, 0.45);
    background: rgba(139, 92, 246, 0.12);
    color: #ddd6fe;
    font-size: 0.9rem;
}

.btn-secondary:hover {
    border-color: var(--color-accent-purple);
    background: rgba(139, 92, 246, 0.22);
}

.btn-danger {
    padding: 10px 14px;
    border: 1px solid rgba(244, 63, 94, 0.4);
    background: rgba(244, 63, 94, 0.1);
    color: #fca5a5;
    font-size: 0.85rem;
}

.btn-danger:hover {
    border-color: var(--color-accent-rose);
    background: rgba(244, 63, 94, 0.22);
    color: #fff;
}

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

.btn-large {
    padding: 14px 28px;
    font-size: 1.1rem;
    border-radius: var(--radius-lg);
}

/* 6. Dashboard (Stats) */
.dashboard {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 8px;
}

.stat-card {
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.stat-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.stat-value {
    font-family: var(--font-display);
    font-size: 2.2rem;
    font-weight: 800;
    color: #fff;
}

.glow-text {
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

/* Timer Specific Styling */
.timer-card {
    border: 1px solid rgba(59, 130, 246, 0.25);
    background: rgba(30, 41, 59, 0.4);
}

.timer-card .stat-value {
    color: var(--color-accent-blue);
    text-shadow: 0 0 12px rgba(59, 130, 246, 0.5);
}

.timer-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.05);
}

.timer-progress {
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, var(--color-accent-blue), var(--color-accent-purple));
    transition: width 0.1s linear;
}

/* 7. Game Board Section */
.board-wrapper {
    position: relative;
    padding: 16px;
    background: rgba(10, 11, 20, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.05);
    overflow: auto;
}

.game-status {
    margin-bottom: 10px;
    padding: 10px 16px;
    color: var(--color-text-muted);
    font-size: 0.88rem;
    text-align: center;
}

.game-status.success {
    color: var(--color-accent-emerald);
    border-color: rgba(16, 185, 129, 0.35);
}

.game-status.warning {
    color: var(--color-accent-rose);
    border-color: rgba(244, 63, 94, 0.35);
}

.tutorial-panel {
    margin-bottom: 10px;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-color: rgba(139, 92, 246, 0.4);
    background: rgba(76, 29, 149, 0.18);
}

.tutorial-panel h2 {
    margin: 4px 0;
    font-family: var(--font-display);
    font-size: 1.15rem;
}

.tutorial-panel p {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

.tutorial-progress {
    color: #c4b5fd;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.game-board {
    display: grid;
    /* 15 columns, 9 rows */
    grid-template-columns: repeat(15, 1fr);
    grid-template-rows: repeat(9, 1fr);
    gap: 8px;
    width: 100%;
    aspect-ratio: 15 / 9;
    touch-action: none;
    /* Prevents default touch panning/scrolling during drag */
}

/* Cell Style */
.cell {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    position: relative;
    transition: background-color 0.2s, transform 0.15s, border-color 0.2s;
    box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.02);
}

.cell:hover {
    background: rgba(255, 255, 255, 0.07);
    transform: scale(1.03);
    color: #fff;
}

/* Special Number: 1 (Joker) Styling */
.cell[data-value="1"] {
    background: radial-gradient(circle at center, rgba(139, 92, 246, 0.2) 0%, rgba(255, 255, 255, 0.03) 100%);
    border: 1px dashed rgba(139, 92, 246, 0.5);
    color: var(--color-accent-purple);
    font-weight: 800;
    text-shadow: 0 0 8px rgba(139, 92, 246, 0.3);
}

.cell[data-value="1"]::after {
    content: "JOKER";
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 0.48rem;
    color: var(--color-accent-purple);
    opacity: 0.8;
}

/* Prime numbers styling (subtle accent for math lovers) */
.cell.is-prime-subtle {
    color: rgba(255, 255, 255, 0.95);
    border-color: rgba(16, 185, 129, 0.15);
}

/* Empty Cell (Cleared) */
.cell.cleared {
    background: transparent;
    border-color: rgba(255, 255, 255, 0.01);
    color: transparent;
    pointer-events: none;
    box-shadow: none;
}

.cell.cleared::after {
    display: none;
}

/* Active Drag states */
.cell.selected {
    background: rgba(59, 130, 246, 0.2) !important;
    border-color: var(--color-accent-blue) !important;
    color: #fff;
    transform: scale(0.96);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.3);
}

.cell.selected-joker {
    background: rgba(139, 92, 246, 0.25) !important;
    border-color: var(--color-accent-purple) !important;
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.4);
}

.cell.drag-invalid {
    background: rgba(244, 63, 94, 0.2) !important;
    border-color: var(--color-accent-rose) !important;
    box-shadow: 0 0 10px rgba(244, 63, 94, 0.3);
}

.cell.tutorial-target {
    border-color: var(--color-accent-yellow);
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.25), 0 0 16px rgba(245, 158, 11, 0.25);
    animation: tutorialPulse 1.5s ease-in-out infinite;
}

@keyframes tutorialPulse {
    50% {
        border-color: #fcd34d;
        transform: translateY(-2px);
    }
}

/* Drag Guide Overlay element */
.drag-overlay {
    position: absolute;
    border: 2px solid var(--color-accent-blue);
    background: rgba(59, 130, 246, 0.05);
    border-radius: var(--radius-md);
    pointer-events: none;
    z-index: 10;
    display: none;
    transition: border-color 0.1s, background-color 0.1s;
}

.drag-overlay.invalid {
    border-color: var(--color-accent-rose);
    background: rgba(244, 63, 94, 0.05);
}

.timer-card.urgent {
    border-color: rgba(244, 63, 94, 0.55);
}

.timer-card.urgent .stat-value {
    color: var(--color-accent-rose);
}

/* Error/Not Coprime Feedback Style */
.cell.not-coprime-highlight {
    border-color: var(--color-accent-rose) !important;
    background: rgba(244, 63, 94, 0.3) !important;
    color: #fff !important;
    box-shadow: 0 0 14px rgba(244, 63, 94, 0.6);
    z-index: 5;
}

/* 8. Animations */
.error-shake {
    animation: shake 0.35s cubic-bezier(.36, .07, .19, .97) both;
}

@keyframes shake {

    10%,
    90% {
        transform: translate3d(-1px, 0, 0);
    }

    20%,
    80% {
        transform: translate3d(2px, 0, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-4px, 0, 0);
    }

    40%,
    60% {
        transform: translate3d(4px, 0, 0);
    }
}

/* Fade pop animation when cells clear */
.pop-out {
    animation: popOut 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

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

    50% {
        transform: scale(1.15);
        opacity: 0.8;
        background-color: var(--color-accent-emerald);
    }

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

/* 9. Game Guide / Footer */
footer {
    margin-top: 10px;
}

.instruction-card {
    padding: 20px 24px;
}

.instruction-card h3 {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--color-accent-blue);
    display: flex;
    align-items: center;
    gap: 8px;
}

.instruction-card ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.instruction-card li {
    font-size: 0.88rem;
    line-height: 1.5;
    color: var(--color-text-muted);
}

.instruction-card li strong {
    color: var(--color-text-main);
}

.desc-detail {
    display: inline-block;
    font-size: 0.8rem;
    color: #6b7280;
    margin-left: 18px;
}

.record-actions {
    display: flex;
    justify-content: center;
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.record-actions .btn-danger {
    min-width: 240px;
    padding: 16px 32px;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* 10. Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(5, 5, 8, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    width: 90%;
    max-width: 440px;
    padding: 32px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 20px;
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.hidden .modal-content {
    transform: translateY(40px);
}

.modal-header h2 {
    font-family: var(--font-display);
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--color-accent-rose);
    letter-spacing: -0.01em;
}

.modal-header p {
    font-size: 0.95rem;
    color: var(--color-text-muted);
    margin-top: 4px;
}

.modal-score-box {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.score-item .label {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.score-item .value {
    font-family: var(--font-display);
    font-size: 3rem;
    font-weight: 800;
    color: var(--color-accent-emerald);
}

.new-record {
    background: linear-gradient(135deg, var(--color-accent-yellow), #f97316);
    color: #fff;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 0.75rem;
    padding: 4px 12px;
    border-radius: 9999px;
    letter-spacing: 0.05em;
    box-shadow: 0 4px 10px rgba(245, 158, 11, 0.3);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {

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

    50% {
        transform: scale(1.05);
    }
}

.summary-text {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    line-height: 1.6;
}

/* Responsive Scaling for Grid */
@media (max-width: 900px) {
    header {
        flex-direction: column;
        align-items: stretch;
    }

    .control-panel {
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .control-actions {
        flex: 1 1 100%;
    }

    .control-actions .btn {
        flex: 1;
    }

    .tutorial-panel {
        align-items: stretch;
        flex-direction: column;
    }

    .dashboard {
        gap: 8px;
    }

    .stat-value {
        font-size: 1.6rem;
    }

    .cell {
        font-size: 1.1rem;
        border-radius: var(--radius-sm);
    }

    .board-wrapper {
        padding: 10px;
    }

    .game-board {
        min-width: 760px;
        gap: 5px;
    }
}

@media (max-width: 560px) {
    .app-container {
        padding: 14px;
    }

    .control-group {
        flex: 1 1 120px;
    }

    .control-actions,
    .control-panel .btn {
        width: 100%;
    }

    .dashboard {
        grid-template-columns: 1fr;
    }
}

/* Time Penalty Animation */
.time-penalty {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-accent-rose);
    font-weight: 800;
    font-size: 1.2rem;
    animation: floatUpFade 1s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    pointer-events: none;
    z-index: 10;
}

@keyframes floatUpFade {
    0% { opacity: 1; transform: translateY(-50%) scale(1); }
    100% { opacity: 0; transform: translateY(-150%) scale(1.1); }
}
