/* Pixel Production: game page styles.
   Layout: the map fills the whole window; the HUD floats on top of it.
   Single dark theme on purpose (arcade look, matches pp.css). */

@font-face {
    font-family: "BarcadeBrawl";
    src: url("assets/BarcadeBrawl.ttf") format("truetype");
    font-display: swap;
}
:root {
    --bg: #0a0c1a;
    --map: #05060f;
    --panel: #11152ee6;          /* slightly see-through, the map shows behind */
    --panel-solid: #11152e;
    --line: #2a37d8;
    --line-soft: #1e2654;
    --fg: #e6eaff;
    --dim: #8a92c4;
    --yellow: #f7d73b;
    --yellow-deep: #c9a514;
    --good: #4cb84a;
    --warn: #f5922a;
    --bad: #e8423f;
    --font-display: "BarcadeBrawl", "Press Start 2P", ui-monospace, monospace;
    --font-body: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
    --gap: max(12px, env(safe-area-inset-left, 0px));
    color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.4;
    overflow: hidden;               /* the map pans, the page never scrolls */
}

/* ---------- the map viewport ---------- */
#viewport {
    position: fixed;
    inset: 0;
    overflow: hidden;
    background: var(--map);
    touch-action: none;             /* we handle pinch and drag ourselves */
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}
#viewport.dragging { cursor: grabbing; }
#viewport:not([data-tool="select"]) { cursor: crosshair; }
#board {
    position: absolute;
    left: 0; top: 0;
    transform-origin: 0 0;          /* camera.cssTransform() assumes this */
    will-change: transform;
    /* The floor takes a faint wash of the current layer's color (render.js sets --layer). */
    --layer: var(--yellow);
    background: color-mix(in srgb, var(--layer) 7%, var(--bg));
    outline: 2px solid color-mix(in srgb, var(--layer) 45%, var(--line-soft));
    transition: background-color 250ms;
}
#board::before {                    /* the grid from images/grid.png, dimmed */
    content: ""; position: absolute; inset: 0;
    background-image: url("assets/grid.png");
    background-size: 32px 32px;
    opacity: 0.14;
    transition: opacity 200ms;
}
#board.far::before { opacity: 0; }

/* Zoomed far out: each belt cell is a plain line in the middle of the cell,
   thicker for wider belts, with no animation. Elbows are two half-lines:
   one from the top edge to the middle, one from the middle out the side
   (the same side as in the sprite sheet, before the cell is rotated). */
#board.farther .belt-seg {
    --lw: 22%; --line: linear-gradient(#a9adc4, #a9adc4);
    animation: none;
    background: var(--line) center / var(--lw) 100% no-repeat;
}
#board.farther .belt-seg.w2 { --lw: 34%; }
#board.farther .belt-seg.w3 { --lw: 46%; }
#board.farther .belt-seg.elbow-right {
    background: var(--line) center top / var(--lw) calc(50% + var(--lw) / 2) no-repeat,
                var(--line) left center / calc(50% + var(--lw) / 2) var(--lw) no-repeat;
}
#board.farther .belt-seg.elbow-left {
    background: var(--line) center top / var(--lw) calc(50% + var(--lw) / 2) no-repeat,
                var(--line) right center / calc(50% + var(--lw) / 2) var(--lw) no-repeat;
}

.belt-seg {
    position: absolute;
    background-image: url("assets/belt1.png");
    background-repeat: no-repeat;
    image-rendering: pixelated;
    animation: belt-run 400ms steps(4) infinite;
}
.belt-seg.paused { animation-play-state: paused; }
/* Wide belts: same layout, a wider band (scripts/make-belt-sprites.py). */
.belt-seg.w2 { background-image: url("assets/belt2.png"); }
.belt-seg.w3 { background-image: url("assets/belt3.png"); }
.belt-seg.elbow-right { background-position-y: -32px; }
.belt-seg.elbow-left { background-position-y: -64px; }
@keyframes belt-run { from { background-position-x: 0; } to { background-position-x: -128px; } }

/* A lift: two rails standing over the belt, an arrow, and a stripe in the
   color of the layer at the other end. Items shrink into it (render.js). */
