* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    padding: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.game-container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    flex: 1;
    min-height: 0;
    background: white;
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.game-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.game-header h1 {
    font-size: 20px;
    margin: 0;
    white-space: nowrap;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.game-info {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(255, 255, 255, 0.2);
    padding: 3px 10px;
    border-radius: 14px;
    backdrop-filter: blur(10px);
}

.info-item .label {
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
}

.info-item .value {
    font-size: 15px;
    font-weight: bold;
    min-width: 18px;
    text-align: center;
}

.game-main {
    display: flex;
    gap: 12px;
    padding: 10px;
    flex: 1;
    min-height: 0;
}

.game-canvas-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f5f5f5;
    border-radius: 12px;
    padding: 8px;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

#gameCanvas {
    border: 2px solid #667eea;
    border-radius: 8px;
    background: #2a2a2a;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.game-message {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 8px 20px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: bold;
    text-align: center;
    white-space: nowrap;
    max-width: 90%;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 10;
    animation: msgIn 0.3s ease-in;
}

.game-message.hidden {
    display: none;
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

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

.game-sidebar {
    width: 250px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    min-height: 0;
    padding-right: 4px;
}

.inventory-section,
.controls-section,
.legend-section {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.inventory-section h3,
.controls-section h3,
.legend-section h3 {
    font-size: 14px;
    margin-bottom: 8px;
    color: #667eea;
    border-bottom: 2px solid #667eea;
    padding-bottom: 5px;
}

.inventory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.inventory-item {
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 6px 2px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    transition: all 0.3s ease;
}

.inventory-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.inventory-item.active {
    border-color: #667eea;
    background: #f0f4ff;
}

.item-icon {
    font-size: 20px;
    line-height: 1;
}

.item-name {
    font-size: 10px;
    color: #666;
    font-weight: 600;
    white-space: nowrap;
}

.item-status,
.item-count {
    font-size: 11px;
    font-weight: bold;
}

.controls-list,
.legend-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.control-item,
.legend-item {
    background: white;
    padding: 5px 8px;
    border-radius: 6px;
    font-size: 11px;
    color: #555;
    border-left: 3px solid #667eea;
}

.legend-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-icon {
    font-size: 15px;
    width: 20px;
    text-align: center;
}

.restart-btn,
.modal-btn {
    width: 100%;
    padding: 9px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.restart-btn:hover,
.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

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

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease-in;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 500px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease-out;
}

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

.modal-content h2 {
    font-size: 32px;
    margin-bottom: 20px;
    color: #667eea;
}

.modal-content p {
    font-size: 18px;
    color: #666;
    margin-bottom: 30px;
    line-height: 1.6;
}

@media (max-width: 1100px) {
    .game-sidebar {
        width: 210px;
    }

    .legend-list {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 860px), (max-height: 520px) {
    .game-main {
        gap: 8px;
        padding: 6px;
    }

    .game-sidebar {
        width: 180px;
    }

    .game-header h1 {
        font-size: 16px;
    }

    .info-item {
        padding: 2px 7px;
    }

    .info-item .label {
        font-size: 11px;
    }

    .info-item .value {
        font-size: 13px;
    }

    .control-item,
    .legend-item {
        font-size: 10px;
        padding: 4px 6px;
    }
}

.page-footer {
    text-align: center;
    padding: 4px 0 2px;
    color: rgba(255, 255, 255, 0.85);
    font-size: 11px;
    flex-shrink: 0;
}

.page-footer p {
    margin: 0;
}