/* Fun page: a small desktop. Windows, icons, dock, karaoke. Sharp corners, hard shadows,
   classic-Mac pinstripe title bars. Own skin, no Apple or Microsoft artwork. */

.desktop {
  position: relative; min-height: calc(100dvh - var(--mb-h)); overflow: hidden; isolation: isolate;
  background-image: radial-gradient(var(--hair) 1px, transparent 1.4px); background-size: 24px 24px; background-position: 12px 12px;
}
.desk-head { position: absolute; left: clamp(16px, 3vw, 40px); top: clamp(24px, 5vw, 56px); z-index: 0; max-width: 28rem; }
.desk-head h1 { margin: 0; font: 450 clamp(3rem, 8vw, 7rem)/0.95 var(--font-serif); letter-spacing: -0.03em; }
.desk-head p { margin: 18px 0 0; color: var(--muted); font-size: 1.125rem; line-height: 1.45; max-width: 30ch; }

/* ---------- Desktop icons ---------- */
.icons { position: absolute; right: clamp(12px, 2.5vw, 32px); top: clamp(16px, 3vw, 32px); z-index: 2; display: grid; gap: 12px; }
.d-icon { appearance: none; background: transparent; border: 0; cursor: pointer; width: 92px; display: grid; justify-items: center; gap: 8px; padding: 4px 0; }
.d-icon .tile { display: grid; place-items: center; width: 60px; height: 60px; background: var(--ground); border: 1px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); font-size: 1.875rem; transition: transform 160ms var(--ease-out), box-shadow 160ms var(--ease-out); }
.d-icon .name { font: 500 0.6875rem/1.2 var(--font-mono); padding: 3px 5px; text-align: center; }
@media (hover: hover) and (pointer: fine) { .d-icon:hover .tile { transform: translate(-2px, -2px); box-shadow: 5px 5px 0 var(--ink); } }
.d-icon:active .tile { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.d-icon[aria-pressed="true"] .name { background: var(--ink); color: var(--ground); }
.d-icon[aria-pressed="true"] .tile { background: var(--ink); color: var(--ground); }

/* ---------- Windows ---------- */
.win {
  position: absolute; left: 0; top: 0; z-index: 10; width: min(480px, calc(100% - 16px));
  background: var(--ground); border: 1px solid var(--ink); box-shadow: 6px 6px 0 var(--ink);
  transform: translate(var(--x, 80px), var(--y, 100px));
}
.win[hidden] { display: none; }
.win:focus, .win:focus-visible { outline: none; }
.win.is-opening { animation: win-in 180ms var(--ease-out) both; }
@keyframes win-in { from { opacity: 0; transform: translate(var(--x, 80px), var(--y, 100px)) scale(0.96); } to { opacity: 1; transform: translate(var(--x, 80px), var(--y, 100px)) scale(1); } }
.win--rack { width: min(440px, calc(100% - 16px)); }
.win--fonema, .win--outrider { width: min(660px, calc(100% - 16px)); }
.win--garage, .win--zen { width: min(480px, calc(100% - 16px)); }

/* Zazen timer inside the Zen window */
.zazen { margin-top: 30px; padding-top: 22px; border-top: 1px solid var(--hair); }
.zz-stage { position: relative; width: min(210px, 70%); aspect-ratio: 1; margin: 16px auto 20px; }
.zz-ring { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.zz-track { fill: none; stroke: var(--hair); stroke-width: 1; }
.zz-prog { fill: none; stroke: var(--accent); stroke-width: 4.5; stroke-linecap: round; }
@media (prefers-reduced-motion: no-preference) { .zz-prog { transition: stroke-dashoffset 420ms linear; } }
.zz-time { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; font: 450 2.25rem/1 var(--font-serif); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.zz-ctrl { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: center; }
.zz-lengths { display: inline-flex; border: 1px solid var(--ink); }
.zz-len { appearance: none; background: transparent; color: var(--ink); border: 0; border-right: 1px solid var(--ink); padding: 0 14px; min-height: 44px; font: 500 0.8125rem/1 var(--font-mono); cursor: pointer; }
.zz-len:last-child { border-right: 0; }
.zz-len[aria-pressed="true"] { background: var(--ink); color: var(--ground); }
.zz-len:disabled { opacity: 0.45; cursor: default; }
.zz-go { appearance: none; background: var(--ink); color: var(--ground); border: 1px solid var(--ink); min-height: 44px; padding: 0 22px; font: 600 0.8125rem/1 var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer; transition: background-color 160ms ease, border-color 160ms ease, transform 160ms var(--ease-out); }
.zz-go:hover { background: var(--accent); border-color: var(--accent); }
.zz-go:active { transform: scale(0.97); }
.zz-status { margin: 16px 0 0; min-height: 3em; text-align: center; color: var(--muted); font: 400 0.8125rem/1.5 var(--font-mono); }
.win--miragem { width: min(660px, calc(100% - 16px)); }

/* Expand: the window fills the desktop for reading (the classic zoom box). */
.win.is-zoomed { left: 8px; top: 8px; width: calc(100% - 16px); height: calc(100% - 112px); transform: none !important; display: flex; flex-direction: column; }
.win.is-zoomed .win-body { max-height: none; flex: 1; }
.win.is-zoomed .cs--win { max-width: 760px; margin-inline: auto; }
.win.is-zoomed .win-title { cursor: default; }

.win-title { position: relative; display: flex; align-items: center; justify-content: center; height: 32px; flex: none; border-bottom: 1px solid var(--ink); cursor: grab; touch-action: none; user-select: none; }
.win-title::before { content: ""; position: absolute; inset: 7px 36px; background: repeating-linear-gradient(var(--ink) 0 1px, transparent 1px 4px); opacity: 0.55; transition: opacity 120ms ease; }
.win.is-active .win-title::before { opacity: 1; }
.win-title:active { cursor: grabbing; }
.win-title h2 { position: relative; margin: 0; padding: 0 12px; background: var(--ground); font: 600 0.75rem/1 var(--font-mono); letter-spacing: 0.03em; }

.win-close, .win-zoom { position: absolute; top: 50%; translate: 0 -50%; z-index: 2; width: 16px; height: 16px; padding: 0; background: var(--ground); border: 1px solid var(--ink); cursor: pointer; }
.win-close { left: 10px; }
.win-zoom { right: 10px; }
.win-close::before, .win-close::after { content: ""; position: absolute; left: 50%; top: 50%; width: 10px; height: 1.5px; background: var(--ink); opacity: 0; transition: opacity 100ms ease; }
.win-close::before { transform: translate(-50%, -50%) rotate(45deg); }
.win-close::after { transform: translate(-50%, -50%) rotate(-45deg); }
.win-close:hover::before, .win-close:hover::after, .win-close:focus-visible::before, .win-close:focus-visible::after { opacity: 1; }
.win-zoom::before { content: ""; position: absolute; inset: 3px; border: 1px solid var(--ink); transition: inset 140ms var(--ease-out); }
.win-zoom:hover::before, .win-zoom:focus-visible::before, .win-zoom[aria-pressed="true"]::before { inset: 2px; background: var(--ink); }
/* The boxes are small to look classic, so give them a 44px hit area. */
.win-close span, .win-zoom span { position: absolute; inset: -14px; }
.win-close, .win-zoom { outline-offset: 6px; }

.win-body { padding: 18px; max-height: min(72dvh, 680px); overflow: auto; }
.win-body.win-long { padding: 22px 24px 32px; max-height: min(80dvh, 760px); }

/* ---------- Dock ---------- */
.dock { position: absolute; left: 50%; bottom: 16px; translate: -50% 0; z-index: 1000; display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px; background: var(--ground); border: 1px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.dock-item { --s: 1; position: relative; appearance: none; cursor: pointer; width: 48px; height: 48px; display: grid; place-items: center; background: var(--ground); border: 1px solid var(--ink); font-size: 1.5rem; text-decoration: none; transform-origin: 50% 100%; transform: scale(var(--s)); margin-inline: calc((var(--s) - 1) * 14px); transition: transform 90ms linear, margin 90ms linear; }
.dock-item::after { content: attr(data-label); position: absolute; bottom: calc(100% + 10px); left: 50%; translate: -50% 0; transform-origin: 50% 100%; scale: calc(1 / var(--s)); opacity: 0; pointer-events: none; white-space: nowrap; background: var(--ink); color: var(--ground); font: 500 0.6875rem/1 var(--font-mono); padding: 6px 8px; transition: opacity 100ms ease; }
.dock-item:hover::after, .dock-item:focus-visible::after { opacity: 1; }
.dock-item[data-running="true"]::before { content: ""; position: absolute; bottom: -7px; left: 50%; translate: -50% 0; width: 6px; height: 3px; background: var(--ink); }
.dock-item:active { transition-duration: 0ms; }
.dock-sep { align-self: stretch; width: 1px; background: var(--hair); margin-inline: 2px; }

/* ---------- Rack window ---------- */
.rack-win { padding: 22px 26px 26px 18px; }
.rack-win .hint { margin: 0 0 18px 8px; font: 400 0.75rem/1.5 var(--font-mono); color: var(--muted); }

/* ---------- Mobile: windows become sheets, the dock goes away ---------- */
@media (max-width: 860px) {
  .desktop { padding: 20px 16px 24px; min-height: calc(100dvh - 96px); display: flex; flex-direction: column; gap: 20px; }
  .desk-head { position: static; }
  .icons { position: static; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .d-icon { width: 100%; }
  .dock { display: none; }
  .win { position: fixed; inset: 8px 8px 8px 8px; width: auto !important; height: auto !important; transform: none !important; z-index: 800; display: flex; flex-direction: column; box-shadow: none; }
  .win[hidden] { display: none; }
  .win.is-opening { animation: none; }
  .win-body, .win-body.win-long { max-height: none; flex: 1; }
  .win-title { cursor: default; }
  .win-zoom { display: none; }
}
@media (max-width: 420px) { .icons { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (prefers-reduced-motion: reduce) { .win.is-opening, .journal.is-in { animation: none !important; } .dock-item { transition: none !important; } }

.d-icon .tile svg, .dock-item svg { width: 1em; height: 1em; display: block; }