.lift-shaft {
    position: absolute;
    --to: var(--fg);
    box-sizing: border-box;
    border-left: 4px solid #8a8fa8;
    border-right: 4px solid #8a8fa8;
    box-shadow: inset 0 -4px 0 var(--to), inset 0 4px 0 var(--to);
    background: radial-gradient(circle, rgba(0,0,0,0.75) 0 35%, transparent 36%);
    color: var(--to);
    font-size: 10px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    text-shadow: 0 0 2px #000;
    pointer-events: none;
    z-index: 1;
}
.item.on-lift { box-shadow: 0 0 0 2px #8a8fa8; }
#inspector .warn { color: var(--warn); }
.belt-tag {
    position: absolute;
    font-family: var(--font-display);
    font-size: 7px;
    color: var(--dim);
    display: flex; align-items: flex-start; justify-content: center;
    padding-top: 1px;
    pointer-events: none;
}

.bld {
    position: absolute;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px;
    border: 2px solid var(--line);
    background: var(--panel-solid);
    color: var(--fg);
    font: inherit;
    padding: 2px;
    text-align: center;
}
.bld-name { font-family: var(--font-display); font-size: 7px; letter-spacing: 0.05em; }
.bld-info { font-size: 9px; color: var(--dim); line-height: 1.2; }
.bld-storage, .bld-sorter { border-color: var(--warn); }
.bld-pile {
    cursor: pointer;
    --pile: var(--yellow);          /* render.js sets the pile's own color */
    border-color: color-mix(in srgb, var(--pile) 75%, #000);
    background:
        repeating-linear-gradient(90deg, rgba(0,0,0,0.18) 0 2px, transparent 2px 8px),
        repeating-linear-gradient(0deg, rgba(0,0,0,0.18) 0 2px, transparent 2px 8px),
        var(--pile);
    color: #111;
}
.bld-pile .bld-info { color: rgba(0,0,0,0.6); }
.bld-pile:hover { filter: brightness(1.08); }
.bld-pile.flash { animation: flash 400ms ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 var(--yellow); } 100% { box-shadow: 0 0 0 14px transparent; } }

.recipe { display: flex; align-items: center; gap: 4px; font-size: 10px; }
.recipe .px, .recipe .blk { position: static; transform: none; display: inline-block; }
.meter { width: 80%; height: 5px; background: var(--line-soft); }
.meter span { display: block; height: 100%; width: 0; background: var(--yellow); }
.bld-producer[data-state="output-full"], .bld-producer[data-state="stopped"] { border-color: var(--bad); }
.bld-consumer { border-color: var(--good); }
.bld-consumer.chomp { background: #173a1c; }

.layer { position: absolute; inset: 0; pointer-events: none; }
#items { z-index: 2; }
#ghost { z-index: 3; }
.ghost { position: absolute; border: 2px dashed; }
.ghost.ok { border-color: var(--good); background: rgba(76, 184, 74, 0.18); }
.ghost.bad { border-color: var(--bad); background: rgba(232, 66, 63, 0.18); }
.ghost.cell { border-style: solid; border-width: 1px; }
.ghost.draft-end { border: 3px solid var(--fg); animation: pulse 900ms ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.3; } }

/* Layer tabs: a color chip and the name. The current layer is filled in. */
.layers { display: flex; gap: 4px; }
.layer-tab { display: flex; align-items: center; gap: 6px; }
.layer-tab i { width: 10px; height: 10px; background: var(--c); box-shadow: inset -2px -2px 0 rgba(0,0,0,0.3); }
.layer-tab[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 22%, transparent); }
#draftBar { margin-right: 8px; }
.selected { outline: 2px solid var(--fg); outline-offset: 1px; z-index: 1; }
.belt-seg.selected { outline-offset: -2px; }
.item { position: absolute; left: 0; top: 0; will-change: transform; }
.item { --c: var(--yellow); }
.px { width: 10px; height: 10px; background: var(--c); box-shadow: inset -2px -2px 0 rgba(0,0,0,0.25); }
.blk {
    width: 18px; height: 18px;
    background:
        linear-gradient(var(--bg), var(--bg)) 8px 0 / 2px 100% no-repeat,
        linear-gradient(var(--bg), var(--bg)) 0 8px / 100% 2px no-repeat,
        var(--c);
    outline: 1px solid rgba(0,0,0,0.35);
}

