html, body {
    height: 100%;
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: 'Nanum Gothic', sans-serif;
    background-color: #f0f8ff;
    color: #333;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100dvh;
}

/* Login Container */
.container {
    background-color: white;
    padding: 30px 20px;
    border-radius: 25px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    text-align: center;
    width: 90%;
    max-width: 380px;
}

h1 {
    color: #4a90e2;
    font-family: 'Jua', sans-serif;
    font-size: 2.5rem;
    margin-top: 0;
}

input[type="text"] {
    padding: 12px 15px;
    font-size: 1.1rem;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    margin-bottom: 20px;
    width: 85%;
    font-family: 'Nanum Gothic', sans-serif;
    text-align: center;
}

button {
    background-color: #ffcc00;
    border: none;
    padding: 12px 25px;
    font-size: 1.2rem;
    font-family: 'Jua', sans-serif;
    border-radius: 15px;
    cursor: pointer;
    box-shadow: 0 4px 0 #e6b800;
    transition: all 0.1s;
}

button:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #e6b800;
}

.creator-info {
    margin-top: 30px;
    font-size: 1rem;
    color: #999;
    border-top: 1px dashed #eee;
    padding-top: 20px;
}

/* Game View Layout */
#game-container {
    width: 100vw;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Top Navigation (Portrait) */
.top-nav {
    display: flex;
    flex-direction: row !important;
    flex-shrink: 0;
    padding: 8px 15px;
    background-color: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    align-items: center;
    justify-content: space-between;
    height: auto;
    min-height: 80px;
    max-height: 25vh;
    box-sizing: border-box;
    z-index: 100;
    overflow: visible;
    gap: 15px;
}

.ai-chat-area {
    flex: 1;
    min-width: 150px;
    max-width: calc(100% - 200px);
    overflow: visible;
    display: flex !important;
    flex-direction: column;
    max-height: calc(25vh - 20px);
    min-height: 60px !important;
    visibility: visible !important;
    opacity: 1 !important;
    align-self: center;
}

.ai-character {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 60px !important;
    height: auto;
    overflow: visible;
    flex: 1;
}

#ai-img {
    width: 45px;
    height: 45px;
    background-color: #eee;
    border-radius: 50%;
    flex-shrink: 0;
}

.speech-bubble {
    position: relative;
    background: #fff9c4;
    border-radius: 12px;
    padding: 8px 12px;
    font-size: 1rem;
    line-height: 1.4;
    box-shadow: 1px 1px 5px rgba(0,0,0,0.05);
    text-align: left;
    white-space: normal;
    word-break: keep-all;
    overflow-y: auto;
    overflow-x: hidden;
    font-weight: 500;
    flex: 1;
    min-height: 40px !important;
    min-width: 100px !important;
    max-height: calc(25vh - 50px) !important;
    display: flex !important;
    align-items: center;
    visibility: visible !important;
    opacity: 1 !important;
}

#ai-message {
    margin: 0;
    padding: 0;
    color: #333 !important;
    width: 100%;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    font-size: 1rem !important;
    line-height: 1.4 !important;
    white-space: normal !important;
    word-break: keep-all !important;
}

/* 스크롤바 스타일링 */
.speech-bubble::-webkit-scrollbar {
    width: 6px;
}

.speech-bubble::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

.speech-bubble::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.speech-bubble::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

.speech-bubble:after {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 0;
    height: 0;
    border: 6px solid transparent;
    border-right-color: #fff9c4;
    border-left: 0;
    margin-top: -6px;
    margin-left: -6px;
}

.header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
    align-self: center;
    min-width: 120px;
}

.status-container {
    background-color: #e3f2fd;
    padding: 4px 10px;
    border-radius: 8px;
}

#game-status {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: #1976d2;
    white-space: nowrap;
}

.game-creator {
    font-size: 0.7rem;
    color: #bbb;
    margin-top: 2px;
}

.nav-controls {
    display: flex;
    gap: 8px;
}

.nav-controls button {
    padding: 5px 12px;
    font-size: 0.9rem;
    background-color: #f5f5f5;
    border-radius: 8px;
    box-shadow: none;
    font-family: 'Nanum Gothic', sans-serif;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

#btn-nudge {
    background-color: #ff9800 !important;
    color: white !important;
}

#btn-nudge:disabled {
    background-color: #ccc !important;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    overflow: hidden;
}

.board-section {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    margin: 0 auto;
}

.captured-area {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    width: 95%;
    min-height: 35px;
    gap: 5px;
    background-color: rgba(0,0,0,0.05);
    border-radius: 10px;
    padding: 2px 10px;
}

.captured-area-landscape {
    display: none !important;
}

.captured-piece {
    width: 26px;
    height: 26px;
    object-fit: contain;
}

.captured-stone {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin: 2px;
    border: 1px solid #333;
}

