:root {
    --bg-color: #e6f7ff;
    --panel-bg: #ffffff;
    --border-color: #88c7ff;
    --primary-color: #1890ff;
    --tile-size: 48px;
    --gap-size: 4px;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    user-select: none;
    overflow: hidden;
}

.game-container {
    display: flex;
    background: #fff;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    gap: 20px;
    width: 1200px; /* Fixed width instead of max-width to prevent shifting */
    max-width: 95vw;
    height: 800px; /* Fixed height to contain absolute elements */
    max-height: 95vh;
    z-index: 1;
    position: relative;
    backdrop-filter: blur(10px);
    overflow: hidden; /* Prevent absolute elements from overflowing */
}

/* Sidebar */
.sidebar {
    width: 160px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.panel {
    background: #f0f9ff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px;
    text-align: center;
}
.user-panel .avatar { font-size: 48px; margin-bottom: 5px; }
.info { font-size: 15px; font-weight: bold; color: #333; }

/* Props */
.props-panel { display: flex; flex-direction: column; gap: 12px; }
.prop-btn {
    background: white;
    border: 1px solid #d9d9d9;
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 24px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.prop-btn:hover { background: #e6f7ff; transform: translateY(-2px); border-color: #1890ff; }
.prop-btn:active { transform: scale(0.95); }
.prop-btn .count {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4d4f;
    color: white;
    font-size: 10px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.controls button {
    width: 100%;
    margin-bottom: 8px;
    padding: 10px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    transition: filter 0.2s;
}
#btn-start { background: linear-gradient(135deg, #52c41a, #389e0d); color: white; box-shadow: 0 4px 10px rgba(82,196,26,0.3); }
#btn-start:hover { filter: brightness(1.1); }
#btn-pause { display: none; } /* Hiding redundant button */

/* Main Area */
.main-area {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.time-bar-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}
.time-bar-container {
    flex: 1;
    height: 18px;
    background: #f0f0f0;
    border-radius: 9px;
    overflow: hidden;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.1);
    position: relative;
}
.time-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #69c0ff, #1890ff);
    transition: width 0.3s ease-out, background-color 0.3s;
    border-radius: 9px;
    position: relative;
}
.time-bar-fill::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(45deg, rgba(255,255,255,0.2) 25%, transparent 25%, transparent 50%, rgba(255,255,255,0.2) 50%, rgba(255,255,255,0.2) 75%, transparent 75%, transparent);
    background-size: 20px 20px;
    animation: moveStripe 1s linear infinite;
    opacity: 0.5;
}
@keyframes moveStripe { from { background-position: 0 0; } to { background-position: 20px 0; } }

#time-text {
    font-weight: bold;
    color: #1890ff;
    min-width: 50px;
    text-align: right;
    font-family: 'Consolas', monospace;
    font-size: 18px;
}

/* Board Wrapper */
.board-wrapper {
    position: relative;
    padding: 10px;
    background: #cce9ff;
    border-radius: 12px;
    border: 6px solid #88c7ff;
    box-shadow: inset 0 0 20px rgba(24, 144, 255, 0.15), 0 10px 25px rgba(0,0,0,0.1);
}

.game-board {
    position: relative;
    display: block;
}

.tile {
    position: absolute;
    width: var(--tile-size);
    height: var(--tile-size);
    background: white;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 0 #d9d9d9, 0 5px 10px rgba(0,0,0,0.1);
    transition: top 0.4s cubic-bezier(0.25, 1.5, 0.5, 1), left 0.4s cubic-bezier(0.25, 1.5, 0.5, 1), transform 0.1s, opacity 0.2s, background-color 0.3s, color 0.3s;
    z-index: 10;
    user-select: none;
}

.tile:hover {
    transform: translateY(-2px);
    background: #fcfcfc;
}

.tile:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #ccc, inset 0 2px 5px rgba(0,0,0,0.1);
}

.tile.selected {
    border: 3px solid #1890ff;
    background: #e6f7ff;
    transform: translateY(-4px) scale(1.1);
    box-shadow: 0 8px 0 rgba(24, 144, 255, 0.3), 0 10px 20px rgba(24, 144, 255, 0.3);
    z-index: 20;
}

.tile.hint-highlight {
    border: 3px solid #faad14;
    box-shadow: 0 0 15px #faad14;
    z-index: 20;
    animation: pulse 1s infinite;
}

.tile.eliminating {
    transform: scale(1.3) rotate(15deg);
    opacity: 0;
    transition: transform 0.3s ease-out, opacity 0.3s ease-in;
    pointer-events: none;
}

.tile.danger-tile {
    border: 2px solid #ff4d4f;
    background: #fff1f0;
    animation: dangerPulse 0.5s infinite;
    z-index: 25;
}