/* ---------- HUD (floats over the map) ---------- */
.hud {
    position: fixed;
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
    background: var(--panel);
    border: 2px solid var(--line-soft);
    padding: 8px 12px;
    backdrop-filter: blur(4px);
    z-index: 10;
}
.hud-top { top: var(--gap); left: var(--gap); right: var(--gap); justify-content: space-between; }
.hud-right { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.hud-bottom {
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    left: var(--gap);
    max-width: calc(100% - 2 * var(--gap) - 64px);   /* leave room for the zoom column */
    flex-direction: column; align-items: stretch; flex-wrap: nowrap;
}
.hud-zoom { bottom: max(12px, env(safe-area-inset-bottom, 0px)); right: var(--gap); flex-direction: column; gap: 6px; padding: 6px; }

.tools { display: flex; flex-wrap: wrap; gap: 4px; }
button.tool { display: flex; flex-direction: column; align-items: center; line-height: 1.1; padding: 4px 8px; font-size: 12px; }
button.tool small { font-size: 9px; color: var(--dim); }
button.tool[aria-pressed="true"] { background: var(--line); }
button.tool[aria-pressed="true"] small { color: var(--fg); }
.tool-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 12px; color: var(--dim); min-height: 20px; }
select {
    font: inherit; font-size: 12px; color: var(--fg); background: var(--panel-solid);
    border: 1px solid var(--line); padding: 4px 6px;
}
#toast {
    position: absolute; left: 0; bottom: calc(100% + 8px);
    background: var(--panel-solid); border: 2px solid var(--good);
    padding: 4px 10px; font-size: 12px; white-space: nowrap;
}
#toast[data-kind="bad"] { border-color: var(--bad); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#inspector {
    top: 84px; right: var(--gap);
    width: min(300px, calc(100% - 2 * var(--gap)));
    max-height: calc(100% - 84px - 180px);
    overflow-y: auto;
    flex-direction: column; align-items: stretch; gap: 8px;
    font-size: 12px;
}
#inspector[hidden] { display: none; }
#inspector header { display: flex; justify-content: space-between; align-items: center; }
#inspector h2 { font-family: var(--font-display); font-weight: normal; font-size: 11px; margin: 0; color: var(--yellow); }
#inspector p { margin: 0; }
#inspector .dim, .dim { color: var(--dim); }
#inspector .row { display: flex; flex-wrap: wrap; gap: 6px; }
#inspector .field { display: flex; gap: 8px; align-items: center; }
/* Long option text (belt levels with parts) must not stretch the panel. */
#inspector select { min-width: 0; max-width: 100%; flex: 1; width: 100%; }
#inspector > * { min-width: 0; max-width: 100%; }
#inspector { overflow-x: hidden; }
#inspector .close { background: none; border: 0; color: var(--dim); font-size: 20px; cursor: pointer; padding: 0 4px; }
#inspector .stacks { margin: 0; padding-left: 16px; max-height: 120px; overflow-y: auto; }
#inspector .filter { border: 1px solid var(--line-soft); padding: 6px 8px; display: grid; gap: 6px; }
#inspector .filter legend { color: var(--dim); padding: 0 4px; }
#inspector .checks { display: grid; gap: 2px; }
#inspector .checks[hidden] { display: none; }
#menu {
    top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: min(420px, calc(100% - 2 * var(--gap)));
    flex-direction: column; align-items: stretch; gap: 10px;
    font-size: 12px; z-index: 20;
    background: var(--panel-solid);
}
#menu[hidden] { display: none; }
#menu header { display: flex; justify-content: space-between; align-items: center; }
#menu h2 { font-family: var(--font-display); font-weight: normal; font-size: 11px; margin: 0; color: var(--yellow); }
#menu p { margin: 0; }
#menu .row { display: flex; flex-wrap: wrap; gap: 6px; }
#menu .close { background: none; border: 0; color: var(--dim); font-size: 20px; cursor: pointer; padding: 0 4px; }
#menu textarea {
    font: inherit; font-size: 11px; color: var(--fg); background: var(--bg);
    border: 1px solid var(--line); padding: 6px; resize: vertical; width: 100%;
}
label.file { display: inline-flex; align-items: center; cursor: pointer; }
label.file input { position: absolute; width: 1px; height: 1px; opacity: 0; }
label.file:focus-within { outline: 2px solid var(--fg); outline-offset: 2px; }
/* ---------- BIT ---------- */
#bit {
    left: var(--gap); bottom: 150px;
    width: min(360px, calc(100% - 2 * var(--gap)));
    flex-wrap: nowrap; align-items: flex-start; gap: 12px;
    font-size: 13px;
    border-color: var(--yellow-deep);
    background: var(--panel-solid);
    z-index: 12;
}
#bit[hidden] { display: none; }
#bit p { margin: 0 0 8px; }
#bit .bit-name { font-family: var(--font-display); font-size: 10px; color: var(--yellow); margin-bottom: 4px; }
#bit .row { display: flex; flex-wrap: wrap; gap: 6px; }
#bit .quiet { border-color: var(--line-soft); color: var(--dim); }
/* BIT's face: a little pixel robot made of CSS boxes. */
.bit-face {
    flex: none; width: 40px; height: 40px; position: relative;
    background: var(--yellow); box-shadow: inset -4px -4px 0 var(--yellow-deep);
    animation: bit-bob 2.4s ease-in-out infinite;
}
.bit-face::before {   /* antenna */
    content: ""; position: absolute; left: 18px; top: -8px; width: 4px; height: 8px; background: var(--yellow-deep);
}
.bit-face i {          /* eyes, which blink */
    position: absolute; top: 12px; width: 8px; height: 8px; background: var(--bg);
    animation: bit-blink 5s steps(1) infinite;
}
.bit-face i:first-child { left: 8px; }
.bit-face i:last-child { left: 24px; }
@keyframes bit-bob { 50% { transform: translateY(-3px); } }
@keyframes bit-blink { 0%, 94% { height: 8px; top: 12px; } 95%, 100% { height: 2px; top: 15px; } }
.glow { animation: glow 1.2s ease-in-out infinite; border-color: var(--yellow) !important; }
@keyframes glow { 50% { box-shadow: 0 0 0 4px rgba(247, 215, 59, 0.45); } }

