/* Global Box Model and Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Enhanced gradient palette */
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-boat: linear-gradient(135deg, #ffd166 0%, #ff9a3d 100%);
    --gradient-missionary: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%); /* Sheep-like */
    --gradient-cannibal: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%); /* Tiger-like */

    /* Refined shadows with better depth perception */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.12), 0 2px 4px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 15px 25px rgba(0, 0, 0, 0.15), 0 5px 10px rgba(0, 0, 0, 0.05);

    /* Refined border radiuses */
    --border-radius-sm: 8px;
    --border-radius-md: 16px;
    --border-radius-lg: 24px;

    /* Smooth transitions */
    --transition-fast: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-medium: 300ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Spacing system */
    --space-xs: 0.5rem;
    --space-sm: 1rem;
    --space-md: 1.5rem;
    --space-lg: 2rem;
    --space-xl: 3rem;
}

/* Enhanced Body Styles */
body {
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;

    padding: 20px;

    font-family: 'Poppins', system-ui, sans-serif;

    background: var(--gradient-primary);
    background-attachment: fixed;

    color: #fff;

    display: flex;
    flex-direction: column;

    justify-content: flex-start;
    align-items: center;

    line-height: 1.6;
}

/* Enhanced Typography */
h1 {
    font-size: clamp(1.6rem, 4vw, 2.8rem);
    margin: 10px 0;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 3px;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    background: linear-gradient(135deg, #fff 0%, #f0f0f0 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Improved Instructions Panel */
.instructions {
    background: rgba(255, 255, 255, 0.98);
    padding: var(--space-lg);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    margin: var(--space-md) auto var(--space-lg);
    color: #2d3748;
    font-size: 1.1rem;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Enhanced Game Container */
.game-container {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    max-width: 1200px;
    width: 100%;
    perspective: 1000px;
    align-items: stretch;
    position: relative;
    gap: 15px;
    margin-top: 10px;
    margin-bottom: 10px;


}

.game-container::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
    transform: translateY(-50%);
    z-index: -1;
}

/* Improved Banks and Boat */
.bank,
.boat {
    background: rgba(255, 255, 255, 0.98);
    padding: 1.5rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    min-height: 260px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: transform var(--transition-medium);
    position: relative;
    overflow: hidden;
}

.bank:hover,
.boat:hover {
    transform: translateY(-5px);
}

.boat {
    background: var(--gradient-boat);
    position: relative;
    transition: all 0.4s ease;
}

.boat::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0));
    pointer-events: none;
}

.bank h2 {
    margin-bottom: var(--space-md);
    color: #2d3748;
    font-weight: 700;
    letter-spacing: 1px;
}

/* Enhanced People Container */
.people {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    justify-content: center;
    padding: var(--space-sm);
}

/* Improved Individual Person (Sheep/Tigers) */
.person {
    width: 65px;
    height: 65px;
    border-radius: 18px; /* Slightly rounded square for modern look */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    color: white;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
    box-shadow: var(--shadow-sm);
    border: 3px solid transparent;
}

.person:hover {
    transform: translateY(-8px) scale(1.1);
    box-shadow: var(--shadow-lg);
    z-index: 10;
    cursor: pointer;
}

.person:active {
    transform: scale(0.95);
}

.selected {
    border-color: #ffd700;
    transform: scale(1.15);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
}

.missionary {
    background: var(--gradient-missionary);
    border: 2px solid #e2e8f0;
}

.cannibal {
    background: var(--gradient-cannibal);
    border: 2px solid #ed8936;
}

/* Character Legned in Modal */
.emoji-legend {
    font-size: 1.5rem;
    margin-right: 8px;
}

/* Enhanced Controls */
.controls {
    display: flex;
    gap: var(--space-md);
    margin-top: var(--space-xl);
    justify-content: center;
    flex-wrap: wrap;
}

button {
    padding: 0.875rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
    background: var(--gradient-primary);
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-medium);
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

