/* ====================================
   Windows 3.1 Faithful Recreation
   ==================================== */

/* Web font - closest to Windows 3.1 system font */
@import url('https://fonts.googleapis.com/css2?family=Pixelify+Sans:wght@400;700&display=swap');

:root {
  /* Windows 3.1 16-color VGA palette */
  --win-black: #000000;
  --win-white: #FFFFFF;
  --win-light-gray: #C0C0C0;  /* Button face / desktop */
  --win-dark-gray: #808080;
  --win-blue: #000080;         /* Title bar / active */
  --win-cyan: #00FFFF;
  --win-red: #FF0000;
  --win-green: #008000;
  --win-yellow: #FFFF00;

  /* Derived */
  --win-desktop: #008080;      /* Teal desktop background */
  --win-title-active: #000080;
  --win-title-inactive: #808080;
  --win-title-text-active: #FFFFFF;
  --win-title-text-inactive: #C0C0C0;
  --win-button-face: #C0C0C0;
  --win-button-highlight: #FFFFFF;
  --win-button-shadow: #808080;
  --win-button-dark-shadow: #000000;
  --win-window-bg: #FFFFFF;
  --win-field-bg: #FFFFFF;
  
  /* System font */
  --win-font: 'Pixelify Sans', 'MS Sans Serif', 'Microsoft Sans Serif', Tahoma, Arial, sans-serif;
  --win-font-size: 12px;
}

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

/* Disable text selection globally for authentic feel */
body {
  font-family: var(--win-font);
  font-size: var(--win-font-size);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  cursor: default;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
  image-rendering: pixelated;
}

.hidden { display: none !important; }

/* ============ BOOT SCREEN ============ */
#boot-screen {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  color: #C0C0C0;
  font-family: 'Courier New', monospace;
}

.boot-content {
  text-align: center;
}

.boot-ascii {
  font-size: 11px;
  line-height: 1.2;
  color: #fff;
  white-space: pre;
  margin-bottom: 30px;
}

.boot-version {
  font-size: 18px;
  color: #C0C0C0;
  margin-bottom: 40px;
  letter-spacing: 4px;
}

.boot-loading {
  width: 300px;
  margin: 0 auto;
}

.boot-bar {
  width: 100%;
  height: 20px;
  border: 2px solid #808080;
  background: #000;
}

.boot-bar-fill {
  height: 100%;
  width: 0%;
  background: #000080;
  transition: width 0.1s linear;
}

.boot-text {
  margin-top: 10px;
  font-size: 14px;
  color: #808080;
}

/* ============ DESKTOP ============ */
#desktop {
  position: fixed;
  inset: 0;
  background: var(--win-desktop);
  overflow: hidden;
}

/* ============ WINDOWS ============ */
.window {
  position: absolute;
  background: var(--win-button-face);
  /* Windows 3.1 3D border effect */
  border-top: 2px solid var(--win-button-highlight);
  border-left: 2px solid var(--win-button-highlight);
  border-right: 2px solid var(--win-button-dark-shadow);
  border-bottom: 2px solid var(--win-button-dark-shadow);
  box-shadow:
    inset 1px 1px 0 var(--win-button-face),
    inset -1px -1px 0 var(--win-button-shadow);
  display: flex;
  flex-direction: column;
  min-width: 200px;
  min-height: 100px;
}

.window.maximized {
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
}

/* ============ TITLE BAR ============ */
.title-bar {
  background: var(--win-title-active);
  color: var(--win-title-text-active);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 3px;
  height: 22px;
  min-height: 22px;
  cursor: move;
  user-select: none;
  flex-shrink: 0;
}

.title-bar.inactive {
  background: var(--win-title-inactive);
  color: var(--win-title-text-inactive);
}

.title-bar-left {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
}

