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

body {
    font-family: 'Segoe UI', 'Courier New', monospace;
    background: radial-gradient(circle at 20% 50%, #0a0a2e, #000000);
    min-height: 100vh;
    padding: 20px;
}

.game-container {
    max-width: 1400px;
    margin: 0 auto;
    background: rgba(10, 10, 30, 0.85);
    backdrop-filter: blur(5px);
    border-radius: 20px;
    border: 1px solid #00ffcc;
    box-shadow: 0 0 40px rgba(0, 255, 204, 0.2);
    overflow: hidden;
}

/* HEADER */
.header {
    text-align: center;
    padding: 20px;
    background: linear-gradient(135deg, #0a0a2e, #1a1a3e);
    border-bottom: 2px solid #00ffcc;
}

.header h1 {
    color: #00ffcc;
    text-shadow: 0 0 10px #00ffcc;
    font-size: 1.8em;
    margin-bottom: 5px;
}

.subtitle {
    color: #888;
    font-size: 0.9em;
}

/* 3-COLUMN LAYOUT */
.main-layout {
    display: flex;
    gap: 20px;
    padding: 20px;
}

/* LEFT PANEL - STATS */
.left-panel {
    width: 260px;
    flex-shrink: 0;
}

.panel-title {
    color: #ffcc00;
    font-size: 0.9em;
    font-weight: bold;
    margin-bottom: 12px;
    border-left: 3px solid #ffcc00;
    padding-left: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stats-panel {
    background: rgba(0, 0, 0, 0.5);
    border-radius: 12px;
    padding: 12px;
}

/* ========== STAT CARDS ========== */
.stat-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    margin-bottom: 8px;
    background: rgba(0, 255, 204, 0.05);
    border-radius: 10px;
    transition: all 0.2s ease;
}

.stat-card:hover {
    background: rgba(0, 255, 204, 0.12);
}

.stat-icon {
    font-size: 28px;
    width: 40px;
    text-align: center;
}

.stat-info {
    flex: 1;
}

.stat-label {
    font-size: 0.7em;
    color: #aaa;
    letter-spacing: 1px;
}

.stat-value {
    font-size: 1.4em;
    font-weight: bold;
    color: #00ffcc;
    line-height: 1;
}

.stat-max {
    font-size: 0.7em;
    color: #ffcc00;
    margin-top: 2px;
}

/* ========== SPECIAL: SCORE CARD (BIG & GLOWING) ========== */
.score-card {
    background: linear-gradient(135deg, rgba(255, 204, 0, 0.15), rgba(255, 102, 0, 0.1));
    border: 1px solid #ffcc00;
    margin-bottom: 12px;
    padding: 12px;
    animation: scorePulse 2s infinite;
}

.score-card .stat-icon {
    font-size: 36px;
}

.score-card .stat-label {
    font-size: 0.8em;
    color: #ffcc00;
    letter-spacing: 2px;
}

.score-card .stat-value {
    font-size: 2.2em;
    color: #ffcc00;
    text-shadow: 0 0 10px #ffcc00;
}

.score-card .stat-max {
    font-size: 0.8em;
    color: #ffaa00;
}

@keyframes scorePulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 204, 0, 0.3);
        border-color: rgba(255, 204, 0, 0.5);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(255, 204, 0, 0);
        border-color: rgba(255, 204, 0, 1);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 204, 0, 0);
        border-color: rgba(255, 204, 0, 0.5);
    }
}

/* ========== SPECIAL: RESOURCES CARD (BIG & BRIGHT) ========== */
.resource-card {
    background: linear-gradient(135deg, rgba(0, 255, 204, 0.12), rgba(0, 153, 255, 0.08));
    border: 1px solid #00ffcc;
    margin-bottom: 12px;
    padding: 12px;
}

.resource-card .stat-icon {
    font-size: 36px;
}

.resource-card .stat-label {
    font-size: 0.8em;
    color: #00ffcc;
    letter-spacing: 2px;
}

.resource-card .stat-value {
    font-size: 2em;
    color: #00ffcc;
    text-shadow: 0 0 8px #00ffcc;
}

.resource-card .stat-max {
    font-size: 0.8em;
    color: #00ffcc;
}

/* ========== SPECIAL: LOOP CARD ========== */
.loop-card {
    background: rgba(0, 0, 0, 0.4);
    border-left: 3px solid #ffcc00;
}

.loop-card .stat-value {
    font-size: 1.8em;
    color: #ffcc00;
}

/* ========== NORMAL STATS (Smaller, subtle) ========== */
.normal-card {
    background: rgba(255, 255, 255, 0.03);
}

