/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #F5F7FA;
    --board-bg: #F4ECD8;
    --board-line: #3D3D3D;
    --black-stone: #1A1A1A;
    --white-stone: #FFFFFF;
    --ai-recommend: #FFD700;
    --ai-threat: #FF4444;
    --btn-primary: #4A90E2;
    --btn-primary-hover: #3A7BD5;
    --btn-danger: #E74C3C;
    --btn-danger-hover: #C0392B;
    --text-primary: #2C3E50;
    --text-secondary: #7F8C8D;
    --card-bg: #FFFFFF;
    --border: #E0E0E0;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ===== Page States ===== */
.page {
    display: none;
    width: 100%;
    max-width: 960px;
    padding: 20px;
}

.page.active {
    display: block;
}

/* ===== Buttons ===== */
.btn {
    display: inline-block;
    padding: 12px 32px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    outline: none;
}

.btn:hover {
    transform: translateY(-1px);
}

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

.btn-primary {
    background: var(--btn-primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--btn-primary-hover);
}

.btn-secondary {
    background: #fff;
    color: var(--btn-primary);
    border: 2px solid var(--btn-primary);
}

.btn-secondary:hover {
    background: #f0f7ff;
}

.btn-danger {
    background: var(--btn-danger);
    color: #fff;
}

.btn-danger:hover {
    background: var(--btn-danger-hover);
}

.btn-danger-text {
    background: none;
    color: var(--btn-danger);
    padding: 8px 16px;
    font-size: 14px;
}

.btn-small {
    padding: 8px 16px;
    font-size: 14px;
    border-radius: 8px;
}

/* ===== Home Page ===== */
.home-card {
    text-align: center;
    background: var(--card-bg);
    border-radius: 20px;
    padding: 60px 40px;
    box-shadow: var(--shadow);
    max-width: 400px;
    margin: 0 auto;
}

.home-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.home-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 32px;
}

.home-card .btn {
    width: 100%;
    margin-bottom: 12px;
}

/* ===== Waiting Page ===== */
.waiting-card {
    text-align: center;
    background: var(--card-bg);
    border-radius: 20px;
    padding: 48px 40px;
    box-shadow: var(--shadow);
    max-width: 400px;
    margin: 0 auto;
}

.waiting-card h2 {
    margin-bottom: 24px;
    font-size: 20px;
}

.room-code-wrapper {
    margin-bottom: 20px;
}

.room-label {
    display: block;
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 8px;
}

.room-code {
    font-family: "Courier New", monospace;
    font-size: 48px;
    font-weight: 700;
    letter-spacing: 8px;
    color: var(--text-primary);
}

.waiting-hint {
    color: var(--text-secondary);
    font-size: 13px;
    margin: 16px 0;
}

.waiting-dots {
    margin: 20px 0;
}

.waiting-dots span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--btn-primary);
    margin: 0 4px;
    animation: dot-pulse 1.4s infinite ease-in-out;
}

.waiting-dots span:nth-child(1) { animation-delay: 0s; }
.waiting-dots span:nth-child(2) { animation-delay: 0.2s; }
.waiting-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1.2); }
}

/* ===== Join Page ===== */
.join-card {
    text-align: center;
    background: var(--card-bg);
    border-radius: 20px;
    padding: 48px 40px;
    box-shadow: var(--shadow);
    max-width: 400px;
    margin: 0 auto;
}

.join-card h2 {
    margin-bottom: 24px;
    font-size: 20px;
}

.input-room {
    display: block;
    width: 100%;
    padding: 14px;
    font-size: 28px;
    font-family: "Courier New", monospace;
    font-weight: 700;
    letter-spacing: 8px;
    text-align: center;
    text-transform: uppercase;
    border: 2px solid var(--border);
    border-radius: 12px;
    outline: none;
    margin-bottom: 20px;
    transition: border-color 0.2s;
}

.input-room:focus {
    border-color: var(--btn-primary);
}

.join-card .btn {
    width: 100%;
    margin-bottom: 8px;
}

/* ===== Game Page ===== */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    margin-bottom: 8px;
}

.game-room-name {
    font-weight: 600;
    font-size: 14px;
}

.game-conn-status {
    font-size: 13px;
    color: #27AE60;
}

.game-main {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.board-wrapper {
    flex-shrink: 0;
    position: relative;
}

#board {
    display: block;
    border-radius: 8px;
    box-shadow: var(--shadow);
    cursor: pointer;
}

.turn-indicator {
    text-align: center;
    padding: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 8px;
}

.turn-indicator.my-turn {
    color: var(--btn-primary);
}

/* ===== Sidebar ===== */
.sidebar {
    flex: 1;
    min-width: 200px;
    max-width: 260px;
}

.sidebar-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
}

.ai-panel {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.ai-section {
    margin-bottom: 12px;
}

.ai-label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.ai-value {
    font-size: 16px;
    font-weight: 600;
}

.ai-safe {
    color: #27AE60;
}

.ai-warning {
    color: #F39C12;
}

.ai-danger {
    color: var(--ai-threat);
}

.winrate-bar {
    width: 100%;
    height: 8px;
    background: #E8E8E8;
    border-radius: 4px;
    overflow: hidden;
    margin: 4px 0;
}

.winrate-fill {
    height: 100%;
    background: var(--btn-primary);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.op-panel {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.op-panel .btn {
    width: 100%;
    margin-bottom: 8px;
}

.op-panel .btn:last-child {
    margin-bottom: 0;
}

/* ===== Game Footer ===== */
.game-footer {
    margin-top: 8px;
    padding: 8px 0;
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    white-space: nowrap;
}

.footer-label {
    flex-shrink: 0;
    font-weight: 600;
}

.move-history {
    font-family: "Courier New", monospace;
    font-size: 12px;
}

/* ===== Dialog ===== */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.dialog-overlay[hidden] {
    display: none;
}

.dialog-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    text-align: center;
    max-width: 360px;
    width: 90%;
}

.dialog-message {
    font-size: 16px;
    margin-bottom: 24px;
    line-height: 1.5;
}

.result-message {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 24px;
}

.dialog-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.dialog-buttons .btn {
    min-width: 100px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .game-main {
        flex-direction: column;
        align-items: center;
    }

    .sidebar {
        width: 100%;
        max-width: 100%;
        display: flex;
        gap: 12px;
    }

    .ai-panel, .op-panel {
        flex: 1;
        margin-bottom: 0;
    }

    #board {
        width: 100% !important;
        height: auto !important;
    }
}

@media (max-width: 480px) {
    .home-card, .waiting-card, .join-card {
        padding: 32px 20px;
    }

    .room-code {
        font-size: 36px;
        letter-spacing: 6px;
    }

    .sidebar {
        flex-direction: column;
    }
}
