@font-face {
    font-family: "PressStart2P";
    src: url("assets/fonts/PressStart2P.ttf") format("truetype");
    font-display: swap;
}
:root {
    --bg: #0d1620;
    --bg-alt: #122130;
    --panel: rgba(8, 17, 26, 0.92);
    --panel-edge: #2b475a;
    --text: #d8f1f7;
    --muted: #8aa8b5;
    --accent: #ffb347;
    --accent-2: #72e6b8;
    --danger: #ff7f6b;
    --shadow: rgba(0, 0, 0, 0.35);
    --font-ui: "PressStart2P", "Courier New", monospace;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background:
        radial-gradient(circle at top, rgba(72, 126, 168, 0.25), transparent 38%),
        linear-gradient(180deg, #08111a 0%, #102130 48%, #091118 100%);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 10px;
}

body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0) 0,
        rgba(255, 255, 255, 0) 3px,
        rgba(0, 0, 0, 0.14) 4px,
        rgba(0, 0, 0, 0.14) 5px
    );
    mix-blend-mode: multiply;
}

button,
input {
    font: inherit;
}

.shell {
    width: min(1480px, calc(100vw - 24px));
    margin: 0 auto;
    padding: 16px 0 24px;
}

.topbar,
.panel,
.viewport-panel {
    border: 2px solid var(--panel-edge);
    background: var(--panel);
    box-shadow: 0 14px 28px var(--shadow);
}

.topbar {
    display: grid;
    grid-template-columns: minmax(0, auto) minmax(340px, 1fr);
    gap: 14px;
    align-items: center;
    padding: 10px 14px;
}

.panel-label {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: clamp(1.5rem, 3vw, 1.9rem);
    line-height: 1;
}

h2 {
    font-size: 1.25rem;
}

.titlebar {
    display: grid;
    gap: 8px;
    min-width: 0;
}

.title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.cog-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 4px;
    flex: 0 0 auto;
}

.cog-btn img {
    width: 16px;
    height: 16px;
    image-rendering: pixelated;
}

.title-row h1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.title-editor {
    display: flex;
    align-items: center;
    gap: 8px;
}

.title-editor[hidden] {
    display: none;
}

.title-editor input {
    width: clamp(200px, 24vw, 280px);
    max-width: 100%;
    padding: 8px 10px;
    color: var(--text);
    background: #071019;
    border: 2px solid var(--panel-edge);
}

button {
    cursor: pointer;
    color: #091118;
    background: var(--accent);
    border: 0;
    padding: 8px 12px;
    font-weight: 700;
    font-size: 1.1rem;
}

.ghost-btn {
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 6px 10px;
    font-size: 1em;
}

.danger-btn {
    border-color: rgba(255, 127, 107, 0.45);
    color: #ffc4b7;
}

.danger-btn:hover,
.danger-btn:focus-visible {
    background: rgba(255, 127, 107, 0.14);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.resource-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
    padding: 0;
}

.resource-bar-header {
    align-self: stretch;
    min-width: 0;
}

.resource-chip {
    min-width: 0;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.resource-chip span {
    display: block;
    color: var(--muted);
    font-size: 1.1em;
    margin-bottom: 4px;
}

.layout {
    --sidebar-width: clamp(280px, 24vw, 360px);
    --layout-gap: 16px;
    --layout-top-offset: 16px;
    --layout-bottom-gap: 24px;
    --layout-chrome-height: clamp(220px, 26vh, 300px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--sidebar-width);
    justify-content: stretch;
    align-items: start;
    gap: var(--layout-gap);
    margin-top: 16px;
}

.viewport-panel {
    align-self: start;
    min-width: 0;
}

.viewport-panel,
.panel {
    padding: 14px;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: start;
    margin-bottom: 12px;
}

.panel-head.compact {
    align-items: center;
}

.selection-summary,
.building-card p,
.cost-line,
.small {
    color: var(--muted);
    font-size: 1em;
    line-height: 1.45;
}

.selection-summary{
    max-width: 50%;
    flex: 1 1 50%;
    font-size: .8em;
    text-align: right;
    &.has-feedback {
        color: #ffd166;
    }
    
}

.canvas-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #040a10;
    border: 2px solid #294252;
    overflow: hidden;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

.sidebar {
    display: grid;
    gap: 16px;
    align-content: start;
    position: sticky;
    top: var(--layout-top-offset);
    max-height: calc(100vh - (var(--layout-top-offset) * 2));
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-gutter: stable;
}

.sidebar::-webkit-scrollbar,
.toast-stack::-webkit-scrollbar {
    width: 10px;
}

.sidebar::-webkit-scrollbar-thumb,
.toast-stack::-webkit-scrollbar-thumb {
    background: rgba(114, 230, 184, 0.32);
    border: 2px solid transparent;
    background-clip: padding-box;
}

.sidebar::-webkit-scrollbar-track,
.toast-stack::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.04);
}

