/* 農夫過河遊戲 - 現代化設計 */

/* 全局樣式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', 'Microsoft JhengHei', 'Arial', sans-serif;
    background: url('img/bg.png') center center / cover no-repeat, linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #2c3e50;
    overflow-x: auto;
}

/* 標題樣式 */
h1 {
    text-align: center;
    color: white;
    font-size: 2.5rem;
    margin: 20px 0;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    animation: titleGlow 2s ease-in-out infinite alternate;
}

@keyframes titleGlow {
    from { text-shadow: 2px 2px 4px rgba(0,0,0,0.3); }
    to { text-shadow: 2px 2px 20px rgba(255,255,255,0.5); }
}

/* 主布局 */
#main-layout {
    display: flex;
    max-width: 1600px;
    margin: 0 auto;
    gap: 24px;
    padding: 0 24px;
}

#game-panel {
    flex: 2.5;
    background: rgba(255,255,255,0.98);
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.2);
}

#info-panel {
    flex: 1;
    background: rgba(255,255,255,0.95);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.2);
    max-height: 800px;
    overflow-y: auto;
}

/* 遊戲容器 */
#game-container {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.08);
    position: relative;
    min-height: 400px;
    border: 1px solid rgba(0,0,0,0.05);
    overflow: visible;
}

/* 岸邊樣式 */
.bank {
    width: 280px;
    height: 350px;
    background: #ffffff;
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    position: relative;
    border: 2px solid #e9ecef;
    overflow-y: auto;
    transition: all 0.3s ease;
}

.bank:hover {
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
    border-color: #6c757d;
}

#left-bank::before {
    content: '左岸';
    position: absolute;
    top: 8px;
    left: 8px;
    background: #667eea;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.75rem;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    z-index: 25;
    white-space: nowrap;
}

#right-bank::before {
    content: '右岸';
    position: absolute;
    top: 8px;
    left: 8px;
    background: #28a745;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.75rem;
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
    z-index: 25;
    white-space: nowrap;
}

/* 河流樣式 */
#river {
    flex: 1;
    height: 350px;
    background: linear-gradient(135deg, #74c0fc 0%, #339af0 100%);
    margin: 0 24px;
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    border: 2px solid #228be6;
    box-shadow: inset 0 4px 12px rgba(34, 139, 230, 0.2);
}

#river::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        90deg,
        transparent,
        transparent 20px,
        rgba(255,255,255,0.1) 20px,
        rgba(255,255,255,0.1) 40px
    );
    animation: waves 4s linear infinite;
    z-index: 1;
}

@keyframes waves {
    0% { transform: translateX(0); }
    100% { transform: translateX(40px); }
}

/* 船的樣式 */
#boat {
    position: absolute;
    bottom: 25%;
    left: 0;
    width: 100px;
    height: 100px;
    background: none !important;
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
    transition: transform 1s ease-in-out;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 5px;
    padding: 5px !important;
    margin: 0 !important;
    z-index: 100;
    overflow: visible;
}

/* 移除 CSS 中的船圖片樣式，使用 HTML 內聯樣式 */

#boat::before {
    content: '';
}

#boat::after {
    content: '';
}

/* 物品樣式 */
.item {
    width: 100px;
    height: 100px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid #e9ecef;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    background: #ffffff;
    padding: 4px;
    object-fit: contain;
    position: relative;
    z-index: 10;
}

.item:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
    border-color: #667eea;
}

.item:active {
    transform: translateY(0) scale(0.98);
}

.item.on-boat {
    width: 45px;
    height: 45px;
    border-color: #28a745;
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
    animation: boatFloat 2s ease-in-out infinite alternate;
    position: relative;
    z-index: 50;
    margin: 2px;
    flex-shrink: 0;
    min-width: 30px;
    min-height: 30px;
}

@keyframes boatFloat {
    from { transform: translateY(0px); }
    to { transform: translateY(-2px); }
}

/* 農夫樣式 - 顯示為可點擊的農夫圖標 */
#farmer {
    background: linear-gradient(135deg, #667eea, #764ba2);
    position: relative;
    border-color: #667eea;
}

#farmer::before {
    content: '👨‍🌾';
    font-size: 2.2rem;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
}

#farmer:hover {
    background: linear-gradient(135deg, #5a67d8, #667eea);
    border-color: #5a67d8;
}

/* 控制按鈕 */
#controls {
    text-align: center;
    margin: 24px 0;
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

#controls button {
    background: #667eea;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    min-width: 120px;
}

#controls button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    background: #5a67d8;
}

#controls button:active {
    transform: translateY(0);
}

#controls button:disabled {
    background: #adb5bd;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#reset-btn {
    background: #dc3545 !important;
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3) !important;
}

