/* ═══════════════════════════════════════════════════════════════
   Missionaries & Cannibals — Enhanced Edition
   ═══════════════════════════════════════════════════════════════ */

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #0c1220 0%, #162032 50%, #1a2a4a 100%);
    color: #e0e0e0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 15px;
    overflow-x: hidden;
}

.container {
    max-width: 1100px;
    width: 100%;
    text-align: center;
}

h1 {
    font-size: 2.4rem;
    margin-bottom: 4px;
    color: #f4e285;
    text-shadow: 2px 2px 6px rgba(0,0,0,0.6);
}

.subtitle {
    font-size: 1rem;
    color: #8ecae6;
    margin-bottom: 14px;
}

/* ─── Info Bar ────────────────────────────────────────────── */
.info-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.info-bar span {
    background: rgba(255,255,255,0.08);
    padding: 7px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
}

.info-bar button {
    padding: 7px 18px;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: transform 0.15s, filter 0.2s;
}
.info-bar button:hover { transform: scale(1.06); }

#reset-btn { background: #e76f51; color: #fff; }
#hint-btn  { background: #f4e285; color: #1a1a2e; }

/* ─── Message ─────────────────────────────────────────────── */
.message {
    min-height: 36px;
    margin-bottom: 8px;
    font-size: 1.05rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}