.title-bar-text {
  font-size: 12px;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.title-bar-controls {
  display: flex;
  gap: 2px;
}

/* System menu button (the dash in top-left) */
.system-menu-btn {
  width: 18px;
  height: 16px;
  background: var(--win-button-face);
  border-top: 1px solid var(--win-button-highlight);
  border-left: 1px solid var(--win-button-highlight);
  border-right: 1px solid var(--win-button-dark-shadow);
  border-bottom: 1px solid var(--win-button-dark-shadow);
  font-size: 12px;
  font-weight: bold;
  line-height: 12px;
  text-align: center;
  cursor: pointer;
  color: var(--win-black);
  padding: 0;
  font-family: var(--win-font);
  flex-shrink: 0;
}

.system-menu-btn:active {
  border-top: 1px solid var(--win-button-dark-shadow);
  border-left: 1px solid var(--win-button-dark-shadow);
  border-right: 1px solid var(--win-button-highlight);
  border-bottom: 1px solid var(--win-button-highlight);
}

/* Min/Max buttons */
.win-btn {
  width: 18px;
  height: 16px;
  background: var(--win-button-face);
  border-top: 1px solid var(--win-button-highlight);
  border-left: 1px solid var(--win-button-highlight);
  border-right: 1px solid var(--win-button-dark-shadow);
  border-bottom: 1px solid var(--win-button-dark-shadow);
  font-size: 8px;
  line-height: 14px;
  text-align: center;
  cursor: pointer;
  color: var(--win-black);
  padding: 0;
  font-family: var(--win-font);
}

.win-btn:active {
  border-top: 1px solid var(--win-button-dark-shadow);
  border-left: 1px solid var(--win-button-dark-shadow);
  border-right: 1px solid var(--win-button-highlight);
  border-bottom: 1px solid var(--win-button-highlight);
  padding-top: 1px;
  padding-left: 1px;
}

/* ============ MENU BAR ============ */
.menu-bar {
  background: var(--win-button-face);
  border-bottom: 1px solid var(--win-button-shadow);
  padding: 1px 4px;
  display: flex;
  gap: 2px;
  height: 20px;
  min-height: 20px;
  align-items: center;
  flex-shrink: 0;
}

.menu-item {
  padding: 1px 8px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}

.menu-item:hover {
  background: var(--win-title-active);
  color: var(--win-white);
}

.menu-item u {
  text-decoration: underline;
}

/* ============ WINDOW BODY ============ */
.window-body {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ============ PROGRAM MANAGER ============ */
.program-manager {
  top: 20px;
  left: 20px;
  width: calc(100vw - 40px);
  height: calc(100vh - 60px);
  z-index: 1;
}

.pm-body {
  background: var(--win-button-face);
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
}

/* ============ PROGRAM GROUPS (MDI children) ============ */
.program-group {
  border-top: 2px solid var(--win-button-highlight);
  border-left: 2px solid var(--win-button-highlight);
  border-right: 2px solid var(--win-button-dark-shadow);
  border-bottom: 2px solid var(--win-button-dark-shadow);
  background: var(--win-white);
  min-width: 280px;
  display: flex;
  flex-direction: column;
}

.program-group .group-title-bar {
  background: var(--win-title-active);
  color: var(--win-title-text-active);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 3px;
  height: 20px;
  min-height: 20px;
  user-select: none;
  flex-shrink: 0;
}

.program-group .group-title-bar .title-bar-text {
  font-size: 11px;
}

.group-body {
  display: flex;
  flex-wrap: wrap;
  padding: 12px;
  gap: 16px;
  align-content: flex-start;
  min-height: 100px;
}

/* Minimized groups — show only title bar, no body */
.minimized-group {
  min-width: 120px;
  width: auto;
  background: var(--win-button-face);
  align-self: flex-start;
}

.minimized-group .group-body {
  display: none !important;
}

.minimized-group .group-title-bar {
  background: var(--win-title-inactive);
  color: var(--win-title-text-inactive);
}

/* ============ PROGRAM ICONS ============ */
.program-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 70px;
  cursor: pointer;
  padding: 4px;
  text-align: center;
}

.program-icon:hover {
  outline: 1px dotted var(--win-black);
}

.program-icon.selected {
  background: var(--win-title-active);
}

.program-icon.selected .icon-label {
  background: var(--win-title-active);
  color: var(--win-white);
}

.icon {
  width: 32px;
  height: 32px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-label {
  font-size: 10px;
  word-wrap: break-word;
  max-width: 70px;
  line-height: 1.2;
}

/* ============ GENERIC BUTTON ============ */
.win-button {
  font-family: var(--win-font);
  font-size: 12px;
  padding: 4px 20px;
  background: var(--win-button-face);
  border-top: 2px solid var(--win-button-highlight);
  border-left: 2px solid var(--win-button-highlight);
  border-right: 2px solid var(--win-button-dark-shadow);
  border-bottom: 2px solid var(--win-button-dark-shadow);
  cursor: pointer;
  color: var(--win-black);
  min-width: 75px;
  text-align: center;
  outline: none;
}

.win-button:active {
  border-top: 2px solid var(--win-button-dark-shadow);
  border-left: 2px solid var(--win-button-dark-shadow);
  border-right: 2px solid var(--win-button-highlight);
  border-bottom: 2px solid var(--win-button-highlight);
  padding: 5px 19px 3px 21px;
}

.win-button:focus {
  outline: 1px dotted var(--win-black);
  outline-offset: -4px;
}

.win-button.default {
  box-shadow: inset 0 0 0 1px var(--win-black);
}

/* ============ TEXT INPUT ============ */
.win-input {
  font-family: var(--win-font);
  font-size: 12px;
  padding: 3px 4px;
  background: var(--win-field-bg);
  border-top: 2px solid var(--win-button-shadow);
  border-left: 2px solid var(--win-button-shadow);
  border-right: 2px solid var(--win-button-highlight);
  border-bottom: 2px solid var(--win-button-highlight);
  box-shadow: inset 1px 1px 0 var(--win-button-dark-shadow);
  outline: none;
  color: var(--win-black);
}

.win-textarea {
  font-family: 'Courier New', 'Fixedsys', monospace;
  font-size: 13px;
  padding: 4px;
  background: var(--win-field-bg);
  border-top: 2px solid var(--win-button-shadow);
  border-left: 2px solid var(--win-button-shadow);
  border-right: 2px solid var(--win-button-highlight);
  border-bottom: 2px solid var(--win-button-highlight);
  box-shadow: inset 1px 1px 0 var(--win-button-dark-shadow);
  outline: none;
  resize: none;
  color: var(--win-black);
}

/* ============ PERPLEXITY APP ============ */
#perplexity-window {
  top: 60px;
  left: 100px;
  width: 600px;
  height: 480px;
  z-index: 10;
}

.perplexity-app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.perplexity-toolbar {
  background: var(--win-button-face);
  padding: 6px 8px;
  border-bottom: 1px solid var(--win-button-shadow);
  flex-shrink: 0;
}

.perplexity-search-row {
  display: flex;
  gap: 4px;
  align-items: center;
}

.perplexity-search-row .win-input {
  flex: 1;
  height: 24px;
}

.perplexity-search-row .win-button {
  min-width: 60px;
  height: 24px;
  padding: 2px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.perplexity-header {
  background: var(--win-blue);
  color: var(--win-white);
  padding: 8px 12px;
  text-align: center;
  flex-shrink: 0;
}

.perplexity-header-title {
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 2px;
}

.perplexity-header-subtitle {
  font-size: 10px;
  color: var(--win-cyan);
  margin-top: 2px;
}

.perplexity-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  background: var(--win-white);
  font-size: 12px;
  line-height: 1.6;
  color: var(--win-black);
  border-top: 1px solid var(--win-button-shadow);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.perplexity-results .cursor {
  display: inline-block;
  width: 8px;
  height: 14px;
  background: var(--win-black);
  animation: blink 0.6s step-end infinite;
  vertical-align: text-bottom;
}

@keyframes blink {
  50% { opacity: 0; }
}

.perplexity-status {
  background: var(--win-button-face);
  border-top: 1px solid var(--win-button-shadow);
  padding: 2px 8px;
  font-size: 10px;
  color: var(--win-dark-gray);
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
}

.perplexity-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--win-dark-gray);
  padding: 20px;
}

