/* The computer around the screen. Desktop only: on phones the screen is the
   page and this file does nothing. The screen itself is untouched; the case is
   a separate, inert element drawn behind it, and the room is Cory Land paper.
   Each OS gets the machine it shipped on, without logos or model names. */

#case,
.room-label { display: none; }

@media (min-width: 761px) {
  body.desktop-page {
    --paper: #f6f4ed;
    --paper-edge: #e9e6db;
    --ink: #292c2a;
    --ink-muted: #777a72;
    --rule: #d6d4cb;
    --floor: rgba(41, 34, 26, 0.22);

    /* The display's native resolution, as before. */
    --sw: 1024;
    --sh: 768;
    /* Case geometry, overridden per machine below. */
    --bz: 30px;        /* bezel on top and sides */
    --chin: 44px;      /* extra plastic under the screen */
    --stand: 54px;     /* how far the stand drops below the case */
    --room: 56px;      /* breathing room around the case (the stand may run off the page) */

    /* Screen size: the native resolution if it fits, else scaled to fit with
       the case and stand still on the page. */
    --H: min(
      calc(var(--sh) * 1px),
      calc((100vw - 2 * var(--bz) - 2 * var(--room)) * var(--sh) / var(--sw)),
      calc(100vh - 2 * var(--bz) - var(--chin) - var(--room))
    );
    --W: calc(var(--H) * var(--sw) / var(--sh));
    /* Top-left of the case, with the whole machine (case + stand) centered. */
    --case-x: calc(50vw - var(--W) / 2 - var(--bz));
    /* Center case + stand when they fit; otherwise keep the case on the page and
       let the stand run off the bottom edge. */
    --case-y: max(
      calc(var(--room) / 2),
      calc(50vh - (var(--H) + 2 * var(--bz) + var(--chin) + var(--stand)) / 2)
    );

    background:
      radial-gradient(ellipse 70% 60% at 50% 42%, var(--paper) 55%, var(--paper-edge) 100%);
  }
  body.desktop-page[data-os='os7'] { --sw: 832; --sh: 624; }
  body.desktop-page[data-os='win'] { --sw: 800; --sh: 600; }

  @media (prefers-color-scheme: dark) {
    body.desktop-page {
      --paper: #1c1d1a;
      --paper-edge: #141513;
      --ink: #e9e5d9;
      --ink-muted: #8f8d82;
      --rule: #393a35;
      --floor: rgba(0, 0, 0, 0.55);
    }
  }

  /* The screen sits in the case's opening. Width/height use the same --H/--W,
     so window layout keeps measuring the screen exactly as it always has. */
  body.desktop-page #screen {
    inset: auto;
    left: calc(var(--case-x) + var(--bz));
    top: calc(var(--case-y) + var(--bz));
    margin: 0;
    width: var(--W);
    height: var(--H);
    box-shadow: 0 0 0 3px var(--tube, #111), 0 0 0 4px rgba(0, 0, 0, 0.25);
  }

  #case {
    display: block;
    position: fixed;
    z-index: 0;
    left: var(--case-x);
    top: var(--case-y);
    width: calc(var(--W) + 2 * var(--bz));
    height: calc(var(--H) + 2 * var(--bz) + var(--chin));
    pointer-events: none;
    border-radius: var(--case-r, 14px);
  }
  #screen { z-index: 1; }

  /* Stand and the shadow it casts on the paper. */
  #case::before,
  #case::after { content: ''; position: absolute; left: 50%; pointer-events: none; }
  #case::after {
    z-index: -2;
    top: calc(100% + var(--stand) - 10px);
    width: 78%;
    height: 26px;
    transform: translateX(-50%);
    background: radial-gradient(ellipse 50% 50% at 50% 50%, var(--floor), transparent 70%);
    filter: blur(2px);
  }

  .case-part { position: absolute; }

  /* A quiet colophon in the room, in the collection's voice. */
  .room-label {
    display: flex;
    position: fixed;
    left: 28px;
    right: 28px;
    top: 22px;
    z-index: 0;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    color: var(--ink-muted);
    font: 12px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    pointer-events: none;
  }
  .room-label a {
    color: inherit;
    text-decoration: none;
    pointer-events: auto;
    transition: color 140ms cubic-bezier(0.2, 0, 0, 1);
  }
  .room-label a:hover { color: var(--ink); }
  .room-label a:focus-visible { outline: 2px solid #a84e36; outline-offset: 3px; border-radius: 2px; }
  .room-label .room-home { color: var(--ink); font: 20px/1 Georgia, 'Times New Roman', serif; letter-spacing: -0.02em; }
  /* Only where it clears the case. */
  @media (max-width: 1279px), (max-height: 799px) { .room-label { display: none; } }

  /* ------------------------------------------------ System 7: platinum CRT */
  body[data-os='os7'] {
    --bz: 34px;
    --chin: 38px;
    --stand: 40px;
    --case-r: 10px;
    --tube: #161616;
  }
  body[data-os='os7'] #case {
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.55), transparent 18%),
      linear-gradient(180deg, #e7e1d2, #d5cdba);
    box-shadow:
      inset 0 -3px 0 rgba(0, 0, 0, 0.08),
      inset 0 1px 0 rgba(255, 255, 255, 0.8),
      0 0 0 1px rgba(90, 78, 56, 0.16),
      0 1px 0 #b6ad97,
      0 24px 50px -24px rgba(40, 32, 20, 0.45);
  }
  body[data-os='os7'] #case::before {
    z-index: -1;
    top: 100%;
    width: 36%;
    height: var(--stand);
    transform: translateX(-50%);
    background: linear-gradient(180deg, #bdb4a0, #d8d0bd 30%, #cfc7b3);
    clip-path: polygon(14% 0, 86% 0, 100% 100%, 0 100%);
    border-radius: 0 0 4px 4px;
  }
  /* Six-color stripe plate and a recessed brightness wheel. */
  body[data-os='os7'] .case-badge {
    left: calc(var(--bz) + 2px);
    bottom: 13px;
    width: 14px;
    height: 12px;
    border-radius: 2px;
    background: linear-gradient(180deg, #61bb46 0 16.6%, #fdb827 0 33.3%, #f5821f 0 50%, #e03a3e 0 66.6%, #963d97 0 83.3%, #009ddc 0);
    opacity: 0.9;
  }
  body[data-os='os7'] .case-control {
    right: calc(var(--bz) + 2px);
    bottom: 12px;
    width: 36px;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(180deg, #b9b09b, #ddd6c5);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
  }
  body[data-os='os7'] .case-led { display: none; }

  /* ------------------------------------------- Mac OS 9: translucent all-in-one */
  body[data-os='os9'] {
    --bz: 42px;
    --chin: 70px;
    --stand: 30px;
    --case-r: 46px 46px 34px 34px;
    --tube: #0d0f12;
  }
  body[data-os='os9'] #case {
    background:
      radial-gradient(ellipse 120% 70% at 50% 0%, rgba(255, 255, 255, 0.5), transparent 55%),
      repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.06) 0 2px, transparent 2px 7px),
      linear-gradient(180deg, #e9f2f3 0, #dce8ea 8%, #cddbde 100%);
    box-shadow:
      inset 0 0 0 9px rgba(42, 152, 176, 0.55),
      inset 0 0 0 10px rgba(255, 255, 255, 0.35),
      inset 0 -26px 40px -20px rgba(16, 104, 128, 0.35),
      0 1px 0 rgba(16, 104, 128, 0.4),
      0 30px 60px -28px rgba(10, 40, 50, 0.5);
  }
  body[data-os='os9'] #case::before {
    z-index: -1;
    top: calc(100% - 14px);
    width: 30%;
    height: calc(var(--stand) + 14px);
    transform: translateX(-50%);
    border-radius: 0 0 50% 50% / 0 0 22px 22px;
    background:
      repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.08) 0 2px, transparent 2px 6px),
      linear-gradient(180deg, rgba(42, 152, 176, 0.7), rgba(26, 120, 146, 0.85));
  }
  /* Speaker grilles either side of the chin. */
  body[data-os='os9'] .case-badge,
  body[data-os='os9'] .case-control {
    bottom: 20px;
    width: 64px;
    height: 26px;
    background: radial-gradient(circle, rgba(16, 90, 110, 0.45) 1.2px, transparent 1.6px) 0 0 / 6px 6px;
    border-radius: 13px;
  }
  body[data-os='os9'] .case-badge { left: calc(var(--bz) + 14px); }
  body[data-os='os9'] .case-control { right: calc(var(--bz) + 14px); }
  body[data-os='os9'] .case-led {
    left: 50%;
    bottom: 31px;
    width: 7px;
    height: 7px;
    margin-left: -3.5px;
    border-radius: 50%;
    background: #7fd47a;
    box-shadow: 0 0 6px rgba(127, 212, 122, 0.8);
  }

  /* ---------------------------------------------- Mac OS X: clear-framed display */
  body[data-os='osx'] {
    --bz: 24px;
    --chin: 0px;
    --stand: 64px;
    --case-r: 20px;
    --tube: #0a0a0a;
  }
  body[data-os='osx'] #case {
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.55) 40%, rgba(255, 255, 255, 0.75)),
      #eef0f2;
    box-shadow:
      inset 0 0 0 1px rgba(255, 255, 255, 0.9),
      inset 0 0 0 7px rgba(205, 214, 222, 0.55),
      0 0 0 1px rgba(120, 130, 140, 0.25),
      0 28px 60px -30px rgba(20, 30, 40, 0.45);
  }
  /* Easel leg, seen from the front: a clear acrylic slab. */
  body[data-os='osx'] #case::before {
    z-index: -1;
    top: calc(100% - 40px);
    width: 22%;
    height: calc(var(--stand) + 40px);
    transform: translateX(-50%);
    border-radius: 0 0 10px 10px;
    background: linear-gradient(180deg, rgba(225, 232, 238, 0.65), rgba(196, 206, 214, 0.85));
    box-shadow: inset 1px 0 0 rgba(255, 255, 255, 0.9), inset -1px 0 0 rgba(255, 255, 255, 0.9), inset 0 -2px 0 rgba(120, 130, 140, 0.25);
  }
  body[data-os='osx'] .case-badge,
  body[data-os='osx'] .case-control { display: none; }
  body[data-os='osx'] .case-led {
    right: calc(var(--bz) / 2 - 3px);
    bottom: calc(var(--bz) / 2 - 3px);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 35%, #fff, #c9d6e2);
    box-shadow: 0 0 0 1px rgba(120, 130, 140, 0.3);
  }

  /* ------------------------------------------------- Windows 95: beige CRT */
  body[data-os='win'] {
    --bz: 38px;
    --chin: 54px;
    --stand: 44px;
    --case-r: 12px 12px 8px 8px;
    --tube: #121212;
  }
  body[data-os='win'] #case {
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.45), transparent 22%),
      linear-gradient(180deg, #dfd8c6, #cfc6b1);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.7),
      inset 0 -4px 0 rgba(0, 0, 0, 0.07),
      0 0 0 1px rgba(90, 78, 56, 0.18),
      0 1px 0 #ada38c,
      0 26px 54px -26px rgba(40, 32, 20, 0.5);
  }
  /* Swivel base. */
  body[data-os='win'] #case::before {
    z-index: -1;
    top: 100%;
    width: 44%;
    height: var(--stand);
    transform: translateX(-50%);
    background:
      linear-gradient(180deg, #a99f88 0 6px, #cdc4ae 6px 28%, #d9d1bd 28% 70%, #c3baa4 70%);
    clip-path: polygon(30% 0, 70% 0, 72% 40%, 100% 72%, 100% 100%, 0 100%, 0 72%, 28% 40%);
  }
  /* Vents on the left, power button and LED on the right of the chin. */
  body[data-os='win'] .case-badge {
    left: calc(var(--bz) + 4px);
    bottom: 20px;
    width: 90px;
    height: 12px;
    background: repeating-linear-gradient(90deg, rgba(60, 50, 34, 0.32) 0 2px, transparent 2px 7px);
    border-radius: 1px;
  }
  body[data-os='win'] .case-control {
    right: calc(var(--bz) + 4px);
    bottom: 16px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(180deg, #e7e1d1, #c4bba5);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6), inset 0 -1px 2px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(80, 70, 50, 0.25);
  }
  body[data-os='win'] .case-led {
    right: calc(var(--bz) + 36px);
    bottom: 24px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #6fdc5a;
    box-shadow: 0 0 5px rgba(111, 220, 90, 0.85);
  }

  /* Night paper: same plastic, a touch less glare so the case doesn't glow. */
  @media (prefers-color-scheme: dark) {
    #case { filter: brightness(0.86) saturate(0.95); }
  }
}
