/* === 3D Printer Tycoon - Main Layout === */

:root {
    --bg-dark: #0f0f23;
    --bg-panel: #1a1a3e;
    --bg-card: #252552;
    --border-color: #4a4a8a;
    --text-primary: #e0e0ff;
    --text-secondary: #8888bb;
    --money-color: #66ffaa;
    --progress-color: #ffdd44;
    --progress-bg: #333366;
    --btn-bg: #3a3a6a;
    --btn-hover: #4a4a8a;
    --btn-active: #5a5aaa;
    --danger: #ff4466;
    --success: #44ff88;
    --tier1: #88ccff;
    --tier2: #88ff88;
    --tier3: #ffcc44;
    --tier4: #ff8844;
    --tier5: #ff44ff;
    --printer-idle: #556688;
    --printer-active: #44aaff;
    --printer-done: #44ff88;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

#game-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    max-width: 1400px;
    margin: 0 auto;
}

/* === HEADER === */
#header {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 10px 20px;
    background: var(--bg-panel);
    border-bottom: 3px solid var(--border-color);
    min-height: 50px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.stat-label {
    font-size: 8px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.stat-value {
    font-size: 12px;
}

.money-color {
    color: var(--money-color);
}

.sell-btn {
    padding: 6px 10px;
    background: var(--btn-bg);
    border: 2px solid var(--border-color);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 8px;
    cursor: pointer;
    border-radius: 2px;
    transition: background 0.2s, border-color 0.2s;
}

.sell-btn:hover:not(:disabled) {
    background: var(--success);
    color: #000;
    border-color: var(--success);
}

.sell-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.sell-btn.has-items {
    border-color: var(--success);
    animation: pulse-glow 1.5s infinite;
}

/* === MAIN AREA === */
#main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* === PRINTER AREA === */
#printer-area {
    flex: 0 0 65%;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

#printer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    width: 100%;
    max-width: 900px;
}

/* === ROOM VIEW (below printers) === */
#room-view {
    width: 100%;
    max-width: 900px;
    height: 320px;
    position: relative;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    background: #1c1c35;
}

#room-canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}


.printer-card {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 4px;
    padding: 12px;
    cursor: pointer;
    transition: border-color 0.2s;
    position: relative;
}

.printer-card:hover {
    border-color: var(--printer-active);
}

.printer-card.selected {
    border-color: var(--printer-active);
    box-shadow: 0 0 10px rgba(68, 170, 255, 0.3);
}

.printer-card.locked {
    opacity: 0.4;
    cursor: default;
    border-style: dashed;
}

.printer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    margin-bottom: 8px;
}

.printer-name {
    font-size: 9px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    margin-right: 4px;
}

.printer-status {
    font-size: 7px;
    padding: 2px 4px;
    border-radius: 2px;
    flex-shrink: 0;
    white-space: nowrap;
    text-transform: uppercase;
}

.printer-status.idle {
    background: var(--printer-idle);
}

.printer-status.printing {
    background: var(--printer-active);
    color: #000;
}

.printer-status.done {
    background: var(--printer-done);
    color: #000;
}

.printer-status.failed {
    background: var(--danger);
}

.printer-sprite {
    width: 100%;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
}

.printer-current-item {
    font-size: 7px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    min-height: 14px;
}

.progress-container {
    width: 100%;
    height: 12px;
    background: var(--progress-bg);
    border: 1px solid var(--border-color);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 6px;
}

.progress-bar {
    height: 100%;
    background: var(--progress-color);
    width: 0%;
    transition: width 0.05s linear;
}

.progress-bar.complete {
    background: var(--success);
}

.printer-queue {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    min-height: 16px;
}

