:root {
  --doom-red: #b0000c;
  --doom-gold: #e8c060;
  --panel: rgba(20, 12, 8, 0.92);
  --edge: #6b4a2a;
  --text: #f0e0c0;
  --muted: #a89070;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; color: var(--text); overflow: hidden; font: 15px/1.35 "Courier New", ui-monospace, monospace; -webkit-tap-highlight-color: transparent; }
#app { position: fixed; inset: 0; height: 100dvh; }
#view, #hud { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; }
#view { touch-action: none; }
#hud { pointer-events: none; }
.hidden { display: none !important; }

#loading { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: #000; z-index: 50; }
.ltitle { font-size: 34px; font-weight: bold; letter-spacing: 6px; color: var(--doom-red); text-shadow: 3px 3px 0 #300; }
.lbar { width: min(70vw, 360px); height: 10px; border: 2px solid var(--edge); }
#lfill { height: 100%; width: 0; background: var(--doom-red); transition: width .15s; }
#lstage { color: var(--muted); min-height: 1.4em; text-align: center; max-width: 90vw; }
#loading.indeterminate #lfill { width: 30% !important; animation: lsweep 1.1s linear infinite; }
@keyframes lsweep { from { margin-left: -30%; } to { margin-left: 100%; } }
.lbar { overflow: hidden; }
.lhelp { color: var(--muted); font-size: 12px; opacity: .75; text-align: center; max-width: 90vw; }
#lretry { font: bold 15px "Courier New", monospace; color: var(--doom-gold); background: rgba(60, 20, 10, 0.8); border: 2px solid var(--edge); padding: 8px 16px; cursor: pointer; }
/* Background download of the remaining assets (menus only, not over play). */
#store { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(6px + var(--safe-b)); z-index: 40; width: max-content; max-width: calc(100vw - 32px); padding: 3px 10px; font-size: 12px; color: var(--muted); background: rgba(0, 0, 0, 0.7); border: 1px solid var(--edge); text-align: center; pointer-events: none; }
#store button { pointer-events: auto; margin-left: 8px; font: inherit; color: var(--doom-gold); background: none; border: 1px solid var(--edge); cursor: pointer; }

#touch { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.tbtn { position: absolute; pointer-events: auto; border: 3px solid var(--edge); background: rgba(60, 20, 10, 0.55); color: var(--doom-gold); font: bold 16px "Courier New", monospace; border-radius: 50%; touch-action: none; user-select: none; -webkit-user-select: none; }
.tbtn.fire { right: 16px; bottom: calc(18% + var(--safe-b)); width: 84px; height: 84px; }
.tbtn.weapon { right: 112px; bottom: calc(18% + var(--safe-b)); width: 56px; height: 56px; font-size: 13px; }
.tbtn.pause { right: 14px; top: calc(10px + var(--safe-t)); width: 46px; height: 46px; border-radius: 8px; }
.tbtn:active, .tbtn.on { background: rgba(176, 0, 12, 0.7); }
.thint { position: absolute; left: 0; right: 0; top: calc(56px + var(--safe-t)); text-align: center; color: var(--doom-gold); text-shadow: 2px 2px 0 #000; font-size: 14px; transition: opacity 1s; }

#screens { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
/* DOOM-font text (ui.mjs doomify): word canvases sized in em; 16px = 2x the 8px font. */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.dword { image-rendering: pixelated; image-rendering: crisp-edges; vertical-align: -0.12em; }
.dtext.dim .dword { opacity: .62; }
.screen, .toast, #store, #touch { font-size: 16px; }
.screen { padding-bottom: calc(56px + var(--safe-b)) !important; } /* room for the #store line */
/* DOOM frames (ui.mjs frames()): BRDR_* around panels and cards, the save-slot
   box for buttons and tabs; drawn 2x, over the FLOOR4_8 pattern. States that
   used border colours become outlines. */
.doom-frames .panel, .doom-frames .card, .doom-frames #store, .doom-frames .toast {
  background: none; box-shadow: none; border: 6px solid transparent;
  border-image: var(--doom-frame) 3 fill / 6px round; image-rendering: pixelated;
}
.doom-frames .card.sel, .doom-frames .card.equipped { outline: 2px solid var(--doom-gold); outline-offset: -2px; }
.doom-frames .btn, .doom-frames .tab {
  background: none; border: 0 solid transparent; border-width: 0 16px;
  border-image: var(--doom-slot) 0 8 fill / 0 16px stretch; padding: 8px 4px; image-rendering: pixelated;
}
.doom-frames .btn.primary, .doom-frames .tab.on { outline: 2px solid var(--doom-red); outline-offset: 2px; }
.doom-frames .btn:hover:not(:disabled), .doom-frames .btn:focus-visible, .doom-frames .tab:hover { background: none; outline: 2px solid var(--doom-gold); outline-offset: 2px; }
.doom-frames .tabs { background: rgba(12, 6, 3, 0.92); border-bottom: 0; } /* sticky: stays opaque over scrolled cards */
.screen { position: absolute; inset: 0; pointer-events: auto; overflow-y: auto; -webkit-overflow-scrolling: touch; background-color: #1a0f08; background-size: 128px 128px; image-rendering: pixelated; padding: calc(12px + var(--safe-t)) 14px calc(16px + var(--safe-b)); }
.screen.dim { background-color: rgba(0, 0, 0, 0.72); background-image: none !important; }
.wrap { max-width: 860px; margin: 0 auto; }
.center { text-align: center; }
.logo { display: block; margin: 8px auto 4px; image-rendering: pixelated; max-width: 92vw; height: auto; }
.gfx { image-rendering: pixelated; vertical-align: middle; }
.doomtext { image-rendering: pixelated; display: inline-block; vertical-align: middle; }
h2.dt, h3.dt { margin: 10px 0 6px; font-weight: normal; }
.menu { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 10px 0; }
button.mi { background: none; border: 0; padding: 6px 10px; cursor: pointer; min-height: 44px; display: flex; align-items: center; gap: 8px; color: var(--text); font: inherit; }
button.mi:focus-visible, button.mi:hover { outline: 2px solid var(--doom-red); }
.skull { display: inline-grid; visibility: hidden; flex: none; }
.skull > canvas { grid-area: 1 / 1; }
/* M_SKULL1/M_SKULL2 alternate like DOOM's blinking cursor. */
.skull > canvas:last-child { animation: skullblink .46s steps(1) infinite; }
@keyframes skullblink { 0% { opacity: 0; } 50% { opacity: 1; } }
button.mi:hover .skull, button.mi:focus-visible .skull, button.mi.sel .skull, .thermo-row:focus-within .skull { visibility: visible; }
.dmenu { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: fit-content; max-width: 100%; margin: 0 auto; }
.dmenu button.mi.opt { width: 100%; justify-content: flex-start; }
.dmenu button.mi.opt .state { margin-left: auto; padding-left: 16px; }
.mi-label { display: flex; align-items: center; gap: 8px; padding: 6px 10px 0; }
.thermo-row { display: flex; flex-direction: column; }
.thermo { margin: 4px 0 6px 10px; max-width: calc(100% - 10px); image-rendering: pixelated; cursor: pointer; touch-action: none; }
.thermo:focus-visible { outline: 2px solid var(--doom-red); }
.thermo.off { opacity: .4; }
/* Narrow phones: draw the menu graphics at 1.5x instead of 2x so ON/OFF fit. */
@media (max-width: 480px) { .dmenu { zoom: 0.75; } }
.panel { background: var(--panel); border: 3px solid var(--edge); padding: 10px 12px; margin: 10px 0; box-shadow: inset 0 0 0 2px #2a1a10; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); gap: 8px; }
.card { background: #24150c; border: 2px solid var(--edge); padding: 8px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.card.equipped { border-color: var(--doom-gold); }
.card .head { display: flex; gap: 8px; align-items: center; }
.card .icon { width: 56px; height: 40px; display: flex; align-items: center; justify-content: center; flex: none; }
.card .icon canvas { max-width: 56px; max-height: 40px; image-rendering: pixelated; }
.card .name { font-weight: bold; overflow-wrap: anywhere; }
.card .stats { color: var(--muted); font-size: 12px; }
.card .acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.btn { background: #4a1a0c; color: var(--doom-gold); border: 2px solid var(--edge); padding: 8px 12px; min-height: 44px; min-width: 44px; font: bold 16px "Courier New", monospace; cursor: pointer; }
.btn:hover:not(:disabled), .btn:focus-visible { background: var(--doom-red); color: #fff; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--doom-red); color: #fff; font-size: 16px; padding: 10px 18px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 3px solid var(--edge); margin-top: 8px; position: sticky; top: calc(-12px - var(--safe-t)); background: #1a0f08; padding-top: 6px; z-index: 2; }
.tab { background: #2a160c; color: var(--muted); border: 2px solid var(--edge); border-bottom: 0; padding: 8px 10px; min-height: 44px; font: bold 16px "Courier New", monospace; cursor: pointer; }
.tab.on { background: var(--doom-red); color: #fff; }
.credits { color: var(--doom-gold); font-weight: bold; }
.good { color: #7fe07f; } .bad { color: #ff7a6a; } .muted { color: var(--muted); }
.cmp { font-size: 12px; padding: 2px 6px; border: 1px solid currentColor; display: inline-block; }
.note { font-size: 12px; color: var(--muted); margin-top: 14px; }
table.stats { border-collapse: collapse; width: 100%; font-size: 14px; }
table.stats td { padding: 3px 6px; border-bottom: 1px solid #3a2414; vertical-align: top; }
.toast { position: absolute; left: 50%; transform: translateX(-50%); top: calc(64px + var(--safe-t)); background: var(--panel); border: 2px solid var(--doom-gold); padding: 6px 12px; z-index: 20; pointer-events: none; max-width: 92vw; text-align: center; }
.choice { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.choice .card { width: min(100%, 250px); cursor: pointer; }
.choice .card.sel { border-color: var(--doom-gold); background: #3a1c0c; }
@media (max-width: 520px) { body { font-size: 14px; } .tabs .tab { flex: 1 1 30%; padding: 8px 4px; } }

/* Real byte progress of background asset-cache downloads. */
#store::after{content:"";position:absolute;left:0;bottom:0;height:3px;width:var(--store-progress,0%);background:var(--doom-red);transition:width .12s linear}

/* The boot screen is drawn with the selected IWAD's own menu/font pixels.
   Its tiny skin is inline, so it works before the main atlas/module downloads. */
.doom-loader-art{position:relative;width:min(640px,96vw,calc((100dvh - 16px)*320/280));aspect-ratio:320/280}
.doom-loader-art>canvas{display:block;width:100%;height:100%;image-rendering:pixelated;image-rendering:crisp-edges}
.doom-loader-ready>.ltitle,.doom-loader-ready>#lstage,.doom-loader-ready>.lbar,.doom-loader-ready>.lhelp{position:absolute!important;width:1px!important;height:1px!important;padding:0!important;margin:0!important;clip-path:inset(50%);overflow:hidden;white-space:nowrap}
.doom-loader-ready #lretry{position:absolute;bottom:6%;left:50%;transform:translateX(-50%);padding:6px 10px;background:#100c08;border:2px solid #6b4a2a;cursor:pointer;max-width:85%}
.doom-loader-ready #lretry canvas{display:block;width:auto;height:16px;max-width:100%;image-rendering:pixelated}
.doom-loader-ready #lretry:focus-visible{outline:2px solid #e8c060;outline-offset:3px}