/* Midnight Mode: Fog of War */
.tile.fog {
    color: transparent !important;
    background-color: #222 !important;
    border-color: #444 !important;
    box-shadow: inset 0 0 10px #000 !important;
    cursor: default;
}
.tile.fog::after {
    content: '?';
    position: absolute;
    color: #444;
    font-size: 20px;
    font-weight: bold;
}
.tile.revealed {
    animation: revealFlash 0.4s ease-out;
}

@keyframes revealFlash {
    0% { filter: brightness(2); }
    100% { filter: brightness(1); }
}

@keyframes dangerPulse {
    0%, 100% { box-shadow: 0 0 5px #ff4d4f; transform: scale(1); }
    50% { box-shadow: 0 0 15px #ff4d4f; transform: scale(1.05); }
}

.shake-board {
    animation: shake 0.3s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-3px, 0, 0); }
    40%, 60% { transform: translate3d(3px, 0, 0); }
}

#line-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 30;
}

/* Darkness Overlay (Simplified, mostly handled by .fog tiles now) */
#darkness-overlay {
    display: none; /* Deprecated in favor of .fog tiles */
}

/* Main Menu */
.main-menu {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    z-index: 200;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    transition: opacity 0.4s ease, visibility 0.4s;
}
.main-menu.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.mode-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    max-width: 800px;
}
.mode-card {
    background: white;
    padding: 20px;
    border-radius: 16px;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 8px 15px rgba(0,0,0,0.05);
    border: 2px solid transparent;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
    min-width: 200px;
}
.mode-card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 15px 30px rgba(24, 144, 255, 0.15);
    border-color: #1890ff;
}
.mode-card .icon { font-size: 48px; margin-bottom: 10px; }
.mode-card h3 { margin: 5px 0; font-size: 20px; color: #333; }
.mode-card p { color: #888; font-size: 13px; line-height: 1.4; margin: 0; }

.badge {
    position: absolute;
    top: 10px;
    right: -25px;
    background: #ff4d4f;
    color: white;
    font-size: 12px;
    padding: 2px 25px;
    transform: rotate(45deg);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* Modal & Toast */
.modal-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    z-index: 300;
    opacity: 1;
    transition: opacity 0.3s;
    backdrop-filter: blur(2px);
}
.modal-overlay.hidden { opacity: 0; pointer-events: none; z-index: -1; }
.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    animation: popIn 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}
@keyframes popIn { 0% { transform: scale(0.8); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

.highlight-prop {
    animation: flash 1s infinite;
    border: 2px solid #ff4d4f;
    box-shadow: 0 0 10px #ff4d4f;
}
@keyframes flash {
    0%, 100% { transform: scale(1); box-shadow: 0 0 5px #ff4d4f; }
    50% { transform: scale(1.1); box-shadow: 0 0 15px #ff4d4f; }
}

.particle {
    position: absolute;
    pointer-events: none;
    border-radius: 50%;
    animation: particleFade 0.6s ease-out forwards;
    z-index: 40;
}
@keyframes particleFade {
    0% { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

/* Wave Bar for Endless Mode */
#wave-container {
    box-shadow: 0 -4px 10px rgba(0,0,0,0.1);
}

/* --- Mobile Optimization (Landscape Driven) --- */

/* 1. Portrait Warning Overlay */
#portrait-warning {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.95);
    color: white;
    z-index: 9999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-size: 18px;
    backdrop-filter: blur(10px);
}

/* Show warning on Mobile Portrait */
@media screen and (orientation: portrait) and (max-width: 900px) {
    #portrait-warning { display: flex; }
    .game-container { display: none !important; } /* Hide game behind */
}

/* 2. Landscape Layout Optimization (For Phones/Tablets) */
@media screen and (orientation: landscape) and (max-height: 700px) {
    body {
        padding: 0;
        height: 100vh;
        align-items: stretch;
        background-color: #333; /* Dark background for immersion */
    }

    .game-container {
        width: 100%;
        height: 100vh;
        max-width: none;
        padding: 5px;
        gap: 10px;
        border-radius: 0;
        flex-direction: row; /* Side-by-Side */
        align-items: center;
        justify-content: center;
        background: #f0f2f5;
    }

    /* Left Sidebar: Compact */
    .sidebar {
        width: 120px;
        height: 100%;
        justify-content: center;
        gap: 10px;
    }

    .user-panel {
        padding: 5px;
    }
    .user-panel .avatar { display: none; }
    .user-panel .info { font-size: 12px; }

    .props-panel { gap: 5px; }
    .prop-btn { padding: 8px; font-size: 20px; }
    
    .controls button {
        padding: 8px;
        font-size: 12px;
    }

    /* Main Area: Maximize Board */
    .main-area {
        flex: 1;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
    }

    /* Top Bar (Timer) */
    .time-bar-wrapper {
        width: 100%;
        height: 20px;
    }
    .time-bar-container { height: 12px; }
    #time-text { font-size: 14px; }

    /* Board Scaling */
    .board-wrapper {
        flex: 1;
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 0;
        border: none;
        background: transparent;
        box-shadow: none;
        overflow: hidden; /* Ensure scaling works */
    }

    /* Hide connection lines on mobile to fix offset bug/clutter */
    #line-canvas { display: none !important; }

    .game-board {
        /* Auto scale using zoom or transform */
        transform-origin: center;
        /* Default zoom for safety, JS usually handles this better but let's try CSS zoom */
        zoom: 0.65;
    }
    
    /* IAP Modal Fix for Mobile */
    .modal-content.iap-content {
        transform: scale(0.8);
    }
}

/* Extremely Small Height (e.g. iPhone SE Landscape) */
@media screen and (orientation: landscape) and (max-height: 400px) {
    .sidebar { width: 90px; }
    .prop-btn { font-size: 16px; padding: 5px; }
    .game-board { zoom: 0.5; }
    .sidebar h3 { display: none; } /* Hide titles */
}

/* IAP Buy Mode Styles */
.prop-btn.buy-mode {
    border: 2px dashed #faad14;
    background: #fffbe6;
}
.prop-btn.buy-mode .count {
    background: #52c41a;
    transform: scale(1.2);
    box-shadow: 0 2px 6px rgba(82,196,26,0.5);
}

/* Online Lobby */
#online-lobby {
    background: #f0f2f5;
    justify-content: flex-start;
    padding-top: 60px;
}

.lobby-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 30px;
}

.seats-container {
    display: flex;
    gap: 20px;
    margin-bottom: 40px;
    flex-wrap: wrap;
    justify-content: center;
}

.seat {
    width: 100px;
    height: 140px;
    position: relative;
    cursor: pointer;
    transition: transform 0.2s;
}
.seat:hover { transform: translateY(-5px); }

.seat-inner {
    width: 100%;
    height: 100%;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: white;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    border: 2px dashed #d9d9d9;
}

.seat-inner.empty { color: #999; }
.seat-inner.empty .plus { font-size: 40px; font-weight: bold; margin-bottom: 5px; }
.seat-inner.empty .text { font-size: 12px; }

.seat-inner.occupied {
    border: 2px solid #1890ff;
    background: #e6f7ff;
}
.seat-avatar { font-size: 40px; margin-bottom: 5px; }
.seat-name { font-weight: bold; color: #333; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 90%; text-align: center; }
.seat-tag {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: #faad14;
    color: white;
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.lobby-controls {
    display: flex;
    gap: 20px;
}

.secondary-btn { background: #ff4d4f; color: white; border: none; padding: 10px 25px; border-radius: 8px; cursor: pointer; font-size: 16px; }
.primary-btn { background: #1890ff; color: white; border: none; padding: 10px 40px; border-radius: 8px; cursor: pointer; font-size: 16px; font-weight: bold; }
.primary-btn:disabled { background: #d9d9d9; cursor: not-allowed; }
.small-btn { background: white; border: 1px solid #d9d9d9; border-radius: 4px; cursor: pointer; padding: 2px 8px; font-size: 12px; }

/* Mobile Lobby */
@media screen and (max-width: 600px) {
    .seats-container { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
    .seat { width: 100%; height: 120px; }
}

/* Opponent Sidebar (In-Game) */
.opponent-bar {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 90;
}
.opp-card {
    width: 100px;
    background: rgba(255,255,255,0.9);
    border-radius: 8px;
    padding: 5px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    border: 2px solid transparent;
}
.opp-card.finished { border-color: #52c41a; opacity: 0.8; }
.opp-thumb {
    width: 100%;
    height: 60px;
    background: #eee;
    border-radius: 4px;
    margin-bottom: 5px;
    overflow: hidden;
}
.opp-info { font-size: 12px; text-align: center; }
.opp-count { color: #1890ff; font-weight: bold; }

@media screen and (max-width: 1400px) {
    .opponent-bar {
        right: 10px;
        transform: translateY(-50%) scale(0.9);
        transform-origin: right center;
    }
}

@media screen and (max-width: 900px) {
    .opponent-bar {
        position: static;
        flex-direction: column;
        width: auto;
        margin-top: 0;
        /* Hidden or minimized in mobile landscape if not enough space */
        transform: scale(0.8);
        transform-origin: top right;
        position: fixed;
        right: 10px;
        top: 60px;
    }
}