:root {
  --win-desktop: #008080;
  --win-face: #c0c0c0;
  --win-light: #ffffff;
  --win-highlight: #dfdfdf;
  --win-shadow: #808080;
  --win-dark: #000000;
  --win-blue: #000080;
  --win-blue-light: #1084d0;
  --win-title-inactive: #7f7f7f;
  --win-title-inactive2: #9f9f9f;
  --win-menu-hover: #000080;
  --win-warning: #ff0000;
  --win-yellow: #ffff00;
  --win-green: #008000;
  --win-text: #000000;
  --win-text-invert: #ffffff;
  --win-border-raised: inset 1px 1px var(--win-light), inset -1px -1px var(--win-dark), inset 2px 2px var(--win-highlight), inset -2px -2px var(--win-shadow);
  --win-border-sunken: inset 1px 1px var(--win-dark), inset -1px -1px var(--win-light), inset 2px 2px var(--win-shadow), inset -2px -2px var(--win-highlight);
  --win-border-window: inset 1px 1px var(--win-light), inset -1px -1px var(--win-dark);
  --win-font: 'MS Sans Serif', 'Tahoma', 'Arial', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--win-font);
  font-size: 11px;
  color: var(--win-text);
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
}

body {
  background: var(--win-desktop);
  cursor: default;
}

