*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --win-teal: #008080;
  --win-silver: #c0c0c0;
  --win-navy: #000080;
  --win-white: #ffffff;
  --win-gray: #808080;
  --win-darkgray: #404040;
  --win-black: #000000;
  --win-title-active: #000080;
  --win-title-inactive: #7a7a7a;
  --win-title-text: #ffffff;
  --win-desktop: #008080;
  --win-taskbar: #c0c0c0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--win-desktop);
  font-family: "MS Sans Serif", "Microsoft Sans Serif", "Segoe UI", Tahoma, Geneva, sans-serif;
  font-size: 11px;
  cursor: default;
  user-select: none;
}

#desktop {
  width: 100%;
  height: calc(100% - 40px);
  position: relative;
  overflow: hidden;
  background: var(--win-teal);
}

/* ─── Desktop Icons ─── */
.desktop-icon {
  position: absolute;
  width: 75px;
  text-align: center;
  cursor: pointer;
  padding: 4px;
}

.desktop-icon .icon-wrapper {
  width: 48px;
  height: 48px;
  margin: 0 auto 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.desktop-icon .icon-wrapper svg {
  width: 48px;
  height: 48px;
}

.desktop-icon .icon-label {
  display: block;
  color: var(--win-white);
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
  word-wrap: break-word;
  text-shadow: 1px 1px 1px rgba(0,0,0,0.8);
  padding: 1px 2px;
  pointer-events: none;
}

.desktop-icon.selected .icon-label {
  background: var(--win-navy);
  text-shadow: none;
}

.desktop-icon:focus {
  outline: 1px dotted var(--win-white);
  outline-offset: -1px;
}

/* ─── Taskbar ─── */
#taskbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: var(--win-silver);
  border-top: 2px solid var(--win-white);
  display: flex;
  align-items: center;
  padding: 2px 2px;
  z-index: 10000;
}

#start-button {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 28px;
  padding: 0 8px;
  background: var(--win-silver);
  border: 2px solid;
  border-color: var(--win-white) var(--win-darkgray) var(--win-darkgray) var(--win-white);
  font-family: inherit;
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
}

#start-button:active {
  border-color: var(--win-darkgray) var(--win-white) var(--win-white) var(--win-darkgray);
}

#start-button.active {
  border-color: var(--win-darkgray) var(--win-white) var(--win-white) var(--win-darkgray);
}

#start-button svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.taskbar-divider {
  width: 2px;
  height: 28px;
  background: var(--win-gray);
  border-right: 1px solid var(--win-white);
  margin: 0 4px;
  flex-shrink: 0;
}

#taskbar-windows {
  flex: 1;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  min-width: 0;
  padding: 0 2px;
}

#taskbar-windows::-webkit-scrollbar {
  height: 0;
}

.taskbar-window-btn {
  height: 26px;
  min-width: 80px;
  max-width: 180px;
  padding: 0 6px;
  background: var(--win-silver);
  border: 2px solid;
  border-color: var(--win-white) var(--win-darkgray) var(--win-darkgray) var(--win-white);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
}

.taskbar-window-btn:active,
.taskbar-window-btn.active {
  border-color: var(--win-darkgray) var(--win-white) var(--win-white) var(--win-darkgray);
  background: #a0a0a0;
}

.taskbar-window-btn.active {
  background: #a0a0a0;
}

#taskbar-tray {
  height: 28px;
  display: flex;
  align-items: center;
  padding: 0 6px;
  border: 1px solid;
  border-color: var(--win-darkgray) var(--win-white) var(--win-white) var(--win-darkgray);
  margin-left: 4px;
  flex-shrink: 0;
  font-size: 11px;
  background: var(--win-silver);
}

/* ─── Start Menu ─── */
#start-menu {
  position: fixed;
  bottom: 40px;
  left: 0;
  width: 220px;
  background: var(--win-silver);
  border: 2px solid;
  border-color: var(--win-white) var(--win-darkgray) var(--win-darkgray) var(--win-white);
  box-shadow: 2px 2px 0 rgba(0,0,0,0.5);
  z-index: 10001;
  display: none;
}