.normal-card .stat-icon {
    font-size: 22px;
    opacity: 0.7;
}

.normal-card .stat-value {
    font-size: 1.2em;
    color: #88aaff;
}

.normal-card .stat-label {
    font-size: 0.65em;
}

/* Progress Bar */
.progress-container {
    margin-top: 15px;
    padding: 12px 10px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 10px;
    border-top: 1px solid rgba(0, 255, 204, 0.3);
}

.progress-label {
    font-size: 0.7em;
    color: #aaa;
    margin-bottom: 5px;
}

.progress-bar {
    width: 100%;
    height: 10px;
    background: #222;
    border-radius: 5px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #ffcc00, #ff8800);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-percent {
    font-size: 0.7em;
    color: #ffcc00;
    text-align: right;
    margin-top: 5px;
}

/* MIDDLE PANEL - GAME */
.game-panel {
    flex: 1;
    text-align: center;
}

#gameCanvas {
    background: #0a0a1a;
    border: 2px solid #00ffcc;
    border-radius: 12px;
    cursor: crosshair;
    box-shadow: 0 0 20px rgba(0, 255, 204, 0.2);
    width: 100%;
    height: auto;
}

.selected-indicator {
    margin-top: 10px;
    color: #888;
    font-size: 0.85em;
}

.selected-name {
    color: #ffcc00;
    font-weight: bold;
}

/* RIGHT PANEL - CONTROLS */
.right-panel {
    width: 200px;
    flex-shrink: 0;
}

