/* Bundled retro fonts (SIL Open Font License 1.1, see content/fonts/LICENSES.txt). Missing files fall back to the next font. */
@font-face { font-family: "VT323"; src: url("content/fonts/vt323.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Press Start 2P"; src: url("content/fonts/press-start-2p.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Silkscreen"; src: url("content/fonts/silkscreen.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Share Tech Mono"; src: url("content/fonts/share-tech-mono.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Pixelify Sans"; src: url("content/fonts/pixelify-sans.woff2") format("woff2"); font-display: swap; }

:root {
  --font: "Courier New", monospace;
  --fs: 16px;
  --screen-bg: #0b3d91;
  --boot-text: #7cfc9a;
  --win-bg: #e8e4d4;
  --title-bg: #222222;
  --title-fg: #ffffff;
  --text: #111111;
  --accent: #ffcc00;
  --icon-text: #ffffff;
  --page-bg: #15110d;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--page-bg); font-family: var(--font); }
.noscript { color: #fff; padding: 20px; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
[hidden] { display: none !important; }

#small-note { display: none; position: fixed; inset: 0; align-items: center; justify-content: center; padding: 24px; text-align: center; color: #cfc6a8; font-size: 18px; background: var(--page-bg); }
#stagewrap { position: fixed; inset: 0; }
#stage { position: absolute; inset: 0; overflow: hidden; }
#stage.busy { pointer-events: none; }
#fx-canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; pointer-events: none; opacity: 0; z-index: 50; }
#mute { position: absolute; top: 10px; right: 10px; z-index: 60; font: 12px/1 "Courier New", monospace; padding: 5px 9px; color: #fff; background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.5); cursor: pointer; border-radius: 3px; }

/* ---- scenes ---- */
.wrap { position: absolute; overflow: hidden; }
.wrap.edit { overflow: visible; }
.scene { position: absolute; overflow: hidden; user-select: none; font-family: var(--font); font-size: var(--fs); color: var(--text); }
.scene.top { left: 50%; top: 50%; transform-origin: center center; }
.scene.nested { left: 0; top: 0; pointer-events: auto; }
.wrap.edit .scene.top { overflow: visible; box-shadow: 0 6px 30px rgba(0,0,0,.35); }
.wrap.edit .scene.top > .bg { box-shadow: none; }
.scene > .bg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; object-fit: fill; }

/* ---- objects ---- */
.obj { position: absolute; pointer-events: none; }
.obj.hit, .obj.act { pointer-events: auto; }
.obj.act { cursor: pointer; }
.obj.hidden { display: none; }
.obj.ghost { opacity: .3 !important; }
.fx { position: absolute; inset: 0; }
.fxl, .fxg { overflow: visible; }
.obj > .fx { pointer-events: inherit; }
.c-shape, .c-image, .c-video, .c-frame, .c-text, .c-icon { position: absolute; inset: 0; }
.c-shape.invisible { background: none; }
.wrap.edit .c-shape.invisible { outline: 1px dashed rgba(255,255,255,.55); background: rgba(120,160,255,.12); }
.c-text { font-family: var(--font); white-space: pre-wrap; word-break: break-word; line-height: 1.15; }
.c-text .b { visibility: hidden; }
.c-text.shadow { text-shadow: 0 0 4px #000, 0 0 2px #000; }
.c-image img, .c-video video { display: block; width: 100%; height: 100%; pointer-events: none; }
.c-video video { background: #000; }
.obj.hit .c-video video { pointer-events: auto; }
.c-frame { overflow: hidden; }
.c-icon { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; font-family: var(--font); text-align: center; }
.c-icon canvas, .c-icon img { display: block; width: 70%; height: auto; max-height: 76%; aspect-ratio: 1; margin: 0 auto 4px; image-rendering: pixelated; object-fit: contain; }
.c-icon .lbl { display: block; line-height: 1.1; word-break: break-word; text-shadow: 1px 1px 0 #000; }
.c-sound { display: none; }
.wrap.edit .c-sound { display: flex; align-items: center; justify-content: center; border: 2px dashed #7aa7ff; color: #7aa7ff; font: 600 14px system-ui, sans-serif; background: rgba(0,0,0,.35); }
.wrap.edit .scene, .wrap.edit .scene * { pointer-events: none; }
.wrap.edit .scene.top { pointer-events: auto; }

/* ---- effects ---- */
.ov { position: absolute; inset: 0; pointer-events: none; }
.ov-scan { background: repeating-linear-gradient(to bottom, rgba(0,0,0,var(--sa, .25)) 0 1px, transparent 1px 3px), radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,var(--sa, .25)) 100%); animation: rs-scanflick 6s infinite; z-index: 5; }
.ov-tint { mix-blend-mode: multiply; z-index: 4; }
.scene-ov { z-index: 1000; }
@keyframes rs-scanflick { 0%, 100% { opacity: 1; } 47% { opacity: .9; } 50% { opacity: .75; } 53% { opacity: .95; } }
@keyframes rs-glow { 0%, 100% { box-shadow: 0 0 calc(var(--r) * .35) 0 var(--c); } 50% { box-shadow: 0 0 var(--r) calc(var(--r) * .25) var(--c); } }
@keyframes rs-glowf { 0%, 100% { filter: drop-shadow(0 0 calc(var(--r) * .35) var(--c)); } 50% { filter: drop-shadow(0 0 var(--r) var(--c)); } }
@keyframes rs-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(calc(var(--a) * -1)); } }
@keyframes rs-drift { from { transform: translateX(calc(var(--a) * -1)); } to { transform: translateX(var(--a)); } }
@keyframes rs-spin { to { transform: rotate(360deg); } }
@keyframes rs-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(var(--s)); } }
@keyframes rs-sway { 0%, 100% { transform: rotate(calc(var(--d) * -1)); } 50% { transform: rotate(var(--d)); } }
@keyframes rs-shake { 0%, 100% { transform: translate(0, 0); } 20% { transform: translate(var(--a), calc(var(--a) * -.5)); } 40% { transform: translate(calc(var(--a) * -1), calc(var(--a) * .4)); } 60% { transform: translate(calc(var(--a) * .6), calc(var(--a) * .6)); } 80% { transform: translate(calc(var(--a) * -.6), calc(var(--a) * -.4)); } }
@keyframes rs-flicker { 0%, 100% { opacity: 1; } 7% { opacity: .5; } 9% { opacity: 1; } 31% { opacity: .85; } 33% { opacity: .35; } 35% { opacity: 1; } 62% { opacity: .7; } 64% { opacity: 1; } }
@keyframes rs-glitch {
  0%, 86%, 100% { transform: none; filter: none; }
  87% { transform: translate(calc(var(--a) * -1), 1px) skewX(8deg); filter: hue-rotate(90deg) saturate(2); }
  89% { transform: translate(var(--a), -1px); filter: hue-rotate(-60deg); }
  91% { transform: translate(calc(var(--a) * -.5), 0) skewX(-6deg); filter: invert(.15) hue-rotate(160deg); }
  94% { transform: none; filter: none; }
}

/* ---- windows (floating on any scene, or inside a TV) ---- */
.fwin { position: absolute; inset: 0; pointer-events: none; z-index: 800; font-family: var(--font); font-size: var(--fs); }
.win { position: absolute; display: flex; flex-direction: column; background: var(--win-bg); color: var(--text); pointer-events: auto; }
.ws-retro { border: 2px solid var(--text); box-shadow: 4px 4px 0 rgba(0,0,0,.5); }
.ws-plain { border: 1px solid rgba(0,0,0,.35); border-radius: 8px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,.45); }
.ws-borderless { background: transparent; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.ws-borderless .titlebar { position: absolute; top: 0; right: 0; background: transparent; padding: 4px; opacity: 0; transition: opacity .2s; z-index: 2; }
.ws-borderless:hover .titlebar { opacity: 1; }
.ws-borderless .titlebar .t { display: none; }
.titlebar { display: flex; align-items: center; gap: 6px; padding: 2px 4px; background: var(--title-bg); color: var(--title-fg); cursor: move; user-select: none; touch-action: none; font-size: calc(var(--fs) * .8); }
.ws-plain .titlebar { padding: 5px 8px; }
.titlebar .t { flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-btn { width: 18px; height: 18px; padding: 0; line-height: 1; font: inherit; font-size: 12px; color: var(--title-fg); background: rgba(0,0,0,.4); border: 2px solid var(--title-fg); cursor: pointer; }
.body { flex: 1; min-height: 0; overflow: auto; position: relative; }
.body img.view, .body video { display: block; width: 100%; height: 100%; object-fit: contain; background: #000; }
.body pre { margin: 0; padding: 10px; white-space: pre-wrap; word-break: break-word; font: inherit; font-size: calc(var(--fs) * .85); }
.audio-box { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; height: 100%; padding: 12px; }
.audio-box audio { width: 100%; }
.audio-box canvas { width: 48px; height: 48px; image-rendering: pixelated; }
.err { padding: 12px; }
.body > .scene.nested { position: absolute; }
.lightbox { position: absolute; inset: 0; z-index: 900; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.88); font-family: var(--font); }
.lightbox .lb-body { max-width: 94%; max-height: 92%; width: 94%; height: 92%; display: flex; align-items: center; justify-content: center; color: #fff; position: relative; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox pre { max-height: 100%; overflow: auto; white-space: pre-wrap; padding: 24px; font: inherit; font-size: 28px; background: var(--win-bg); color: var(--text); }
.lightbox .lb-x { position: absolute; top: 14px; right: 18px; width: 36px; height: 36px; font: 20px monospace; color: #fff; background: rgba(0,0,0,.5); border: 2px solid #fff; cursor: pointer; }

/* ---- desktop only ---- */
@media (max-width: 899px) {
  #stagewrap { display: none; }
  #small-note { display: flex; }
}
@media (prefers-reduced-motion: reduce) {
  .fx, .ov-scan, .scene { animation: none !important; }
}