.build-menu {
    display: grid;
    gap: 10px;
}

.building-card {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.025);
    padding: 10px;
}

.building-card.active {
    border-color: var(--accent-2);
    box-shadow: inset 0 0 0 1px rgba(114, 230, 184, 0.5);
}

.building-card.locked {
    opacity: 0.6;
}

.card-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
}

.cost-line {
    margin: 5px 0;
}

.toast-stack {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 20;
    width: min(360px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    display: grid;
    gap: 10px;
    overflow-y: auto;
    pointer-events: none;
}

.toast {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 12px;
    border: 1px solid rgba(255, 209, 102, 0.35);
    border-left: 4px solid #ffd166;
    background: rgba(8, 17, 26, 0.96);
    box-shadow: 0 14px 28px var(--shadow);
    pointer-events: auto;
    overflow: hidden;
}

.toast p {
    color: var(--text);
    font-size: 1.1rem;
    line-height: 1.45;
}

.toast-with-action {
    grid-template-columns: minmax(0, 1fr) auto;
}

.toast-server {
    border-color: rgba(114, 230, 184, 0.35);
    border-left-color: var(--accent-2);
}

.toast-dismiss {
    color: var(--muted);
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 4px 8px;
    font-size: 1.1rem;
}

.toast-dismiss:disabled {
    opacity: 0.5;
}

.travel-overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(4, 10, 16, 0.72);
}

.travel-overlay[hidden] {
    display: none;
}

.travel-modal {
    width: min(540px, calc(100vw - 32px));
    border: 2px solid var(--panel-edge);
    background:
        linear-gradient(180deg, rgba(9, 17, 24, 0.98), rgba(18, 33, 48, 0.96)),
        radial-gradient(circle at top, rgba(255, 179, 71, 0.14), transparent 50%);
    box-shadow: 0 18px 36px var(--shadow);
    padding: 16px;
}

.travel-head {
    margin-bottom: 10px;
}

.travel-description {
    color: var(--text);
    font-size: 1.3rem;
    line-height: 1.55;
}

.travel-note {
    margin-top: 10px;
    color: var(--muted);
    font-size: 1.2rem;
    line-height: 1.45;
}

.factory-panel {
    margin-top: 16px;
    padding: 14px;
    border: 1px solid rgba(255, 179, 71, 0.28);
    background: rgba(255, 179, 71, 0.08);
}

.factory-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.factory-stats div {
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(7, 16, 25, 0.68);
}

.factory-stats strong {
    display: block;
    margin-top: 6px;
    font-size: 1.5rem;
    color: #ffd166;
}

.factory-work-btn {
    width: 100%;
    margin-top: 14px;
    padding: 14px 16px;
    font-size: 1.5rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    background: linear-gradient(180deg, #ffd166 0%, #ffb347 100%);
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2);
}

.factory-work-btn:active:not(:disabled) {
    transform: translateY(2px);
}

@media (max-width: 720px) {
    .factory-stats {
        grid-template-columns: 1fr;
    }

    .factory-work-btn {
        font-size: 1.5rem;
    }
}

@media (max-width: 980px) {
    .layout {
        grid-template-columns: 1fr;
        justify-content: stretch;
    }

    .canvas-wrap {
        width: 100%;
    }

    .sidebar {
        position: static;
        max-height: none;
        overflow: visible;
        padding-right: 0;
    }

    .topbar {
        grid-template-columns: 1fr;
        align-items: start;
    }

    .title-row {
        flex-wrap: wrap;
    }

    .title-editor {
        width: 100%;
        flex-wrap: wrap;
    }

    .resource-bar-header {
        width: 100%;
    }

    .toast-stack {
        top: auto;
        right: 12px;
        bottom: 12px;
        width: min(420px, calc(100vw - 24px));
        max-height: min(40vh, 320px);
    }
}

.resource-chip.stress-warning {
    border-color: rgba(255, 179, 71, 0.58);
    box-shadow: inset 0 0 0 1px rgba(255, 179, 71, 0.35);
}

.resource-chip.stress-critical {
    border-color: rgba(255, 127, 107, 0.7);
    box-shadow: inset 0 0 0 1px rgba(255, 127, 107, 0.45);
}

.building-card.active button {
    margin-top: 6px;
}