.queue-slot {
    width: 14px;
    height: 14px;
    background: var(--progress-bg);
    border: 1px solid var(--border-color);
    border-radius: 2px;
    font-size: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.queue-slot.filled {
    background: var(--btn-bg);
    border-color: var(--printer-active);
}

.printer-filament {
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.filament-bar {
    flex: 1;
    height: 6px;
    background: var(--progress-bg);
    border-radius: 3px;
    overflow: hidden;
}

.filament-fill {
    height: 100%;
    background: #ff6688;
    transition: width 0.1s;
}

.filament-label {
    font-size: 6px;
    color: var(--text-secondary);
}

.btn-refill {
    font-size: 6px;
    padding: 2px 4px;
    background: var(--btn-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    border-radius: 2px;
}

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

.btn-refill.needs-refill {
    animation: pulse-refill 1s ease-in-out infinite;
    border-color: #ff6688;
    color: #ff6688;
}

@keyframes pulse-refill {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.4); }
}

.filament-warning {
    font-size: 6px;
    color: #ff6688;
    animation: blink-warning 1.2s step-end infinite;
    white-space: nowrap;
}

.filament-warning.hidden {
    display: none;
}

@keyframes blink-warning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.auto-refill-badge {
    font-size: 7px;
    padding: 2px 4px;
    background: var(--success);
    color: #000;
    border-radius: 2px;
    font-family: inherit;
    font-weight: bold;
}

/* === SIDE PANEL === */
#side-panel {
    flex: 0 0 35%;
    background: var(--bg-panel);
    border-left: 3px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#panel-tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
}

.tab {
    flex: 1;
    padding: 10px 5px;
    background: var(--bg-card);
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

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

.tab.active {
    background: var(--bg-panel);
    color: var(--text-primary);
    border-bottom: 2px solid var(--printer-active);
}

#panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

/* === CATALOG ITEMS === */
.catalog-item {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color 0.2s, opacity 0.2s;
    user-select: none;
    -webkit-user-select: none;
}

.catalog-item:hover:not(.locked) {
    border-color: var(--printer-active);
}

.catalog-item.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.catalog-item.tier-1 { border-left: 3px solid var(--tier1); }
.catalog-item.tier-2 { border-left: 3px solid var(--tier2); }
.catalog-item.tier-3 { border-left: 3px solid var(--tier3); }
.catalog-item.tier-4 { border-left: 3px solid var(--tier4); }
.catalog-item.tier-5 { border-left: 3px solid var(--tier5); }

.catalog-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.catalog-item-name {
    font-size: 8px;
    display: flex;
    align-items: center;
}

.catalog-sprite {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

.catalog-item-reward {
    font-size: 8px;
    color: var(--money-color);
}

.catalog-item-details {
    display: flex;
    justify-content: space-between;
    font-size: 7px;
    color: var(--text-secondary);
    padding-left: 38px;
}

.catalog-item-time {
    color: var(--progress-color);
}

.catalog-item-size {
    color: var(--text-secondary);
}

.catalog-item-unlock {
    font-size: 7px;
    color: var(--danger);
    margin-top: 4px;
    padding-left: 38px;
}

.catalog-item-unlock.develop-cost {
    color: var(--progress-color);
}

.catalog-item-flavor {
    font-size: 7px;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 5px;
    padding: 4px 6px 4px 8px;
    margin-left: 38px;
    border-left: 2px solid var(--border-color);
    background: rgba(255, 255, 255, 0.03);
    border-radius: 0 2px 2px 0;
}

.catalog-item.undeveloped .catalog-item-flavor {
    color: var(--text-secondary);
    opacity: 0.6;
}

.catalog-item.undeveloped {
    border-style: dashed;
    opacity: 0.8;
}

.catalog-item.undeveloped:hover {
    border-color: var(--progress-color);
    opacity: 1;
}

/* === UPGRADES === */
.upgrade-item {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.upgrade-item:hover:not(.maxed) {
    border-color: var(--success);
}

.upgrade-item.maxed {
    opacity: 0.6;
    cursor: default;
    border-color: var(--success);
}

.upgrade-item.cant-afford {
    opacity: 0.7;
}

.upgrade-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.upgrade-name {
    font-size: 8px;
}

.upgrade-level {
    font-size: 7px;
    color: var(--text-secondary);
}

.upgrade-desc {
    font-size: 7px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.upgrade-cost {
    font-size: 8px;
    color: var(--money-color);
}

/* === STATS === */
.stats-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 4px;
    border-bottom: 1px solid var(--border-color);
    font-size: 8px;
}

.stats-label {
    color: var(--text-secondary);
}

.stats-value {
    color: var(--text-primary);
}

/* === FOOTER === */
#footer {
    display: flex;
    justify-content: center;
    gap: 15px;
    padding: 8px 20px;
    background: var(--bg-panel);
    border-top: 3px solid var(--border-color);
}

.footer-btn {
    padding: 6px 12px;
    background: var(--btn-bg);
    border: 2px solid var(--border-color);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 8px;
    cursor: pointer;
    border-radius: 2px;
    transition: background 0.2s;
}

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

.footer-btn:active {
    background: var(--btn-active);
}

/* === FLOATING TEXT === */
#floating-texts {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
}

.floating-text {
    position: absolute;
    font-size: 12px;
    font-family: inherit;
    color: var(--money-color);
    animation: float-up 1.5s ease-out forwards;
    pointer-events: none;
    text-shadow: 0 0 4px rgba(102, 255, 170, 0.5);
}

@keyframes float-up {
    0% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-60px); }
}

