/* ═══════════════════════════════════════════════════════════════════════════
   BLOCK BLAST SOLVER — Refined Light Edition
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=DM+Mono:wght@400;500&display=swap');

/* ─────────────────────────────────────────────────────────────────────────────
   CSS Variables
   ───────────────────────────────────────────────────────────────────────────── */
:root {
    /* Warm, inviting palette */
    --bg-page: #f8f6f3;
    --bg-card: #ffffff;
    --bg-subtle: #f2efeb;
    --bg-input: #fafaf9;

    /* Primary accent - warm coral instead of generic purple */
    --accent-primary: #e85d4c;
    --accent-primary-hover: #d14a3a;
    --accent-secondary: #2d7d6f;
    --accent-tertiary: #d4a853;

    /* Text colors */
    --text-primary: #1a1a1a;
    --text-secondary: #5c5c5c;
    --text-muted: #8a8a8a;

    /* Borders & Shadows */
    --border-light: #e8e5e0;
    --border-medium: #d4d0c8;
    --shadow-soft: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-medium: 0 4px 20px rgba(0,0,0,0.08);
    --shadow-lifted: 0 8px 30px rgba(0,0,0,0.12);

    /* Functional */
    --success: #2d7d6f;
    --error: #d64545;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Reset & Base
   ───────────────────────────────────────────────────────────────────────────── */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-page);
    min-height: 100vh;
    padding: 24px;
    color: var(--text-primary);
    line-height: 1.5;
}

/* Subtle dot pattern for texture */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(circle, var(--border-light) 1px, transparent 1px);
    background-size: 24px 24px;
    opacity: 0.5;
    pointer-events: none;
    z-index: -1;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Header
   ───────────────────────────────────────────────────────────────────────────── */
