@font-face { font-family: "Press Start 2P"; src: url(/fonts/PressStart2P-Regular.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "VT323"; src: url(/fonts/VT323-Regular.woff2) format("woff2"); font-display: swap; }

:root {
  --bg: #000;
  --panel: #0a0a10;
  --line: #22222e;
  --text: #e8e6e3;
  --dim: #8a8a9c;
  --or: #ff7a18;
  --or-hi: #ffb347;
  --or-lo: #a84300;
  --bl: #2ea8ff;
  --bl-hi: #8fd8ff;
  --bl-lo: #0b5c99;
  --pixel: "Press Start 2P", ui-monospace, monospace;
  --mono: "VT323", ui-monospace, monospace;
  --cur: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='22' viewBox='-1 -1 16 22' shape-rendering='crispEdges'%3E%3Cpath d='M0 0h2v2h2v2h2v2h2v2h2v2h2v2h2v2h-6v2h2v2h2v2h-4v-2h-2v-2h-2v2h-2v2h-2z' fill='%23ff7a18' stroke='%23000'/%3E%3C/svg%3E") 0 0, auto;
  --cur-link: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='22' viewBox='-1 -1 16 22' shape-rendering='crispEdges'%3E%3Cpath d='M0 0h2v2h2v2h2v2h2v2h2v2h2v2h2v2h-6v2h2v2h2v2h-4v-2h-2v-2h-2v2h-2v2h-2z' fill='%232ea8ff' stroke='%23000'/%3E%3C/svg%3E") 0 0, pointer;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 22px/1.35 var(--mono); overflow-x: hidden; cursor: var(--cur);
}
a, button, select, label { cursor: var(--cur-link); }
input[type="text"], textarea { cursor: text; }
a { color: var(--bl); }
a:hover { color: var(--or); }
::selection { background: var(--or); color: #000; }
:focus-visible { outline: 4px dashed var(--bl); outline-offset: 4px; }
h1, h2, h3, h4 { font-family: var(--pixel); font-weight: normal; }
.sep { color: var(--line); padding: 0 .4em; }
/* ---------- background layers ---------- */
#stars, #fx { position: fixed; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; pointer-events: none; }
#stars { z-index: -1; }
#fx { z-index: 99999; }
.crt {
  position: fixed; inset: 0; pointer-events: none; z-index: 100001;
  background:
    repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0 2px, rgba(0,0,0,.28) 2px 4px),
    radial-gradient(ellipse at center, rgba(0,0,0,0) 60%, rgba(0,0,0,.55) 100%);
  animation: flicker 6s steps(1) infinite;
}
@keyframes flicker { 0%, 100% { opacity: 1; } 47% { opacity: .85; } 48% { opacity: 1; } 73% { opacity: .92; } 74% { opacity: 1; } }

/* ---------- pixel frame: notched 4px border via box-shadow ---------- */
.px {
  --c: var(--line);
  background: var(--panel);
  margin: 4px;
  box-shadow: 0 -4px 0 0 var(--c), 0 4px 0 0 var(--c), -4px 0 0 0 var(--c), 4px 0 0 0 var(--c);
}

/* ---------- buttons ---------- */
.btn {
  --f: var(--or); --hi: var(--or-hi); --lo: var(--or-lo);
  display: inline-block; font: 12px/1 var(--pixel); color: #000; text-decoration: none;
  background: var(--f); border: 0; padding: 14px 18px; margin: 4px;
  box-shadow: inset -4px -4px 0 0 var(--lo), inset 4px 4px 0 0 var(--hi),
              0 -4px 0 0 #000, 0 4px 0 0 #000, -4px 0 0 0 #000, 4px 0 0 0 #000;
  transition: transform .08s steps(2);
}
.btn:hover { color: #000; transform: translateY(-2px); }
.btn:active { transform: translateY(2px); box-shadow: inset 4px 4px 0 0 var(--lo), inset -4px -4px 0 0 var(--hi), 0 -4px 0 0 #000, 0 4px 0 0 #000, -4px 0 0 0 #000, 4px 0 0 0 #000; }
.btn.alt, .btn[aria-selected="false"], .btn[data-tool]:not(.on) { --f: var(--bl); --hi: var(--bl-hi); --lo: var(--bl-lo); }
.btn.sm { font-size: 10px; padding: 10px 12px; }
.btn[aria-pressed="true"] { --f: var(--or); --hi: var(--or-hi); --lo: var(--or-lo); }

/* ---------- wallpaper title ---------- */
.glitch {
  position: relative; margin: 0 0 16px; font-size: clamp(32px, 9vw, 110px); line-height: 1.1; color: var(--text);
  text-shadow: 4px 4px 0 var(--or), 8px 8px 0 var(--bl);
  animation: boot 1s steps(8) both;
}
.glitch::before, .glitch::after { content: attr(data-text); position: absolute; inset: 0; text-shadow: none; clip-path: inset(0 0 100% 0); }
.glitch::before { color: var(--or); animation: g1 3.1s steps(1) infinite 1s; }
.glitch::after { color: var(--bl); animation: g2 2.3s steps(1) infinite 1.4s; }
@keyframes boot { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes g1 {
  0%, 86%, 100% { clip-path: inset(0 0 100% 0); transform: none; }
  87% { clip-path: inset(10% 0 70% 0); transform: translate(-8px, 0); }
  89% { clip-path: inset(55% 0 25% 0); transform: translate(8px, 0); }
  91% { clip-path: inset(30% 0 50% 0); transform: translate(-4px, 0); }
  93% { clip-path: inset(80% 0 5% 0); transform: translate(6px, 0); }
}
@keyframes g2 {
  0%, 80%, 100% { clip-path: inset(0 0 100% 0); transform: none; }
  81% { clip-path: inset(65% 0 15% 0); transform: translate(8px, 0); }
  83% { clip-path: inset(5% 0 80% 0); transform: translate(-8px, 0); }
  85% { clip-path: inset(40% 0 40% 0); transform: translate(4px, 0); }
}
.type { font-size: 30px; color: var(--bl); min-height: 1.4em; margin: 0; }
.caret { color: var(--or); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.blink { animation: blink 1s steps(2) infinite; font-family: var(--pixel); font-size: 12px; color: var(--or); }

/* ---------- shared content ---------- */
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 8px 0; }
.dim { color: var(--dim); }
code { font: inherit; color: var(--or-hi); }
.readme h2 { font-size: 16px; color: var(--or); margin: 4px 0 16px; }
.readme p { margin: 0 0 14px; }
.email { font: 14px var(--pixel); color: var(--or); margin-right: 12px; word-break: break-all; }

/* ---------- no-JS / base layout: plain stacked page ---------- */
html:not(.js) .os-only, html:not(.js) .ident { display: none !important; }
.wall { text-align: center; padding: 60px 20px 30px; }
.win { width: min(1100px, 100% - 32px); margin: 0 auto 32px; background: var(--panel); border: 4px solid var(--line); }
.tb { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 10px; background: var(--line); font: 10px var(--pixel); color: var(--text); user-select: none; }
.tt { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wb { padding: 18px; container-type: inline-size; }

/* ---------- desktop (JS on) ---------- */
.js body { overflow: hidden; height: 100vh; height: 100dvh; }
.js #desktop { position: fixed; inset: 0 0 48px 0; }
.js .wall { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0 20px; pointer-events: none; }
#icons { list-style: none; margin: 0; padding: 12px; position: absolute; inset: 0 auto 0 0; display: grid; grid-auto-flow: column;
  grid-template-rows: repeat(auto-fill, 96px); grid-auto-columns: 96px; gap: 4px; align-content: start; }
.icon { width: 96px; height: 96px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: none; border: 0; padding: 4px; color: var(--text); font: 8px/1.3 var(--pixel); text-align: center; }
.icon canvas, .ico { image-rendering: pixelated; flex: none; }
.icon canvas { width: 48px; height: 48px; filter: drop-shadow(3px 3px 0 #000); }
.icon span { padding: 2px 3px; text-shadow: 2px 2px 0 #000; }
.icon small { font: inherit; }
.icon:hover span { background: var(--bl-lo); }
.icon.sel span, .icon:focus-visible span { background: var(--or); color: #000; text-shadow: none; }
.icon:focus-visible { outline: none; }

.js .win {
  position: absolute; margin: 0; display: flex; flex-direction: column; border: 0;
  min-width: 260px; min-height: 140px; max-width: 100%; max-height: 100%;
  resize: both; overflow: hidden;
  box-shadow: 0 -4px 0 0 var(--line), 0 4px 0 0 var(--line), -4px 0 0 0 var(--line), 4px 0 0 0 var(--line), 10px 10px 0 4px #0009;
  animation: winOpen .2s steps(4);
}
.js .win:not(.open) { display: none; }
.js .win.active { box-shadow: 0 -4px 0 0 var(--or), 0 4px 0 0 var(--or), -4px 0 0 0 var(--or), 4px 0 0 0 var(--or), 10px 10px 0 4px #0009; }
@keyframes winOpen { from { transform: scale(.85); opacity: 0; } }
.js .tb { cursor: var(--cur-link); touch-action: none; background: var(--line); color: var(--dim); }
.js .win.active .tb { background: repeating-linear-gradient(0deg, var(--or) 0 2px, var(--or-hi) 2px 4px); color: #000; }
.tb .ico, #tasks .ico, #startBtn .ico { width: 16px; height: 16px; }
.tb button { width: 24px; height: 22px; padding: 0; border: 0; font: 10px var(--pixel); color: var(--text); background: var(--panel);
  box-shadow: inset -2px -2px 0 #000, inset 2px 2px 0 #5a5a6e; }
.tb button:hover { background: var(--bl-lo); }
.tb button.x:hover { background: #ff3b5c; color: #000; }
.tb .x .m { display: none; }
.js .wb { flex: 1; overflow: auto; min-height: 0; }
.win.max { inset: 0 !important; width: auto !important; height: auto !important; resize: none; }
#snap { position: fixed; z-index: 99998; border: 4px dashed var(--bl); background: #2ea8ff14; pointer-events: none; }
#snap[hidden] { display: none; }

/* window default sizes */
.js #w-about { width: 560px; height: 420px; }
.js #w-projects { width: 760px; height: 520px; }
.js #w-mail { width: 480px; height: 220px; }
.js #w-term { width: 640px; height: 400px; }
.js #w-pixel, .js #w-encode, .js #w-color, .js #w-pass { width: 920px; height: 640px; }
.js #w-sys { width: 980px; height: 640px; }

/* taskbar */
#taskbar {
  position: fixed; left: 0; right: 0; bottom: 0; height: 48px; z-index: 100000; display: flex; align-items: center; gap: 6px; padding: 0 8px;
  background: #000; border-top: 4px solid;
  border-image: repeating-linear-gradient(90deg, var(--or) 0 8px, transparent 8px 16px, var(--bl) 16px 24px, transparent 24px 32px) 4;
}
#startBtn { display: inline-flex; align-items: center; gap: 8px; margin: 0 6px 0 4px; padding: 6px 10px; }
#startBtn[aria-expanded="true"] { --f: var(--or-hi); }
#tasks { flex: 1; min-width: 0; display: flex; gap: 6px; overflow: hidden; }
#tasks button { display: flex; align-items: center; gap: 6px; min-width: 0; max-width: 170px; padding: 4px 8px; height: 30px;
  font: 8px var(--pixel); color: var(--text); background: var(--panel); border: 0; box-shadow: inset -2px -2px 0 #000, inset 2px 2px 0 #5a5a6e; }
#tasks button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tasks button.on { background: var(--or); color: #000; box-shadow: inset 2px 2px 0 var(--or-lo), inset -2px -2px 0 var(--or-hi); }
#tasks button.min { opacity: .6; }
#tray { display: flex; align-items: center; gap: 14px; padding: 0 6px; color: var(--dim); font-size: 20px; white-space: nowrap; }
#tray b { color: var(--or); font-weight: normal; }
#clock { color: var(--text); }

/* menus */
.menu { position: fixed; z-index: 100000; min-width: 220px; padding: 6px; }
.menu[hidden] { display: none; }
.menu button, .menu a { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 10px; border: 0; background: none;
  color: var(--text); font: 9px var(--pixel); text-align: left; text-decoration: none; }
.menu button:hover, .menu a:hover, .menu button:focus-visible, .menu a:focus-visible { background: var(--or); color: #000; outline: none; }
.menu hr { border: 0; border-top: 2px dashed var(--line); margin: 6px 0; }
.menu .ico { width: 24px; height: 24px; display: inline-block; }
#startMenu { left: 6px; bottom: 54px; display: grid; grid-template-columns: 30px 1fr; padding: 0; }
#startMenu[hidden] { display: none; }
.banner { writing-mode: vertical-rl; transform: rotate(180deg); background: linear-gradient(var(--bl), var(--bl-lo)); color: #000;
  font: 11px var(--pixel); padding: 10px 8px; letter-spacing: 2px; }
.banner b { color: var(--or-hi); font-weight: normal; }
#startMenu .items { padding: 6px; }
#startMenu small { display: block; font: 16px var(--mono); color: var(--dim); padding: 4px 10px 0; }

/* boot + halt screens */
#boot, #halt { position: fixed; inset: 0; z-index: 100003; background: #000; color: var(--text); padding: 28px; font-size: 22px; }
#boot .ok { color: #3bff8a; }
#boot .skip { color: var(--dim); margin-top: 16px; }
#boot.off { opacity: 0; transition: opacity .25s steps(3); }
#halt { display: grid; place-items: center; text-align: center; font: 12px/2 var(--pixel); color: var(--dim); }

body.turbo { --or: #ff2fd0; --or-hi: #ff8fe8; --or-lo: #8c0071; }
body.wall-grid #stars, body.wall-plain #stars { display: none; }
body.wall-grid { background: #000 repeating-conic-gradient(#0b0b14 0 25%, #000 0 50%) 0 0 / 32px 32px; }

/* ---------- phone: home screen + full-screen apps ---------- */
@media (max-width: 700px) {
  .js #desktop { inset: 32px 0 0 0; overflow-y: auto; }
  .js .wall { position: static; padding: 28px 16px 8px; }
  .glitch { font-size: 40px; }
  .type { font-size: 24px; }
  #icons { position: static; grid-auto-flow: row; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: none; grid-auto-columns: auto; padding: 16px 8px; gap: 12px 0; }
  .icon { width: 100%; height: auto; }
  .icon canvas { width: 56px; height: 56px; }
  .icon small { display: none; }
  #taskbar { top: 0; bottom: auto; height: 32px; border-top: 0; border-bottom: 4px solid; }
  #startBtn, #tasks, #ctx, #startMenu { display: none !important; }
  #tray { width: 100%; justify-content: space-between; font-size: 18px; }
  .js .win { position: fixed; inset: 32px 0 0 0 !important; width: auto !important; height: auto !important; resize: none;
    box-shadow: none !important; animation: slideUp .2s steps(4); }
  @keyframes slideUp { from { transform: translateY(30%); opacity: 0; } }
  .js .win .tb { padding: 8px; background: var(--or); color: #000; }
  .tb .min, .tb .max { display: none; }
  .tb .x { order: -1; width: auto; padding: 0 10px; height: 28px; }
  .tb .x .d { display: none; }
  .tb .x .m { display: inline; }
  .wb { padding: 14px; }
  #toast { bottom: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Lite mode: static, no per-frame work. */
.lite *, .lite *::before, .lite *::after { animation: none !important; transition: none !important; }
.lite #fx { display: none; }
