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

body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    padding: 20px;
}

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

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 20px;
}

.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    background-color: #007bff;
    color: white;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s;
}

.btn:hover {
    background-color: #0056b3;
}

.btn:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
}

.btn-primary {
    background-color: #28a745;
}

.btn-primary:hover {
    background-color: #218838;
}

.score-info {
    display: flex;
    gap: 20px;
}

.score-info span {
    font-weight: bold;
    color: #333;
}

.game-board {
    display: flex;
    gap: 20px;
    justify-content: center;
    align-items: flex-start;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(7, 120px);
    grid-template-rows: repeat(3, 160px);
    gap: 8px;
}

.card {
    width: 120px;
    height: 160px;
    border: 2px solid #ccc;
    border-radius: 8px;
    background-color: white;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card:hover {
    border-color: #007bff;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.card.selected {
    background-color: lightblue;
    border-color: #007bff;
    border-width: 3px;
}

.card.empty {
    background-color: #f8f9fa;
    border-style: dashed;
    cursor: default;
}

.card.empty:hover {
    transform: none;
    box-shadow: none;
    border-color: #ccc;
}

.card.placeholder {
    background-color: lightgray;
    cursor: default;
}

.card.placeholder:hover {
    transform: none;
    box-shadow: none;
    border-color: #ccc;
}

.selected-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.selected-card {
    width: 120px;
    height: 160px;
    border: 2px solid #ccc;
    border-radius: 8px;
    background-color: lightgray;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-shapes {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 8px;
}

.shape {
    width: 30px;
    height: 25px;
    position: relative;
}

.shape.circle {
    border-radius: 50%;
}

.shape.triangle {
    width: 0;
    height: 0;
    border-style: solid;
}

.shape.square {
    border-radius: 2px;
}

.shape.red { color: #dc3545; }
.shape.green { color: #28a745; }
.shape.blue { color: #007bff; }

.shape.filled.circle { 
    background-color: currentColor;
    border: 2px solid currentColor;
}

.shape.outline.circle { 
    background-color: white;
    border: 2px solid currentColor;
}

.shape.striped.circle { 
    background-color: white;
    border: 2px solid currentColor;
    background-image: repeating-linear-gradient(
        90deg,
        transparent,
        transparent 2px,
        currentColor 2px,
        currentColor 4px
    );
}

.shape.filled.square { 
    background-color: currentColor;
    border: 2px solid currentColor;
}

.shape.outline.square { 
    background-color: white;
    border: 2px solid currentColor;
}

.shape.striped.square { 
    background-color: white;
    border: 2px solid currentColor;
    background-image: repeating-linear-gradient(
        90deg,
        transparent,
        transparent 2px,
        currentColor 2px,
        currentColor 4px
    );
}

.shape.filled.triangle { 
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-bottom: 25px solid currentColor;
}

.shape.outline.triangle {
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-bottom: 25px solid currentColor;
    position: relative;
}

.shape.outline.triangle::after {
    content: '';
    position: absolute;
    left: -12px;
    top: 3px;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-bottom: 19px solid white;
}

.shape.striped.triangle {
    width: 30px;
    height: 25px;
    background: white;
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
    border: 2px solid currentColor;
    position: relative;
    background-image: repeating-linear-gradient(
        45deg,
        currentColor 0px,
        currentColor 2px,
        transparent 2px,
        transparent 6px
    );
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 20px;
    border: none;
    border-radius: 10px;
    width: 90%;
    max-width: 600px;
    position: relative;
    max-height: 80vh;
    overflow-y: auto;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    right: 20px;
    top: 15px;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: #000;
}

.help-content h3 {
    color: #333;
    margin: 15px 0 10px 0;
}

.help-content ul {
    margin: 10px 0 10px 20px;
}

.help-content li {
    margin: 5px 0;
}

.help-content p {
    margin: 10px 0;
}

.modal-buttons {
    text-align: center;
    margin-top: 20px;
    display: flex;
    gap: 10px;
    justify-content: center;
}

#resultMessage {
    white-space: pre-line;
    font-family: monospace;
    background-color: #f8f9fa;
    padding: 15px;
    border-radius: 5px;
    margin: 15px 0;
    border: 1px solid #dee2e6;
}

/* Tablet and small desktop */
@media (max-width: 1000px) {
    .card-grid {
        grid-template-columns: repeat(4, 120px);
        grid-template-rows: repeat(6, 160px);
    }
    
    .game-board {
        flex-direction: column;
        align-items: center;
    }
    
    .selected-cards {
        flex-direction: row;
        margin-top: 20px;
    }
}

/* Mobile portrait */
@media (max-width: 600px) {
    body {
        padding: 10px;
    }
    
    h1 {
        font-size: 24px;
        margin-bottom: 15px;
    }
    
    .controls {
        gap: 10px;
        margin-bottom: 15px;
    }
    
    .btn {
        padding: 8px 15px;
        font-size: 12px;
    }
    
    .score-info {
        gap: 15px;
    }
    
    .score-info span {
        font-size: 14px;
    }
    
    .card-grid {
        grid-template-columns: repeat(4, 80px);
        grid-template-rows: repeat(6, 100px);
        gap: 5px;
    }
    
    .card {
        width: 80px;
        height: 100px;
    }
    
    .selected-cards {
        gap: 5px;
        margin-top: 15px;
    }
    
    .selected-card {
        width: 80px;
        height: 100px;
    }
    
    .shape {
        width: 20px;
        height: 16px;
    }
    
    .card-shapes {
        gap: 4px;
    }
    
    .shape.filled.triangle, 
    .shape.outline.triangle {
        border-left-width: 10px;
        border-right-width: 10px;
        border-bottom-width: 16px;
    }
    
    .shape.outline.triangle::after {
        left: -8px;
        top: 2px;
        border-left-width: 8px;
        border-right-width: 8px;
        border-bottom-width: 12px;
    }
    
    .shape.striped.triangle {
        width: 20px;
        height: 16px;
    }
    
    /* Mobile-specific modal styling */
    .modal-content {
        margin: 10px;
        margin-left: 5px;
        width: 60%;
        max-width: 300px;
        max-height: 70vh;
        padding: 15px;
        font-size: 12px;
    }
    
    #resultMessage {
        font-size: 11px;
        padding: 10px;
        max-height: 40vh;
        overflow-y: auto;
    }
    
    .modal-buttons {
        margin-top: 10px;
    }
    
    .modal-buttons .btn {
        padding: 6px 10px;
        font-size: 10px;
    }
}

/* Mobile landscape - optimized for phone landscape */
@media (max-width: 900px) and (max-height: 600px) and (orientation: landscape) {
    body {
        padding: 5px;
    }
    
    h1 {
        font-size: 20px;
        margin-bottom: 8px;
    }
    
    .controls {
        gap: 8px;
        margin-bottom: 10px;
        flex-wrap: wrap;
    }
    
    .btn {
        padding: 6px 12px;
        font-size: 11px;
    }
    
    .score-info {
        gap: 10px;
    }
    
    .score-info span {
        font-size: 12px;
    }
    
    .game-board {
        flex-direction: row;
        gap: 10px;
        justify-content: center;
        align-items: flex-start;
    }
    
    .card-grid {
        grid-template-columns: repeat(7, 65px);
        grid-template-rows: repeat(3, 85px);
        gap: 3px;
    }
    
    .card {
        width: 65px;
        height: 85px;
        border-width: 1px;
    }
    
    .selected-cards {
        flex-direction: column;
        gap: 3px;
        margin-top: 0;
    }
    
    .selected-card {
        width: 65px;
        height: 85px;
        border-width: 1px;
    }
    
    .shape {
        width: 18px;
        height: 14px;
    }
    
    .card-shapes {
        gap: 3px;
    }
    
    .shape.filled.triangle, 
    .shape.outline.triangle {
        border-left-width: 9px;
        border-right-width: 9px;
        border-bottom-width: 14px;
    }
    
    .shape.outline.triangle::after {
        left: -7px;
        top: 2px;
        border-left-width: 7px;
        border-right-width: 7px;
        border-bottom-width: 10px;
    }
    
    .shape.striped.triangle {
        width: 18px;
        height: 14px;
    }
    
    .modal-content {
        margin: 5px;
        margin-left: 3px;
        padding: 12px;
        width: 45%;
        max-width: 280px;
        max-height: 85vh;
        font-size: 12px;
    }
    
    #resultMessage {
        font-size: 10px;
        padding: 8px;
        max-height: 60vh;
        overflow-y: auto;
    }
    
    .modal-buttons .btn {
        padding: 5px 8px;
        font-size: 9px;
    }
    
    .help-content h3 {
        font-size: 14px;
        margin: 8px 0 6px 0;
    }
    
    .help-content li, .help-content p {
        font-size: 11px;
        margin: 2px 0;
    }
}

/* Very small screens */
@media (max-width: 400px) {
    .card-grid {
        grid-template-columns: repeat(4, 70px);
        grid-template-rows: repeat(6, 90px);
        gap: 4px;
    }
    
    .card {
        width: 70px;
        height: 90px;
    }
    
    .selected-card {
        width: 70px;
        height: 90px;
    }
    
    /* Even smaller modal for very small screens */
    .modal-content {
        width: 55%;
        max-width: 250px;
        margin: 8px;
        margin-left: 3px;
        padding: 12px;
    }
    
    #resultMessage {
        font-size: 10px;
        padding: 8px;
    }
    
    .modal-buttons .btn {
        padding: 4px 8px;
        font-size: 9px;
    }
}