#start-menu.visible {
  display: block;
}

.start-menu-sidebar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 24px;
  background: var(--win-gray);
  writing-mode: vertical-lr;
  text-orientation: mixed;
  color: var(--win-white);
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 0;
}

.start-menu-items {
  margin-left: 24px;
  padding: 4px 0;
}

.start-menu-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 11px;
  border: 1px solid transparent;
}

.start-menu-item:hover,
.start-menu-item.highlighted {
  background: var(--win-navy);
  color: var(--win-white);
}

.start-menu-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.start-menu-divider {
  height: 2px;
  background: var(--win-gray);
  border-top: 1px solid var(--win-white);
  margin: 4px 8px;
}

.start-menu-submenu {
  position: absolute;
  left: 220px;
  top: 0;
  min-width: 180px;
  background: var(--win-silver);
  border: 2px solid;
  border-color: var(--win-white) var(--win-darkgray) var(--win-darkgray) var(--win-white);
  box-shadow: 2px 2px 0 rgba(0,0,0,0.5);
  display: none;
  padding: 4px 0;
}

.start-menu-item:hover .start-menu-submenu,
.start-menu-item.highlighted .start-menu-submenu {
  display: block;
}

/* ─── Windows ─── */
.window {
  position: absolute;
  background: var(--win-silver);
  border: 2px solid;
  border-color: var(--win-white) var(--win-black) var(--win-black) var(--win-white);
  display: flex;
  flex-direction: column;
  min-width: 200px;
  min-height: 100px;
  box-shadow: 2px 2px 5px rgba(0,0,0,0.3);
}

.window.maximized {
  border-color: var(--win-silver);
}

