:root {
  --desk: #1f6f78;
  --desk-dark: #17565d;
  --face: #c9c0b0;
  --light: #fffaf0;
  --shadow: #7d7466;
  --dark: #1a1410;
  --title: #3b2463;
  --title2: #8a4fd0;
  --gold: #f5b83a;
  --pixel: 'Press Start 2P', monospace;
  --body: 'VT323', monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 22px/1.15 var(--body);
  color: var(--dark);
  background-color: var(--desk);
  /* 2x2 dither, like an old 16 colour desktop */
  background-image:
    linear-gradient(45deg, var(--desk-dark) 25%, transparent 25%, transparent 75%, var(--desk-dark) 75%),
    linear-gradient(45deg, var(--desk-dark) 25%, transparent 25%, transparent 75%, var(--desk-dark) 75%);
  background-size: 4px 4px;
  background-position: 0 0, 2px 2px;
  overflow: hidden;
  user-select: none;
}
canvas { image-rendering: pixelated; }

/* chunky 3D bevel */
.bevel, .window, #taskbar, #startmenu, #start, .task, .tbtn {
  background: var(--face);
  box-shadow: inset -2px -2px 0 var(--dark), inset 2px 2px 0 var(--light), inset -4px -4px 0 var(--shadow);
}

#desktop {
  position: fixed;
  inset: 0 0 44px 0;
  padding: 16px;
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(auto-fill, 112px);
  grid-auto-columns: 120px;
  gap: 8px;
}

.icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px 4px;
  text-decoration: none;
  color: #fff;
  text-align: center;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}
.icon canvas { width: 56px; height: 56px; filter: drop-shadow(3px 3px 0 #0006); }
.icon span {
  font: 9px/1.5 var(--pixel);
  padding: 2px 4px;
  text-shadow: 1px 1px 0 #000;
  overflow-wrap: anywhere;
  white-space: nowrap;
}
.icon.sel span, .icon:focus-visible span { background: var(--title); outline: 1px dotted #fff; }
.icon.sel canvas { filter: drop-shadow(3px 3px 0 #0006) brightness(.75) sepia(1) hue-rotate(220deg) saturate(3); }

/* --- windows --- */
.window {
  position: absolute;
  width: min(400px, calc(100vw - 24px));
  padding: 4px;
  display: flex;
  flex-direction: column;
  max-height: calc(100% - 16px);
}
.window[hidden] { display: none; }
.window header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 6px;
  background: linear-gradient(90deg, var(--title), var(--title2));
  color: #fff;
  cursor: grab;
  touch-action: none;
}
.window:not(.active) header { background: linear-gradient(90deg, #6b6459, #9c9384); }
.window header canvas { width: 16px; height: 16px; }
.window header b { flex: 1; font: 10px/1.4 var(--pixel); font-weight: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tbtn {
  width: 26px; height: 24px; padding: 0;
  border: 0;
  display: grid; place-items: center;
  font: 12px var(--pixel);
  color: var(--dark);
  text-decoration: none;
  cursor: pointer;
}
.tbtn.close { margin-left: 2px; }
.tbtn:active, #start:active, #start[aria-expanded="true"], .task.active {
  box-shadow: inset 2px 2px 0 var(--dark), inset -2px -2px 0 var(--light), inset 4px 4px 0 var(--shadow);
}
.window .body { padding: 12px; overflow: auto; }
.window .body p { margin: 0 0 10px; }
.window .body ul { margin: 0 0 14px; padding-left: 20px; }
.window .body li::marker { content: '► '; color: var(--title2); font-size: 14px; }
.window .body.text {
  margin: 6px 4px 4px;
  background: #fff;
  box-shadow: inset 2px 2px 0 var(--shadow), inset -2px -2px 0 var(--light);
  font-size: 24px;
  user-select: text;
}
.caret { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }


/* app windows: the game in an iframe */
.window.app { width: min(1040px, calc(100vw - 40px)); height: min(700px, calc(100% - 40px)); max-height: none; }
.window.app .frame { flex: 1; min-height: 0; margin-top: 4px; background: #000; box-shadow: inset 2px 2px 0 var(--shadow), inset -2px -2px 0 var(--light); padding: 2px; }
.window.app iframe { display: block; width: 100%; height: 100%; border: 0; background: #000; }
.window.max { left: 0 !important; top: 0 !important; width: 100% !important; height: 100% !important; }
.window.max .grip { display: none; }
.grip {
  position: absolute; right: 2px; bottom: 2px; width: 16px; height: 16px;
  cursor: nwse-resize; touch-action: none;
  background: linear-gradient(135deg, transparent 45%, var(--shadow) 45%, var(--shadow) 55%, transparent 55%, transparent 70%, var(--shadow) 70%, var(--shadow) 80%, transparent 80%);
}
/* while dragging or resizing, the iframe must not swallow the pointer */
body.busy iframe { pointer-events: none; }
body.busy, body.busy * { user-select: none; }

/* --- taskbar and start menu --- */
#taskbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  box-shadow: inset 0 2px 0 var(--light), 0 -2px 0 var(--face);
}
#start, .task {
  height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 8px;
  border: 0;
  font: 11px var(--pixel);
  color: var(--dark);
  cursor: pointer;
}
#start canvas, .task canvas { width: 16px; height: 16px; }
#tasks { flex: 1; display: flex; gap: 6px; min-width: 0; overflow: hidden; }
.task { max-width: 180px; min-width: 0; font-size: 9px; }
.task span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#clock {
  padding: 6px 12px;
  font-size: 22px;
  box-shadow: inset 2px 2px 0 var(--shadow), inset -2px -2px 0 var(--light);
}

#startmenu {
  position: fixed;
  left: 6px;
  bottom: 42px;
  display: flex;
  padding: 4px;
  min-width: 230px;
  z-index: 100;
}
#startmenu[hidden] { display: none; }
#startmenu .side {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  padding: 10px 6px;
  background: linear-gradient(0deg, var(--title), var(--title2));
  color: var(--gold);
  font: 14px var(--pixel);
}
#startmenu ul { list-style: none; margin: 0; padding: 4px 0; flex: 1; }
#startmenu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  color: var(--dark);
  text-decoration: none;
  font-size: 24px;
}
#startmenu a:hover, #startmenu a:focus-visible { background: var(--title); color: #fff; outline: none; }
#startmenu canvas { width: 32px; height: 32px; }
#startmenu .sep { margin: 4px 6px; border-top: 2px solid var(--shadow); border-bottom: 2px solid var(--light); }

/* phones: icons in a row on top, windows fill the width */
@media (max-width: 600px) {
  #desktop {
    grid-auto-flow: row;
    grid-template-rows: none;
    grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
    grid-auto-rows: 112px;
    align-content: start;
  }
  .window { left: 8px !important; right: 8px; width: auto; top: 8px !important; }
  .task { display: none; }
  .icon span { white-space: normal; font-size: 8px; }
}

/* phones (upright or sideways): a game takes the whole screen, only its title bar stays */
@media (max-width: 600px), (max-height: 500px) {
  .window.app { position: fixed; inset: 0; left: 0 !important; top: 0 !important; width: 100% !important; height: 100% !important; padding: 2px; }
  /* over the taskbar too */
  body:has(.window.app:not([hidden])) #desktop { inset: 0; z-index: 50; }
  .window.app header { padding: 2px 2px 2px 6px; }
  .window.app .frame { margin-top: 2px; padding: 0; }
  .window.app .grip, .window.app .max { display: none; }
}
