/* ── Scribe desktop ────────────────────────────────────────────────────────
   A window manager around the standard Scribe views. Vintage Macintosh by way
   of Obelisk: hard 1px ink borders, offset shadows with no blur, pinstriped
   title bars, square window boxes.

   The chrome is styled here and nowhere else. Everything inside
   `.desktop-window__content` is a real `_view_*` partial and must look exactly
   as it does on the standard page, so this file resets its own typography at
   that boundary rather than letting it leak in.
   ───────────────────────────────────────────────────────────────────────── */

.fullscreen-shell {
  overflow: hidden;
}

.fullscreen-container,
.fullscreen-container > main {
  min-height: 100vh;
  width: 100%;
  padding: 0 !important;
  overflow: hidden;
}

/* A page framed inside a desktop window is a bare document — the window
   supplies the chrome. */
body.is-embedded .main-container {
  background: var(--color-bg);
}

body.is-embedded > .main-container > main {
  padding-top: 0;
}

.desktop {
  /* The desk is gray, not beige, and the windows are the app's own surfaces —
     so a partial dropped into one needs no restyling to belong. */
  --dt-ink: #0a0a0a;
  --dt-surface: #8d9095;
  --dt-chrome: #e9e9ec;
  --dt-chrome-edge: #ffffff;
  --dt-chrome-shade: #c3c4c9;
  --dt-line: rgba(10, 10, 10, 0.8);
  --dt-hairline: rgba(10, 10, 10, 0.28);
  --dt-shadow: 3px 3px 0 rgba(10, 10, 10, 0.32);
  --dt-menu-height: 30px;
  --dt-title-height: 26px;

  position: relative;
  display: flex;
  width: 100%;
  height: 100vh;
  flex-direction: column;
  overflow: hidden;
  color: var(--dt-ink);
  font-family: var(--font-stack-sans-serif);
}

/* ── Menu bar ──────────────────────────────────────────────────────────── */

.desktop-menubar {
  position: relative;
  z-index: 500;
  display: flex;
  height: var(--dt-menu-height);
  flex-shrink: 0;
  align-items: stretch;
  justify-content: space-between;
  border-bottom: 1px solid var(--dt-line);
  background: linear-gradient(var(--dt-chrome-edge), var(--dt-chrome) 55%, var(--dt-chrome-shade));
  padding: 0 0.5rem;
}

.desktop-menubar__menus {
  display: flex;
  min-width: 0;
  align-items: stretch;
}

.desktop-menubar__status {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding-left: 0.75rem;
}

.desktop-menu {
  position: relative;
  display: flex;
  align-items: stretch;
}

.desktop-menu__title {
  appearance: none;
  display: flex;
  height: 100%;
  align-items: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--dt-ink);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  min-height: 0;
  padding: 0 0.6rem;
  transition: none;
  white-space: nowrap;
}

.desktop-menu__title:hover,
.desktop-menu__title.is-open {
  background: var(--dt-ink);
  color: var(--dt-chrome-edge);
}

/* The diamond stands where the Apple used to. */
.desktop-menu__title.is-mark {
  font-size: 0.9rem;
  padding: 0 0.7rem;
}

.desktop-menu__drop {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 20;
  display: flex;
  min-width: 190px;
  flex-direction: column;
  border: 1px solid var(--dt-line);
  border-top: 0;
  background: var(--dt-chrome-edge);
  box-shadow: var(--dt-shadow);
  padding: 0.2rem 0;
}

.desktop-menu__item {
  appearance: none;
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.5rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--dt-ink);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  justify-content: flex-start;
  min-height: 0;
  padding: 0.3rem 0.9rem;
  text-align: left;
  text-decoration: none;
  transition: none;
  white-space: nowrap;
}

.desktop-menu__item i {
  width: 1rem;
  color: rgba(10, 10, 10, 0.55);
  font-size: 0.9rem;
}

.desktop-menu__item:hover {
  background: var(--dt-ink);
  color: var(--dt-chrome-edge);
}

.desktop-menu__item:hover i {
  color: inherit;
}

.desktop-menu__item.is-disabled {
  color: rgba(10, 10, 10, 0.35);
  cursor: default;
  pointer-events: none;
}

.desktop-menu__check {
  margin-left: auto;
  padding-left: 0.75rem;
}

.desktop-menu__drop hr {
  border: 0;
  border-top: 1px solid var(--dt-hairline);
  margin: 0.25rem 0;
}

