/* ---------- tokens ---------- */
:root {
  --face: #c3bdb2;
  --face-hi: #f3efe6;
  --face-lo: #7d766a;
  --face-dk: #2a2620;
  --ink: #1d1a16;
  --muted: #5b554b;
  --title-a: #6b3d14;
  --title-b: #c8893b;
  --title-off-a: #8a8478;
  --title-off-b: #b5afa4;
  --title-ink: #fff8ea;
  --desk: #2f7d78;
  --select: #6b3d14;
  --select-ink: #fff8ea;
  --icon-ink: #fff;
  --pixel: 'Pixelify Sans', 'VT323', ui-monospace, monospace;
  --mono: 'VT323', ui-monospace, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --taskbar-h: 40px;
}
:root[data-theme="dark"] {
  --face: #2c2a33;
  --face-hi: #4a4756;
  --face-lo: #16151b;
  --face-dk: #050507;
  --ink: #ece6da;
  --muted: #a39d92;
  --title-a: #3a1d5c;
  --title-b: #c8457a;
  --title-off-a: #2a2833;
  --title-off-b: #3e3b48;
  --select: #c8457a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--desk);
  color: var(--ink);
  font: 14px/1.35 var(--sans);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- bevels ---------- */
.bevel {
  background: var(--face);
  border: 0;
  box-shadow: inset -1px -1px var(--face-dk), inset 1px 1px var(--face-hi),
              inset -2px -2px var(--face-lo), inset 2px 2px var(--face);
}
.bevel-in {
  background: var(--face);
  box-shadow: inset -1px -1px var(--face-hi), inset 1px 1px var(--face-lo),
              inset -2px -2px var(--face), inset 2px 2px var(--face-dk);
}
button.bevel { cursor: pointer; }
button.bevel:active, button.bevel.pressed {
  box-shadow: inset -1px -1px var(--face-hi), inset 1px 1px var(--face-dk),
              inset -2px -2px var(--face), inset 2px 2px var(--face-lo);
}
button.bevel:focus-visible { outline: 1px dotted var(--ink); outline-offset: -5px; }

/* ---------- wallpaper ---------- */
#wallpaper { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; }

/* ---------- desktop ---------- */
#desktop {
  position: fixed; inset: 0 0 var(--taskbar-h) 0; z-index: 1;
}
.icon {
  position: absolute; width: 88px; padding: 6px 2px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: none; border: 0; cursor: pointer; color: var(--icon-ink);
  text-align: center; border-radius: 2px;
}
.icon .glyph {
  width: 48px; height: 48px; display: grid; place-items: center;
  font-size: 30px; line-height: 1;
  filter: drop-shadow(2px 2px 0 rgba(0,0,0,.35));
}
.icon .glyph.tile {
  border-radius: 10px;
  box-shadow: inset 0 -3px rgba(0,0,0,.25), inset 0 2px rgba(255,255,255,.25), 2px 2px 0 rgba(0,0,0,.3);
  filter: none;
}
.icon .label {
  font: 13px/1.15 var(--pixel); padding: 1px 3px;
  text-shadow: 1px 1px 0 rgba(0,0,0,.7);
  max-width: 100%; overflow-wrap: anywhere;
}
.icon:focus-visible .label, .icon.selected .label {
  background: var(--select); color: var(--select-ink); text-shadow: none;
  outline: 1px dotted var(--select-ink);
}
.icon.selected .glyph { filter: drop-shadow(2px 2px 0 rgba(0,0,0,.35)) brightness(.75) sepia(.6) hue-rotate(-20deg); }
.icon .badge {
  position: absolute; top: 2px; right: 14px; font: 11px var(--pixel);
  background: #e0402a; color: #fff; padding: 0 4px; border-radius: 6px; transform: rotate(8deg);
}