button:hover {
    filter: brightness(1.08);
}

button:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

button:active:not(:disabled) {
    transform: translateY(1px);
}

button:disabled {
    background: #a0aec0;
    cursor: not-allowed;
    opacity: 0.8;
}

.hint-btn {
    background: #48bb78;
}

.hint-btn:hover:not(:disabled) {
    background: #38a169;
}

/* Results Modal Specific Styling */
.result-content {
    text-align: center;
    padding: 3rem;
    max-width: 450px;
}

.result-icon {
    font-size: 5rem;
    margin-bottom: 1.5rem;
    display: inline-block;
}

.win .result-icon::before { content: "🏆"; }
.loss .result-icon::before { content: "☠️"; }

.win #result-title {
    color: #38a169;
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.loss #result-title {
    color: #e53e3e;
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

#result-message {
    font-size: 1.2rem;
    color: #4a5568;
    margin-bottom: 2rem;
    line-height: 1.5;
}

.result-stats {
    background: #f7fafc;
    padding: 1.5rem;
    border-radius: var(--border-radius-md);
    margin-bottom: 2.5rem;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-label {
    font-weight: 600;
    color: #718096;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: #2d3748;
}

/* Re-apply and refine primary button for result modal */
#restart-btn {
    width: 100%;
}

.win .primary-btn {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    box-shadow: 0 10px 15px -3px rgba(72, 187, 120, 0.4);
}

.loss .primary-btn {
    background: linear-gradient(135deg, #f56565 0%, #e53e3e 100%);
    box-shadow: 0 10px 15px -3px rgba(245, 101, 101, 0.4);
}

/* Ensure the stats container in main UI is properly aligned */
.stats-container {
    display: flex;
    justify-content: center;
    gap: var(--space-lg);
    margin-top: 8px;

}

.move-counter {
    background: rgba(255, 255, 255, 0.15);
    padding: 0.5rem 1.5rem;
    border-radius: var(--border-radius-sm);
    font-weight: 700;
    font-size: 1.2rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: var(--shadow-sm);
}

.guidance-text {
    text-align: center;
    margin: 16px auto;
    padding: 14px 20px;

    width: 90%;
    max-width: 700px;

    background: rgba(255,255,255,0.12);

    border: 1px solid rgba(255,255,255,0.2);

    border-radius: 14px;

    color: #f8fafc;

    font-size: 1rem;
    font-weight: 500;

    backdrop-filter: blur(10px);

    min-height: 55px;

    display: flex;
    align-items: center;
    justify-content: center;

    transition: 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Enhanced Message Display with Types */
#message {
    font-size: 1.3rem;
    font-weight: 700;
    text-align: center;
    margin: var(--space-md) 0;
    padding: 0.8rem 1.2rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-md);
    backdrop-filter: blur(5px);
    transition: all var(--transition-medium);
    max-width: 800px;
    width: 90%;
    border-left: 5px solid transparent;
}

#message.success {
    background: rgba(72, 187, 120, 0.2);
    border-left-color: #48bb78;
    color: #f0fff4;
}

#message.warning {
    background: rgba(237, 137, 54, 0.2);
    border-left-color: #ed8936;
    color: #fffaf0;
}

#message.error {
    background: rgba(245, 101, 101, 0.2);
    border-left-color: #f56565;
    color: #fff5f5;
}

#message.victory {
    background: linear-gradient(90deg, rgba(236, 110, 173, 0.3), rgba(52, 148, 230, 0.3));
    border-left-color: #ecc94b;
    color: #feebc8;
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(236, 201, 75, 0.3);
}

#message,
.guidance-text,
.hint-display-text {
    margin: 8px auto;
    padding: 10px;
    min-height: auto;
    font-size: 0.95rem;
}