/* ── Status items ──────────────────────────────────────────────────────── */

.desktop-activity {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
  color: rgba(10, 10, 10, 0.7);
  cursor: pointer;
  font-family: var(--font-stack-monospace);
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  min-height: 0;
  padding: 0.12rem 0.4rem;
  text-transform: uppercase;
  transition: none;
  white-space: nowrap;
}

.desktop-activity:hover {
  border-color: var(--dt-hairline);
  color: var(--dt-ink);
}

.desktop-activity__dial {
  display: block;
  width: 0.6rem;
  height: 0.6rem;
  border: 1px solid var(--dt-line);
  border-radius: 999px;
  background: transparent;
}

/* Work in progress reads at a glance — that is the whole reason the desk
   exists. A busy dial fills and turns; a waiting one holds amber. */
.desktop-activity.is-busy {
  color: var(--dt-ink);
}

.desktop-activity.is-busy .desktop-activity__dial {
  background: conic-gradient(var(--dt-ink) 0 90deg, transparent 90deg 360deg);
  animation: desktop-dial-spin 1.6s linear infinite;
}

.desktop-activity.is-waiting:not(.is-busy) .desktop-activity__dial {
  background: var(--color-warning);
}

@keyframes desktop-dial-spin {
  to { transform: rotate(360deg); }
}

.desktop-status-dot {
  display: block;
  width: 0.5rem;
  height: 0.5rem;
  border: 1px solid var(--dt-line);
  border-radius: 999px;
}

.desktop-status-dot.is-live { background: var(--color-green-mute); }
.desktop-status-dot.is-offline { background: var(--color-danger); }