#reset-btn:hover {
    background: #c82333 !important;
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.4) !important;
}

#solve-btn {
    background: #ffc107 !important;
    color: #212529 !important;
    box-shadow: 0 2px 8px rgba(255, 193, 7, 0.3) !important;
}

#solve-btn:hover {
    background: #e0a800 !important;
    box-shadow: 0 4px 12px rgba(255, 193, 7, 0.4) !important;
}

/* 訊息區域 */
#message-area {
    background: #667eea;
    color: white;
    padding: 16px;
    border-radius: 8px;
    text-align: center;
    font-size: 1rem;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    margin-top: 16px;
    border: 1px solid rgba(255,255,255,0.1);
}

#message-area p {
    margin: 0;
    line-height: 1.5;
}

/* 資訊面板樣式 */
#rules-container h2 {
    color: #2d3436;
    margin-bottom: 15px;
    font-size: 1.3rem;
    border-bottom: 2px solid #74b9ff;
    padding-bottom: 5px;
}

#rules-container ul {
    list-style: none;
    padding: 0;
}

#rules-container li {
    background: rgba(116, 185, 255, 0.1);
    margin: 8px 0;
    padding: 10px;
    border-radius: 8px;
    border-left: 4px solid #74b9ff;
    font-size: 0.9rem;
    line-height: 1.4;
}

/* 操作記錄 */
#history-log h3 {
    color: #2d3436;
    margin: 20px 0 10px 0;
    font-size: 1.1rem;
    border-bottom: 2px solid #00b894;
    padding-bottom: 5px;
}

#history-list {
    list-style: none;
    padding: 0;
    max-height: 450px;
    overflow-y: auto;
}

#history-list li {
    background: rgba(0, 184, 148, 0.1);
    margin: 8px 0;
    padding: 12px;
    border-radius: 8px;
    border-left: 4px solid #00b894;
    font-size: 0.9rem;
    line-height: 1.4;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* 動畫效果 */
.fade-in {
    animation: fadeIn 1s ease-in;
}

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

/* 響應式設計 */
@media (max-width: 1200px) {
    #main-layout {
        flex-direction: column;
    }
    
    #info-panel {
        max-height: none;
        min-height: 400px;
    }
    
    #history-list {
        max-height: 350px;
    }
    
    h1 {
        font-size: 2rem;
    }
}

@media (max-width: 768px) {
    #main-layout {
        flex-direction: column;
        padding: 16px;
        gap: 16px;
    }
    
    #game-container {
        flex-direction: column;
        gap: 15px;
        padding: 20px;
        min-height: 600px;
        align-items: center;
    }
    
    .bank {
        width: 100%;
        height: 160px;
        margin: 0 auto;
        max-width: 350px;
        order: 1;
    }
    
    #left-bank {
        order: 1;
    }
    
    #river {
        width: 100%;
        height: 80px;
        margin: 0;
        max-width: 350px;
        align-self: center;
        position: relative;
        min-height: 70px;
        order: 2;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    #right-bank {
        order: 3;
    }
    
    #boat {
        width: 120px;
        height: 70px;
        bottom: auto;
        left: 50%;
        top: 0;
        right: auto;
        transform: translateX(-50%);
        position: absolute;
        background: rgba(139, 69, 19, 0.1) !important;
        border: 2px dashed rgba(139, 69, 19, 0.3) !important;
        border-radius: 8px;
        z-index: 10;
        transition: top 1s ease-in-out;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 3px;
        padding: 3px !important;
    }
    
    #boat-image {
        width: 80px !important;
        height: 60px !important;
        position: absolute !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        z-index: 1 !important;
    }
    
    .item {
        width: 70px;
        height: 70px;
        cursor: pointer;
        transition: all 0.3s ease;
    }
    
    .item:hover {
        transform: scale(1.1);
        box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    }
    
    .item.on-boat {
        width: 40px;
        height: 40px;
        z-index: 20;
        position: relative;
        border: 2px solid #fff;
        border-radius: 4px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.3);
        flex-shrink: 0;
        margin: 0 2px;
    }
    
    h1 {
        font-size: 1.8rem;
        margin: 16px 0;
    }
    
    #controls {
        margin: 16px 0;
        gap: 8px;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    #controls button {
        padding: 12px 20px;
        font-size: 1rem;
        min-width: 120px;
        border-radius: 8px;
        font-weight: 600;
    }
    
    #message-area {
        padding: 15px;
        font-size: 1rem;
        text-align: center;
        background: rgba(255,255,255,0.9);
        border-radius: 8px;
        margin: 10px 0;
        border: 1px solid #ddd;
    }
}