.hint-display-text {
    margin-top: 12px;
    padding: 10px 16px;

    max-width: 500px;
    width: 90%;

    text-align: center;
    font-style: italic;
    font-weight: 500;

    color: #fff8dc;

    background: rgba(255, 209, 102, 0.15);

    border: 1px solid rgba(255, 209, 102, 0.4);

    border-radius: 12px;

    backdrop-filter: blur(6px);

    min-height: 45px;

    display: flex;
    align-items: center;
    justify-content: center;

    transition: all 0.3s ease;
}

/* Modal Overlay */
.modal {
    position: fixed;
    inset: 0;

    display: flex;
    justify-content: center;
    align-items: center;

    padding: 20px;

    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);

    z-index: 1000;

    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    transition:
        opacity 0.3s ease,
        visibility 0.3s ease;
}

.modal.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Modal Box */
.modal-content {
    background: #ffffff;
    color: #2d3748;
    padding: 2.5rem;
    border-radius: var(--border-radius-lg);
    max-width: 650px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    position: relative;
    transform: scale(0.8) translateY(30px);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal.show .modal-content {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* Modal Header & Sections */
.modal-header {
    text-align: center;
    margin-bottom: 2rem;
    border-bottom: 2px solid #f7fafc;
    padding-bottom: 1.5rem;
}

.modal-header h2 {
    font-size: 2rem;
    color: #1a202c;
    margin-bottom: 0.5rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.story-text {
    font-style: italic;
    color: #4a5568;
    font-size: 1.1rem;
}

.modal-section {
    margin-bottom: 1.5rem;
}

.modal-section h3 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    color: #2d3748;
    margin-bottom: 0.75rem;
}

.modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-top: 1rem;
}

.modal-content ul {
    list-style: none;
    padding: 0;
}

.modal-content li {
    position: relative;
    padding-left: 1.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
    line-height: 1.4;
}

.modal-content li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: #667eea;
    font-weight: bold;
}

/* Close Button */
#close-modal {
    position: absolute;
    top: 20px;
    right: 25px;
    font-size: 1.5rem;
    cursor: pointer;
    color: #a0aec0;
    transition: color 0.2s;
}

#close-modal:hover {
    color: #2d3748;
}

/* Modal Footer & Buttons */
.modal-footer {
    margin-top: 2.5rem;
    display: flex;
    justify-content: center;
}

.primary-btn {
    padding: 1rem 3rem;
    font-size: 1.25rem;
    background: var(--gradient-primary);
    box-shadow: 0 10px 15px -3px rgba(102, 126, 234, 0.4);
}

.primary-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 20px 25px -5px rgba(102, 126, 234, 0.5);
}

@media (max-width: 640px) {
    .modal-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    
    .modal-content {
        padding: 1.5rem;
    }
}

/* Top Section */
.top-bar {
    width: 100%;
    max-width: 1200px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    padding: 0 20px;
    flex-wrap: wrap;
}
/* Instructions Button */
.instructions-btn {
    padding: 8px 16px;

    border: none;
    border-radius: 10px;

    cursor: pointer;

    font-size: 0.95rem;
    font-weight: 600;

    background: rgba(255, 255, 255, 0.9);
    color: #667eea;

    box-shadow: 0 4px 12px rgba(0,0,0,0.2);

    transition: 0.3s ease;

    text-transform: none;

    white-space: nowrap;
}

.instructions-btn:hover {
    transform: translateY(-2px);
    background: white;
}

/* Responsive Design */
@media (max-width: 768px) {
    .game-container {
        grid-template-columns: 1fr;
        gap: var(--space-lg);
    }

    .bank,
    .boat {
        min-height: 190px;
        padding: 1rem;
    }

    h1 {
        font-size: clamp(1.5rem, 4vw, 2.5rem);
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
        margin-top: 12px;
        gap: 10px;
    }

    button {
        width: 100%;
    }
}
@media (max-width: 768px) {

    .top-bar {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .instructions-btn {
        width: auto;
    }
}