.desktop-clock {
  color: rgba(10, 10, 10, 0.72);
  font-family: var(--font-stack-monospace);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

/* ── Surface ───────────────────────────────────────────────────────────── */

.desktop-surface {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  /* A fine dither over the wallpaper: the desk keeps its picture but reads as
     the gray the chrome was drawn for. */
  background:
    repeating-linear-gradient(
      45deg,
      rgba(10, 10, 10, 0.07) 0 1px,
      transparent 1px 3px
    ),
    linear-gradient(rgba(141, 144, 149, 0.55), rgba(124, 127, 133, 0.7)),
    url("/images/desktop_wallpapers/mountain_1.webp") center / cover no-repeat,
    var(--dt-surface);
}

/* ── Icons ─────────────────────────────────────────────────────────────── */

.desktop-icons {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  display: flex;
  max-height: 100%;
  flex-flow: column wrap;
  align-content: flex-start;
  gap: 0.35rem 0.25rem;
  padding: 0.75rem 0.5rem;
}

.desktop-icon {
  appearance: none;
  display: flex;
  width: 104px;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-family: inherit;
  min-height: 0;
  padding: 0.3rem 0.15rem;
  text-align: center;
  transition: none;
}

.desktop-icon__tile {
  display: grid;
  width: 46px;
  height: 46px;
  border: 1px solid var(--dt-line);
  border-radius: 3px;
  background: linear-gradient(var(--dt-chrome-edge), var(--dt-chrome) 60%, var(--dt-chrome-shade));
  box-shadow:
    inset -1px -1px 0 rgba(10, 10, 10, 0.16),
    inset 1px 1px 0 rgba(255, 255, 255, 0.9),
    2px 2px 0 rgba(10, 10, 10, 0.25);
  place-items: center;
}

.desktop-icon__tile i {
  color: var(--dt-ink);
  font-size: 1.45rem;
}

.desktop-icon:hover .desktop-icon__tile {
  background: linear-gradient(var(--dt-chrome-edge), var(--dt-chrome-edge));
}

/* A selected icon inverts, the way it always did. */
.desktop-icon.is-open .desktop-icon__tile {
  background: var(--dt-ink);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.desktop-icon.is-open .desktop-icon__tile i {
  color: var(--dt-chrome-edge);
}

/* The label sits on its own plate rather than fighting the wallpaper with a
   text shadow. */
.desktop-icon__label {
  max-width: 100%;
  overflow: hidden;
  border-radius: 2px;
  background: rgba(10, 10, 10, 0.62);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
  padding: 0.1rem 0.35rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.desktop-icon.is-open .desktop-icon__label {
  background: var(--dt-ink);
}

/* ── Windows ───────────────────────────────────────────────────────────── */

.desktop-window {
  position: absolute;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--dt-line);
  border-radius: 3px;
  background: var(--color-bg);
  box-shadow: var(--dt-shadow);
}

.desktop-window.is-focused {
  box-shadow: 4px 4px 0 rgba(10, 10, 10, 0.36);
}

.desktop-window__titlebar {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  height: var(--dt-title-height);
  flex-shrink: 0;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--dt-line);
  background: var(--dt-chrome);
  cursor: default;
  padding: 0 0.4rem;
  touch-action: none;
  user-select: none;
}

/* Pinstripes on the focused window only — the classic tell for which window is
   listening to the keyboard. */
.desktop-window.is-focused .desktop-window__titlebar {
  background:
    repeating-linear-gradient(
      to bottom,
      var(--dt-chrome) 0 1px,
      rgba(10, 10, 10, 0.22) 1px 2px
    );
}

.desktop-window__title {
  display: inline-flex;
  min-width: 0;
  max-width: 100%;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  /* The title interrupts the pinstripes instead of sitting on them, and the ink
     is full-strength dark: legible on chrome, which the old shell was not. */
  background: var(--dt-chrome);
  color: var(--dt-ink);
  font-size: 0.76rem;
  font-weight: 600;
  justify-self: center;
  padding: 0 0.5rem;
}

.desktop-window:not(.is-focused) .desktop-window__title {
  color: rgba(10, 10, 10, 0.42);
}

.desktop-window__title i {
  font-size: 0.85rem;
  opacity: 0.65;
}

.desktop-window__title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.desktop-window__boxes {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.desktop-window__box {
  appearance: none;
  position: relative;
  display: block;
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  border: 1px solid var(--dt-line);
  border-radius: 2px;
  background: linear-gradient(var(--dt-chrome-edge), var(--dt-chrome-shade));
  cursor: pointer;
  min-height: 0;
  padding: 0;
  transition: none;
}

.desktop-window:not(.is-focused) .desktop-window__box {
  border-color: var(--dt-hairline);
  background: var(--dt-chrome);
}

.desktop-window__box::after {
  content: "";
  position: absolute;
  border: 1px solid var(--dt-ink);
}

/* Close: a dot. Collapse: a rule. Zoom: a box inside a box. */
.desktop-window__box.is-close::after {
  inset: 4px;
  border-radius: 999px;
  background: var(--dt-ink);
}

.desktop-window__box.is-collapse::after {
  inset: 5px 3px;
  border-width: 1px 0 0 0;
}

.desktop-window__box.is-zoom::after {
  inset: 2px 5px 5px 2px;
}

.desktop-window:not(.is-focused) .desktop-window__box::after {
  display: none;
}

.desktop-window__box:hover {
  background: var(--dt-ink);
}

.desktop-window__box:hover::after {
  border-color: var(--dt-chrome-edge);
}

.desktop-window__box.is-close:hover::after {
  background: var(--dt-chrome-edge);
}

/* ── Window contents ───────────────────────────────────────────────────────
   The boundary. Below this line it is the standard app again: the app's fonts,
   the app's colours, no desktop chrome bleeding in. */

.desktop-window__content {
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-stack-sans-serif);
  font-size: var(--font-size-base);
  letter-spacing: normal;
  text-transform: none;
}

/* Store views are built to fill a pane with a pinned header and a scrolling
   body — which is exactly a window, so they need nothing but a height. */
.desktop-window__content > .scribe-scrollable-view {
  flex: 1;
  min-height: 0;
  height: auto;
  max-height: none;
}

.desktop-window__frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.desktop-window__grip {
  appearance: none;
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  border: 0;
  border-top: 1px solid var(--dt-hairline);
  border-left: 1px solid var(--dt-hairline);
  border-radius: 0;
  background:
    repeating-linear-gradient(
      135deg,
      transparent 0 2px,
      rgba(10, 10, 10, 0.38) 2px 3px
    ),
    var(--dt-chrome);
  cursor: nwse-resize;
  min-height: 0;
  padding: 0;
  touch-action: none;
}

.desktop-window.is-zoomed .desktop-window__grip {
  display: none;
}

/* ── About box ─────────────────────────────────────────────────────────── */

/* An About box has a close box and nothing else — there is nothing in it worth
   zooming. */
.desktop-window--about .desktop-window__boxes {
  visibility: hidden;
}

.desktop-window__content.is-about {
  display: grid;
  align-content: start;
  overflow: auto;
  padding: 1.35rem 1.5rem;
  text-align: center;
}

.desktop-about__mark {
  font-size: 1.6rem;
  line-height: 1;
  margin: 0 0 0.5rem;
}

.desktop-about__name {
  font-size: 1.25rem;
  line-height: 1.2;
  margin: 0 0 0.25rem;
}

.desktop-about__tagline {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin: 0 0 1.1rem;
}

.desktop-about__facts {
  display: grid;
  gap: 0;
  margin: 0;
  text-align: left;
}

.desktop-about__facts div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-top: 1px solid var(--color-border);
  padding: 0.4rem 0;
}

