/* ============================================================
   Desktop shell: menubar, wallpaper, icons, taskbar, menus (Section 06)
   ============================================================ */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--desk-bg); }

/* ---------- Menubar ---------- */
.menubar {
  position: relative; z-index: 3000; flex: none;
  height: var(--menubar-h); display: flex; align-items: stretch;
  background: var(--face); border-bottom: 2px solid var(--border);
  box-shadow: inset 0 -2px 0 var(--shadow);
  font-family: var(--font-pixel); font-size: 14px; user-select: none;
}
.menubar .brand { display: flex; align-items: center; gap: 6px; padding: 0 10px 0 8px; font-weight: 600; }
.menubar .brand img { width: 20px; height: 20px; }
.menu-root { position: relative; }
.menu-root > button {
  height: 100%; padding: 0 10px; border: 0; background: none; cursor: pointer;
  font-family: var(--font-pixel); font-size: 14px;
}
.menu-root > button[aria-expanded="true"], .menu-root > button:hover { background: var(--title-active); }
.menubar .spacer { flex: 1; }
.demo-badge {
  align-self: center; margin-right: 8px; padding: 1px 8px;
  background: var(--cream); color: #302D43; border: 2px solid var(--border);
  font-family: var(--font-label); font-size: 10px; letter-spacing: .04em;
}
.menubar .mb-status { display: flex; align-items: center; gap: 6px; padding: 0 10px; font-size: 13px; color: var(--text-2); }

.dropdown, .start-menu, .ctx-menu {
  position: absolute; z-index: 4000; min-width: 210px; padding: 4px;
  background: var(--face); border: 2px solid var(--border);
  box-shadow: var(--bevel), var(--drop);
  font-family: var(--font-pixel); font-size: 14px;
}
.dropdown { top: 100%; left: 0; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 5px 10px; border: 0; background: none; text-align: left; cursor: pointer;
  font-family: var(--font-pixel); font-size: 14px; color: var(--text);
}
.menu-item img { width: 20px; height: 20px; }
.menu-item:hover, .menu-item:focus-visible { background: var(--title-active); outline: none; }
.menu-item .kbd { margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--text-2); }
.menu-item .check { width: 14px; text-align: center; }
.menu-sep { height: 2px; margin: 4px 2px; background: var(--shadow); }

/* ---------- Desktop + wallpaper ---------- */
.desktop { position: relative; flex: 1; overflow: hidden; }
.wallpaper {
  position: absolute; inset: 0;
  background-color: var(--desk-bg);
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='640' height='480' shape-rendering='crispEdges'><g fill='white' fill-opacity='.5'><rect x='60' y='70' width='4' height='4'/><rect x='420' y='40' width='4' height='4'/><rect x='560' y='300' width='4' height='4'/><rect x='250' y='420' width='4' height='4'/><rect x='130' y='300' width='2' height='2'/><rect x='500' y='150' width='2' height='2'/><rect x='330' y='220' width='2' height='2'/></g><g font-family='Georgia,serif' font-style='italic' fill='white' fill-opacity='.16'><text x='380' y='120' font-size='44'>Σ</text><text x='80' y='210' font-size='26'>∀ε&gt;0 ∃δ</text><text x='420' y='400' font-size='24'>e^{iπ}+1=0</text><text x='170' y='380' font-size='34'>∫</text><text x='560' y='230' font-size='28'>λ</text></g></svg>"),
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    linear-gradient(160deg, var(--desk-bg) 0%, var(--desk-bg-2) 100%);
  background-size: 640px 480px, 32px 32px, 32px 32px, 100% 100%;
}
.wallpaper::after {
  /* pixel sine wave across the bottom — the mathematical horizon */
  content: ""; position: absolute; left: 0; right: 0; bottom: 18%; height: 60px; opacity: .28;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='256' height='60' shape-rendering='crispEdges'><path d='M0 30 h8 v-6 h8 v-6 h8 v-4 h8 v-2 h16 v2 h8 v4 h8 v6 h8 v6 h8 v6 h8 v6 h8 v4 h8 v2 h16 v-2 h8 v-4 h8 v-6 h8 v-6 h8' fill='none' stroke='white' stroke-width='4'/></svg>") repeat-x;
}
.desktop-crt {
  position: absolute; inset: 0; pointer-events: none; z-index: 2500; display: none;
  background: repeating-linear-gradient(to bottom, rgba(40, 30, 80, .05) 0 1px, transparent 1px 3px);
}
.desktop.scanlines .desktop-crt { display: block; }

