body.os-mode {
  overflow: hidden !important;
}

body.os-mode main > section:not(#hero) {
  display: none !important;
}

body.os-mode .site-footer {
  display: none !important;
}

body.os-mode .hero {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  border: none;
}

.theme-toggle.os-toggle-active {
  border-color: var(--accent);
}

.os-toggle-art {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  white-space: pre;
  text-align: center;
}

.os-desktop-layer {
  --os-top: 76px;
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  pointer-events: none;
  font-family: var(--font-body);
}

body.os-mode .os-desktop-layer {
  display: block;
}

.os-desktop-layer::before {
  content: '';
  position: absolute;
  top: 64px;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: -1;
  background: rgba(0, 0, 0, 0.6);
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.os-icons-grid {
  position: absolute;
  top: 80px;
  left: 24px;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 88px;
  grid-template-rows: repeat(auto-fill, 100px);
  gap: 12px 16px;
  height: calc(100vh - 140px);
  pointer-events: none;
}

.os-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 88px;
  height: 100px;
  padding: 8px;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  pointer-events: auto;
  transition: background 0.15s, border-color 0.15s;
}

.os-icon:hover {
  background: var(--panel-hover);
  border-color: var(--border);
}

.os-icon:focus-visible {
  outline: 1px dashed var(--accent);
  outline-offset: 2px;
}

.os-icon-glyph {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 42px;
  height: 42px;
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  color: var(--heading);
}

.os-icon span {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-align: center;
  text-transform: uppercase;
  color: var(--text);
  word-break: break-all;
}

.os-window {
  position: absolute;
  display: none;
  flex-direction: column;
  width: min(560px, 90vw);
  height: min(420px, 75vh);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-soft);
  pointer-events: auto;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.2s var(--ease-out), transform 0.2s var(--ease-out);
}

.os-window.open {
  opacity: 1;
  transform: none;
}

.os-resize {
  position: absolute;
  z-index: 5;
  touch-action: none;
}

.os-resize-n {
  top: -4px;
  left: 10px;
  right: 10px;
  height: 6px;
  cursor: ns-resize;
}

.os-resize-s {
  bottom: -4px;
  left: 10px;
  right: 10px;
  height: 6px;
  cursor: ns-resize;
}

.os-resize-e {
  right: -4px;
  top: 10px;
  bottom: 10px;
  width: 6px;
  cursor: ew-resize;
}

.os-resize-w {
  left: -4px;
  top: 10px;
  bottom: 10px;
  width: 6px;
  cursor: ew-resize;
}

.os-resize-ne,
.os-resize-nw,
.os-resize-se,
.os-resize-sw {
  width: 10px;
  height: 10px;
}

.os-resize-ne {
  top: -4px;
  right: -4px;
  cursor: nesw-resize;
}

.os-resize-nw {
  top: -4px;
  left: -4px;
  cursor: nwse-resize;
}

.os-resize-se {
  bottom: -4px;
  right: -4px;
  cursor: nwse-resize;
}

.os-resize-sw {
  bottom: -4px;
  left: -4px;
  cursor: nesw-resize;
}

.os-window.maximized .os-resize {
  display: none;
}

.os-window.maximized {
  top: var(--os-top) !important;
  left: 8px !important;
  width: calc(100vw - 16px) !important;
  height: calc(100vh - var(--os-top) - 50px) !important;
}

.os-window.crt-flash .os-titlebar {
  animation: crtFlicker 0.35s ease-out;
}

@keyframes crtFlicker {
  0% { filter: brightness(2.2) contrast(1.4); }
  50% { filter: brightness(1.4) contrast(1.2); }
  100% { filter: brightness(1) contrast(1); }
}

.os-titlebar {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  height: 32px;
  padding: 0 8px 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border-strong);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.os-titlebar:active {
  cursor: grabbing;
}

.os-window.maximized .os-titlebar {
  cursor: default;
}