/* === POPUPS === */
.hidden {
    display: none !important;
}

#tutorial-overlay, #offline-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.tutorial-box, .popup-box {
    background: var(--bg-panel);
    border: 3px solid var(--border-color);
    border-radius: 4px;
    padding: 20px;
    max-width: 400px;
    text-align: center;
}

.tutorial-box p, .popup-box p {
    margin-bottom: 15px;
    font-size: 9px;
    line-height: 1.8;
}

.popup-box h3 {
    font-size: 12px;
    margin-bottom: 10px;
    color: var(--money-color);
}

.pixel-btn {
    padding: 8px 16px;
    background: var(--btn-bg);
    border: 2px solid var(--border-color);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 9px;
    cursor: pointer;
    border-radius: 2px;
}

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

/* === TOAST NOTIFICATIONS === */
#toast-container {
    position: fixed;
    top: 60px;
    right: 10px;
    z-index: 1800;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    max-width: 280px;
}

.toast {
    background: var(--bg-panel);
    border: 2px solid var(--border-color);
    border-radius: 4px;
    padding: 10px 12px;
    animation: toast-in 0.3s ease-out forwards;
    pointer-events: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.toast.milestone {
    border-color: var(--progress-color);
}

.toast.event {
    border-color: var(--printer-active);
}

.toast-title {
    font-size: 8px;
    color: var(--progress-color);
    margin-bottom: 4px;
}

.toast.event .toast-title {
    color: var(--printer-active);
}

.toast-message {
    font-size: 7px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 6px;
}

.toast-choices {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.toast-choice-btn {
    padding: 4px 8px;
    background: var(--btn-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 7px;
    cursor: pointer;
    border-radius: 2px;
    transition: background 0.2s;
    text-align: left;
}

.toast-choice-btn:hover {
    background: var(--btn-hover);
    border-color: var(--printer-active);
}

.toast-result {
    font-size: 7px;
    color: var(--money-color);
    line-height: 1.6;
    margin-top: 4px;
}

.toast.removing {
    animation: toast-out 0.3s ease-in forwards;
}

@keyframes toast-in {
    0% { opacity: 0; transform: translateX(30px); }
    100% { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
    0% { opacity: 1; transform: translateX(0); }
    100% { opacity: 0; transform: translateX(30px); }
}

/* === PARTICLE SYSTEM === */
.particle {
    position: fixed;
    width: 4px;
    height: 4px;
    pointer-events: none;
    z-index: 1500;
    animation: particle-burst var(--particle-duration, 0.8s) ease-out forwards;
}

@keyframes particle-burst {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(var(--px, 20px), var(--py, -30px)) scale(0.5);
    }
}

/* === ITEM POP-OUT ANIMATION === */
.pop-out-item {
    position: fixed;
    pointer-events: none;
    z-index: 1500;
    animation: pop-out 1.2s ease-out forwards;
}

@keyframes pop-out {
    0% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
    30% {
        opacity: 1;
        transform: scale(2) translateY(-5px);
    }
    100% {
        opacity: 0;
        transform: scale(1.5) translateY(-40px);
    }
}

/* === SCROLLBAR === */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--btn-hover);
}

/* === RESPONSIVE === */
@media (max-width: 900px) {
    #main {
        flex-direction: column;
    }

    #printer-area {
        flex: 0 0 auto;
        max-height: 60vh;
    }

    #side-panel {
        flex: 1;
        border-left: none;
        border-top: 3px solid var(--border-color);
    }

    #printer-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }

    #room-view {
        height: 240px;
    }
}