/* 針對更小螢幕的額外優化 (iPhone 8 Plus 等) */
@media (max-width: 414px) {
    #main-layout {
        padding: 12px;
        gap: 12px;
    }
    
    #game-panel {
        padding: 16px;
    }
    
    #game-container {
        min-height: 550px;
        gap: 12px;
        padding: 16px;
    }
    
    .bank {
        height: 150px;
        max-width: 320px;
    }
    
    #river {
        height: 70px;
        max-width: 320px;
        min-height: 60px;
    }
    
    #boat {
        width: 80px;
        height: 50px;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        gap: 2px;
        padding: 3px !important;
        background: rgba(139, 69, 19, 0.15) !important;
        border: 2px dashed rgba(139, 69, 19, 0.4) !important;
        transition: top 1s ease-in-out;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: row;
        flex-wrap: nowrap;
    }
    
    #boat-image {
        width: 70px !important;
        height: 50px !important;
        position: absolute !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        z-index: 1 !important;
    }
    
    .item {
        width: 60px;
        height: 60px;
    }
    
    .item.on-boat {
        width: 32px;
        height: 32px;
        margin: 0 1px;
        min-width: 28px;
        min-height: 28px;
        border: 1px solid #fff;
        z-index: 20;
        position: relative;
        flex-shrink: 0;
    }
    
    h1 {
        font-size: 1.4rem;
        margin: 12px 0;
    }
    
    #controls {
        gap: 6px;
        margin: 12px 0;
    }
    
    #controls button {
        padding: 10px 16px;
        font-size: 0.9rem;
        min-width: 100px;
        border-radius: 6px;
    }
    
    #message-area {
        padding: 12px;
        font-size: 0.9rem;
        margin: 8px 0;
    }
    
    #info-panel {
        padding: 16px;
    }
    
    #rules-container h2 {
        font-size: 1.1rem;
    }
    
    #rules-container li {
        font-size: 0.8rem;
        padding: 8px;
    }
}

/* 手機版觸控優化 */
@media (max-width: 768px) {
    .item {
        -webkit-tap-highlight-color: rgba(0,0,0,0.1);
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
    }
    
    .item:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
    
    #controls button {
        -webkit-tap-highlight-color: rgba(0,0,0,0.1);
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
    }
    
    #controls button:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
    
    /* 確保船在手機上可見 */
    #boat {
        min-width: 80px;
        min-height: 60px;
        border: 2px solid rgba(139, 69, 19, 0.5) !important;
        background: rgba(139, 69, 19, 0.2) !important;
        transition: top 1s ease-in-out, transform 1s ease-in-out !important;
    }
    
    /* 物品在船上的視覺增強 */
    .item.on-boat {
        background: rgba(255,255,255,0.9);
        border: 2px solid #007bff !important;
        box-shadow: 0 3px 10px rgba(0,123,255,0.3) !important;
        animation: onBoatPulse 2s ease-in-out infinite alternate;
    }
    
    @keyframes onBoatPulse {
        from { box-shadow: 0 3px 10px rgba(0,123,255,0.3); }
        to { box-shadow: 0 3px 15px rgba(0,123,255,0.5); }
    }
}

/* 失敗提示視窗樣式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
    animation: modalFadeIn 0.3s ease-out;
}

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

.modal-content {
    background: white;
    border-radius: 20px;
    padding: 0;
    max-width: 90%;
    width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease-out;
    overflow: hidden;
}

@keyframes modalSlideIn {
    from { transform: translateY(-50px) scale(0.9); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-header {
    background: linear-gradient(135deg, #ff6b6b, #ee5a52);
    color: white;
    padding: 20px;
    text-align: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.modal-body {
    padding: 30px;
    text-align: center;
}

.modal-body p {
    font-size: 1.3rem;
    color: #2c3e50;
    margin-bottom: 30px;
    line-height: 1.5;
    font-weight: 600;
}

.modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.modal-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 140px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.modal-btn.primary {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
}

.modal-btn.primary:hover {
    background: linear-gradient(135deg, #45a049, #3d8b40);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.3);
}

.modal-btn.secondary {
    background: linear-gradient(135deg, #6c757d, #5a6268);
    color: white;
}

.modal-btn.secondary:hover {
    background: linear-gradient(135deg, #5a6268, #495057);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(108, 117, 125, 0.3);
}

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

/* 手機版模態框優化 */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        max-width: 350px;
    }
    
    .modal-header h2 {
        font-size: 1.5rem;
    }
    
    .modal-body p {
        font-size: 1.1rem;
    }
    
    .modal-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .modal-btn {
        width: 100%;
        max-width: 200px;
    }
}

/* 滾動條美化 */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(116, 185, 255, 0.6);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(116, 185, 255, 0.8);
}