/* Cutout Craft. Layout: full-bleed canvas world, HUD pinned to the bottom like a hotbar game,
   menus as dark stone panels lit by one torchlight-amber accent. Single dark look by design. */
:root {
  --night: #0f0d14;
  --stone: #1c1922;
  --stone-2: #26222e;
  --edge: #3d3747;
  --edge-hi: #5a5266;
  --ink: #f4efe6;
  --muted: #b3aabd;
  --amber: #ffb547;
  --amber-deep: #c9771c;
  --blood: #e5484d;
  --leaf: #6fd36a;
  --display: "Pixelify Sans", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --body: "Pixelify Sans", ui-rounded, "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--night); color: var(--ink); font-family: var(--body); font-size: 16px; }
button { font: inherit; color: inherit; }
canvas#game { position: fixed; inset: 0; display: block; cursor: crosshair; }
#cam { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
[hidden] { display: none !important; }
kbd { display: inline-block; min-width: 1.6em; padding: 1px 6px; margin-right: 3px; border: 1px solid var(--edge-hi); border-bottom-width: 3px; border-radius: 4px; background: var(--stone-2); font-family: var(--display); font-size: 0.85em; text-align: center; color: var(--ink); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 18px; border: 2px solid var(--edge-hi); border-bottom-width: 4px; border-radius: 6px; background: var(--stone-2); font-family: var(--display); font-size: 1.05rem; letter-spacing: 0.02em; cursor: pointer; transition: transform .08s, background .15s; }
.btn:hover:not(:disabled) { background: #332d3c; }
.btn:active:not(:disabled) { transform: translateY(2px); border-bottom-width: 2px; }
.btn:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--amber); border-color: #ffd28a; border-bottom-color: var(--amber-deep); color: #2a1702; font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: #ffc363; }
.btn.danger { border-color: #8d3a3e; color: #ffb4b6; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; gap: 24px; padding: 24px 16px; background: rgba(10, 8, 14, 0.55); overflow-y: auto; z-index: 20; }
.panel { background: var(--stone); border: 2px solid var(--edge); border-radius: 10px; box-shadow: 0 0 0 4px rgba(0,0,0,.35), 0 24px 60px rgba(0,0,0,.5); padding: 22px; }
.panel.small { width: min(420px, 100%); text-align: center; }
.panel h2, .keys-card h2 { font-family: var(--display); font-weight: 700; font-size: 1.5rem; margin: 0 0 12px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.fine { color: var(--muted); font-size: .9rem; line-height: 1.4; margin: 14px 0 0; }
.hint { color: var(--muted); font-size: .88rem; line-height: 1.4; margin: 0 0 12px; max-width: 60ch; }
.confirm { border: 2px dashed #8d3a3e; border-radius: 8px; padding: 12px; }
.confirm p { margin: 0 0 10px; }
.confirm .row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.dead { background: rgba(80, 0, 6, 0.55); }
.dead h2 { color: #ff8d90; font-size: 2.2rem; }

/* ---------- title ---------- */
#title { background: linear-gradient(90deg, rgba(10,8,14,.92) 0%, rgba(10,8,14,.7) 45%, rgba(10,8,14,.25) 100%); justify-content: flex-start; align-items: center; padding-inline: max(16px, 6vw); flex-wrap: wrap; }
.title-card { width: min(520px, 100%); }
.eyebrow { font-family: var(--display); color: var(--amber); text-transform: uppercase; letter-spacing: .18em; font-size: .85rem; margin: 0 0 6px; }
#title h1 { font-family: var(--display); font-weight: 700; font-size: clamp(3.2rem, 9vw, 6.4rem); line-height: .86; margin: 0 0 18px; letter-spacing: -0.01em; text-wrap: balance;
  color: var(--ink); text-shadow: 4px 4px 0 #000, -2px -2px 0 var(--amber-deep); }
#title h1::after { content: ""; display: block; width: 2.2em; height: 6px; margin-top: 16px; background: repeating-linear-gradient(90deg, var(--amber) 0 10px, transparent 10px 16px); }
.lede { font-size: 1.15rem; line-height: 1.5; color: #e4dcd0; margin: 0 0 22px; max-width: 46ch; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.actions .btn.primary { font-size: 1.25rem; padding-inline: 26px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: .92rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--amber); }
#load-steps { list-style: none; padding: 12px 14px; margin: 14px 0 0; background: rgba(0,0,0,.35); border: 1px solid var(--edge); border-radius: 8px; display: grid; gap: 6px; font-size: .95rem; }
#load-steps li { display: flex; align-items: center; gap: 10px; color: var(--muted); }
#load-steps li::before { content: ""; width: 12px; height: 12px; border: 2px solid var(--edge-hi); flex: none; }
#load-steps li[data-state="active"] { color: var(--ink); }
#load-steps li[data-state="active"]::before { border-color: var(--amber); animation: blink .6s steps(2) infinite; }
#load-steps li[data-state="done"] { color: var(--ink); }
#load-steps li[data-state="done"]::before { background: var(--leaf); border-color: var(--leaf); }
#load-steps li[data-state="fail"]::before { background: var(--blood); border-color: var(--blood); }
@keyframes blink { 50% { background: var(--amber); } }
.error { color: #ffb4b6; background: rgba(229,72,77,.12); border: 1px solid #8d3a3e; border-radius: 8px; padding: 10px 12px; margin: 12px 0 0; line-height: 1.4; }
.keys-card { width: min(380px, 100%); background: rgba(20,17,26,.82); border: 2px solid var(--edge); border-radius: 10px; padding: 18px 20px; backdrop-filter: blur(3px); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; font-size: .92rem; align-items: center; }
.keys dt { font-family: var(--display); white-space: nowrap; color: var(--amber); }
.keys dd { margin: 0; color: #ddd5ca; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.topbar { position: absolute; top: 10px; left: 12px; display: flex; gap: 8px; align-items: center; }
.menu-btn { pointer-events: auto; min-height: 34px; padding: 3px 12px; font-size: .95rem; }
.craft-btn { position: relative; border-color: #ffd28a; }
.count { position: absolute; top: -8px; right: -8px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; background: var(--amber); color: #2a1702; font-size: .78rem; font-weight: 700; line-height: 20px; text-align: center; box-shadow: 0 0 0 2px #000; }
.inv-panel { overflow-y: auto; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 .btn { font-size: .92rem; padding-inline: 8px; }
#clock { font-family: var(--display); font-size: 1rem; padding: 4px 10px; background: rgba(0,0,0,.4); border-radius: 6px; text-shadow: 1px 1px 0 #000; font-variant-numeric: tabular-nums; }
#body-chip { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); }
.chip { display: inline-block; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--edge-hi); color: var(--muted); font-size: .82rem; background: rgba(0,0,0,.4); }
.chip.on { color: #2a1702; background: var(--amber); border-color: #ffd28a; }
.bottom { position: absolute; left: 50%; bottom: max(10px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
#stats { width: 100%; display: flex; justify-content: space-between; gap: 12px; }
#hearts, #food { display: flex; gap: 1px; }
#food { flex-direction: row-reverse; }
#hearts img, #food img { width: 20px; height: 20px; image-rendering: pixelated; }
#hearts.low img { animation: shake .4s infinite; }
@keyframes shake { 25% { transform: translateY(-1px); } 75% { transform: translateY(1px); } }
#hotbar { display: flex; gap: 2px; padding: 3px; background: rgba(12,10,16,.75); border: 2px solid #000; border-radius: 4px; pointer-events: auto; }
#hotbar-name { font-family: var(--display); font-size: 1.05rem; text-shadow: 2px 2px 0 #000; opacity: 0; transition: opacity .3s; min-height: 1.3em; }
#hotbar-name.on { opacity: 1; }

.slot { position: relative; width: 48px; height: 48px; background: #8b8b8b; border: 2px solid; border-color: #373737 #fff #fff #373737; display: grid; place-items: center; user-select: none; }
#hotbar .slot { background: rgba(110,106,118,.55); border-color: rgba(0,0,0,.6) rgba(255,255,255,.35) rgba(255,255,255,.35) rgba(0,0,0,.6); cursor: pointer; }
#hotbar .slot.sel { outline: 3px solid var(--amber); outline-offset: -1px; z-index: 1; box-shadow: 0 0 12px rgba(255,181,71,.6); }
.slot img { width: 32px; height: 32px; image-rendering: pixelated; pointer-events: none; }
.slot .n, .recipe .n { position: absolute; right: 2px; bottom: 0; font-family: var(--display); font-size: .95rem; font-weight: 600; text-shadow: 2px 2px 0 #3a3a3a; color: #fff; pointer-events: none; font-variant-numeric: tabular-nums; }
.slot .key { position: absolute; left: 3px; top: 0; font-size: .65rem; color: rgba(255,255,255,.65); pointer-events: none; }
.slot .dur { position: absolute; left: 6px; right: 6px; bottom: 4px; height: 3px; background: #000; pointer-events: none; }
.slot .dur b { display: block; height: 100%; }
#pip { position: fixed; top: 12px; right: 12px; width: 200px; border: 2px solid var(--edge-hi); border-radius: 8px; background: repeating-conic-gradient(#1f1b25 0 25%, #17141c 0 50%) 0 0 / 16px 16px; z-index: 6; box-shadow: 0 6px 20px rgba(0,0,0,.4); }

#toasts { position: fixed; top: 54px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 15; pointer-events: none; width: min(560px, calc(100% - 32px)); }
.toast { font-family: var(--display); font-size: 1rem; background: rgba(16,13,20,.88); border: 1px solid var(--edge-hi); border-left: 4px solid var(--amber); padding: 8px 14px; border-radius: 6px; text-align: center; animation: pop .25s ease-out; transition: opacity .4s, transform .4s; }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(.97); } }

/* ---------- backpack ---------- */
.inv-panel { position: relative; display: flex; gap: 22px; flex-wrap: wrap; width: min(1000px, 100%); max-height: calc(100vh - 48px); }
.inv-left { flex: 0 1 auto; min-width: 0; }
.inv-right { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; max-height: min(560px, calc(100vh - 100px)); }
.inv-head { display: flex; gap: 14px; align-items: flex-end; margin-bottom: 12px; }
#inv-avatar { background: radial-gradient(ellipse at 50% 95%, rgba(255,181,71,.25), transparent 60%), #120f17; border: 2px solid var(--edge); border-radius: 8px; flex: none; }
.inv-head .hint { max-width: 34ch; }
.grid { display: grid; grid-template-columns: repeat(9, 48px); gap: 0; background: #c6c6c6; padding: 6px; border-radius: 4px; width: max-content; }
.grid.hot { margin-top: 10px; }
.grid .slot { cursor: pointer; }
.grid .slot:hover { background: #a6a6a6; }
.craft-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.craft-head h2 { margin: 0; }
.stations { display: flex; gap: 6px; }
#recipes { overflow-y: auto; display: grid; gap: 6px; padding-right: 4px; min-height: 0; }
.recipe { display: flex; gap: 12px; align-items: center; text-align: left; padding: 6px 10px 6px 6px; background: var(--stone-2); border: 2px solid var(--edge); border-radius: 6px; cursor: pointer; opacity: .55; }
.recipe.can { opacity: 1; border-color: var(--edge-hi); }
.recipe.can:hover { border-color: var(--amber); background: #302a37; }
.recipe:focus-visible { outline: 3px solid var(--amber); }
.recipe .out { position: relative; width: 44px; height: 44px; display: grid; place-items: center; background: #8b8b8b; border: 2px solid; border-color: #373737 #fff #fff #373737; flex: none; }
.recipe .out img { width: 30px; height: 30px; image-rendering: pixelated; }
.rinfo { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.rname { font-family: var(--display); font-size: 1rem; }
.ings { display: flex; gap: 10px; flex-wrap: wrap; }
.ing { display: inline-flex; align-items: center; gap: 3px; font-size: .85rem; color: #ff9a9d; font-variant-numeric: tabular-nums; }
.ing.ok { color: var(--leaf); }
.ing img { width: 18px; height: 18px; image-rendering: pixelated; }
.need { font-size: .78rem; color: var(--amber); }
.inv-panel .close { position: absolute; top: 14px; right: 14px; min-height: 36px; padding: 4px 12px; font-size: .9rem; }
#held { position: fixed; left: 0; top: 0; width: 44px; height: 44px; display: grid; place-items: center; pointer-events: none; z-index: 40; }
#held img { width: 34px; height: 34px; image-rendering: pixelated; filter: drop-shadow(2px 3px 0 rgba(0,0,0,.4)); }
#held .n { position: absolute; right: 0; bottom: -2px; font-family: var(--display); font-weight: 600; text-shadow: 2px 2px 0 #333; }
#tooltip { position: fixed; left: 0; top: 0; z-index: 41; pointer-events: none; padding: 5px 9px; background: #1a0f22; border: 2px solid #2b0f5a; border-radius: 4px; font-family: var(--display); font-size: .92rem; white-space: nowrap; }

/* ---------- online lobby ---------- */
#title { align-items: safe center; }
.online { margin-top: 22px; padding: 16px; background: rgba(20,17,26,.85); border: 2px solid var(--edge); border-radius: 10px; }
.online-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.online h2 { font-family: var(--display); font-size: 1.35rem; margin: 0; }
.online .hint { margin: 6px 0 12px; }
.online-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.field { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .92rem; }
.online input[type="text"], .online input:not([type]) { min-height: 40px; padding: 6px 10px; border: 2px solid var(--edge-hi); border-radius: 6px; background: #120f17; color: var(--ink); font: inherit; font-family: var(--display); }
#opt-name { width: 11em; }
#opt-code { width: 5.2em; text-transform: uppercase; letter-spacing: .15em; text-align: center; }
.online input:focus-visible { outline: 3px solid var(--amber); outline-offset: 1px; }
.or { color: var(--muted); font-size: .88rem; }
.games-head { font-family: var(--display); font-size: 1rem; margin: 8px 0 6px; color: var(--muted); font-weight: 500; }
#games { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 210px; overflow-y: auto; }
#games li { display: grid; grid-template-columns: 1fr auto auto auto; gap: 10px; align-items: center; padding: 6px 6px 6px 12px; background: var(--stone-2); border: 1px solid var(--edge); border-radius: 6px; }
#games li.empty { display: block; color: var(--muted); font-size: .9rem; padding: 10px 12px; }
#games .g-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--display); }
#games .g-code { font-family: var(--display); letter-spacing: .12em; color: var(--amber); font-size: .9rem; }
#games .g-n { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .9rem; }
#games .btn { min-height: 36px; padding: 4px 14px; }
#load-steps.nocam [data-step="cam"], #load-steps.nocam [data-step="ai"] { display: none; }
#net-chip { font-size: .8rem; }

/* ---------- touch buttons ---------- */
#touch { position: fixed; inset: auto 0 0 0; pointer-events: none; z-index: 7; }
.pad { position: absolute; bottom: max(14px, env(safe-area-inset-bottom, 0px)); display: flex; gap: 10px; pointer-events: auto; }
.pad-left { left: max(14px, env(safe-area-inset-left, 0px)); }
.pad-right { right: max(14px, env(safe-area-inset-right, 0px)); flex-wrap: wrap; justify-content: flex-end; width: 160px; }
.tb { width: 68px; height: 68px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35); background: rgba(16,13,20,.55); color: #fff; font-family: var(--display); font-size: 1.05rem; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.tb.small { width: 54px; height: 54px; font-size: .85rem; }
.tb.down { background: rgba(255,181,71,.55); border-color: var(--amber); }
body.touch canvas#game { touch-action: none; }
body.touch .menu-btn { min-height: 40px; }
/* in portrait the hotbar takes the bottom middle, so lift the buttons above it */
@media (orientation: portrait) { .pad { bottom: calc(118px + env(safe-area-inset-bottom, 0px)); } }

@media (max-width: 720px) {
  .slot, .grid { --s: 36px; }
  .slot { width: 36px; height: 36px; }
  .grid { grid-template-columns: repeat(9, 36px); }
  .slot img { width: 24px; height: 24px; }
  #pip { width: 120px; }
  .keys-card { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