.perplexity-welcome-logo {
  margin-bottom: 16px;
}

.perplexity-welcome h2 {
  font-size: 16px;
  color: var(--win-blue);
  margin-bottom: 8px;
}

.perplexity-welcome p {
  font-size: 11px;
  text-align: center;
  line-height: 1.5;
  max-width: 300px;
}

/* ============ NOTEPAD ============ */
#notepad-window {
  top: 80px;
  left: 150px;
  width: 500px;
  height: 380px;
  z-index: 10;
}

.notepad-body {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.notepad-body .win-textarea {
  flex: 1;
  width: 100%;
  border: none;
  box-shadow: none;
}

/* ============ CALCULATOR ============ */
#calculator-window {
  top: 100px;
  left: 200px;
  width: 260px;
  height: 320px;
  z-index: 10;
  resize: none;
}

.calc-body {
  padding: 8px;
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 6px;
  background: var(--win-button-face);
}

.calc-display {
  font-family: 'Courier New', monospace;
  font-size: 18px;
  text-align: right;
  padding: 4px 8px;
  background: var(--win-field-bg);
  border-top: 2px solid var(--win-button-shadow);
  border-left: 2px solid var(--win-button-shadow);
  border-right: 2px solid var(--win-button-highlight);
  border-bottom: 2px solid var(--win-button-highlight);
  box-shadow: inset 1px 1px 0 var(--win-button-dark-shadow);
  height: 30px;
  line-height: 22px;
  overflow: hidden;
  color: var(--win-black);
}