.desktop-about__facts dt,
.desktop-about__facts dd {
  font-family: var(--font-stack-monospace);
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  margin: 0;
  text-transform: uppercase;
}

.desktop-about__facts dt {
  color: var(--color-text-muted);
}

.desktop-about__footer {
  color: var(--color-text-muted);
  font-family: var(--font-stack-monospace);
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  margin: 1.1rem 0 0;
  text-transform: uppercase;
}

/* ── Collapsed windows ─────────────────────────────────────────────────── */

.desktop-tray {
  position: absolute;
  right: 0.6rem;
  bottom: 0.6rem;
  z-index: 400;
  display: flex;
  max-width: calc(100% - 1.2rem);
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem;
}

.desktop-tray__item {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--dt-line);
  border-radius: 3px;
  background: var(--dt-chrome);
  box-shadow: 2px 2px 0 rgba(10, 10, 10, 0.28);
  color: var(--dt-ink);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  min-height: 0;
  padding: 0.2rem 0.55rem;
  transition: none;
}

.desktop-tray__item:hover {
  background: var(--dt-chrome-edge);
}

/* ── Dark ──────────────────────────────────────────────────────────────── */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .desktop {
    --dt-ink: rgba(255, 255, 255, 0.92);
    --dt-surface: #3a3c40;
    --dt-chrome: #3b3d41;
    --dt-chrome-edge: #4a4c51;
    --dt-chrome-shade: #2c2e31;
    --dt-line: rgba(0, 0, 0, 0.65);
    --dt-hairline: rgba(255, 255, 255, 0.16);
    --dt-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5);
  }

  :root:not([data-theme="light"]) .desktop-menu__title:hover,
  :root:not([data-theme="light"]) .desktop-menu__title.is-open,
  :root:not([data-theme="light"]) .desktop-menu__item:hover {
    background: rgba(255, 255, 255, 0.92);
    color: #1a1a1c;
  }

  :root:not([data-theme="light"]) .desktop-menu__drop {
    background: var(--dt-chrome);
  }

  :root:not([data-theme="light"]) .desktop-menu__item i,
  :root:not([data-theme="light"]) .desktop-clock,
  :root:not([data-theme="light"]) .desktop-activity {
    color: rgba(255, 255, 255, 0.66);
  }

  :root:not([data-theme="light"]) .desktop-window.is-focused .desktop-window__titlebar {
    background:
      repeating-linear-gradient(
        to bottom,
        var(--dt-chrome) 0 1px,
        rgba(255, 255, 255, 0.14) 1px 2px
      );
  }

  :root:not([data-theme="light"]) .desktop-window:not(.is-focused) .desktop-window__title {
    color: rgba(255, 255, 255, 0.42);
  }

  :root:not([data-theme="light"]) .desktop-window__box::after {
    border-color: var(--dt-ink);
  }

  :root:not([data-theme="light"]) .desktop-window__box.is-close::after {
    background: var(--dt-ink);
  }

  :root:not([data-theme="light"]) .desktop-icon.is-open .desktop-icon__tile {
    background: rgba(255, 255, 255, 0.92);
  }

  :root:not([data-theme="light"]) .desktop-icon.is-open .desktop-icon__tile i {
    color: #1a1a1c;
  }
}

/* ── Narrow ────────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .desktop-icon {
    width: 84px;
  }

  .desktop-icon__tile {
    width: 40px;
    height: 40px;
  }

  .desktop-icon__label {
    font-size: 0.64rem;
  }
}

@media (max-width: 640px) {
  .desktop-menubar {
    padding: 0 0.25rem;
  }

  .desktop-menu__title {
    padding: 0 0.4rem;
  }

  .desktop-activity__label {
    display: none;
  }

  /* One window at a time on a phone: a desk needs room. */
  .desktop-window {
    inset: 0.4rem !important;
    width: auto !important;
    height: auto !important;
  }

  .desktop-window__grip {
    display: none;
  }
}
