/* Catastrophe 98: desktop, windows, taskbar. */
#desk { background: var(--plum) url('../assets/os/wallpaper.webp') center / cover no-repeat; }
#desk.plain { background-image: none; }
#desk.glitch { animation: glitch 0.2s steps(4) infinite; }
@keyframes glitch {
  0% { transform: none; filter: none; }
  25% { transform: translate(-18px, 4px) skewX(3deg); filter: hue-rotate(100deg) saturate(3); }
  50% { transform: translate(12px, -3px); filter: invert(1); }
  75% { transform: translate(-6px, 8px) scaleY(1.03); filter: contrast(3) hue-rotate(-60deg); }
}

/* Desktop icons */
#icons { position: absolute; inset: 14px auto calc(var(--bar-h) + 10px) 10px; z-index: 1; margin: 0; padding: 0; list-style: none;
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(auto-fill, 92px); grid-auto-columns: 96px; gap: 4px; }
#icons button { width: 96px; height: 92px; padding: 4px 2px; border: 0; background: none; display: grid; justify-items: center; align-content: start; gap: 2px; }
#icons img { width: 54px; height: 54px; filter: drop-shadow(2px 3px 0 rgba(20, 8, 30, 0.45)); pointer-events: none; }
#icons span { padding: 0 4px 1px; font-size: 15px; line-height: 1.15; color: var(--paper); text-shadow: 1px 1px 0 var(--ink), 2px 2px 0 var(--ink); text-align: center; }
#icons button:focus-visible, #icons button.sel { outline: 0; }
#icons button:focus-visible span, #icons button.sel span { background: var(--plum-mid); outline: 1px dotted var(--paper); }
#icons button.sel img { filter: drop-shadow(2px 3px 0 rgba(20, 8, 30, 0.45)) sepia(1) hue-rotate(220deg) saturate(2.2); }
#icons.fell li { transition: transform 0.7s cubic-bezier(0.5, 0, 0.9, 0.4); transform: translateY(120vh) rotate(40deg); }

/* Windows */
#wins { position: absolute; inset: 0 0 var(--bar-h) 0; z-index: 10; }
.win { position: absolute; left: 0; top: 0; min-width: 200px; max-width: calc(100vw - 12px); padding: 6px; background: var(--putty); box-shadow: var(--out), var(--drop); }
.win.pop { animation: win-pop 0.12s cubic-bezier(0.2, 1.5, 0.5, 1); }
.win.shut { animation: win-shut 0.13s ease-in forwards; pointer-events: none; }
.win.dying { animation: win-die 0.7s ease-in forwards; pointer-events: none; }
.win.poof { animation: win-poof 0.2s ease-out forwards; pointer-events: none; }
.win.fall { animation: win-fall 1.5s cubic-bezier(0.6, 0, 0.9, 0.5) forwards; pointer-events: none; }
.win.wig { animation: win-wig 0.3s steps(6); }
@keyframes win-pop { from { transform: scale(0.7); opacity: 0.4; } }
@keyframes win-shut { to { transform: scale(0.92); opacity: 0; } }
@keyframes win-die { 0% { transform: none; } 25% { transform: scale(1.08, 0.86) rotate(-2deg); } 55% { transform: scale(1.22, 0.1); opacity: 1; } 100% { transform: scale(1.5, 0.02); opacity: 0; } }
@keyframes win-poof { to { transform: scale(1.35); opacity: 0; filter: blur(6px); } }
@keyframes win-fall { 20% { transform: rotate(-7deg); } 100% { transform: translateY(130vh) rotate(38deg); } }
@keyframes win-wig { 25% { transform: translateX(-6px) rotate(-1deg); } 50% { transform: translateX(6px) rotate(1deg); } 75% { transform: translateX(-3px); } }

.win-bar { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 4px 0 8px; color: var(--paper); font-weight: 600; letter-spacing: 0.02em;
  background: linear-gradient(90deg, var(--plum), var(--plum-mid)); touch-action: none; }
.win-title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.win-ico { width: 20px; height: 20px; }
.win-x { flex: none; width: 30px; height: 24px; padding: 0; border: 0; display: grid; place-items: center; background: var(--putty); color: var(--ink);
  box-shadow: inset -2px -2px 0 var(--putty-dk), inset 2px 2px 0 var(--putty-hi); }