.calc-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  flex: 1;
}

.calc-btn {
  font-family: var(--win-font);
  font-size: 13px;
  font-weight: bold;
  background: var(--win-button-face);
  border-top: 2px solid var(--win-button-highlight);
  border-left: 2px solid var(--win-button-highlight);
  border-right: 2px solid var(--win-button-dark-shadow);
  border-bottom: 2px solid var(--win-button-dark-shadow);
  cursor: pointer;
  color: var(--win-black);
  display: flex;
  align-items: center;
  justify-content: center;
}

.calc-btn:active {
  border-top: 2px solid var(--win-button-dark-shadow);
  border-left: 2px solid var(--win-button-dark-shadow);
  border-right: 2px solid var(--win-button-highlight);
  border-bottom: 2px solid var(--win-button-highlight);
}

.calc-btn.op {
  color: var(--win-red);
}

.calc-btn.wide {
  grid-column: span 2;
}

/* ============ MINESWEEPER ============ */
#minesweeper-window {
  top: 50px;
  left: 250px;
  width: auto;
  height: auto;
  z-index: 10;
}

.mine-body {
  padding: 6px;
  background: var(--win-button-face);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mine-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 6px;
  border-top: 2px solid var(--win-button-shadow);
  border-left: 2px solid var(--win-button-shadow);
  border-right: 2px solid var(--win-button-highlight);
  border-bottom: 2px solid var(--win-button-highlight);
  background: var(--win-button-face);
}

.mine-counter {
  font-family: 'Courier New', monospace;
  font-size: 18px;
  font-weight: bold;
  background: #000;
  color: #FF0000;
  padding: 2px 4px;
  min-width: 45px;
  text-align: center;
  border-top: 1px solid var(--win-button-shadow);
  border-left: 1px solid var(--win-button-shadow);
  border-right: 1px solid var(--win-button-highlight);
  border-bottom: 1px solid var(--win-button-highlight);
}