.controls-panel {
    background: rgba(0, 0, 0, 0.5);
    border-radius: 12px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn {
    padding: 12px;
    font-size: 0.9em;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: monospace;
    width: 100%;
}

.btn-primary {
    background: linear-gradient(135deg, #00ffcc, #0099ff);
    color: #000;
}

.btn-primary:hover {
    transform: scale(1.02);
    box-shadow: 0 0 15px #00ffcc;
}

.btn-secondary {
    background: linear-gradient(135deg, #ffcc00, #ff8800);
    color: #000;
}

.btn-secondary:hover {
    transform: scale(1.02);
}

.btn-danger {
    background: linear-gradient(135deg, #ff3366, #cc0033);
    color: white;
}

.btn-danger:hover {
    transform: scale(1.02);
}

.btn-help {
    background: linear-gradient(135deg, #6c5ce7, #4834d4);
    color: white;
}

.btn-help:hover {
    transform: scale(1.02);
}

.tips-panel {
    margin-top: 20px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 12px;
    padding: 15px;
}

.panel-title-small {
    color: #ffcc00;
    font-size: 0.8em;
    font-weight: bold;
    margin-bottom: 10px;
}

.tip-text {
    color: #ccc;
    font-size: 0.8em;
    line-height: 1.4;
}

/* LIBRARY SECTION */
.library-section {
    padding: 0 20px 20px 20px;
}

.machines {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
}

.machine-card {
    background: linear-gradient(135deg, #1a1a3e, #0a0a2e);
    border: 1px solid #00ffcc;
    border-radius: 12px;
    padding: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 100px;
    flex: 1;
    max-width: 120px;
}

.machine-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 20px rgba(0, 255, 204, 0.3);
    border-color: #ffcc00;
}

.machine-card.selected {
    border: 2px solid #ffcc00;
    background: linear-gradient(135deg, #2a2a5e, #1a1a4e);
    box-shadow: 0 0 15px #ffcc00;
}

.machine-icon {
    font-size: 2.2em;
}

.machine-name {
    font-weight: bold;
    color: #00ffcc;
    margin: 5px 0;
    font-size: 0.8em;
}

.machine-cost {
    font-size: 0.7em;
    color: #ffcc00;
}

.machine-desc {
    font-size: 0.6em;
    color: #aaa;
    margin-top: 4px;
}

/* LOG SECTION */
.log-section {
    padding: 0 20px 20px 20px;
}

.log-container {
    background: rgba(0, 0, 0, 0.5);
    border-radius: 12px;
    padding: 12px;
    height: 120px;
    overflow-y: auto;
    font-size: 0.8em;
}

.log-entry {
    padding: 5px 8px;
    margin: 3px 0;
    border-left: 3px solid #00ffcc;
    color: #ddd;
    font-family: monospace;
}

.log-entry.welcome {
    border-left-color: #ffcc00;
    color: #ffcc00;
}

/* MODAL */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(8px);
}

.modal-content {
    background: linear-gradient(135deg, #1a1a3e, #0a0a2e);
    margin: 5% auto;
    padding: 0;
    border: 2px solid #00ffcc;
    border-radius: 20px;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #00ffcc;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: linear-gradient(135deg, #1a1a3e, #0a0a2e);
}

.modal-header h2 {
    color: #ffcc00;
    margin: 0;
}

.close {
    color: #00ffcc;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
}

.help-section {
    margin-bottom: 20px;
}

.help-section h3 {
    color: #00ffcc;
    margin-bottom: 10px;
    border-left: 3px solid #ffcc00;
    padding-left: 10px;
}

.help-section p, .help-section ul {
    color: #ddd;
    line-height: 1.5;
    margin-left: 15px;
}

.gold {
    color: #ffcc00;
    font-weight: bold;
}

.step-guide {
    background: rgba(0, 0, 0, 0.4);
    padding: 12px;
    border-radius: 10px;
}

.step {
    padding: 5px;
    color: #ddd;
}

.strategy-box {
    background: rgba(0, 255, 204, 0.1);
    padding: 12px;
    border-radius: 10px;
    border: 1px solid #00ffcc;
}

.strategy-box p {
    margin: 5px 0;
}

.machine-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8em;
}

.machine-table th, .machine-table td {
    padding: 6px;
    text-align: left;
    border-bottom: 1px solid #333;
    color: #ddd;
}

.machine-table th {
    color: #ffcc00;
}

/* ========== WIN/LOSS POPUP MODALS ========== */
.game-result-modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease;
}

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

.result-card {
    background: linear-gradient(135deg, #1a1a3e, #0a0a2e);
    border-radius: 30px;
    padding: 40px;
    text-align: center;
    max-width: 450px;
    width: 90%;
    animation: slideUp 0.4s ease;
    box-shadow: 0 0 60px rgba(0, 255, 204, 0.3);
}

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

.result-card.win {
    border: 2px solid #ffcc00;
    box-shadow: 0 0 50px rgba(255, 204, 0, 0.4);
}

.result-card.lose {
    border: 2px solid #ff3366;
    box-shadow: 0 0 50px rgba(255, 51, 102, 0.4);
}

.result-icon {
    font-size: 80px;
    margin-bottom: 20px;
}

.result-title {
    font-size: 2.5em;
    font-weight: bold;
    margin-bottom: 20px;
}

.result-card.win .result-title {
    color: #ffcc00;
    text-shadow: 0 0 10px #ffcc00;
}

.result-card.lose .result-title {
    color: #ff3366;
    text-shadow: 0 0 10px #ff3366;
}

.result-stats {
    background: rgba(0, 0, 0, 0.5);
    border-radius: 15px;
    padding: 20px;
    margin: 20px 0;
}

.result-stat-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    color: #ddd;
    font-size: 1.1em;
}

.result-stat-row .stat-label {
    color: #888;
}

.result-stat-row .stat-value {
    color: #00ffcc;
    font-weight: bold;
    font-size: 1.2em;
}

.result-stat-row.highlight .stat-value {
    color: #ffcc00;
    font-size: 1.5em;
}

.result-message {
    color: #aaa;
    margin: 20px 0;
    line-height: 1.5;
}

.result-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

.result-btn {
    padding: 12px 24px;
    font-size: 1em;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: monospace;
}

.result-btn-play {
    background: linear-gradient(135deg, #00ffcc, #0099ff);
    color: #000;
}

.result-btn-play:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px #00ffcc;
}

.result-btn-close {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid #888;
}

.result-btn-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1999;
}


/* RESPONSIVE */
@media (max-width: 900px) {
    .main-layout {
        flex-direction: column;
    }
    
    .left-panel, .right-panel {
        width: 100%;
    }
    
    .stats-panel {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .stat-card {
        margin-bottom: 0;
    }
    
    .score-card {
        grid-column: span 2;
    }
    
    .resource-card {
        grid-column: span 2;
    }
    
    .progress-container {
        grid-column: span 2;
    }
    
    .controls-panel {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    
    .btn {
        flex: 1;
        padding: 12px 16px;
        font-size: 0.9em;
    }
    
    .machine-card {
        min-width: 70px;
        max-width: none;
        padding: 10px;
    }
    
    .machine-icon {
        font-size: 1.6em;
    }
    
    .machine-name {
        font-size: 0.8em;
    }
    
    .machine-cost {
        font-size: 0.75em;
    }
    
    .machine-desc {
        font-size: 0.7em;
    }
}

@media (max-width: 750px) {
    .controls-panel {
        flex-direction: column;
        gap: 8px;
    }
    
    .btn {
        padding: 10px 14px;
        font-size: 0.85em;
    }
    
    .machine-card {
        min-width: 65px;
        padding: 8px;
    }
    
    .machine-icon {
        font-size: 1.5em;
    }
    
    .machine-name {
        font-size: 0.75em;
    }
    
    .machine-cost {
        font-size: 0.7em;
    }
    
    .machine-desc {
        font-size: 0.65em;
    }
}

@media (max-width: 600px) {
    body {
        padding: 10px;
    }
    
    .stats-panel {
        grid-template-columns: 1fr;
    }
    
    .score-card {
        grid-column: span 1;
    }
    
    .resource-card {
        grid-column: span 1;
    }
    
    .progress-container {
        grid-column: span 1;
    }
    
    .machines {
        gap: 8px;
    }
    
    .machine-card {
        padding: 8px;
    }
    
    .machine-icon {
        font-size: 1.8em;
    }
    
    /* Mobile Game Result Modals */
    .game-result-modal {
        padding: 20px;
    }
    
    .result-card {
        padding: 25px 20px;
        max-width: 95%;
        width: 100%;
        margin: 0 auto;
    }
    
    .result-icon {
        font-size: 60px;
        margin-bottom: 15px;
    }
    
    .result-title {
        font-size: 2em;
        margin-bottom: 15px;
    }
    
    .result-stats {
        padding: 15px;
        margin: 15px 0;
    }
    
    .result-stat-row {
        padding: 6px 0;
        font-size: 1em;
    }
    
    .result-stat-row .stat-value {
        font-size: 1.1em;
    }
    
    .result-stat-row.highlight .stat-value {
        font-size: 1.3em;
    }
    
    .result-message {
        font-size: 0.95em;
        margin: 15px 0;
    }
    
    .result-buttons {
        flex-direction: column;
        gap: 12px;
        margin-top: 15px;
    }
    
    .result-btn {
        padding: 15px 20px;
        font-size: 1.1em;
        width: 100%;
        max-width: 250px;
        margin: 0 auto;
    }
    
    /* Mobile Canvas and Grid */
    .game-panel {
        padding: 0 5px;
    }
    
    #gameCanvas {
        max-width: 100%;
        height: auto;
        border-radius: 8px;
        touch-action: manipulation;
    }
    
    .selected-indicator {
        font-size: 0.8em;
        margin-top: 8px;
    }
}

/* Landscape orientation adjustments */
@media (max-height: 600px) and (orientation: landscape) {
    .game-result-modal {
        padding: 10px;
    }
    
    .result-card {
        padding: 20px 25px;
        max-width: 500px;
        width: 90%;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    .result-icon {
        font-size: 50px;
        margin-bottom: 10px;
    }
    
    .result-title {
        font-size: 1.8em;
        margin-bottom: 10px;
    }
    
    .result-stats {
        padding: 12px;
        margin: 10px 0;
    }
    
    .result-stat-row {
        padding: 4px 0;
        font-size: 0.9em;
    }
    
    .result-message {
        font-size: 0.85em;
        margin: 10px 0;
    }
    
    .result-buttons {
        flex-direction: row;
        gap: 10px;
        margin-top: 10px;
    }
    
    .result-btn {
        padding: 10px 15px;
        font-size: 0.9em;
        width: auto;
        max-width: none;
        margin: 0;
    }
}

/* Very small landscape screens */
@media (max-height: 450px) and (orientation: landscape) {
    .result-card {
        padding: 15px 20px;
        max-width: 400px;
    }
    
    .result-icon {
        font-size: 40px;
    }
    
    .result-title {
        font-size: 1.5em;
    }
    
    .result-stats {
        padding: 8px;
        margin: 8px 0;
    }
    
    .result-stat-row {
        padding: 3px 0;
        font-size: 0.8em;
    }
    
    .result-message {
        font-size: 0.8em;
        margin: 8px 0;
    }
    
    .result-buttons {
        gap: 8px;
    }
    
    .result-btn {
        padding: 8px 12px;
        font-size: 0.85em;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .machine-card {
        padding: 15px;
        min-width: 85px;
    }
    
    .machine-icon {
        font-size: 2em;
    }
    
    .btn {
        padding: 14px;
        font-size: 1em;
    }
    
    #gameCanvas {
        touch-action: none; /* Prevents browser scroll on canvas */
    }
    
    .machine-card:active {
        transform: scale(0.95);
        background: linear-gradient(135deg, #2a2a5e, #1a1a4e);
    }
}

/* Visual feedback for touch taps */
.machine-card, .btn {
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}