/* ---------- windows ---------- */
#windows { position: fixed; inset: 0 0 var(--taskbar-h) 0; z-index: 2; pointer-events: none; }
.win {
  position: absolute; display: flex; flex-direction: column; padding: 4px;
  pointer-events: auto; min-width: 240px; min-height: 140px;
  will-change: transform;
}
.win.max { inset: 0 !important; width: auto !important; height: auto !important; }
.win.min { visibility: hidden; pointer-events: none; }
.titlebar {
  display: flex; align-items: center; gap: 6px; height: 26px; padding: 0 3px 0 6px;
  background: linear-gradient(90deg, var(--title-off-a), var(--title-off-b));
  color: var(--title-ink); cursor: default; touch-action: none; flex: none;
}
.win.active .titlebar { background: linear-gradient(90deg, var(--title-a), var(--title-b)); }
.titlebar .t-icon { font-size: 15px; }
.titlebar .t-text {
  flex: 1; font: 600 14px var(--pixel); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.titlebar .ctl {
  width: 22px; height: 20px; padding: 0; display: grid; place-items: center;
  font: 13px/1 var(--pixel); color: var(--ink);
}
.titlebar .ctl + .ctl.close { margin-left: 3px; }
.menubar {
  display: flex; gap: 2px; padding: 2px 2px; font-size: 13px; flex: none;
}
.menubar button { background: none; border: 0; padding: 2px 8px; cursor: pointer; }
.menubar button:hover { background: var(--select); color: var(--select-ink); }
.menubar .spacer { flex: 1; }
.menubar .addr { font: 13px var(--mono); color: var(--muted); align-self: center; padding-right: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.win-body { position: relative; flex: 1; min-height: 0; margin-top: 2px; padding: 2px; display: flex; }
.win-body > iframe { flex: 1; border: 0; width: 100%; height: 100%; background: #fff; display: block; }
.win.dragging iframe, body.dragging iframe { pointer-events: none; }
.win-body .shield { position: absolute; inset: 2px; display: none; }
.win:not(.active) .win-body .shield { display: block; }
.win .loading {
  position: absolute; inset: 2px; display: grid; place-items: center; background: var(--face);
  font: 22px var(--mono); color: var(--muted); pointer-events: none;
}
.win .loading span { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.status {
  display: flex; gap: 2px; margin-top: 2px; font-size: 12px; flex: none;
}
.status > div { padding: 2px 6px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status > div:last-child { flex: none; }
.rz { position: absolute; z-index: 2; touch-action: none; }
.rz.n, .rz.s { left: 8px; right: 8px; height: 6px; cursor: ns-resize; }
.rz.e, .rz.w { top: 8px; bottom: 8px; width: 6px; cursor: ew-resize; }
.rz.n { top: -2px; } .rz.s { bottom: -2px; } .rz.e { right: -2px; } .rz.w { left: -2px; }
.rz.ne, .rz.nw, .rz.se, .rz.sw { width: 12px; height: 12px; }
.rz.ne { top: -2px; right: -2px; cursor: nesw-resize; }
.rz.sw { bottom: -2px; left: -2px; cursor: nesw-resize; }
.rz.nw { top: -2px; left: -2px; cursor: nwse-resize; }
.rz.se { bottom: -2px; right: -2px; cursor: nwse-resize; }
.win.max .rz { display: none; }
.win:fullscreen { padding: 0; }
.win:fullscreen .titlebar, .win:fullscreen .menubar, .win:fullscreen .status, .win:fullscreen .rz { display: none; }
.win:fullscreen .win-body { margin: 0; padding: 0; }
.win::backdrop { background: #000; }

/* folder / explorer view */
.explorer {
  flex: 1; overflow: auto; background: #fffdf8; color: #1d1a16;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); align-content: start;
  gap: 6px; padding: 10px; user-select: none;
}
:root[data-theme="dark"] .explorer { background: #18171c; color: var(--ink); }
.explorer .icon { position: relative; width: auto; color: inherit; }
.explorer .icon .label { text-shadow: none; }
.explorer.list { grid-template-columns: 1fr; gap: 0; padding: 4px; }
.explorer.list .icon { flex-direction: row; justify-content: flex-start; gap: 10px; padding: 3px 6px; text-align: left; }
.explorer.list .icon .glyph { width: 26px; height: 26px; font-size: 16px; border-radius: 5px; }
.explorer.list .icon .label { flex: none; width: 180px; }
.explorer.list .icon .blurb { display: block; }
.icon .blurb { display: none; font-size: 12px; color: #6b655b; }
.explorer .empty { grid-column: 1 / -1; color: #8a8478; font: 18px var(--mono); padding: 20px; }

/* notepad / dialogs */
.notepad {
  flex: 1; margin: 0; padding: 10px 12px; overflow: auto; background: #fffdf8; color: #1d1a16;
  font: 18px/1.3 var(--mono); white-space: pre-wrap; user-select: text; -webkit-user-select: text;
}
.notepad a { color: #6b3d14; }
.dialog-body { display: flex; gap: 14px; padding: 16px 16px 8px; align-items: flex-start; font-size: 14px; }
.dialog-body .big { font-size: 34px; line-height: 1; }
.dialog-actions { display: flex; justify-content: center; gap: 8px; padding: 8px 16px 14px; }
.dialog-actions button { min-width: 84px; padding: 5px 10px; }
.win.dialog .win-body { flex-direction: column; }

/* run dialog */
.run { display: flex; flex-direction: column; gap: 8px; padding: 12px; flex: 1; min-height: 0; }
.run input {
  font: 20px var(--mono); padding: 6px 8px; border: 0; background: #fffdf8; color: #1d1a16; outline: none;
}
.run ul { list-style: none; margin: 0; padding: 2px; overflow: auto; flex: 1; background: #fffdf8; color: #1d1a16; }
.run li { display: flex; gap: 10px; align-items: center; padding: 4px 8px; cursor: pointer; }
.run li small { color: #6b655b; margin-left: auto; font-size: 12px; }
.run li.on { background: var(--select); color: var(--select-ink); }
.run li.on small { color: inherit; opacity: .8; }

/* display properties */
.props { padding: 14px; display: grid; gap: 14px; flex: 1; align-content: start; overflow: auto; }
.props fieldset { border: 1px solid var(--face-lo); box-shadow: 1px 1px var(--face-hi); padding: 8px 12px 12px; margin: 0; }
.props legend { padding: 0 4px; }
.props .swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.props .swatches button { width: 92px; height: 64px; padding: 0; position: relative; cursor: pointer; border: 2px solid transparent; }
.props .swatches button.on { border-color: var(--select); }
.props .swatches button span { position: absolute; left: 0; right: 0; bottom: -18px; font-size: 12px; }
.props .swatches { padding-bottom: 18px; }
.props label { display: flex; align-items: center; gap: 8px; }
.props .saver-row { display: flex; gap: 8px; margin-bottom: 10px; }
.props .saver-row select { flex: 1; font: inherit; height: 28px; padding: 0 4px; border: 0; background: #fffdf8; color: #1d1a16;
  box-shadow: inset -1px -1px var(--face-hi), inset 1px 1px var(--face-lo), inset -2px -2px var(--face), inset 2px 2px var(--face-dk); }
.props .saver-row button { padding: 0 14px; }

/* potato clock */
.potclock { padding: 12px; display: flex; flex-direction: column; gap: 8px; flex: 1; overflow: auto; }
.potclock-art { background: #e9e2d2; line-height: 0; flex: none; }
.potclock-art svg { width: 100%; height: auto; display: block; }
.potclock-art .lcd-time { font: 30px var(--mono); fill: #1d2a1a; }
.potclock-art .lcd-ampm, .potclock-art .lcd-sec { font: 11px var(--mono); fill: #1d2a1a; }
.potclock-art .lcd-tag { font: 12px var(--mono); fill: #e9e2d2; }
.potclock-date { font: 600 16px var(--pixel); text-align: center; }
.potclock-meter { font: 16px var(--mono); text-align: center; color: var(--muted); white-space: pre; }
.potclock fieldset { border: 1px solid var(--face-lo); box-shadow: 1px 1px var(--face-hi); padding: 6px 10px 10px; margin: 0; }
.potclock legend { padding: 0 4px; }
.potclock-month { text-align: center; margin-bottom: 6px; }
.potclock-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; font: 16px var(--mono); }
.potclock-grid b { font-weight: 400; color: var(--muted); }
.potclock-grid span.on { background: var(--select); color: var(--select-ink); }

/* ---------- taskbar ---------- */
#taskbar {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--taskbar-h); z-index: 50;
  display: flex; align-items: center; gap: 4px; padding: 4px 4px;
  padding-bottom: calc(4px + env(safe-area-inset-bottom));
  background: var(--face); box-shadow: inset 0 1px var(--face-hi), inset 0 2px var(--face);
}
#start-btn { display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px 0 6px; font: 600 16px var(--pixel); flex: none; }
#start-btn span { font-size: 18px; }
#tasks { flex: 1; display: flex; gap: 4px; min-width: 0; height: 32px; }
#tasks button {
  flex: 0 1 170px; min-width: 40px; display: flex; align-items: center; gap: 6px; padding: 0 8px;
  font-size: 13px; text-align: left; white-space: nowrap; overflow: hidden;
}
#tasks button span:last-child { overflow: hidden; text-overflow: ellipsis; }
#tasks button.pressed { font-weight: 600; background-image: repeating-conic-gradient(var(--face) 0 25%, var(--face-hi) 0 50%); background-size: 2px 2px; }
#tray { display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 10px; font: 18px var(--mono); flex: none; }
#tray-run { cursor: pointer; font-size: 14px; }
#clock { cursor: pointer; }

#start-menu {
  position: fixed; left: 2px; bottom: calc(var(--taskbar-h) - 2px); z-index: 60;
  display: flex; padding: 3px; min-width: 230px;
}
#start-menu .side {
  width: 30px; background: linear-gradient(0deg, var(--title-a), var(--title-b));
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 8px;
}
#start-menu .side b {
  writing-mode: vertical-rl; transform: rotate(180deg); color: var(--title-ink);
  font: 600 20px var(--pixel); letter-spacing: 1px; white-space: nowrap;
}
#start-menu .side b i { font-style: normal; font-weight: 400; opacity: .75; }
#start-menu ul { list-style: none; margin: 0; padding: 0; flex: 1; }
#start-menu li { position: relative; }
#start-menu li > button {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 6px 22px 6px 8px;
  background: none; border: 0; text-align: left; cursor: pointer; font-size: 14px; white-space: nowrap;
}
#start-menu li > button .e { width: 24px; text-align: center; font-size: 20px; }
#start-menu li > button:hover, #start-menu li > button:focus-visible, #start-menu li.open > button {
  background: var(--select); color: var(--select-ink); outline: none;
}
#start-menu li.sub > button::after { content: '▶'; position: absolute; right: 8px; font-size: 9px; }
#start-menu hr { border: 0; border-top: 1px solid var(--face-lo); border-bottom: 1px solid var(--face-hi); margin: 3px 2px; }
#start-menu .submenu {
  position: absolute; left: 100%; bottom: -3px; padding: 3px; min-width: 210px; display: none;
  max-height: calc(100vh - var(--taskbar-h) - 10px); overflow: auto;
}
#start-menu li.open > .submenu { display: block; }
#start-menu .submenu button { padding: 4px 12px 4px 6px; }
#start-menu .submenu button .e { font-size: 16px; }

/* ---------- boot ---------- */
#boot {
  position: fixed; inset: 0; z-index: 1000; background: #000; color: #b8b8b8;
  font: 20px/1.15 var(--mono); padding: 24px; overflow: hidden; cursor: pointer;
}
#boot .bios { white-space: pre-wrap; }
#boot .bios .ok { color: #7fdc6a; }
#boot .splash {
  position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 18px;
  background: radial-gradient(ellipse at 50% 40%, #3a2410, #000 70%); opacity: 0;
}
#boot .logo { font: 600 clamp(40px, 9vw, 96px) var(--pixel); color: #f3d9a4; letter-spacing: 2px; text-shadow: 4px 4px 0 #6b3d14; }
#boot .logo small { font-size: .4em; vertical-align: super; color: #c8893b; }
#boot .spud { font-size: clamp(60px, 12vw, 120px); line-height: 1; }
#boot .bar { width: min(320px, 70vw); height: 18px; padding: 3px; border: 2px solid #8a6a3a; }
#boot .bar i { display: block; height: 100%; width: 0; background: repeating-linear-gradient(90deg, #c8893b 0 14px, transparent 14px 18px); }
#boot .skip { position: absolute; right: 16px; bottom: 12px; font-size: 16px; color: #666; }

/* ---------- screensaver / bsod / shutdown ---------- */
#screensaver { position: fixed; inset: 0; z-index: 900; background: #000; cursor: none; }
#screensaver .dvd { position: absolute; left: 0; top: 0; font-size: 90px; line-height: 1; will-change: transform; }
#screensaver .dvd small { display: block; font: 600 20px var(--pixel); text-align: center; color: currentColor; }
.fullscreen-msg {
  position: fixed; inset: 0; z-index: 950; display: grid; place-items: center; text-align: center;
  font: 24px/1.3 var(--mono); cursor: pointer; padding: 24px;
}
.bsod { background: #0000a8; color: #fff; }
.bsod .inner { max-width: 640px; text-align: left; }
.bsod .tag { display: inline-block; background: #aaa; color: #0000a8; padding: 0 8px; margin-bottom: 18px; }
.shutdown { background: #000; color: #e89a3c; font: 600 clamp(22px, 4vw, 40px) var(--pixel); }

/* ---------- mobile launcher ---------- */
body.mobile #desktop { overflow-y: auto; padding: calc(16px + env(safe-area-inset-top)) 16px 24px; -webkit-overflow-scrolling: touch; }
body.mobile #windows .win { inset: 0 !important; width: auto !important; height: auto !important; }
body.mobile .rz { display: none; }
.m-head { color: #fff; text-shadow: 2px 2px 0 rgba(0,0,0,.4); margin: 0 0 14px; font: 600 28px var(--pixel); }
.m-head small { font: 18px var(--mono); opacity: .8; display: block; }
.m-cat { margin: 18px 0 8px; color: #fff; font: 600 16px var(--pixel); text-shadow: 1px 1px 0 rgba(0,0,0,.5); opacity: .9; }
.m-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px 4px; }
.m-grid .icon { position: relative; width: auto; text-decoration: none; }
.m-grid .icon .label { font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
  .win .loading span { animation: none; }
}
.icon .glyph { position: relative; }
.icon .glyph .sub { position: absolute; right: 0; bottom: 2px; font-size: 16px; filter: none; }