.message.success { color: #52b788; }
.message.danger  { color: #e76f51; }
.message.info    { color: #f4e285; }

/* ─── Game Board ──────────────────────────────────────────── */
.game-board {
    display: flex;
    align-items: stretch;
    margin-bottom: 18px;
    min-height: 360px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}

/* ─── Banks ───────────────────────────────────────────────── */
.bank {
    flex: 1;
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 340px;
    position: relative;
}

.left-bank {
    background: linear-gradient(180deg, #1b4332 0%, #2d6a4f 40%, #40916c 100%);
    border-radius: 16px 0 0 16px;
}

.right-bank {
    background: linear-gradient(180deg, #1b4332 0%, #2d6a4f 40%, #40916c 100%);
    border-radius: 0 16px 16px 0;
}

.bank h2 {
    font-size: 0.95rem;
    color: #d8f3dc;
    margin-bottom: 10px;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
}

.people-area {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    flex: 1;
    align-content: flex-start;
    padding: 8px 4px;
}

/* ─── River ───────────────────────────────────────────────── */
.river {
    width: 360px;
    min-width: 300px;
    background: linear-gradient(180deg, #023e8a 0%, #0077b6 30%, #0096c7 60%, #00b4d8 100%);
    position: relative;
    overflow: hidden;
}

.water-layer {
    position: absolute;
    top: 0; left: -100%; right: -100%; bottom: 0;
    background: repeating-linear-gradient(
        90deg,
        transparent 0px,
        transparent 30px,
        rgba(255,255,255,0.04) 30px,
        rgba(255,255,255,0.04) 60px
    );
    animation: waterFlow 4s linear infinite;
}
.water-layer.layer2 {
    background: repeating-linear-gradient(
        90deg,
        transparent 0px,
        transparent 50px,
        rgba(255,255,255,0.03) 50px,
        rgba(255,255,255,0.03) 80px
    );
    animation: waterFlow2 6s linear infinite;
}

.water-sparkles {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image:
        radial-gradient(circle 1px, rgba(255,255,255,0.3) 0%, transparent 100%),
        radial-gradient(circle 1px, rgba(255,255,255,0.2) 0%, transparent 100%),
        radial-gradient(circle 1.5px, rgba(255,255,255,0.15) 0%, transparent 100%);
    background-size: 80px 60px, 120px 80px, 100px 100px;
    background-position: 10px 20px, 50px 40px, 30px 70px;
    animation: sparkle 3s ease-in-out infinite alternate;
}

@keyframes waterFlow  { 0% { transform: translateX(0); } 100% { transform: translateX(60px); } }
@keyframes waterFlow2 { 0% { transform: translateX(0); } 100% { transform: translateX(-80px); } }
@keyframes sparkle { 0% { opacity: 0.5; } 100% { opacity: 1; } }

/* ─── Boat Track & Boat ──────────────────────────────────── */
.boat-track {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    padding: 0 10px;
    z-index: 5;
}

.boat {
    position: absolute;
    transition: left 1.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    animation: bobbing 2.5s ease-in-out infinite;
}

.boat-left  { left: 8px; }
.boat-right { left: calc(100% - 160px); }

@keyframes bobbing {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25%  { transform: translateY(-4px) rotate(0.5deg); }
    75%  { transform: translateY(3px) rotate(-0.5deg); }
}

.boat-body {
    background: linear-gradient(180deg, #6b4226 0%, #8B5E3C 40%, #a0724a 100%);
    border-radius: 12px 12px 40% 40%;
    padding: 8px 12px 18px;
    min-width: 140px;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    box-shadow:
        0 6px 20px rgba(0,0,0,0.5),
        inset 0 2px 4px rgba(255,255,255,0.1);
    border: 2px solid #5a3a1a;
    position: relative;
}

.boat-sail {
    font-size: 1.8rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
    line-height: 1;
}

.boat-people {
    display: flex;
    gap: 6px;
    min-height: 60px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.sail-btn {
    background: linear-gradient(180deg, #48cae4, #0096c7);
    color: #fff;
    border: 2px solid #90e0ef;
    padding: 8px 20px;
    border-radius: 25px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 3px 10px rgba(0,0,0,0.3);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
    white-space: nowrap;
}
.sail-btn:hover:not(:disabled) {
    background: linear-gradient(180deg, #90e0ef, #48cae4);
    transform: scale(1.08);
}
.sail-btn:disabled {
    background: #3a3a4a;
    color: #666;
    border-color: #444;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ─── Characters (SVG-based) ─────────────────────────────── */
.person {
    width: 60px;
    height: 78px;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    user-select: none;
    position: relative;
    overflow: hidden;
}

.person:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 18px rgba(0,0,0,0.4);
}
.person:active { transform: scale(0.95); }

.person svg {
    width: 42px;
    height: 52px;
    filter: drop-shadow(1px 2px 2px rgba(0,0,0,0.3));
}

.person .char-label {
    font-size: 0.5rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-top: 1px;
}

/* Missionary */
.person.missionary {
    background: linear-gradient(180deg, #1b4965 0%, #2a6f97 100%);
    border: 2px solid #5fa8d3;
    box-shadow: 0 3px 10px rgba(42,111,151,0.4);
}
.person.missionary .char-label { color: #bee9e8; }

/* Cannibal */
.person.cannibal {
    background: linear-gradient(180deg, #6b2737 0%, #a4303f 100%);
    border: 2px solid #e76f51;
    box-shadow: 0 3px 10px rgba(164,48,63,0.4);
}
.person.cannibal .char-label { color: #ffcdb2; }

/* On boat glow */
.person.on-boat {
    box-shadow: 0 0 16px rgba(244,226,133,0.7);
    border-color: #f4e285;
}

/* ─── Eating Animation ────────────────────────────────────── */
.person.being-eaten {
    animation: beingEaten 0.8s ease-in forwards;
}

@keyframes beingEaten {
    0%   { transform: scale(1) rotate(0deg); opacity: 1; }
    20%  { transform: scale(1.1) rotate(-5deg); opacity: 1; }
    40%  { transform: scale(0.8) rotate(10deg); opacity: 0.8; }
    60%  { transform: scale(0.5) rotate(-15deg); opacity: 0.6; }
    80%  { transform: scale(0.2) rotate(20deg); opacity: 0.3; }
    100% { transform: scale(0) rotate(30deg); opacity: 0; }
}

.person.eating {
    animation: eatingChomp 0.8s ease-in-out;
}

@keyframes eatingChomp {
    0%   { transform: scale(1); }
    15%  { transform: scale(1.15) translateX(-3px); }
    30%  { transform: scale(1.25) translateX(3px); }
    45%  { transform: scale(1.35); }
    60%  { transform: scale(1.2); }
    80%  { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* ─── Screen Shake ────────────────────────────────────────── */
.shake {
    animation: screenShake 0.6s ease-in-out;
}

@keyframes screenShake {
    0%, 100% { transform: translateX(0); }
    10% { transform: translateX(-8px) rotate(-0.5deg); }
    20% { transform: translateX(8px) rotate(0.5deg); }
    30% { transform: translateX(-6px) rotate(-0.3deg); }
    40% { transform: translateX(6px) rotate(0.3deg); }
    50% { transform: translateX(-4px); }
    60% { transform: translateX(4px); }
    70% { transform: translateX(-2px); }
    80% { transform: translateX(2px); }
}

/* Red flash on bank */
.bank.danger-flash {
    animation: dangerFlash 0.6s ease-out;
}

@keyframes dangerFlash {
    0%   { box-shadow: inset 0 0 0 rgba(231,76,60,0); }
    30%  { box-shadow: inset 0 0 60px rgba(231,76,60,0.6); }
    100% { box-shadow: inset 0 0 0 rgba(231,76,60,0); }
}

/* ─── Game Over Overlay ───────────────────────────────────── */
.gameover-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(20,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.4s ease;
}

.gameover-box {
    background: linear-gradient(135deg, #4a1420, #6b2737);
    padding: 40px 50px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 10px 50px rgba(0,0,0,0.6), 0 0 80px rgba(231,76,60,0.2);
    border: 2px solid #a4303f;
    max-width: 500px;
}

.gameover-box .skull {
    font-size: 4rem;
    animation: skullBounce 0.6s ease-out;
}

@keyframes skullBounce {
    0%   { transform: scale(0) rotate(-20deg); }
    60%  { transform: scale(1.3) rotate(5deg); }
    100% { transform: scale(1) rotate(0deg); }
}

.gameover-box h2 {
    font-size: 1.8rem;
    color: #e76f51;
    margin: 10px 0;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

.gameover-box .death-msg {
    font-size: 1.05rem;
    color: #ffcdb2;
    margin-bottom: 20px;
    font-style: italic;
    line-height: 1.5;
}

.gameover-box button {
    padding: 12px 30px;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    background: linear-gradient(180deg, #e76f51, #c1440e);
    color: #fff;
    transition: transform 0.15s;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.gameover-box button:hover { transform: scale(1.08); }

/* ─── Win Overlay ─────────────────────────────────────────── */
.win-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,20,10,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.4s ease;
}

.win-box {
    background: linear-gradient(135deg, #1b4332, #2d6a4f);
    padding: 40px 50px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 10px 50px rgba(0,0,0,0.5), 0 0 80px rgba(82,183,136,0.15);
    border: 2px solid #52b788;
    max-width: 500px;
    position: relative;
    overflow: hidden;
}

.win-box h2 {
    font-size: 2rem;
    color: #f4e285;
    margin-bottom: 10px;
}

.win-box p {
    font-size: 1.05rem;
    color: #d8f3dc;
    margin-bottom: 10px;
    line-height: 1.5;
}

.win-box .stars {
    font-size: 2rem;
    margin-bottom: 15px;
}

.win-box button {
    padding: 12px 30px;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    background: linear-gradient(180deg, #52b788, #2d6a4f);
    color: #fff;
    transition: transform 0.15s;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    margin-top: 8px;
}
.win-box button:hover { transform: scale(1.08); }

/* Confetti */
.confetti-container {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    overflow: hidden;
    pointer-events: none;
}

.confetti {
    position: absolute;
    top: -10px;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    animation: confettiFall linear forwards;
}

@keyframes confettiFall {
    0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(400px) rotate(720deg); opacity: 0; }
}

@keyframes fadeIn {
    from { opacity: 0; } to { opacity: 1; }
}

/* ─── Rules ───────────────────────────────────────────────── */
.rules {
    background: rgba(255,255,255,0.05);
    border-radius: 14px;
    padding: 14px 24px;
    text-align: left;
    border: 1px solid rgba(255,255,255,0.06);
}

.rules h3 {
    color: #f4e285;
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.rules ul { list-style: none; }

.rules li {
    padding: 3px 0;
    font-size: 0.85rem;
    color: #aaa;
}
.rules li::before { content: "▸ "; color: #52b788; }
.rules li strong  { color: #f4e285; }
.rules li em      { color: #e76f51; }

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 800px) {
    .game-board {
        flex-direction: column;
    }
    .bank {
        min-height: 120px;
        border-radius: 16px 16px 0 0;
    }
    .right-bank { border-radius: 0 0 16px 16px; }
    .left-bank  { border-radius: 16px 16px 0 0; }
    .river {
        width: 100%;
        min-width: unset;
        min-height: 200px;
    }
    .boat-left  { left: 8px; }
    .boat-right { left: calc(100% - 160px); }
    h1 { font-size: 1.7rem; }
    .person { width: 50px; height: 66px; }
    .person svg { width: 34px; height: 44px; }
}