.captured-stone.black-stone {
    background: linear-gradient(135deg, #666 0%, #000 100%);
}

.captured-stone.white-stone {
    background: linear-gradient(135deg, #fff 0%, #ddd 100%);
    border-color: #999;
}

.captured-count {
    font-size: 1rem;
    font-weight: bold;
    color: #333;
    margin-left: 4px;
    font-family: 'Nanum Gothic', sans-serif;
}

#myBoard {
    width: min(100vw - 15px, 100vh - 280px) !important;
    height: min(100vw - 15px, 100vh - 280px) !important;
    border: 3px solid #4a90e2;
    box-sizing: border-box;
    touch-action: none;
    margin: 5px auto;
    display: block;
}

/* Portrait Mode - Ensure speech bubble height is limited */
@media (orientation: portrait) {
    .ai-chat-area {
        height: auto !important;
        max-height: 15vh !important;
        min-height: 60px !important;
        max-width: calc(100% - 140px) !important;
        overflow: hidden !important;
    }
    
    .ai-character {
        height: auto !important;
        min-height: 60px !important;
        gap: 8px !important;
    }

    #ai-img {
        width: 45px !important;
        height: 45px !important;
        flex-shrink: 0;
    }
    
    .speech-bubble {
        max-height: calc(15vh - 10px) !important;
        height: auto !important;
        min-height: 35px !important;
        padding: 6px 10px !important;
        font-size: 0.9rem !important;
        overflow-y: auto !important;
    }

    .top-nav {
        padding: 8px 12px !important;
        height: auto !important;
        min-height: 80px !important;
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
    }

    .header-right {
        min-width: 110px !important;
        gap: 5px !important;
    }

    .status-container {
        margin-bottom: 2px !important;
    }

    .status-container p {
        font-size: 0.9rem !important;
    }

    .nav-controls {
        gap: 5px !important;
    }

    .nav-controls button {
        padding: 4px 8px !important;
        font-size: 0.8rem !important;
    }
}

/* Landscape Mode Adjustments */
@media (orientation: landscape) {
    #game-container {
        flex-direction: row !important;
    }

    .top-nav {
        width: 220px !important;
        height: 100vh !important;
        max-height: 100vh !important;
        flex-direction: column !important;
        justify-content: flex-start !important;
        align-items: stretch !important;
        padding: 20px 15px !important;
        border-right: 2px solid #f0f0f0;
        border-bottom: none;
        box-shadow: 2px 0 10px rgba(0,0,0,0.05);
        overflow-y: auto;
        overflow-x: hidden;
        gap: 15px !important;
        position: relative !important;
    }

    .ai-chat-area {
        margin-bottom: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: calc(100vh - 350px) !important;
        min-height: 150px !important;
        overflow: visible !important;
        flex-shrink: 0;
    }

    .ai-character {
        flex-direction: column !important;
        text-align: center !important;
        align-items: center !important;
        gap: 10px !important;
    }

    #ai-img {
        width: 60px !important;
        height: 60px !important;
        margin: 0 auto;
    }

    .speech-bubble {
        max-height: calc(100vh - 400px) !important;
        min-height: 80px !important;
        margin-top: 10px !important;
        font-size: 1rem !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        width: 100% !important;
    }

    .speech-bubble:after {
        border-right-color: transparent !important;
        border-bottom-color: #fff9c4 !important;
        top: -12px !important;
        left: 50% !important;
        margin-left: -6px !important;
        border-left: 6px solid transparent !important;
    }

    .header-right {
        width: 100% !important;
        margin-left: 0 !important;
        margin-top: auto !important;
        align-items: center !important;
        flex-shrink: 0;
        gap: 10px !important;
    }

    .status-container {
        width: 100% !important;
        text-align: center !important;
        margin-bottom: 10px !important;
    }

    #game-status {
        font-size: 1.1rem;
    }

    .nav-controls {
        width: 100%;
        justify-content: center;
        gap: 15px;
    }

    .board-section {
        flex-direction: row;
        gap: 8px;
        padding: 0 10px;
        justify-content: center !important;
        align-items: center !important;
    }

    .captured-area {
        display: flex;
        flex-direction: column;
        width: 35px;
        height: auto;
        max-height: 90%;
        min-height: 120px;
        flex-wrap: wrap;
        align-content: center;
    }

    #myBoard {
        width: min(100vw - 300px, 100vh - 30px) !important;
        height: min(100vw - 300px, 100vh - 30px) !important;
        margin: 0 auto !important;
    }
}

/* Modal styles */
.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: white;
    margin: 10vh auto;
    padding: 25px;
    border-radius: 25px;
    width: 85%;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
    font-family: 'Nanum Gothic', sans-serif;
}

.modal-content h2 {
    font-family: 'Jua', sans-serif;
    color: #4a90e2;
    margin-top: 0;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

#history-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

#history-table th, #history-table td {
    padding: 10px;
    font-size: 1rem;
    border-bottom: 1px solid #eee;
    text-align: center;
}

#history-table th {
    background-color: #f8f9fa;
    color: #666;
    font-weight: 700;
}