/* ---------- Recipes menu ---------- */
#shop {
    top: 84px; left: 50%; transform: translateX(-50%);
    width: min(560px, calc(100% - 2 * var(--gap)));
    max-height: calc(100% - 84px - 150px); overflow-y: auto;
    flex-direction: column; align-items: stretch; flex-wrap: nowrap; gap: 8px;
    font-size: 12px; z-index: 20; background: var(--panel-solid);
}
#shop[hidden] { display: none; }
#shop header { display: flex; justify-content: space-between; align-items: center; }
#shop h2 { font-family: var(--font-display); font-weight: normal; font-size: 11px; margin: 0; color: var(--yellow); }
#shop h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--dim); margin: 8px 0 4px; font-weight: 400; }
#shop p { margin: 0; }
#shop ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
#shop li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
#shop li.is-owned { opacity: 0.6; }
#shop .owned { color: var(--good); font-size: 11px; white-space: nowrap; }
#shop button { flex: none; font-size: 11px; }
#shop button:disabled { opacity: 0.4; cursor: default; }
#shop .close { background: none; border: 0; color: var(--dim); font-size: 20px; cursor: pointer; padding: 0 4px; }

/* ---------- the Screen ---------- */
.bld-screen {
    /* A CRT monitor: a chunky bezel, a curved glass screen with the picture
       on a 16x16 canvas, scanlines, and a slow flicker. */
    border: 3px solid #6b6f86;
    border-radius: 10px;
    background: linear-gradient(#2b2e3f, #1b1d29);
    justify-content: flex-end;
    padding: 8px 8px 4px;
}
.bld-screen .crt {
    position: relative;
    flex: 1; width: 100%;
    border-radius: 14px / 18px;      /* bulging glass */
    overflow: hidden;
    background: #05060f;
    box-shadow: inset 0 0 18px rgba(0,0,0,0.9), 0 0 0 2px #0c0d16;
}
.bld-screen canvas {
    width: 100%; height: 100%; display: block;
    image-rendering: pixelated;
    filter: saturate(1.2) brightness(1.1);
    animation: crt-flicker 3.2s infinite steps(1);
}
.bld-screen .crt::after {           /* scanlines and a soft glare */
    content: ""; position: absolute; inset: 0;
    background:
        repeating-linear-gradient(0deg, rgba(0,0,0,0.35) 0 1px, transparent 1px 3px),
        radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.12), transparent 60%);
    pointer-events: none;
}
@keyframes crt-flicker { 0%, 100% { opacity: 1; } 47% { opacity: 0.93; } 49% { opacity: 1; } 83% { opacity: 0.96; } }
.bld-screen .bld-name { font-size: 9px; color: var(--fg); }
.bld-screen .bld-info { color: var(--dim); font-size: 8px; }
.bld-screen.chomp .crt { box-shadow: inset 0 0 18px rgba(0,0,0,0.9), 0 0 10px var(--yellow); }
.meter.wide { display: block; width: 100%; }