.win-x:active { box-shadow: inset 2px 2px 0 var(--putty-dk), inset -2px -2px 0 var(--putty-hi); }
.win-x:focus-visible { outline: 2px dotted var(--paper); outline-offset: 2px; }
.win-x svg { display: block; pointer-events: none; }
.win-body { padding: 14px 12px 12px; }
.win-body small { display: block; margin-top: 6px; font-size: 14px; color: #5b5346; }

/* The villain: a window that is a cat. Tabby title bar, ears, and eyes that follow the mouse. */
.win.cat .win-bar { color: var(--ink); text-shadow: 1px 1px 0 var(--tabby-hi);
  background: repeating-linear-gradient(112deg, var(--tabby) 0 20px, var(--tabby-dk) 20px 27px); box-shadow: inset 0 2px 0 var(--tabby-hi), inset 0 -2px 0 rgba(0, 0, 0, 0.25); }
.win.cat .win-x { width: 32px; height: 26px; background: var(--stop); color: #fff; box-shadow: inset -2px -2px 0 var(--stop-dk), inset 2px 2px 0 #ff8a70, 0 0 0 2px var(--ink); }
.win.cat .win-x:hover, .win.cat .win-x.hover { background: #f04a3a; }
.win.cat .win-x:active { box-shadow: inset 2px 2px 0 var(--stop-dk), inset -2px -2px 0 #ff8a70, 0 0 0 2px var(--ink); }
.ear { position: absolute; top: -26px; width: 40px; height: 30px; background: var(--putty-dk); clip-path: polygon(0 100%, 26% 0, 100% 100%); }
.ear::after { content: ''; position: absolute; inset: 5px 5px 0 4px; background: var(--tabby); clip-path: polygon(0 100%, 26% 0, 100% 100%); }
.ear.l { left: 8px; }
.ear.r { right: 8px; transform: scaleX(-1); }
.eyes { display: inline-flex; gap: 4px; flex: none; }
.eye { position: relative; width: 17px; height: 15px; overflow: hidden; background: var(--paper); border: 2px solid var(--ink); border-radius: 50%; }
.eye b { position: absolute; left: 50%; top: 50%; width: 4px; height: 9px; margin: -4.5px 0 0 -2px; background: var(--ink); border-radius: 2px; transform: translate(var(--px, 0px), var(--py, 0px)); }
.win[data-face='smug'] .eye { height: 9px; margin-top: 5px; border-radius: 0 0 9px 9px; }
.win[data-face='tired'] .eye { height: 7px; margin-top: 4px; border-radius: 9px 9px 0 0; }
.win[data-face='shock'] .eye { transform: scale(1.25); }
.win[data-face='shock'] .eye b { width: 3px; height: 3px; margin: -1.5px 0 0 -1.5px; }
.win[data-face='dead'] .eye b { width: 11px; height: 2px; margin: -1px 0 0 -5.5px; transform: rotate(45deg); border-radius: 0; }
.win[data-face='dead'] .eye::after { content: ''; position: absolute; left: 50%; top: 50%; width: 11px; height: 2px; margin: -1px 0 0 -5.5px; background: var(--ink); transform: rotate(-45deg); }
.say { min-height: 2.6em; font-size: 18px; }
.say.blip { animation: blip 0.18s steps(2); }
@keyframes blip { from { opacity: 0.2; } }
.win-foot { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding: 6px 8px; font-size: 14px; box-shadow: var(--in); }
.pips { display: flex; gap: 4px; }
.pip { width: 15px; height: 13px; background: var(--tabby); clip-path: polygon(0 0, 26% 28%, 74% 28%, 100% 0, 100% 68%, 78% 100%, 22% 100%, 0 68%); }
.pip.gone { background: var(--putty-lo); }
.pip.losing { animation: pip-lose 0.5s steps(4); background: var(--stop); }
@keyframes pip-lose { 50% { opacity: 0; } }

/* Dialogs, notes and the Task Destroyer */
.dlg { display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: start; }
.dlg img { width: 44px; height: 44px; }
.dlg-btns { position: relative; display: flex; justify-content: center; gap: 10px; margin-top: 16px; }
.dlg-btns.arena { display: block; height: 150px; }
.dlg-btns.arena .btn { position: absolute; transition: left 0.09s, top 0.09s, transform 0.15s; }
.note p + p { margin-top: 8px; }
.tm-list { margin: 0 0 10px; padding: 2px; list-style: none; background: var(--paper); box-shadow: var(--in); }
.tm-list li { display: flex; justify-content: space-between; gap: 16px; padding: 3px 8px; }
.tm-list li[aria-selected='true'] { background: var(--plum-mid); color: var(--paper); }
.tm-list li.dead { color: var(--putty-lo); text-decoration: line-through; }
.tm-row { display: flex; align-items: center; gap: 10px; }
.tm-msg { flex: 1; min-height: 2.5em; font-size: 15px; }

/* Life 2: the countdown. Life 1: the health bar. */
.count { margin: 8px 0 0; font: 400 76px/1 var(--rite); text-align: center; color: var(--stop-dk); font-variant-numeric: tabular-nums; }
.hp { height: 22px; margin-top: 10px; padding: 4px; box-shadow: var(--in); }
.hp i { display: block; height: 100%; width: 100%; background: repeating-linear-gradient(90deg, var(--stop) 0 10px, transparent 10px 13px); transition: width 0.12s; }

/* Taskbar */
#bar { position: absolute; inset: auto 0 0 0; z-index: 400; height: var(--bar-h); display: flex; align-items: center; gap: 6px; padding: 5px 6px 3px;
  background: var(--putty); box-shadow: inset 0 2px 0 var(--putty-hi), inset 0 4px 0 #efe8d6; }
#meow { display: flex; align-items: center; gap: 7px; min-width: 0; padding: 5px 12px 6px 9px; font-weight: 700; }
#meow svg { fill: var(--tabby-dk); }
#tasks { flex: 1; display: flex; gap: 4px; min-width: 0; overflow: hidden; }
.task { flex: 0 1 180px; min-width: 0; padding: 5px 10px 6px; border: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-align: left; background: var(--putty); box-shadow: var(--out); font-size: 15px; }
.task.on { box-shadow: var(--in); background: #e6dfcd; font-weight: 600; }
#tray { display: flex; align-items: center; gap: 12px; height: 34px; padding: 0 12px; box-shadow: var(--in); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
#vol { width: 26px; height: 24px; padding: 0; border: 0; background: none; display: grid; place-items: center; }
#vol svg { fill: var(--ink); }
#vol[aria-pressed='true'] .waves { display: none; }
#vol:focus-visible { outline: 2px dotted var(--ink); }
#hud-ha { color: var(--tabby-dk); }
#hud-ha.bump { animation: bump 0.25s steps(3); }
@keyframes bump { 50% { transform: scale(1.5); color: var(--stop); } }

/* Meow menu, right-click menu, balloon tips */
#menu, #ctx { position: absolute; z-index: 460; min-width: 220px; padding: 5px 5px 5px 34px; background: var(--putty); box-shadow: var(--out), var(--drop); }
#menu { left: 4px; bottom: calc(var(--bar-h) - 2px); }
#ctx { padding-left: 5px; min-width: 170px; }
.menu-side { position: absolute; left: 4px; top: 4px; bottom: 4px; width: 26px; writing-mode: vertical-rl; rotate: 180deg; padding: 8px 0; font-weight: 700; letter-spacing: 0.06em; color: var(--tabby-hi); background: linear-gradient(var(--plum-mid), var(--plum)); }
#menu button, #ctx button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 14px 7px 8px; border: 0; background: none; text-align: left; }
#menu img { width: 26px; height: 26px; }
#menu button:hover, #menu button:focus-visible, #ctx button:hover, #ctx button:focus-visible { background: var(--plum-mid); color: var(--paper); outline: 0; }
#menu hr { margin: 4px 2px; border: 0; height: 2px; background: var(--putty-lo); box-shadow: 0 2px 0 var(--putty-hi); }
#toasts { position: absolute; right: 10px; bottom: calc(var(--bar-h) + 12px); z-index: 450; display: grid; justify-items: end; gap: 8px; pointer-events: none; }
.toast { position: relative; max-width: min(340px, 86vw); padding: 9px 13px 10px; background: #fff3b8; color: var(--ink); box-shadow: 0 0 0 2px var(--ink), 4px 5px 0 rgba(20, 8, 30, 0.4); animation: toast-in 0.14s steps(3); }
.toast::after { content: ''; position: absolute; right: 22px; bottom: -11px; border: 6px solid transparent; border-top-color: var(--ink); }
.toast.out { opacity: 0; transition: opacity 0.2s; }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }

@media (max-width: 640px) {
  :root { --bar-h: 44px; }
  #icons { grid-template-rows: repeat(auto-fill, 84px); grid-auto-columns: 80px; }
  #icons button { width: 80px; height: 84px; }
  #icons img { width: 44px; height: 44px; }
  #icons span { font-size: 13px; }
  #tray { gap: 8px; padding: 0 8px; font-size: 15px; }
  #meow { padding-right: 9px; }
  .say { font-size: 17px; }
}
@media (prefers-reduced-motion: reduce) {
  #desk.glitch, .win.wig { animation: none; }
}