.os-titlebar-title {
  font-family: var(--font-display);
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--heading);
}

.os-titlebar-controls {
  display: flex;
  gap: 4px;
}

.os-win-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  font-size: 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--heading);
  transition: background 0.15s, border-color 0.15s;
}

.os-win-btn:hover {
  background: var(--panel-hover);
  border-color: var(--accent);
}

.os-win-body {
  flex: 1;
  min-height: 0;
  padding: 16px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--text-muted) transparent;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text-muted);
}

@supports not (scrollbar-width: thin) {
  .os-win-body::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }

  .os-win-body::-webkit-scrollbar-track {
    background: transparent;
  }

  .os-win-body::-webkit-scrollbar-thumb {
    background: var(--text-muted);
  }

  .os-win-body::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
  }

  .os-win-body::-webkit-scrollbar-button {
    display: none;
  }
}

.os-win-body img,
.os-win-body svg,
.os-win-body video,
.os-win-body canvas {
  max-width: 100%;
}

.os-win-body .plist,
.os-win-body .term,
.os-win-body .log-list {
  max-width: 100%;
  min-width: 0;
}

.os-win-body .term-body {
  overflow-x: auto;
}

.os-win-body > section {
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  max-width: none !important;
  border: 0 !important;
}

.os-win-body .reveal {
  opacity: 1 !important;
  transform: none !important;
  visibility: visible !important;
  transition: none !important;
}

.os-win-body .section-header {
  margin-bottom: 16px !important;
}

.os-win-body .section-title {
  font-size: clamp(1.4rem, 4vw, 2rem) !important;
}

.os-win-body .about-cards,
.os-win-body .art-grid,
.os-win-body .ach-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)) !important;
  gap: 12px !important;
}

.os-win-body .about-cards > *,
.os-win-body .art-grid > *,
.os-win-body .ach-grid > * {
  min-width: 0;
}

.os-window.maximized .os-win-body {
  padding: clamp(16px, 2.5vw, 40px);
}

.os-window.maximized .os-win-body .section-title {
  font-size: clamp(1.8rem, 4vw, 3.2rem) !important;
}

.os-window.maximized .os-win-body .about-cards,
.os-window.maximized .os-win-body .art-grid,
.os-window.maximized .os-win-body .ach-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)) !important;
  gap: clamp(12px, 1.6vw, 24px) !important;
}

.os-taskbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 42px;
  z-index: 300;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--nav-bg);
  border-top: 1px solid var(--border-strong);
  backdrop-filter: blur(8px);
}

body.os-mode .os-taskbar {
  display: flex;
}

.os-start-btn {
  display: flex;
  flex: none;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  font-family: var(--font-display);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--accent);
  border: 1px solid var(--accent);
  cursor: pointer;
}

.os-task-items {
  display: flex;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
}

.os-task-chip {
  flex: none;
  height: 28px;
  padding: 0 12px;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}

.os-task-chip[hidden] {
  display: none;
}

.os-task-chip.active {
  border-color: var(--accent);
  color: var(--heading);
  background: var(--panel-hover);
}

@media (max-width: 640px) {
  .os-icons-grid {
    right: 16px;
    left: 16px;
    top: 72px;
    height: auto;
    grid-auto-flow: row;
    grid-auto-columns: auto;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: none;
  }

  .os-icon {
    width: auto;
  }

  .os-window {
    top: var(--os-top) !important;
    left: 8px !important;
    width: calc(100vw - 16px) !important;
    height: calc(100vh - var(--os-top) - 50px) !important;
    height: calc(100dvh - var(--os-top) - 50px) !important;
  }

  .os-max,
  .os-resize {
    display: none;
  }

  .os-titlebar {
    cursor: default;
  }
}

@media (prefers-reduced-motion: reduce) {
  .os-window {
    transition: none;
  }

  .os-window.crt-flash .os-titlebar {
    animation: none;
  }
}