.window-titlebar {
  display: flex;
  align-items: center;
  height: 22px;
  background: linear-gradient(90deg, var(--win-title-active) 0%, #1084d0 100%);
  padding: 2px 2px 2px 4px;
  flex-shrink: 0;
  cursor: default;
}

.window.inactive .window-titlebar {
  background: var(--win-title-inactive);
  background: linear-gradient(90deg, var(--win-title-inactive) 0%, #999999 100%);
}

.window-title-icon {
  width: 16px;
  height: 16px;
  margin-right: 4px;
  flex-shrink: 0;
}

.window-title-text {
  flex: 1;
  color: var(--win-white);
  font-size: 11px;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.window-controls {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  margin-left: 4px;
}

.window-controls button {
  width: 20px;
  height: 18px;
  padding: 0;
  border: 1px solid;
  border-color: var(--win-white) var(--win-darkgray) var(--win-darkgray) var(--win-white);
  background: var(--win-silver);
  font-family: "Marlett", "MS Sans Serif", sans-serif;
  font-size: 10px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  line-height: 1;
}

.window-controls button:active {
  border-color: var(--win-darkgray) var(--win-white) var(--win-white) var(--win-darkgray);
}

.window-body {
  flex: 1;
  margin: 2px;
  background: var(--win-white);
  overflow: auto;
  position: relative;
}

.window-body.no-content-bg {
  background: var(--win-silver);
}

/* ─── Resize handles ─── */
.window-resize-handles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.window-resize-handle {
  position: absolute;
  pointer-events: auto;
  z-index: 1;
}

.window-resize-n {
  top: -3px; left: 4px; right: 4px; height: 6px;
  cursor: n-resize;
}
.window-resize-s {
  bottom: -3px; left: 4px; right: 4px; height: 6px;
  cursor: s-resize;
}
.window-resize-e {
  right: -3px; top: 4px; bottom: 4px; width: 6px;
  cursor: e-resize;
}
.window-resize-w {
  left: -3px; top: 4px; bottom: 4px; width: 6px;
  cursor: w-resize;
}
.window-resize-ne {
  top: -3px; right: -3px; width: 10px; height: 10px;
  cursor: ne-resize;
}
.window-resize-nw {
  top: -3px; left: -3px; width: 10px; height: 10px;
  cursor: nw-resize;
}
.window-resize-se {
  bottom: -3px; right: -3px; width: 12px; height: 12px;
  cursor: se-resize;
}
.window-resize-sw {
  bottom: -3px; left: -3px; width: 10px; height: 10px;
  cursor: sw-resize;
}

.window-resize-se::after {
  content: '';
  position: absolute;
  bottom: 2px; right: 2px;
  width: 8px; height: 8px;
  background:
    linear-gradient(135deg, var(--win-gray) 33%, transparent 33%),
    linear-gradient(135deg, var(--win-gray) 33%, transparent 33%);
  background-size: 4px 4px;
  background-position: 0 0, 2px 2px;
  pointer-events: none;
  opacity: 0.6;
}

/* ─── Folder View (category) ─── */
.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 80px);
  gap: 8px;
  padding: 12px;
  justify-content: center;
}

.folder-item {
  width: 80px;
  text-align: center;
  cursor: pointer;
  padding: 4px;
  border: 1px solid transparent;
}

.folder-item:hover,
.folder-item.selected {
  background: var(--win-navy);
  color: var(--win-white);
}

.folder-item .icon-wrapper {
  width: 48px;
  height: 48px;
  margin: 0 auto 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.folder-item .icon-wrapper svg {
  width: 48px;
  height: 48px;
}

.folder-item .folder-label {
  font-size: 11px;
  line-height: 1.2;
  word-wrap: break-word;
  pointer-events: none;
}

/* ─── Piece detail view ─── */
.piece-detail {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.piece-images {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.piece-image-box {
  text-align: center;
  cursor: pointer;
  border: 1px solid var(--win-gray);
  padding: 4px;
  background: var(--win-white);
}

.piece-image-box img {
  max-width: 280px;
  max-height: 210px;
  display: block;
}

.piece-image-box .img-label {
  font-size: 10px;
  color: var(--win-gray);
  margin-top: 2px;
}

.piece-info-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: var(--win-silver);
  border: 2px solid;
  border-color: var(--win-white) var(--win-darkgray) var(--win-darkgray) var(--win-white);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  width: fit-content;
}

.piece-info-btn:active {
  border-color: var(--win-darkgray) var(--win-white) var(--win-white) var(--win-darkgray);
}

/* ─── Image Viewer ─── */
.viewer-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--win-black);
  overflow: hidden;
}

.viewer-container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.viewer-zoom-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: var(--win-silver);
  border: 1px solid;
  border-color: var(--win-white) var(--win-darkgray) var(--win-darkgray) var(--win-white);
  padding: 2px 6px;
  font-size: 11px;
  color: var(--win-black);
  pointer-events: none;
  z-index: 2;
}

/* ─── Notepad ─── */
.notepad-body {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.notepad-menubar {
  display: flex;
  background: var(--win-silver);
  border-bottom: 1px solid var(--win-gray);
  padding: 2px 0;
  flex-shrink: 0;
}

.notepad-menubar span {
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}

.notepad-menubar span:hover {
  background: var(--win-navy);
  color: var(--win-white);
}

.notepad-textarea {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font-family: "Courier New", "Courier", monospace;
  font-size: 12px;
  padding: 4px;
  line-height: 1.4;
  background: var(--win-white);
  color: var(--win-black);
  overflow: auto;
  white-space: pre-wrap;
  user-select: text;
  cursor: text;
}

/* ─── Shutdown Screen ─── */
#shutdown-screen {
  position: fixed;
  inset: 0;
  background: var(--win-black);
  z-index: 99999;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--win-white);
}

#shutdown-screen.visible {
  display: flex;
}

#shutdown-screen .shutdown-text {
  font-size: 18px;
  margin-top: 20px;
  animation: shutdownPulse 2s infinite;
}

@keyframes shutdownPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

#shutdown-screen .shutdown-logo svg {
  width: 80px;
  height: 80px;
}