/* Boot sequence */
.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: #000;
  color: #c0c0c0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.4;
}
.bios-text {
  position: absolute;
  top: 24px;
  left: 24px;
  white-space: pre;
  display: none;
}
.splash {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #000080 0%, #0a2463 70%, #000 100%);
  color: #fff;
}
.splash-clouds {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 20% 30%, rgba(255,255,255,0.15) 0%, transparent 30%),
              radial-gradient(circle at 80% 20%, rgba(255,255,255,0.12) 0%, transparent 25%);
  pointer-events: none;
}
.splash-logo {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.splash-logo .flag {
  width: 64px;
  height: 64px;
  position: relative;
  transform: perspective(60px) rotateY(-20deg);
}
.splash-logo .flag::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, #ff0000 0%, #ff0000 20%, transparent 20%),
    linear-gradient(90deg, #00ff00 0%, #00ff00 40%, transparent 40%),
    linear-gradient(90deg, #0000ff 0%, #0000ff 60%, transparent 60%),
    linear-gradient(90deg, #ffff00 0%, #ffff00 80%, transparent 80%);
  background-size: 100% 25%;
  background-repeat: repeat-y;
  box-shadow: inset -2px -2px rgba(0,0,0,0.4);
}
.splash-logo .text { font-size: 48px; letter-spacing: -2px; }
.splash-logo .text b { font-weight: 900; }
.splash-copy { color: #c0c0c0; margin-bottom: 48px; }
.splash-loader {
  width: 240px;
  height: 18px;
  background: var(--win-face);
  box-shadow: var(--win-border-sunken);
  position: relative;
  overflow: hidden;
}
.splash-loader::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  height: calc(100% - 4px);
  width: 0%;
  background: #000080;
  transition: width 0.1s linear;
}

/* Desktop */
.desktop {
  position: fixed;
  inset: 0;
  z-index: 1;
  background-color: var(--win-desktop);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

.desktop-icon {
  position: absolute;
  width: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 4px 2px;
  cursor: default;
  outline: none;
}
.desktop-icon .icon-glyph {
  width: 32px;
  height: 32px;
  margin-bottom: 4px;
  image-rendering: pixelated;
}
.desktop-icon .icon-label {
  color: #fff;
  text-shadow: 1px 1px #000;
  padding: 1px 2px;
  line-height: 1.2;
  max-width: 100%;
  overflow-wrap: break-word;
}
.desktop-icon.selected .icon-label {
  background: #000080;
  color: #fff;
}
.desktop-icon.selected .icon-glyph { filter: drop-shadow(0 0 0 #000080); }

/* Marquee selection */
.marquee {
  position: absolute;
  border: 1px dotted #fff;
  background: rgba(0,0,128,0.15);
  pointer-events: none;
  z-index: 2;
}

/* Taskbar */
.taskbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 28px;
  background: var(--win-face);
  box-shadow: var(--win-border-raised);
  z-index: 100000;
  display: flex;
  align-items: center;
  padding: 2px;
  gap: 2px;
}

.start-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 6px;
  font-family: var(--win-font);
  font-size: 11px;
  font-weight: bold;
  background: var(--win-face);
  border: 2px solid;
  border-color: var(--win-light) var(--win-dark) var(--win-dark) var(--win-light);
  cursor: pointer;
  user-select: none;
}
.start-btn:active, .start-btn.pressed {
  border-color: var(--win-dark) var(--win-light) var(--win-light) var(--win-dark);
  padding: 1px 5px 0 7px;
  box-shadow: inset 1px 1px #000, inset 2px 2px #808080;
}
.start-btn .win-flag {
  display: inline-block;
  width: 16px;
  height: 14px;
  background: conic-gradient(from 90deg,
    #ff0000 0deg 45deg,
    #00ff00 45deg 90deg,
    #0000ff 90deg 135deg,
    #ffff00 135deg 180deg,
    #ff0000 180deg 225deg,
    #00ff00 225deg 270deg,
    #0000ff 270deg 315deg,
    #ffff00 315deg 360deg
  );
  border: 1px solid #fff;
  box-shadow: inset -1px -1px rgba(0,0,0,0.3);
}

.taskbar-divider {
  width: 1px;
  height: 22px;
  background: var(--win-shadow);
  border-left: 1px solid var(--win-light);
  margin: 0 2px;
}

.task-buttons {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  overflow: hidden;
  min-width: 0;
}

.task-button {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 6px;
  max-width: 160px;
  min-width: 0;
  background: var(--win-face);
  border: 2px solid;
  border-color: var(--win-light) var(--win-dark) var(--win-dark) var(--win-light);
  cursor: pointer;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.task-button:active, .task-button.pressed, .task-button.minimized:active {
  border-color: var(--win-dark) var(--win-light) var(--win-light) var(--win-dark);
  box-shadow: inset 1px 1px #000, inset 2px 2px #808080;
}
.task-button.active {
  border-color: var(--win-dark) var(--win-light) var(--win-light) var(--win-dark);
  box-shadow: inset 1px 1px #000, inset 2px 2px #808080;
  font-weight: bold;
}
.task-button .tb-icon { width: 16px; height: 16px; flex: 0 0 auto; }

.taskbar-tray {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
  height: 22px;
  box-shadow: var(--win-border-sunken);
  min-width: 70px;
  justify-content: flex-end;
}
.tray-icons { display: none; }
.clock { font-size: 11px; white-space: nowrap; }

/* Start menu */
.start-menu {
  position: fixed;
  left: 2px;
  bottom: 28px;
  z-index: 100010;
  background: var(--win-face);
  box-shadow: var(--win-border-raised);
  display: flex;
  min-width: 190px;
}
.start-menu[aria-hidden="true"] { display: none; }
.start-banner {
  width: 24px;
  background: linear-gradient(180deg, #000080 0%, #1084d0 100%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 4px;
}
.win98-banner {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 1px;
}
.win98-banner span { color: #c0c0c0; font-weight: 900; }
.start-list {
  list-style: none;
  margin: 0;
  padding: 2px;
  flex: 1;
}
.start-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
  position: relative;
}
.start-list li:hover, .start-list li.active {
  background: var(--win-menu-hover);
  color: #fff;
}
.start-list li .smi-icon { width: 20px; height: 20px; flex: 0 0 auto; }
.start-list li .smi-arrow { margin-left: auto; font-size: 10px; }
.start-list .sep {
  height: 1px;
  margin: 2px 4px;
  background: var(--win-shadow);
  border-top: 1px solid var(--win-light);
  padding: 0;
}
.start-list .submenu {
  display: none;
  position: absolute;
  left: 100%;
  top: -2px;
  background: var(--win-face);
  box-shadow: var(--win-border-raised);
  min-width: 150px;
  list-style: none;
  padding: 2px;
}
.start-list li:hover .submenu { display: block; }

/* Context menu */
.context-menu {
  position: fixed;
  z-index: 100020;
  background: var(--win-face);
  box-shadow: var(--win-border-raised);
  min-width: 140px;
  padding: 2px;
}
.context-menu[aria-hidden="true"] { display: none; }
.context-menu .cm-item {
  padding: 3px 18px 3px 22px;
  cursor: pointer;
  white-space: nowrap;
  position: relative;
}
.context-menu .cm-item:hover, .context-menu .cm-item.active {
  background: var(--win-menu-hover);
  color: #fff;
}
.context-menu .cm-item.disabled { color: var(--win-shadow); pointer-events: none; }
.context-menu .cm-item .cm-check { position: absolute; left: 6px; }
.context-menu .cm-sep {
  height: 1px;
  margin: 2px 4px;
  background: var(--win-shadow);
  border-top: 1px solid var(--win-light);
}

/* Windows */
.windows-layer { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.windows-layer > * { pointer-events: auto; }

.window {
  position: absolute;
  background: var(--win-face);
  box-shadow: var(--win-border-raised);
  min-width: 140px;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.window.inactive .title-bar { background: var(--win-title-inactive); }
.window.inactive .title-bar .title-text { color: #d0d0d0; }
.window.inactive .title-bar .title-btn svg { fill: #d0d0d0; }

.title-bar {
  height: 18px;
  background: linear-gradient(90deg, var(--win-blue) 0%, var(--win-blue-light) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 2px;
  user-select: none;
  cursor: default;
}
.title-bar .title-icon { width: 16px; height: 16px; margin-right: 2px; }
.title-bar .title-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; line-height: 1; }
.title-bar .title-btns { display: flex; gap: 2px; margin-left: 4px; }
.title-bar .title-btn {
  width: 14px;
  height: 14px;
  background: var(--win-face);
  border: 1px solid;
  border-color: var(--win-light) var(--win-dark) var(--win-dark) var(--win-light);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.title-bar .title-btn:active { border-color: var(--win-dark) var(--win-light) var(--win-light) var(--win-dark); }
.title-bar .title-btn svg { width: 8px; height: 8px; fill: #000; }

.window-body {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.resize-handle {
  position: absolute;
  z-index: 5;
}
.resize-handle.n { top: -3px; left: 4px; right: 4px; height: 6px; cursor: ns-resize; }
.resize-handle.s { bottom: -3px; left: 4px; right: 4px; height: 6px; cursor: ns-resize; }
.resize-handle.e { right: -3px; top: 4px; bottom: 4px; width: 6px; cursor: ew-resize; }
.resize-handle.w { left: -3px; top: 4px; bottom: 4px; width: 6px; cursor: ew-resize; }
.resize-handle.ne { top: -3px; right: -3px; width: 8px; height: 8px; cursor: nesw-resize; }
.resize-handle.nw { top: -3px; left: -3px; width: 8px; height: 8px; cursor: nwse-resize; }
.resize-handle.se { bottom: -3px; right: -3px; width: 8px; height: 8px; cursor: nwse-resize; }
.resize-handle.sw { bottom: -3px; left: -3px; width: 8px; height: 8px; cursor: nesw-resize; }

/* Menu bar */
.menubar {
  display: flex;
  gap: 4px;
  padding: 2px 4px;
  border-bottom: 1px solid var(--win-shadow);
  background: var(--win-face);
  user-select: none;
}
.menubar .menuitem {
  padding: 2px 6px;
  cursor: pointer;
}
.menubar .menuitem:hover, .menubar .menuitem.active {
  background: var(--win-menu-hover);
  color: #fff;
}
.menubar .menuitem .accel { text-decoration: underline; }

/* Buttons and inputs */
.win-btn {
  font-family: var(--win-font);
  font-size: 11px;
  background: var(--win-face);
  border: 2px solid;
  border-color: var(--win-light) var(--win-dark) var(--win-dark) var(--win-light);
  padding: 2px 12px;
  min-width: 60px;
  cursor: pointer;
}
.win-btn:active { border-color: var(--win-dark) var(--win-light) var(--win-light) var(--win-dark); padding: 3px 11px 1px 13px; }
.win-btn:focus { outline: 1px dotted #000; outline-offset: -3px; }

.win-input, .win-textarea, .win-select {
  font-family: var(--win-font);
  font-size: 11px;
  border: 2px solid;
  border-color: var(--win-dark) var(--win-light) var(--win-light) var(--win-dark);
  background: #fff;
  padding: 2px 4px;
}
.win-input:focus, .win-textarea:focus, .win-select:focus { outline: none; }

/* Scrollbars */
::-webkit-scrollbar { width: 16px; height: 16px; background: var(--win-face); }
::-webkit-scrollbar-thumb { background: var(--win-face); box-shadow: var(--win-border-raised); border: 1px solid var(--win-dark); }
::-webkit-scrollbar-button { background: var(--win-face); box-shadow: var(--win-border-raised); height: 16px; width: 16px; }
::-webkit-scrollbar-corner { background: var(--win-face); }

/* Tooltip */
.tooltip {
  position: fixed;
  z-index: 100030;
  background: #ffffe1;
  border: 1px solid #000;
  padding: 2px 4px;
  font-size: 11px;
  pointer-events: none;
}

/* Status bar */
.statusbar {
  display: flex;
  border-top: 1px solid var(--win-light);
  border-bottom: 1px solid var(--win-shadow);
  background: var(--win-face);
  padding: 2px;
  font-size: 11px;
}
.statusbar .status-cell {
  padding: 0 4px;
  border-right: 1px solid var(--win-shadow);
  border-left: 1px solid var(--win-light);
  flex: 1;
}

/* Dialog overlay */
.overlay-layer {
  position: fixed;
  inset: 0;
  z-index: 50000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.2);
}
.message-box {
  background: var(--win-face);
  box-shadow: var(--win-border-raised);
  padding: 12px;
  min-width: 240px;
  max-width: 400px;
}
.message-box .msg-row { display: flex; gap: 12px; margin-bottom: 12px; }
.message-box .msg-icon { width: 32px; height: 32px; flex: 0 0 auto; }
.message-box .msg-btns { display: flex; gap: 8px; justify-content: center; }

/* App specific containers */
.app-content { flex: 1; overflow: auto; min-height: 0; position: relative; }
.explorer { display: flex; height: 100%; }
.explorer .tree { width: 150px; border-right: 1px solid var(--win-shadow); overflow: auto; background: #fff; }
.explorer .list { flex: 1; overflow: auto; background: #fff; }
.explorer .list table { width: 100%; border-collapse: collapse; }
.explorer .list th, .explorer .list td { text-align: left; padding: 1px 4px; border-bottom: 1px solid var(--win-highlight); }
.explorer .list th { background: var(--win-face); }
.explorer .list tr.selected { background: #000080; color: #fff; }

.notepad { flex: 1; display: flex; flex-direction: column; }
.notepad textarea { flex: 1; resize: none; border: none; padding: 2px; font-family: 'Courier New', monospace; font-size: 13px; outline: none; }

.paint { display: flex; flex-direction: column; height: 100%; }
.paint .toolbar { display: flex; gap: 4px; padding: 4px; border-bottom: 1px solid var(--win-shadow); }
.paint .tool { width: 24px; height: 24px; border: 2px solid; border-color: var(--win-light) var(--win-dark) var(--win-dark) var(--win-light); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.paint .tool.active { border-color: var(--win-dark) var(--win-light) var(--win-light) var(--win-dark); background: #e0e0e0; }
.paint canvas { flex: 1; background: #fff; cursor: crosshair; }

.calculator { display: grid; gap: 4px; padding: 8px; grid-template-columns: repeat(5, 34px); justify-content: center; }
.calculator .calc-display { grid-column: 1 / -1; text-align: right; padding: 4px; background: #c0c0c0; border: 2px solid; border-color: var(--win-dark) var(--win-light) var(--win-light) var(--win-dark); font-family: 'Courier New', monospace; font-size: 18px; min-height: 28px; }
.calculator .calc-btn { height: 28px; font-size: 12px; }

.minesweeper { padding: 8px; display: inline-block; }
.minesweeper .ms-header { display: flex; justify-content: space-between; align-items: center; padding: 4px; margin-bottom: 4px; box-shadow: var(--win-border-sunken); }
.minesweeper .ms-counter, .minesweeper .ms-timer { font-family: 'Courier New', monospace; font-size: 18px; color: #ff0000; background: #000; padding: 2px 6px; letter-spacing: 2px; }
.minesweeper .ms-face { width: 26px; height: 26px; background: #ff0; border-radius: 4px; border: 2px solid; border-color: var(--win-light) var(--win-dark) var(--win-dark) var(--win-light); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.minesweeper .ms-grid { display: grid; gap: 0; box-shadow: var(--win-border-sunken); }
.minesweeper .ms-cell { width: 20px; height: 20px; background: var(--win-face); border: 2px solid; border-color: var(--win-light) var(--win-dark) var(--win-dark) var(--win-light); display: flex; align-items: center; justify-content: center; font-weight: bold; cursor: pointer; user-select: none; }
.minesweeper .ms-cell.revealed { border: 1px solid #7f7f7f; background: #c0c0c0; }
.minesweeper .ms-cell.flagged::after { content: '🚩'; font-size: 12px; }
.minesweeper .ms-cell.mine::after { content: '💣'; font-size: 12px; }
.minesweeper .ms-cell.num-1 { color: blue; }
.minesweeper .ms-cell.num-2 { color: green; }
.minesweeper .ms-cell.num-3 { color: red; }
.minesweeper .ms-cell.num-4 { color: navy; }
.minesweeper .ms-cell.num-5 { color: maroon; }
.minesweeper .ms-cell.num-6 { color: teal; }
.minesweeper .ms-cell.num-7 { color: #000; }
.minesweeper .ms-cell.num-8 { color: #808080; }

.ie { display: flex; flex-direction: column; height: 100%; }
.ie .ie-bar { display: flex; gap: 4px; padding: 2px 4px; border-bottom: 1px solid var(--win-shadow); }
.ie .ie-content { flex: 1; overflow: auto; padding: 8px; background: #fff; }

.dos { background: #000; color: #c0c0c0; font-family: 'Courier New', monospace; font-size: 13px; padding: 4px; flex: 1; overflow: auto; white-space: pre-wrap; }
.dos .dos-prompt { display: flex; }
.dos .dos-input { background: transparent; color: #c0c0c0; border: none; font-family: inherit; font-size: inherit; flex: 1; outline: none; }

.screensaver-overlay {
  position: fixed;
  inset: 0;
  z-index: 200000;
  background: #000;
  display: none;
}

.shutdown-screen {
  position: fixed;
  inset: 0;
  z-index: 300000;
  background: #000;
  color: #ff8c00;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  text-align: center;
  display: none;
}

/* Mobile responsive */
@media (max-width: 600px) {
  .desktop { touch-action: none; }
  .taskbar { height: 36px; }
  .start-btn { height: 30px; padding: 0 10px; font-size: 13px; }
  .start-btn .win-flag { width: 20px; height: 18px; }
  .task-button { height: 30px; font-size: 13px; }
  .taskbar-tray { height: 30px; }
  .start-menu { bottom: 36px; left: 0; right: 0; width: 100% !important; min-width: unset; }
  .window { max-width: calc(100% - 8px); }
  .desktop-icon { width: 64px; }
  .title-bar { height: 22px; }
  .title-bar .title-btn { width: 18px; height: 18px; }
}

/* Utilities */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-1 { flex: 1; }