.mine-face-btn {
  width: 28px;
  height: 28px;
  font-size: 16px;
  background: var(--win-button-face);
  border-top: 2px solid var(--win-button-highlight);
  border-left: 2px solid var(--win-button-highlight);
  border-right: 2px solid var(--win-button-dark-shadow);
  border-bottom: 2px solid var(--win-button-dark-shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.mine-face-btn:active {
  border-top: 2px solid var(--win-button-dark-shadow);
  border-left: 2px solid var(--win-button-dark-shadow);
  border-right: 2px solid var(--win-button-highlight);
  border-bottom: 2px solid var(--win-button-highlight);
}

.mine-grid {
  display: grid;
  border-top: 3px solid var(--win-button-shadow);
  border-left: 3px solid var(--win-button-shadow);
  border-right: 3px solid var(--win-button-highlight);
  border-bottom: 3px solid var(--win-button-highlight);
}

.mine-cell {
  width: 22px;
  height: 22px;
  background: var(--win-button-face);
  border-top: 2px solid var(--win-button-highlight);
  border-left: 2px solid var(--win-button-highlight);
  border-right: 2px solid var(--win-button-dark-shadow);
  border-bottom: 2px solid var(--win-button-dark-shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--win-font);
  font-size: 13px;
  font-weight: bold;
  user-select: none;
}

.mine-cell:active:not(.revealed):not(.flagged) {
  border: 1px solid var(--win-button-shadow);
  background: var(--win-button-face);
}

.mine-cell.revealed {
  border: 1px solid var(--win-button-shadow);
  background: var(--win-button-face);
  cursor: default;
}

.mine-cell.exploded {
  background: #FF0000;
}

.mine-cell.flagged {
  cursor: default;
}

.mine-cell[data-num="1"] { color: #0000FF; }
.mine-cell[data-num="2"] { color: #008000; }
.mine-cell[data-num="3"] { color: #FF0000; }
.mine-cell[data-num="4"] { color: #000080; }
.mine-cell[data-num="5"] { color: #800000; }
.mine-cell[data-num="6"] { color: #008080; }
.mine-cell[data-num="7"] { color: #000000; }
.mine-cell[data-num="8"] { color: #808080; }

/* ============ DIALOG ============ */
.dialog {
  z-index: 9999;
}

.dialog-body {
  padding: 16px;
}

.dialog-buttons {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

/* About dialog */
#about-dialog {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 380px;
}

.about-icon-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.about-text {
  font-size: 12px;
  line-height: 1.4;
}

.about-separator {
  height: 2px;
  background: var(--win-button-shadow);
  margin: 12px 0;
  border-bottom: 1px solid var(--win-button-highlight);
}

.about-memory {
  font-size: 11px;
  color: var(--win-dark-gray);
}

/* ============ MINIMIZED TRAY ============ */
#minimized-tray {
  position: fixed;
  bottom: 4px;
  left: 4px;
  display: flex;
  gap: 4px;
  z-index: 9990;
}

.minimized-icon {
  background: var(--win-button-face);
  border-top: 2px solid var(--win-button-highlight);
  border-left: 2px solid var(--win-button-highlight);
  border-right: 2px solid var(--win-button-dark-shadow);
  border-bottom: 2px solid var(--win-button-dark-shadow);
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 160px;
  height: 24px;
}

.minimized-icon:active {
  border-top: 2px solid var(--win-button-dark-shadow);
  border-left: 2px solid var(--win-button-dark-shadow);
  border-right: 2px solid var(--win-button-highlight);
  border-bottom: 2px solid var(--win-button-highlight);
}

.minimized-icon svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ============ DROPDOWN MENU ============ */
.dropdown-menu {
  position: absolute;
  background: var(--win-button-face);
  border-top: 2px solid var(--win-button-highlight);
  border-left: 2px solid var(--win-button-highlight);
  border-right: 2px solid var(--win-button-dark-shadow);
  border-bottom: 2px solid var(--win-button-dark-shadow);
  box-shadow: 2px 2px 0 var(--win-black);
  z-index: 10000;
  min-width: 160px;
  padding: 2px 0;
  font-size: 12px;
}

.dropdown-item {
  padding: 3px 24px 3px 24px;
  cursor: pointer;
  white-space: nowrap;
}

.dropdown-item:hover {
  background: var(--win-title-active);
  color: var(--win-white);
}

.dropdown-separator {
  height: 1px;
  background: var(--win-button-shadow);
  margin: 2px 4px;
  border-bottom: 1px solid var(--win-button-highlight);
}

.dropdown-item.disabled {
  color: var(--win-dark-gray);
  cursor: default;
}

.dropdown-item.disabled:hover {
  background: transparent;
  color: var(--win-dark-gray);
}

/* ============ RESIZE HANDLE ============ */
.window .resize-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
}

/* ============ SCROLLBAR STYLING ============ */
.perplexity-results::-webkit-scrollbar,
.win-textarea::-webkit-scrollbar {
  width: 16px;
}

.perplexity-results::-webkit-scrollbar-track,
.win-textarea::-webkit-scrollbar-track {
  background: var(--win-button-face);
  border-left: 1px solid var(--win-button-shadow);
}

.perplexity-results::-webkit-scrollbar-thumb,
.win-textarea::-webkit-scrollbar-thumb {
  background: var(--win-button-face);
  border-top: 2px solid var(--win-button-highlight);
  border-left: 2px solid var(--win-button-highlight);
  border-right: 2px solid var(--win-button-dark-shadow);
  border-bottom: 2px solid var(--win-button-dark-shadow);
}

.perplexity-results::-webkit-scrollbar-button,
.win-textarea::-webkit-scrollbar-button {
  background: var(--win-button-face);
  border-top: 2px solid var(--win-button-highlight);
  border-left: 2px solid var(--win-button-highlight);
  border-right: 2px solid var(--win-button-dark-shadow);
  border-bottom: 2px solid var(--win-button-dark-shadow);
  height: 16px;
}

/* ============ FOOTER (attribution) ============ */
.win31-footer {
  position: fixed;
  bottom: 0;
  right: 4px;
  z-index: 9999;
  font-size: 9px;
}

.win31-footer a {
  color: var(--win-light-gray);
  text-decoration: none;
  opacity: 0.5;
}

.win31-footer a:hover {
  opacity: 1;
}

/* ============ HOURGLASS CURSOR ============ */
.waiting, .waiting * {
  cursor: wait !important;
}

/* ============ PERPLEXITY ERROR ============ */
.perplexity-error {
  color: var(--win-red);
  padding: 8px;
  font-size: 12px;
}