button.danger { border-color: var(--bad); }
button.danger:hover { background: #3a1416; }

h1 {
    font-family: var(--font-display);
    font-weight: normal;
    font-size: 14px;
    letter-spacing: 0.04em;
    margin: 0;
    color: var(--yellow);
}
.energy { display: flex; align-items: baseline; gap: 10px; }
#drain { font-size: 11px; color: var(--dim); }
#upkeep { font-size: 11px; color: var(--bad); white-space: nowrap; }
#upkeep b { color: var(--warn); font-weight: 600; }
#energy { font-family: var(--font-display); font-size: 22px; color: var(--yellow); font-variant-numeric: tabular-nums; }
#net { font-size: 12px; }
#net[data-sign="up"] { color: var(--good); }
#net[data-sign="down"] { color: var(--bad); }
#status { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; padding: 2px 6px; border: 1px solid currentColor; }
#status[data-state="running"] { color: var(--good); }
#status[data-state="halted"] { color: var(--bad); }

button.act {
    font: inherit; font-size: 13px;
    color: var(--fg); background: transparent;
    border: 2px solid var(--line);
    padding: 6px 10px; cursor: pointer;
    min-height: 36px;
}
button.act:hover { background: var(--line-soft); }
button.primary { background: var(--yellow); color: #2a2100; border-color: var(--yellow); font-weight: 600; }
button.primary:hover { background: #ffe25c; }
button:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.speed { display: flex; }
.speed button { border-right-width: 0; }
.speed button:last-child { border-right-width: 2px; }
.speed button[aria-pressed="true"] { background: var(--line); }

.hud-zoom button { width: 40px; height: 40px; padding: 0; font-size: 18px; }
#zoomLevel { font-size: 10px; color: var(--dim); text-align: center; font-variant-numeric: tabular-nums; }

#haltNote {
    position: fixed; left: 50%; top: 96px; transform: translateX(-50%);
    background: var(--bad); color: #fff;
    font-family: var(--font-display); font-size: 10px; letter-spacing: 0.04em;
    padding: 8px 12px; white-space: nowrap;
    pointer-events: none;
    display: none;
    z-index: 5;
}
body.halted #haltNote { display: block; }

.help { font-size: 11px; color: var(--dim); }
@media (max-width: 640px) {
    h1, #drain { display: none; }
    #energy { font-size: 18px; }
    .hud-top { padding: 6px 8px; gap: 6px; }
    .hud-bottom { padding: 6px 8px; right: calc(var(--gap) + 64px); max-width: none; }
    .tools { min-width: 0; }
    button.act { min-height: 32px; padding: 4px 8px; font-size: 12px; }
    /* One row of tools that scrolls sideways instead of three rows. */
    .tools { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
    button.tool { flex: none; font-size: 11px; }
    /* The top bar can wrap to two rows on a phone: keep the banner below it. */
    #haltNote { top: 148px; font-size: 8px; }
    /* On a phone the inspector becomes a sheet above the toolbar. */
    #consumeBtn .long, .layer-tab .long, #upkeep .long { display: none; }
    .layer-tab { padding: 4px 6px; }
    #bit { bottom: 150px; left: var(--gap); right: calc(var(--gap) + 64px); width: auto; font-size: 12px; }
    body.inspecting #bit { display: none; }   /* the inspector sheet sits in the same spot */
    .bit-face { width: 28px; height: 28px; }
    .bit-face i { top: 8px; width: 6px; height: 6px; }
    .bit-face i:first-child { left: 5px; } .bit-face i:last-child { left: 17px; }
    .bit-face::before { left: 12px; }
    #inspector { top: auto; bottom: 150px; left: var(--gap); right: var(--gap); width: auto; max-height: 40%; }
}

@media (prefers-reduced-motion: reduce) {
    .belt-seg, .bit-face, .bit-face i, .glow, .bld-screen canvas { animation: none; }
    .bld-pile.flash { animation: none; }
}

/* Recipe prices: one chip per part, with have/need. Red when short. */
#shop .price { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
#shop .chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 1px 6px;
    border: 1px solid var(--line-soft);
    font-size: 10px; font-variant-numeric: tabular-nums;
}
#shop .chip img { image-rendering: pixelated; object-fit: contain; }
#shop .chip.short { border-color: var(--bad); color: #ff9a97; }
/* Stack tiles: the item's picture on top, the count below. Tap to eat. */
.stack-grid { display: flex; flex-wrap: wrap; gap: 4px; }
.stack-rows { display: flex; gap: 12px; flex-wrap: wrap; }
.stack-rows > div { display: flex; flex-direction: column; gap: 3px; }
.stack-tile {
    width: 44px; height: 50px;
    display: flex; flex-direction: column; align-items: center; justify-content: space-between;
    padding: 4px 2px 2px;
    background: var(--panel-solid);
    border: 2px solid var(--line-soft);
    color: var(--fg);
    font: inherit;
    cursor: pointer;
}
.stack-tile .pic { width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
.stack-tile img { image-rendering: pixelated; }
.stack-tile b { font-size: 10px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.stack-tile small { font-size: 8px; color: var(--dim); font-weight: 400; }
.stack-tile:hover { border-color: var(--yellow); }
.stack-tile:active { transform: translateY(1px); }
.stack-tile.empty { opacity: 0.4; }
.stack-tile.sludge { border-color: #ff3fd2; cursor: not-allowed; }