@media (max-width: 600px) {
    body {
        font-size: 8px;
    }

    #header {
        padding: 8px 10px;
    }

    .stat-value {
        font-size: 10px;
    }

    #printer-grid {
        grid-template-columns: 1fr;
        max-width: 300px;
    }

    #room-view {
        height: 200px;
    }

    .tab {
        font-size: 7px;
        padding: 8px 3px;
    }
}

@media (max-width: 480px) {
    body {
        font-size: 11px;
        overflow-y: auto;
        overflow-x: hidden;
    }

    #game-container {
        height: auto;
        min-height: 100vh;
    }

    /* === HEADER: two-row wrap === */
    #header {
        flex-wrap: wrap;
        padding: 8px 8px;
        gap: 6px 12px;
        min-height: auto;
    }

    .stat {
        gap: 1px;
    }

    .stat-label {
        font-size: 8px;
    }

    .stat-value {
        font-size: 11px;
    }

    .sell-btn {
        padding: 12px 16px;
        font-size: 11px;
        min-height: 44px;
        min-width: 44px;
    }

    /* === MAIN LAYOUT === */
    #main {
        overflow: visible;
    }

    /* === TABS === */
    .tab {
        padding: 12px 8px;
        font-size: 9px;
        min-height: 44px;
    }

    /* === CATALOG === */
    .catalog-item {
        padding: 14px;
        min-height: 48px;
    }

    .catalog-item-name {
        font-size: 10px;
    }

    /* === PRINTER GRID: compact cards === */
    #printer-grid {
        grid-template-columns: 1fr 1fr;
        max-width: 100%;
        gap: 6px;
    }

    .printer-card {
        min-height: auto;
        padding: 8px;
    }

    .printer-sprite {
        display: none;
    }

    .printer-name {
        font-size: 9px;
    }

    .printer-status {
        font-size: 7px;
        padding: 2px 4px;
    }

    .printer-current-item {
        font-size: 7px;
        margin-bottom: 4px;
        min-height: 10px;
    }

    .progress-container {
        height: 8px;
        margin-bottom: 4px;
    }

    .printer-queue {
        gap: 2px;
        min-height: 12px;
    }

    .printer-filament {
        margin-top: 4px;
    }

    /* === QUEUE SLOTS === */
    .queue-slot {
        width: 18px;
        height: 18px;
        font-size: 7px;
    }

    /* === REFILL BUTTON === */
    .btn-refill {
        padding: 6px 8px;
        min-width: 32px;
        min-height: 32px;
        font-size: 7px;
    }

    /* === ROOM VIEW === */
    #room-view {
        height: 140px;
    }

    /* === PRINTER AREA === */
    #printer-area {
        padding: 8px 6px;
        gap: 8px;
        flex: 0 0 auto;
        max-height: none;
        overflow: visible;
    }

    .buy-printer-card {
        min-height: 80px;
        padding: 8px;
    }

    .buy-printer-plus {
        font-size: 18px;
        margin-bottom: 4px;
    }

    /* === SIDE PANEL === */
    #side-panel {
        flex: 1 1 auto;
        max-height: none;
        overflow: visible;
        border-left: none;
        border-top: 3px solid var(--border-color);
    }

    #panel-content {
        padding: 8px;
        overflow-y: visible;
    }

    /* === FOOTER === */
    #footer {
        gap: 8px;
        padding: 6px 8px;
    }

    .footer-btn {
        padding: 12px 16px;
        font-size: 9px;
        min-height: 44px;
        min-width: 44px;
    }

    /* === TOAST CHOICES === */
    .toast-choice-btn {
        padding: 10px 14px;
        font-size: 8px;
        min-height: 44px;
    }

    /* === UPGRADES === */
    .upgrade-item {
        padding: 14px;
        min-height: 48px;
    }
}