/* ─── Scrollbar styling (Win95-like) ─── */
::-webkit-scrollbar {
  width: 16px;
  height: 16px;
}

::-webkit-scrollbar-track {
  background: var(--win-silver);
  border: 1px solid var(--win-gray);
}

::-webkit-scrollbar-thumb {
  background: var(--win-silver);
  border: 2px solid;
  border-color: var(--win-white) var(--win-darkgray) var(--win-darkgray) var(--win-white);
}

::-webkit-scrollbar-button {
  display: block;
  width: 16px;
  height: 16px;
  background: var(--win-silver);
  border: 2px solid;
  border-color: var(--win-white) var(--win-darkgray) var(--win-darkgray) var(--win-white);
}

::-webkit-scrollbar-corner {
  background: var(--win-silver);
}

/* ─── Loading screen ─── */
#loading-screen {
  position: fixed;
  inset: 0;
  background: var(--win-black);
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}

#loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s;
}

#loading-screen .loading-logo svg {
  width: 120px;
  height: 120px;
}

#loading-screen .loading-bar {
  width: 200px;
  height: 16px;
  background: var(--win-black);
  border: 2px solid var(--win-white);
  position: relative;
  overflow: hidden;
}

#loading-screen .loading-bar-fill {
  height: 100%;
  width: 0%;
  background: #0000a0;
  transition: width 0.3s;
}

#loading-screen .loading-text {
  color: var(--win-white);
  font-size: 12px;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  #desktop {
    height: calc(100% - 32px);
  }

  #taskbar {
    height: 32px;
    padding: 1px;
  }

  #start-button {
    height: 24px;
    padding: 0 4px;
    font-size: 10px;
  }

  #start-button svg {
    width: 14px;
    height: 14px;
  }

  #start-button-text {
    display: none;
  }

  .taskbar-divider {
    height: 22px;
  }

  #taskbar-tray {
    height: 22px;
    font-size: 10px;
    padding: 0 4px;
  }

  .taskbar-window-btn {
    height: 22px;
    min-width: 50px;
    max-width: 100px;
    font-size: 10px;
  }

  .window {
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: calc(100% - 32px) !important;
    border-color: var(--win-silver) !important;
  }

  .desktop-icon {
    width: 64px;
    padding: 2px;
  }

  .desktop-icon .icon-wrapper {
    width: 40px;
    height: 40px;
  }

  .desktop-icon .icon-wrapper svg {
    width: 40px;
    height: 40px;
  }

  .desktop-icon .icon-label {
    font-size: 10px;
  }

  #start-menu {
    width: 180px;
  }

  .start-menu-submenu {
    left: 180px;
    min-width: 140px;
  }

  .start-menu-sidebar {
    width: 20px;
    font-size: 14px;
  }

  .start-menu-items {
    margin-left: 20px;
  }

  .folder-grid {
    grid-template-columns: repeat(auto-fill, 70px);
    gap: 4px;
    padding: 8px;
  }

  .folder-item {
    width: 70px;
  }

  .piece-image-box img {
    max-width: 160px;
    max-height: 120px;
  }
}

@media (max-width: 480px) {
  #taskbar-tray {
    display: none;
  }

  .desktop-icon {
    width: 56px;
  }

  .desktop-icon .icon-wrapper {
    width: 32px;
    height: 32px;
  }

  .desktop-icon .icon-wrapper svg {
    width: 32px;
    height: 32px;
  }

  .desktop-icon .icon-label {
    font-size: 9px;
  }

  .folder-grid {
    grid-template-columns: repeat(auto-fill, 60px);
  }

  .folder-item {
    width: 60px;
  }

  .folder-item .icon-wrapper {
    width: 40px;
    height: 40px;
  }

  .folder-item .icon-wrapper svg {
    width: 40px;
    height: 40px;
  }

  .piece-images {
    flex-direction: column;
    align-items: center;
  }

  .piece-image-box img {
    max-width: 100%;
  }
}
