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 */
.top-nav {
    display: flex;
    flex-shrink: 0;
    padding: 8px 15px;
    background-color: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    align-items: flex-start;
    justify-content: space-between;
    height: auto;
    min-height: 80px;
    box-sizing: border-box;
    z-index: 100;
    overflow: visible;
}

.ai-chat-area {
    flex: 1;
    min-width: 0;
    max-width: calc(100% - 200px);
}

.ai-character {
    display: flex;
    align-items: center;
    gap: 10px;
}

#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;
    max-height: none;
    overflow-y: visible;
    font-weight: 500;
}

.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;
    margin-left: 12px;
    flex-shrink: 0;
    min-width: 180px;
    max-width: 200px;
}

.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;
}

#piece-count {
    margin: 5px 0 0 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: #1976d2;
}

.game-creator {
    font-size: 0.7rem;
    color: #bbb;
    margin-top: 2px;
}

.nav-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
    max-width: 100%;
}

.nav-controls button {
    padding: 5px 10px;
    font-size: 0.85rem;
    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;
    flex: 0 0 calc(50% - 3px);
    min-width: calc(50% - 3px);
    max-width: calc(50% - 3px);
    justify-content: center;
    box-sizing: border-box;
}

#btn-nudge {
    background-color: #ff9800 !important;
    color: white !important;
}

#btn-voice-message {
    background-color: #4caf50 !important;
    color: white !important;
}

#btn-voice-message.recording {
    background-color: #f44336 !important;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}

#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;
}

/* Othello Board */
#othello-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: min(100vw - 10px, 100vh - 200px);
    height: min(100vw - 10px, 100vh - 200px);
    max-width: 500px;
    max-height: 500px;
    border: 3px solid #2c5530;
    background-color: #228B22;
    box-sizing: border-box;
    gap: 2px;
    padding: 2px;
}

.othello-cell {
    background-color: #32CD32;
    border: 1px solid #2c5530;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: background-color 0.2s;
}

.othello-cell:hover {
    background-color: #3cb371;
}

.othello-cell.valid-move {
    background-color: #90EE90;
    cursor: pointer;
}

.othello-cell.valid-move::before {
    content: '';
    width: 20%;
    height: 20%;
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 50%;
    position: absolute;
}

.othello-piece {
    width: 85%;
    height: 85%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    transition: transform 0.3s;
}

.othello-piece.black {
    background: radial-gradient(circle at 30% 30%, #555, #000);
}

.othello-piece.white {
    background: radial-gradient(circle at 30% 30%, #fff, #ccc);
}

.othello-piece.flipping {
    animation: flip 0.3s ease-in-out;
}

@keyframes flip {
    0% { transform: scaleY(1); }
    50% { transform: scaleY(0); }
    100% { transform: scaleY(1); }
}

/* 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;
}

/* Responsive adjustments */
@media (orientation: landscape) {
    #game-container {
        flex-direction: row;
    }

    .top-nav {
        width: 280px;
        min-width: 250px;
        max-width: 320px;
        height: 100%;
        flex-direction: column;
        justify-content: flex-start;
        padding: 15px 12px;
        border-right: 2px solid #f0f0f0;
        border-bottom: none;
        box-shadow: 2px 0 10px rgba(0,0,0,0.05);
        overflow-y: auto;
        overflow-x: visible;
        box-sizing: border-box;
    }

    .ai-chat-area {
        flex: 0 0 auto;
        width: 100%;
        max-width: 100%;
        margin-bottom: 15px;
        min-width: 0;
        overflow: visible;
    }

    .ai-character {
        flex-direction: row;
        align-items: flex-start;
        gap: 10px;
        width: 100%;
        min-width: 0;
    }

    #ai-img {
        width: 50px;
        height: 50px;
        flex-shrink: 0;
        align-self: flex-start;
    }

    .speech-bubble {
        flex: 1 1 auto;
        min-width: 0;
        width: auto;
        max-width: none;
        font-size: 0.9rem;
        padding: 10px 12px;
        margin-left: 0;
        word-break: keep-all;
        overflow-wrap: break-word;
        line-height: 1.5;
        overflow: visible;
        white-space: normal;
    }

    .speech-bubble p {
        margin: 0;
        word-break: keep-all;
        overflow-wrap: break-word;
    }

    .speech-bubble:after {
        left: -6px;
        top: 20px;
        border-top-color: transparent;
        border-right-color: #fff9c4;
        border-bottom-color: transparent;
        border-left-color: transparent;
        border-right: 0;
        margin-top: -6px;
        margin-left: 0;
    }

    .header-right {
        width: 100%;
        max-width: 100%;
        margin-left: 0;
        margin-top: 15px;
        min-width: auto;
        max-width: 100%;
    }

    .status-container {
        width: 100%;
        margin-bottom: 12px;
        text-align: center;
    }

    #game-status {
        font-size: 0.9rem;
        text-align: center;
    }

    #piece-count {
        font-size: 0.85rem;
        text-align: center;
    }

    .nav-controls {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: center;
    }

    .nav-controls button {
        flex: 0 0 calc(50% - 4px);
        min-width: calc(50% - 4px);
        max-width: calc(50% - 4px);
        padding: 8px 12px;
        font-size: 0.9rem;
        justify-content: center;
        box-sizing: border-box;
    }

    .game-creator {
        margin-top: 12px;
        text-align: center;
        font-size: 0.7rem;
    }

    #othello-board {
        width: min(100vw - 320px, 100vh - 30px);
        height: min(100vw - 320px, 100vh - 30px);
        max-width: min(100vw - 320px, 100vh - 30px);
        max-height: min(100vw - 320px, 100vh - 30px);
    }
}