/* ---------- Icons ---------- */
.icons { position: absolute; inset: 0; z-index: 1; }
.dicon {
  position: absolute; width: 88px; padding: 6px 2px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: none; border: 2px solid transparent; cursor: default; touch-action: none;
  color: #302D43; user-select: none;
}
.dicon img { width: 48px; height: 48px; pointer-events: none; filter: drop-shadow(2px 2px 0 rgba(48, 45, 67, .25)); }
.dicon .label {
  max-width: 84px; padding: 1px 4px; text-align: center; line-height: 1.25;
  font-family: var(--font-label); font-size: 10px; color: #fff;
  text-shadow: 1px 1px 0 #51466F, -1px 1px 0 #51466F, 1px -1px 0 #51466F, -1px -1px 0 #51466F;
}
.dicon.selected .label, .dicon:focus-visible .label { background: var(--border); text-shadow: none; }
.dicon.selected img { filter: drop-shadow(2px 2px 0 rgba(48, 45, 67, .25)) brightness(.88) sepia(.3) hue-rotate(210deg); }
.dicon:focus-visible { outline: 2px dotted #fff; outline-offset: -2px; }
.dicon.dragging { opacity: .75; z-index: 5; }

/* ---------- Taskbar ---------- */
.taskbar {
  position: relative; z-index: 3000; flex: none;
  height: var(--taskbar-h); display: flex; align-items: center; gap: 6px; padding: 0 6px;
  background: var(--face); border-top: 2px solid var(--border); box-shadow: inset 0 2px 0 var(--hi);
  font-family: var(--font-pixel); font-size: 13px; user-select: none;
}
.start-btn { font-weight: 600; gap: 6px; }
.start-btn img { width: 20px; height: 20px; }
.task-list { flex: 1; display: flex; gap: 4px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; min-width: 0; }
.task-btn { max-width: 180px; min-width: 0; overflow: hidden; text-overflow: ellipsis; justify-content: flex-start; font-size: 13px; }
.task-btn img { width: 16px; height: 16px; }
.task-btn span { overflow: hidden; text-overflow: ellipsis; }
.task-btn.active { box-shadow: var(--bevel-in); background: var(--title-active); }
.tray {
  display: flex; align-items: center; gap: 4px; height: 32px; padding: 0 6px;
  border: 2px solid var(--border); box-shadow: var(--bevel-in);
}
.tray-btn {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 6px;
  background: none; border: 0; cursor: pointer; font-family: var(--font-pixel); font-size: 12px; color: var(--text);
}
.tray-btn:hover { background: var(--title-active); }
.tray-btn img { width: 16px; height: 16px; }
.tray-btn.off img { opacity: .4; }
.svc-dot { width: 10px; height: 10px; border: 2px solid var(--border); background: #DCDCE8; }
.svc-dot.connected { background: #7ED3A8; }
.svc-dot.unavailable { background: #F08BA8; }
.svc-dot.connecting, .svc-dot.paused { background: #F8E4A1; }
.clock { font-family: var(--font-mono); font-size: 12px; padding: 0 4px; min-width: 44px; text-align: center; }
.pet-dock { display: flex; gap: 2px; }
.pet-dock:empty { display: none; }
.pet-dock button { width: 28px; height: 28px; padding: 0; border: 2px solid var(--border); background: var(--pink); cursor: pointer; }
.pet-dock img { width: 24px; height: 24px; display: block; }

/* ---------- Start menu ---------- */
.start-menu {
  position: fixed; left: 4px; bottom: calc(var(--taskbar-h) + 2px);
  display: flex; padding: 0; min-width: 260px;
}
.start-side {
  width: 30px; background: linear-gradient(to top, #9C86D6, #F3C5DC);
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 10px;
}
.start-side span { writing-mode: vertical-rl; transform: rotate(180deg); font-family: var(--font-pixel); font-weight: 600; font-size: 15px; color: #fff; letter-spacing: .08em; text-shadow: 1px 1px 0 #51466F; }
.start-items { flex: 1; padding: 4px; max-height: calc(100vh - var(--taskbar-h) - 50px); overflow: auto; }

/* ---------- Desktop reveal (B04) ---------- */
.screen.revealing .wallpaper { animation: rv-fade .35s ease both; }
.screen.revealing .dicon { animation: rv-pop .28s steps(4) both; animation-delay: calc(.12s + var(--i, 0) * .045s); }
.screen.revealing .menubar { animation: rv-down .3s steps(5) both .35s; }
.screen.revealing .taskbar { animation: rv-up .3s steps(5) both .45s; }
.screen.revealing .tray { animation: rv-fade .25s ease both .65s; }
@keyframes rv-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rv-pop { from { opacity: 0; transform: scale(.4); } to { opacity: 1; transform: none; } }
@keyframes rv-down { from { transform: translateY(-100%); } to { transform: none; } }
@keyframes rv-up { from { transform: translateY(100%); } to { transform: none; } }

/* ============================================================
   Handheld layout (< 768px) — retro palmtop, not a shrunken desktop (13.4)
   ============================================================ */
.handheld-only { display: none; }
.screen.handheld .desktop { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.screen.handheld .wallpaper { position: fixed; top: var(--menubar-h); bottom: var(--taskbar-h); }
.screen.handheld .handheld-only { display: block; position: relative; z-index: 2; padding: 10px 10px 0; }
.screen.handheld .icons {
  position: relative; inset: auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 8px 6px 18px;
}
.screen.handheld .dicon { position: relative; left: auto !important; top: auto !important; width: auto; }
.screen.handheld .dicon img { width: 40px; height: 40px; }
.screen.handheld .menu-root, .screen.handheld .mb-status { display: none; }
.screen.handheld .menubar { padding-top: env(safe-area-inset-top); }
.screen.handheld .taskbar { padding-bottom: env(safe-area-inset-bottom); }
.screen.handheld .task-list, .screen.handheld .tray .tray-label { display: none; }
.screen.handheld .start-menu { left: 0; right: 0; }

.hh-card {
  background: var(--win-bg); border: 2px solid var(--border); box-shadow: var(--bevel), var(--drop);
}
.hh-card .hh-title {
  display: flex; align-items: center; gap: 6px; height: 26px; padding: 0 8px;
  background: var(--title-active); border-bottom: 2px solid var(--border);
  font-family: var(--font-pixel); font-size: 13px;
}
.hh-card .hh-body { padding: 12px; }
.pet-strip {
  position: relative; height: 128px; margin-top: 10px;
  border: 2px dashed rgba(255, 255, 255, .7); background: rgba(255, 255, 255, .14);
}
.pet-strip-label { position: absolute; left: 6px; top: 4px; font-family: var(--font-label); font-size: 9px; color: #fff; text-shadow: 1px 1px 0 #51466F; }