header {
    text-align: center;
    margin-bottom: 32px;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Tab Navigation
   ───────────────────────────────────────────────────────────────────────────── */
.input-method-selector {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 24px;
}

.tab-button {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 2px solid var(--border-light);
    padding: 14px 28px;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tab-button:hover {
    border-color: var(--border-medium);
    background: var(--bg-subtle);
}

.tab-button.active {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-medium);
}

.icon {
    font-size: 1.1rem;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Input Sections / Cards
   ───────────────────────────────────────────────────────────────────────────── */
.input-section {
    display: none;
    background: var(--bg-card);
    border-radius: 20px;
    padding: 32px;
    box-shadow: var(--shadow-medium);
    border: 1px solid var(--border-light);
}

.input-section.active {
    display: block;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    margin-bottom: 32px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Section Headers
   ───────────────────────────────────────────────────────────────────────────── */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ─────────────────────────────────────────────────────────────────────────────
   Game Grid
   ───────────────────────────────────────────────────────────────────────────── */
.grid-container {
    display: flex;
    justify-content: center;
}

.game-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    background: var(--border-medium);
    padding: 4px;
    border-radius: 12px;
    box-shadow: var(--shadow-soft);
    width: fit-content;
}

.grid-cell {
    width: 44px;
    height: 44px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.grid-cell:hover {
    background: var(--bg-subtle);
    transform: scale(1.02);
}

.grid-cell.filled {
    background: linear-gradient(145deg, #5a9cf5 0%, #3b7dd8 100%);
    border-color: #3b7dd8;
    box-shadow: inset 0 2px 4px rgba(255,255,255,0.3), 0 2px 4px rgba(59,125,216,0.3);
}

.grid-cell.placement {
    background: linear-gradient(145deg, #4eca8b 0%, #2d9d6a 100%);
    border-color: #2d9d6a;
    box-shadow: inset 0 2px 4px rgba(255,255,255,0.3), 0 2px 4px rgba(45,157,106,0.3);
    animation: pulse 0.4s ease;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

/* ─────────────────────────────────────────────────────────────────────────────
   Pieces Grid
   ───────────────────────────────────────────────────────────────────────────── */
.all-pieces-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 12px;
    max-height: 480px;
    overflow-y: auto;
    padding: 12px;
    background: var(--bg-subtle);
    border-radius: 12px;
}

.piece-container {
    background: var(--bg-card);
    border: 2px solid var(--border-light);
    border-radius: 12px;
    padding: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.piece-container:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
    border-color: var(--accent-primary);
}

.piece-container.selected {
    border-color: var(--accent-primary);
    background: linear-gradient(145deg, rgba(232,93,76,0.08) 0%, rgba(232,93,76,0.04) 100%);
    box-shadow: var(--shadow-medium);
}

.piece-name {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.piece-preview {
    display: grid;
    gap: 2px;
}

.piece-preview-cell {
    border-radius: 3px;
    background: transparent;
}

.piece-preview-cell.filled {
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    box-shadow: inset 0 -2px 4px rgba(0,0,0,0.15), inset 0 2px 2px rgba(255,255,255,0.4);
}

/* ─────────────────────────────────────────────────────────────────────────────
   Selected Pieces
   ───────────────────────────────────────────────────────────────────────────── */
.selected-pieces-container {
    margin-top: 24px;
}

.selected-pieces-container h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 14px;
}

.selected-pieces {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.selected-piece-slot {
    background: var(--bg-card);
    border: 2px solid var(--success);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.selected-piece-slot:hover {
    border-color: var(--error);
    background: rgba(214, 69, 69, 0.05);
}

.empty-slot {
    background: var(--bg-subtle);
    border: 2px dashed var(--border-medium);
    border-radius: 12px;
    padding: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Buttons
   ───────────────────────────────────────────────────────────────────────────── */
.btn-primary, .btn-secondary {
    font-family: 'DM Sans', sans-serif;
    padding: 14px 28px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
    box-shadow: var(--shadow-soft);
}

.btn-primary:hover {
    background: var(--accent-primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-medium);
}

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

.btn-primary:disabled {
    background: var(--border-medium);
    color: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 2px solid var(--border-light);
}

.btn-secondary:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: rgba(232, 93, 76, 0.05);
}

.btn-secondary:disabled {
    color: var(--text-muted);
    border-color: var(--border-light);
    cursor: not-allowed;
    background: var(--bg-subtle);
}

/* ─────────────────────────────────────────────────────────────────────────────
   Action Section
   ───────────────────────────────────────────────────────────────────────────── */
.action-section {
    text-align: center;
    padding-top: 24px;
    border-top: 1px solid var(--border-light);
}

/* ─────────────────────────────────────────────────────────────────────────────
   Upload Area
   ───────────────────────────────────────────────────────────────────────────── */
.upload-container {
    margin-bottom: 32px;
}

.upload-area {
    border: 2px dashed var(--border-medium);
    border-radius: 16px;
    padding: 48px 32px;
    text-align: center;
    transition: all 0.2s ease;
    background: var(--bg-subtle);
}

.upload-area:hover {
    border-color: var(--accent-primary);
    background: rgba(232, 93, 76, 0.03);
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.6;
}

.upload-area h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.upload-area p {
    color: var(--text-muted);
    margin-bottom: 20px;
}

.preview-container {
    text-align: center;
}

.screenshot-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 20px;
}

.image-container {
    position: relative;
    display: inline-block;
    margin-bottom: 20px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-medium);
}

#screenshot-canvas {
    max-width: 600px;
    max-height: 300px;
    height: auto;
    display: block;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Solution Section
   ───────────────────────────────────────────────────────────────────────────── */
.solution-section {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 32px;
    margin-top: 24px;
    box-shadow: var(--shadow-medium);
    border: 1px solid var(--border-light);
}

.solution-result {
    background: linear-gradient(145deg, rgba(45,125,111,0.08) 0%, rgba(45,125,111,0.04) 100%);
    border-left: 4px solid var(--success);
    padding: 20px 24px;
    border-radius: 12px;
    margin-bottom: 24px;
}

.solution-result h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--success);
    margin-bottom: 12px;
}

.solution-result p {
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.solution-result p strong {
    color: var(--text-primary);
}

.solution-result.no-solution {
    background: linear-gradient(145deg, rgba(214,69,69,0.08) 0%, rgba(214,69,69,0.04) 100%);
    border-left-color: var(--error);
}

.solution-result.no-solution h3 {
    color: var(--error);
}

.solution-steps {
    margin-bottom: 20px;
}

.solution-step {
    background: var(--bg-subtle);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 16px;
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.solution-step.active {
    border-color: var(--accent-primary);
    background: var(--bg-card);
    box-shadow: var(--shadow-medium);
}

.step-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}

.step-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--accent-primary);
}

.step-info {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.step-grid {
    display: flex;
    justify-content: center;
}

.solution-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-light);
}

.step-counter {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 140px;
    text-align: center;
}

.continue-section {
    margin-top: 28px;
    padding-top: 28px;
    border-top: 1px solid var(--border-light);
    text-align: center;
}

.continue-section .hint {
    margin-bottom: 14px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Utility Classes
   ───────────────────────────────────────────────────────────────────────────── */
.hidden {
    display: none !important;
}

.hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 12px;
    text-align: center;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Scrollbar
   ───────────────────────────────────────────────────────────────────────────── */
.all-pieces-grid::-webkit-scrollbar {
    width: 8px;
}

.all-pieces-grid::-webkit-scrollbar-track {
    background: var(--bg-subtle);
    border-radius: 8px;
}

.all-pieces-grid::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 8px;
}

.all-pieces-grid::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

/* ─────────────────────────────────────────────────────────────────────────────
   Responsive
   ───────────────────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .grid-cell {
        width: 40px;
        height: 40px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 16px;
    }

    header {
        margin-bottom: 24px;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    .input-method-selector {
        flex-direction: column;
        gap: 8px;
        margin-bottom: 20px;
    }

    .tab-button {
        width: 100%;
        justify-content: center;
        padding: 12px 20px;
        font-size: 0.9rem;
    }

    .input-section {
        padding: 20px;
        border-radius: 16px;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .section-header h2 {
        font-size: 1.1rem;
    }

    .grid-cell {
        width: 38px;
        height: 38px;
    }

    .game-grid {
        gap: 3px;
        padding: 3px;
    }

    .all-pieces-grid {
        grid-template-columns: repeat(auto-fill, minmax(85px, 1fr));
        gap: 8px;
        padding: 10px;
        max-height: 350px;
    }

    .piece-container {
        padding: 10px;
    }

    .piece-preview {
        gap: 1px;
    }

    .piece-preview-cell.filled {
        width: 14px;
        height: 14px;
        min-width: 14px;
        min-height: 14px;
    }

    .selected-pieces {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .selected-piece-slot {
        padding: 12px 8px;
    }

    .empty-slot {
        padding: 20px 8px;
        font-size: 0.75rem;
    }

    .btn-primary, .btn-secondary {
        padding: 12px 20px;
        font-size: 0.9rem;
        width: 100%;
        justify-content: center;
    }

    .action-section {
        padding-top: 20px;
    }

    .solution-section {
        padding: 20px;
        margin-top: 20px;
    }

    .solution-result {
        padding: 16px;
    }

    .solution-step {
        padding: 16px;
    }

    .solution-controls {
        flex-wrap: wrap;
        gap: 12px;
    }

    .solution-controls .btn-secondary {
        width: auto;
        flex: 1;
        min-width: 100px;
    }

    .step-counter {
        width: 100%;
        order: -1;
        margin-bottom: 8px;
    }

    .upload-area {
        padding: 32px 20px;
    }

    .upload-area h3 {
        font-size: 1.1rem;
    }

    .upload-area p {
        font-size: 0.85rem;
    }
}

/* Extra small screens */
@media (max-width: 400px) {
    body {
        padding: 12px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .grid-cell {
        width: 32px;
        height: 32px;
    }

    .game-grid {
        gap: 2px;
        padding: 2px;
    }

    .all-pieces-grid {
        grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
    }

    .piece-preview-cell.filled {
        width: 12px;
        height: 12px;
        min-width: 12px;
        min-height: 12px;
    }

    .selected-pieces {
        grid-template-columns: 1fr 1fr 1fr;
    }

    .selected-piece-slot,
    .empty-slot {
        padding: 10px 6px;
    }

    .empty-slot {
        font-size: 0.7rem;
    }

    .input-section {
        padding: 16px;
    }
}
