/* ---------- Tokens ---------- */
:root {
  --ui-font: Tahoma, Verdana, "Segoe UI", Geneva, sans-serif;
  --title-font: "Trebuchet MS", Tahoma, "Segoe UI", sans-serif;
  --mono: "Lucida Console", "Courier New", monospace;
  --face: #ece9d8;         /* window body */
  --frame: #0831d9;        /* active window frame */
  --frame-off: #7a96df;    /* inactive window frame */
  --select: #316ac5;       /* selection blue */
  --link: #215dc6;
  --taskbar-h: 30px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 11px/1.35 var(--ui-font);
  color: #000;
  overflow: hidden;
  background: #3a6ea5;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
img { max-width: 100%; }
:focus-visible { outline: 1px dotted #000; outline-offset: 1px; }

/* ---------- Desktop ---------- */
#desktop {
  position: fixed;
  inset: 0 0 calc(var(--taskbar-h) + var(--safe-b)) 0;
  background: #3a6ea5 center 38% / cover no-repeat;
  overflow: hidden;
  padding-top: env(safe-area-inset-top, 0px);
}
#icons { list-style: none; margin: 0; padding: 0; position: absolute; inset: 0; }
.icon {
  position: absolute;
  width: 110px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: none; border: 0; padding: 2px; cursor: default; text-decoration: none;
  transform: translate(-50%, 0);
}
.icon-art { width: 84px; height: 76px; position: relative; display: grid; place-items: center; }
.icon-label {
  color: #fff; font-size: 12px; text-align: center; padding: 1px 3px;
  text-shadow: 1px 1px 1px #000, 0 0 3px rgba(0,0,0,.6);
  max-width: 110px; word-wrap: break-word;
}
.icon.selected .icon-label { background: var(--select); text-shadow: none; }
.icon.selected .icon-art { filter: brightness(.75) sepia(1) hue-rotate(185deg) saturate(3); }
.icon:focus-visible { outline: none; }
.icon:focus-visible .icon-label { outline: 1px dotted #fff; }

/* Folder icon with a peek of the work inside */
.folder { width: 76px; height: 76px; position: relative; }
.folder .back, .folder .front { position: absolute; inset: 0; width: 100%; height: 100%; }
.folder .front { clip-path: polygon(0% 30%, 40% 22%, 46% 17%, 100% 13%, 100% 100%, 0% 100%); }
.folder .peek {
  position: absolute; left: 12px; top: 6px; width: 46px; height: 44px;
  object-fit: cover; border: 2px solid #fff; box-shadow: 0 1px 2px rgba(0,0,0,.4);
  transform: rotate(-5deg);
}
.folder .peek + .peek { left: 22px; top: 9px; transform: rotate(6deg); }

.photo-icon img {
  width: 68px; height: 68px; object-fit: cover; border: 3px solid #fff;
  box-shadow: 1px 2px 3px rgba(0,0,0,.5);
}
.shortcut-arrow { position: absolute; left: 10px; bottom: 4px; width: 16px; height: 16px; }


/* ---------- Windows ---------- */
.win {
  position: absolute;
  display: flex; flex-direction: column;
  background: linear-gradient(to right, #0019cf, #0831d9 2px, #166aee 50%, #0831d9 calc(100% - 2px), #0019cf);
  padding: 0 3px 3px;
  border-radius: 8px 8px 0 0;
  box-shadow: 2px 3px 10px rgba(0,0,0,.45);
  min-width: 260px; min-height: 140px;
}
.win.inactive { background: linear-gradient(to right, #6582d0, #7a96df 2px, #a6b9ea 50%, #7a96df calc(100% - 2px), #6582d0); }
.win.maximized { left: 0 !important; top: 0 !important; width: 100% !important; height: 100% !important; border-radius: 0; }
.win[hidden] { display: none; }

.win-title {
  height: 28px; flex: none;
  display: flex; align-items: center; gap: 5px;
  margin: 0 -3px; padding: 0 5px 0 6px;
  border-radius: 7px 7px 0 0;
  background: linear-gradient(to bottom, #0997ff 0%, #0053ee 8%, #0050ee 40%, #0066ff 88%, #0066ff 93%, #005bff 95%, #003dd7 96%, #003dd7 100%);
  color: #fff; cursor: default; user-select: none; touch-action: none;
}
.win.inactive .win-title {
  background: linear-gradient(to bottom, #7697e7 0%, #7e9ee3 3%, #94afe8 6%, #97b4e9 8%, #82a5e4 14%, #7c9fe2 17%, #7996de 25%, #7b99e1 56%, #82a9e9 81%, #80a5e7 89%, #7b96e1 94%, #7a93df 97%, #abbae3 100%);
  color: #d8e4f8;
}
.win-title img { width: 16px; height: 16px; flex: none; }
.win-title h2 {
  margin: 0; flex: 1; min-width: 0;
  font: bold 13px/1 var(--title-font);
  text-shadow: 1px 1px #0f1089;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.win.inactive .win-title h2 { text-shadow: none; }
.win-btns { display: flex; gap: 2px; }
.win-btns button {
  width: 21px; height: 21px; padding: 0;
  border: 1px solid #fff; border-radius: 3px;
  background: linear-gradient(135deg, #6d9df7 0%, #3a74ea 30%, #2a62e0 60%, #1e4fc9 100%);
  box-shadow: inset 1px 1px 0 rgba(255,255,255,.45), inset -1px -1px 1px rgba(0,22,120,.45);
  display: grid; place-items: center; cursor: pointer;
}
.win-btns button:hover { background: linear-gradient(135deg, #8db6ff 0%, #5a8ef5 30%, #3e78ee 60%, #2b5fd8 100%); }
.win-btns button:active { background: linear-gradient(135deg, #1e4fc9, #2a62e0 50%, #4a82ef); box-shadow: inset 1px 1px 2px rgba(0,0,60,.5); }
.win-btns .close { background: linear-gradient(135deg, #f0a383 0%, #e2683f 30%, #d5502a 60%, #b93c1c 100%); box-shadow: inset 1px 1px 0 rgba(255,255,255,.45), inset -1px -1px 1px rgba(110,20,0,.5); }
.win-btns .close:hover { background: linear-gradient(135deg, #ffbba0 0%, #f07f56 30%, #e2603a 60%, #c94a28 100%); }
.win.inactive .win-btns button { filter: saturate(.55) brightness(1.15); }
.win-btns svg { width: 11px; height: 11px; }

.win-body { flex: 1; min-height: 0; background: var(--face); display: flex; flex-direction: column; }

/* Address bar */
.addr {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 6px; border-bottom: 1px solid #d6d2c2; flex: none;
}
.addr span { color: #555; }
.addr output {
  flex: 1; background: #fff; border: 1px solid #7f9db9; padding: 2px 4px;
  display: flex; align-items: center; gap: 4px; white-space: nowrap; overflow: hidden;
}
.addr output img { width: 14px; height: 14px; }

/* Explorer */
.explorer { flex: 1; min-height: 0; display: grid; grid-template-columns: 200px 1fr; }
.taskpane {
  background: linear-gradient(to bottom, #7ba2e7, #6375d6);
  padding: 12px 10px; overflow: auto;
}
.pane-box { margin-bottom: 12px; border-radius: 3px 3px 0 0; overflow: hidden; }
.thumbs {
  background: #fff; overflow: auto; padding: 12px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 14px 10px; align-content: start;
}
.thumb {
  border: 0; background: none; padding: 0; cursor: default;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.thumb .frame {
  width: 104px; height: 104px; border: 1px solid #d0d0bf; background: #fff;
  display: grid; place-items: center; padding: 3px;
}
.thumb img { max-width: 96px; max-height: 96px; object-fit: contain; display: block; }
.thumb > span:last-child { padding: 0 3px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb.selected .frame { border: 2px solid var(--select); padding: 2px; }
.thumb.selected span { background: var(--select); color: #fff; }
.thumb:focus-visible { outline: none; }
.thumb:focus-visible span { outline: 1px dotted #000; }

.statusbar {
  flex: none; display: flex; gap: 12px; padding: 3px 8px;
  border-top: 1px solid #d6d2c2; color: #333;
}

/* Image viewer */
.viewer-stage { flex: 1; min-height: 0; background: #fff; position: relative; overflow: hidden; }
.viewer-stage img { position: absolute; inset: 10px; width: calc(100% - 20px); height: calc(100% - 20px); object-fit: contain; }
.viewer-bar {
  flex: none; display: flex; justify-content: center; align-items: center; gap: 6px;
  padding: 5px; border-top: 1px solid #d6d2c2;
}
.xp-btn {
  min-width: 72px; padding: 3px 10px;
  border: 1px solid #003c74; border-radius: 3px;
  background: linear-gradient(to bottom, #fff 0%, #ecebe6 86%, #d6d0c5 100%);
  cursor: pointer;
}
.xp-btn:hover { box-shadow: inset 0 0 0 2px #f8b636; }
.xp-btn:active { background: #e3e2da; }
.viewer-bar .count { min-width: 64px; text-align: center; color: #333; }

/* Notepad */
.notepad-text {
  flex: 1; overflow: auto; margin: 0; background: #fff;
  border: 1px solid #7f9db9; border-width: 1px 0 0;
  padding: 6px 8px; font: 13px/1.5 var(--mono); white-space: pre-wrap;
}
.notepad-text a { color: #00c; }

/* ---------- Taskbar ---------- */
#taskbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--taskbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex; align-items: stretch; z-index: 10000;
  background: linear-gradient(to bottom, #1f2f86 0, #3165c4 3%, #3682e5 6%, #4490e6 10%, #3883e5 12%, #2b71e0 15%, #2663da 18%, #235bd6 20%, #2258d5 23%, #2157d6 38%, #245ddb 54%, #2562df 86%, #245fdc 89%, #2158d4 92%, #1d4ec0 95%, #1941a5 98%);
}
#task-buttons { flex: 1; min-width: 0; display: flex; gap: 3px; align-items: center; padding: 0 6px; }
.task-btn {
  flex: 0 1 160px; min-width: 0; height: 24px;
  display: flex; align-items: center; gap: 5px; padding: 0 8px;
  border: 0; border-radius: 3px; color: #fff; cursor: pointer;
  background: #3c81f3; box-shadow: inset -1px -1px #1c47b5, inset 1px 1px #75a6ff;
}
.task-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-btn img { width: 16px; height: 16px; flex: none; }
.task-btn.active { background: #1e52b7; box-shadow: inset 1px 1px 2px #0c2a6c; }
#tray {
  flex: none; display: flex; align-items: center; padding: 0 14px;
  color: #fff; font-size: 11px;
  background: linear-gradient(to bottom, #0c59b9 1%, #139ee9 6%, #18b5f2 10%, #139beb 14%, #1290e8 19%, #0d8dea 63%, #0d9ff1 81%, #0f9eed 88%, #119be9 91%, #1392e2 94%, #137ed7 97%, #095bc9 100%);
  border-left: 1px solid #1042af; box-shadow: inset 1px 0 1px #18bbff;
}

/* ---------- Small screens ---------- */
@media (max-width: 720px), (pointer: coarse) and (max-width: 900px) {
  #icons {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 14px 4px; padding: 16px 8px; align-content: start;
  }
  .icon { position: static; transform: none; width: auto; }
  .win { left: 0 !important; top: 0 !important; width: 100% !important; height: 100% !important; border-radius: 0; }
  .win-title { border-radius: 0; height: 34px; }
  .win-btns .max { display: none; }
  .win-btns button { width: 28px; height: 28px; }
  .explorer { grid-template-columns: 1fr; }
  .taskpane { display: none; }
  .thumbs { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); padding: 10px; }
  .thumb { min-width: 0; }
  .thumb .frame { width: 100%; height: auto; aspect-ratio: 1 / 1; display: block; position: relative; overflow: hidden; }
  .thumb img { position: absolute; inset: 3px; width: calc(100% - 6px); height: calc(100% - 6px); max-width: none; max-height: none; }
  .addr span { display: none; }
  .task-btn { flex-basis: 44px; }
  .task-btn span { display: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .win.opening { animation: open .14s ease-out; }
  @keyframes open { from { transform: scale(.96); opacity: .4; } }
}

/* ---------- Explorer chrome ---------- */
.toolbar {
  display: flex; align-items: center; gap: 2px; padding: 3px 4px; flex: none;
  border-bottom: 1px solid #d6d2c2;
  background: linear-gradient(to bottom, #f8f7f2, var(--face));
}
.tb-btn {
  display: flex; align-items: center; gap: 4px; height: 32px; padding: 0 6px 0 3px;
  border: 1px solid transparent; border-radius: 3px; background: none; cursor: pointer;
}
.tb-btn img { width: 26px; height: 26px; }
.tb-btn:hover:not(:disabled) { border-color: #cecbc0; background: linear-gradient(#fff, #f1efe6); box-shadow: 0 1px 0 #c3bfae; }
.tb-btn:active:not(:disabled) { background: #e3e0d4; box-shadow: inset 1px 1px 1px #b9b5a2; }
.tb-btn:disabled { cursor: default; }
.tb-btn:disabled img { filter: grayscale(1) opacity(.45); }
.tb-btn:disabled span { color: #aca899; }
.tb-sep { width: 1px; height: 26px; background: #c5c2b2; box-shadow: 1px 0 #fff; margin: 0 4px; }

/* Collapsible sidebar boxes */
.pane-head {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  border: 0; padding: 6px 6px 6px 10px; cursor: pointer;
  font-weight: bold; font-size: 11px; color: var(--link); text-align: left;
  background: linear-gradient(to right, #fff 30%, #c6d3f7);
  border-radius: 3px 3px 0 0;
}
.pane-head:hover { color: #428eff; }
.chev {
  width: 17px; height: 17px; border-radius: 50%; flex: none;
  background: #fff; border: 1px solid #b6c5ed; box-shadow: 0 1px 1px rgba(0,0,0,.15);
  display: grid; place-items: center;
}
.chev::before {
  content: ""; width: 8px; height: 8px;
  background: no-repeat center / 8px 8px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath d='M1 4.5L4 1.5 7 4.5M1 7.5L4 4.5 7 7.5' stroke='%23215dc6' stroke-width='1.4' fill='none'/%3E%3C/svg%3E");
}
.pane-head[aria-expanded="false"] .chev::before { transform: rotate(180deg); }
.pane-content ul, .pane-content p { margin: 0; padding: 8px 10px; background: #d6dff7; border: 1px solid #fff; border-top: 0; list-style: none; }
.pane-content li + li { margin-top: 6px; }
.pane-content button, .pane-content a {
  border: 0; background: none; padding: 0; color: var(--link); cursor: pointer; font-size: 11px;
  text-decoration: none; text-align: left; display: flex; align-items: center; gap: 6px;
}
.pane-content button:hover, .pane-content a:hover { text-decoration: underline; color: #428eff; }
.pane-content img { width: 16px; height: 16px; object-fit: contain; }

.folders-view .frame { border-color: transparent; }
.folders-view .folder { transform: scale(1.15); }

/* ---------- Right-click menu ---------- */
.ctx {
  position: fixed; z-index: 10004; min-width: 170px; padding: 2px;
  background: #fff; border: 1px solid #aca899; box-shadow: 2px 2px 3px rgba(0,0,0,.35);
}
.ctx[hidden] { display: none; }
.ctx-item {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 4px 20px 4px 22px; font-size: 11px; cursor: default; position: relative;
}
.ctx-item:hover, .ctx-item:focus-visible { background: var(--select); color: #fff; outline: none; }
.ctx-item.checked::before { content: "✓"; position: absolute; left: 7px; }
.ctx-sep { height: 1px; margin: 3px 1px; background: #aca899; }

/* ---------- Tray + balloon ---------- */
#tray { gap: 8px; }
#tray a, #tray button { display: grid; place-items: center; border: 0; background: none; padding: 0; cursor: pointer; }
#tray img { width: 16px; height: 16px; }
.balloon {
  position: fixed; right: 10px; bottom: calc(var(--taskbar-h) + var(--safe-b) + 14px); z-index: 10003;
  width: 290px; padding: 9px 26px 10px 10px;
  background: #ffffe1; border: 1px solid #000; border-radius: 7px;
  box-shadow: 2px 2px 4px rgba(0,0,0,.3); font-size: 11px; cursor: pointer;
  transition: opacity .3s;
}
.balloon::after, .balloon::before {
  content: ""; position: absolute; right: 70px; bottom: -14px;
  border: 7px solid transparent; border-top: 14px solid #000; border-bottom: 0;
}
.balloon::after { bottom: -12px; right: 71px; border-width: 6px; border-top: 12px solid #ffffe1; border-bottom: 0; }
.balloon.hide { opacity: 0; }
.balloon-title { display: flex; align-items: center; gap: 6px; font-weight: bold; margin-bottom: 4px; }
.balloon-title img { width: 16px; height: 16px; }
.balloon p { margin: 0; }
.balloon-x {
  position: absolute; top: 5px; right: 5px; width: 16px; height: 16px; padding: 0; line-height: 13px;
  border: 1px solid #b9b9a0; border-radius: 3px; background: #ffffe1; cursor: pointer; font-size: 12px; color: #444;
}
.balloon-x:hover { background: #e2604a; color: #fff; border-color: #a33; }

@media (max-width: 720px), (pointer: coarse) and (max-width: 900px) {
  .balloon { left: 10px; right: 10px; width: auto; }
  .balloon::after, .balloon::before { right: 60px; }
}
@media (prefers-reduced-motion: reduce) { .balloon { transition: none; } }

/* ---------- Music player ---------- */
.mp-screen {
  flex: none; margin: 8px 8px 0; padding: 12px 12px 10px; border-radius: 4px;
  background: linear-gradient(to bottom, #0e2a5c, #133f86 55%, #0b2350);
  border: 1px solid #06173a; box-shadow: inset 0 1px 0 rgba(255,255,255,.15);
  color: #fff;
}
.mp-title { font: bold 15px var(--title-font); text-shadow: 0 1px 2px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mp-meta { color: #9fd0ff; margin-top: 3px; min-height: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mp-time { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-variant-numeric: tabular-nums; color: #cfe6ff; }
.mp-seek { flex: 1; accent-color: #5fd34a; min-width: 0; }
.mp-controls { flex: none; display: flex; align-items: center; gap: 6px; padding: 8px; }
.mp-btn {
  width: 32px; height: 32px; border-radius: 50%; padding: 0; cursor: pointer;
  display: grid; place-items: center; color: #1d3f7a;
  border: 1px solid #7c8fb5; background: linear-gradient(#fff, #d9e2f2);
  box-shadow: 0 1px 1px rgba(0,0,0,.2);
}
.mp-btn svg { width: 14px; height: 14px; }
.mp-btn:hover { background: linear-gradient(#fff, #c4d6f5); }
.mp-btn.mp-play { width: 42px; height: 42px; color: #fff; border-color: #1a5e10; background: radial-gradient(circle at 35% 30%, #b9f0a4, #3fae2a 50%, #1d6b12); }
.mp-btn.mp-play:hover { filter: brightness(1.08); }
.mp-btn.mp-play svg { width: 18px; height: 18px; }
.mp-spacer { flex: 1; }
.mp-volico { color: #1d3f7a; display: grid; }
.mp-volico svg { width: 16px; height: 16px; }
.mp-vol { width: 90px; accent-color: #316ac5; }
.mp-list {
  flex: 1; min-height: 0; overflow: auto; margin: 0 8px; padding: 0; list-style: none;
  background: #fff; border: 1px solid #7f9db9;
}
.mp-list button {
  width: 100%; display: grid; grid-template-columns: 24px 1fr; column-gap: 6px; text-align: left;
  border: 0; border-bottom: 1px solid #eef0f4; background: none; padding: 6px 8px; cursor: pointer;
}
.mp-list button:hover { background: #eef3fc; }
.mp-list button.active { background: var(--select); color: #fff; }
.mp-num { grid-row: span 2; color: #888; align-self: center; text-align: right; }
.mp-list button.active .mp-num, .mp-list button.active .mp-sub { color: #dbe7ff; }
.mp-name { font-weight: bold; }
.mp-sub { color: #777; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mp-foot { flex: none; display: flex; gap: 8px; justify-content: space-between; align-items: center; padding: 6px 8px; color: #444; font-size: 10px; }
.mp-foot a { color: var(--link); white-space: nowrap; }
