/*
 * thinking.ink: a pretend desktop OS.
 *
 * One fixed look (no light/dark): wallpaper, menu bar, glass dock and
 * aqua-style windows. Only file previews have a theme (see preview.css).
 */

:root {
  --font: Verdana, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --menubar-h: 30px;
  --select: linear-gradient(#5f8af7, #2a5fe8);
  --select-flat: #3875d7;
  --dock-icon: 72px;
  --dock-gap: 14px;
  --dock-pad: 30px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #000;
  overflow: hidden;
  /* No rubber-band scrolling of the whole page on iOS. */
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.4;
  color: #000;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: default;
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  cursor: pointer;
}

img {
  -webkit-user-drag: none;
}

:focus-visible {
  outline: 2px solid rgb(90 150 255 / 0.85);
  outline-offset: 1px;
}

/* ---------- Screen ---------- */

.os {
  position: fixed;
  inset: 0;
  /* clip, not just hidden: the dock reflections hang off the bottom, and a
     hidden-overflow box can still be scrolled (e.g. by focusing a dock icon). */
  overflow: hidden;
  overflow: clip;
  isolation: isolate;
  /* Black, not a wallpaper colour: iOS Safari 26 tints its status bar with
     the background-color of the fixed element at the top edge. The wallpaper's
     placeholder colour lives on .wallpaper, which isn't fixed. */
  background: #000;
}

/* Fills the area under the iPhone status bar with solid black, so that's the
   fixed element Safari finds at the top edge (see the phone media query). */
.status-strip {
  display: none;
}

.wallpaper {
  position: absolute;
  inset: 0;
  background: #2a1240 center / cover no-repeat;
}

.desktop {
  position: absolute;
  inset: 0;
  z-index: 10;
}

/* ---------- Menu bar ---------- */

.menubar {
  position: absolute;
  inset: 0 0 auto;
  z-index: 30;
  display: flex;
  align-items: stretch;
  height: var(--menubar-h);
  padding: 0 8px;
  color: #fff;
  background: linear-gradient(rgb(0 0 0 / 0.3), rgb(0 0 0 / 0));
  white-space: nowrap;
}

.menubar__menus {
  display: flex;
  min-width: 0;
}

.menubar__logo,
.menubar__item {
  display: flex;
  align-items: center;
  padding: 0 10px;
}

/* Set on the buttons themselves: browsers reset text-shadow on buttons.
   Matches the logo's drop-shadow below. */
.menubar__item {
  text-shadow: 0 1px 1.5px rgb(0 0 0 / 0.45);
}

.menubar__logo svg {
  width: 26px;
  height: auto;
  filter: drop-shadow(0 1px 1.5px rgb(0 0 0 / 0.45));
}

.menubar__item--app {
  font-weight: bold;
}

.menubar__clock {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

.menubar__logo[aria-expanded="true"],
.menubar__item[aria-expanded="true"] {
  background: var(--select);
  text-shadow: none;
}

.menubar__logo[aria-expanded="true"] svg {
  filter: none;
}

.menubar button:focus-visible {
  outline: none;
  background: rgb(255 255 255 / 0.18);
}

/* ---------- Menus ---------- */

.menu {
  position: absolute;
  z-index: 40;
  min-width: 200px;
  max-width: calc(100% - 8px);
  padding: 4px 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  color: #000;
  font-size: 13px;
  background: rgb(255 255 255 / 0.96);
  border-radius: 0 0 6px 6px;
  box-shadow:
    0 0 0 1px rgb(0 0 0 / 0.14),
    0 10px 28px rgb(0 0 0 / 0.38);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  text-shadow: none;
  animation: menu-in 0.12s ease-out;
}

.menu--sub {
  border-radius: 6px;
}

@keyframes menu-in {
  from { opacity: 0; }
}

.menu__item {
  display: flex;
  align-items: center;
  gap: 28px;
  width: 100%;
  min-height: 25px;
  padding: 3px 14px 3px 20px;
  text-align: left;
  outline: none;
}

.menu__item:focus,
.menu__item[data-open] {
  background: var(--select);
  color: #fff;
}

.menu__item[aria-disabled="true"] {
  color: #a3a3a3;
  background: none;
}

.menu__label {
  flex: 1;
  white-space: nowrap;
}

.menu__mark {
  min-width: 10px;
  text-align: right;
}

.menu__mark--shortcut {
  color: #8c8c8c;
  font-size: 12px;
}

.menu__item:focus .menu__mark--shortcut {
  color: inherit;
}

.menu__arrow {
  display: block;
  width: 0;
  height: 0;
  margin-left: auto;
  border-style: solid;
  border-width: 4.5px 0 4.5px 7px;
  border-color: transparent transparent transparent currentColor;
}

.menu__sep {
  height: 1px;
  margin: 5px 1px;
  background: #e1e1e1;
}

.menu__header {
  padding: 4px 20px 2px;
  color: #8a8a8a;
  font-size: 11px;
}

/* ---------- Windows ---------- */

.win {
  position: absolute;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  border-radius: 6px 6px 5px 5px;
  box-shadow:
    0 0 0 1px rgb(0 0 0 / 0.3),
    0 8px 18px rgb(0 0 0 / 0.28),
    0 22px 48px rgb(0 0 0 / 0.36);
  transform-origin: 50% 50%;
}

.win:not([data-active]) {
  box-shadow:
    0 0 0 1px rgb(0 0 0 / 0.22),
    0 6px 16px rgb(0 0 0 / 0.22),
    0 14px 30px rgb(0 0 0 / 0.2);
}

.win--gliding {
  transition: left 0.24s ease, top 0.24s ease, width 0.24s ease, height 0.24s ease;
}

.win__bar {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 24px;
  padding: 0 72px;
  background: linear-gradient(#e8e8e8, #c8c8c8 55%, #b4b4b4);
  border-bottom: 1px solid #7a7a7a;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.8);
  touch-action: none;
}

.win:not([data-active]) .win__bar {
  background: linear-gradient(#f5f5f5, #e2e2e2);
  border-bottom-color: #b2b2b2;
}

.win__title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: #262626;
  text-shadow: 0 1px 0 rgb(255 255 255 / 0.55);
}

.win:not([data-active]) .win__title {
  color: #8a8a8a;
}

.win__body {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

/* Hide the window's content scrollbars from the window-dragging gesture. */
.win--dragging .win__body {
  pointer-events: none;
}

.win__grip {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 15px;
  height: 15px;
  cursor: nwse-resize;
  touch-action: none;
  background: linear-gradient(
    135deg,
    transparent 0 52%,
    rgb(0 0 0 / 0.28) 52% 58%,
    transparent 58% 68%,
    rgb(0 0 0 / 0.28) 68% 74%,
    transparent 74% 84%,
    rgb(0 0 0 / 0.28) 84% 90%,
    transparent 90%
  );
}

/* Traffic lights */

.win__lights {
  position: absolute;
  top: 50%;
  left: 8px;
  display: flex;
  gap: 7px;
  transform: translateY(-50%);
}

.light {
  --hi: #ffd0cb;
  --mid: #f2574e;
  --lo: #a82b24;
  position: relative;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 78%, var(--hi) 0, var(--mid) 48%, var(--lo) 100%);
  box-shadow:
    inset 0 0 0 0.5px rgb(0 0 0 / 0.45),
    0 1px 0 rgb(255 255 255 / 0.5);
}

.light--minimize {
  --hi: #fff1b8;
  --mid: #f7bd2a;
  --lo: #a8730c;
}

.light--zoom {
  --hi: #d9ffc4;
  --mid: #5cc23c;
  --lo: #2c7a19;
}

/* Glossy highlight */
.light::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 3px;
  right: 3px;
  height: 5px;
  border-radius: 50%;
  background: linear-gradient(rgb(255 255 255 / 0.95), rgb(255 255 255 / 0.1));
}

/* Glyphs on hover */
.light::before {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  font: bold 10px/1 Arial, sans-serif;
  color: rgb(0 0 0 / 0.55);
  opacity: 0;
}

.light--close::before { content: "×"; font-size: 12px; }
.light--minimize::before { content: "−"; }
.light--zoom::before { content: "+"; }

.win__lights:hover .light:not(:disabled)::before {
  opacity: 1;
}

.win:not([data-active]) .win__lights:not(:hover) .light {
  --hi: #f4f4f4;
  --mid: #d4d4d4;
  --lo: #a9a9a9;
}

.light:disabled {
  opacity: 0.9;
}

/* ---------- App window: files ---------- */

.finder {
  display: grid;
  grid-template-columns: repeat(auto-fill, 108px);
  align-content: start;
  gap: 18px 8px;
  min-height: 100%;
  padding: 26px 24px;
  background: #fff;
}

.file {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 108px;
  outline: none;
}

.file__icon {
  padding: 5px;
  border-radius: 7px;
}

.file__name {
  max-width: 100%;
  padding: 1px 7px;
  border-radius: 9px;
  font-size: 12px;
  overflow-wrap: anywhere;
  text-align: center;
}

.file[data-selected] .file__icon {
  background: rgb(0 0 0 / 0.13);
}

.file[data-selected] .file__name {
  background: var(--select-flat);
  color: #fff;
}

.win:not([data-active]) .file[data-selected] .file__name {
  background: #d0d0d0;
  color: #000;
}

.file:focus-visible .file__icon {
  outline: 2px solid rgb(90 150 255 / 0.85);
}

/* The file icon: black tile, gradient, shadow, glare, and a still frame. */
.thumb {
  position: relative;
  display: block;
  width: 64px;
  height: 64px;
  overflow: hidden;
  border-radius: 7px;
  color: #fff;
  background: linear-gradient(155deg, #474747 0%, #1a1a1a 42%, #000 100%);
  box-shadow:
    0 0 0 0.5px rgb(0 0 0 / 0.7),
    inset 0 1px 0 rgb(255 255 255 / 0.22),
    0 2px 3px rgb(0 0 0 / 0.35),
    0 5px 10px rgb(0 0 0 / 0.25);
}

.thumb__art {
  position: absolute;
}

.thumb__art svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.thumb::after {
  content: "";
  position: absolute;
  top: -58%;
  left: -30%;
  width: 160%;
  height: 108%;
  border-radius: 50%;
  background: linear-gradient(rgb(255 255 255 / 0.3), rgb(255 255 255 / 0.06) 85%);
  transform: rotate(-14deg);
  pointer-events: none;
}

/* Empty app */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 100%;
  padding: 24px;
  background: #cdcdcd;
  color: #5a5a5a;
  font-size: 12px;
  text-align: center;
}

.empty__icon {
  width: 72px;
  height: 72px;
}

.empty p {
  max-width: 190px;
  margin: 0;
}

/* About */
.about {
  min-height: 100%;
  padding: 26px 22px 20px;
  background: #d6d6d6;
  color: #575757;
  text-align: center;
  font-size: 12px;
}

.about__logo svg {
  display: block;
  width: 100px;
  margin: 0 auto;
  color: #000;
}

.about__name {
  margin: 18px 0 6px;
  color: #000;
  font-size: 18px;
}

.about__text,
.about__credit {
  margin: 0;
  line-height: 1.35;
}

.about__credit {
  margin-top: 26px;
}

/* ---------- Dock ---------- */

.dock {
  --shelf-h: calc(var(--dock-icon) * 0.64);
  /* How far the icons' base sits above the bottom of the shelf. */
  --lift: calc(var(--shelf-h) * 0.5 - 10px);
  position: absolute;
  bottom: 0;
  left: 50%;
  z-index: 20;
  padding: 0 var(--dock-pad);
  transform: translateX(-50%);
}

.dock__shelf {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--shelf-h);
  clip-path: polygon(6.5% 0, 93.5% 0, 100% 100%, 0 100%);
  background:
    linear-gradient(rgb(255 255 255 / 0.85), rgb(255 255 255 / 0.85)) top / 100% 1px no-repeat,
    linear-gradient(rgb(255 255 255 / 0.45), rgb(255 255 255 / 0.45)) bottom / 100% 3px no-repeat,
    linear-gradient(rgb(238 238 244 / 0.66), rgb(176 176 190 / 0.5));
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.dock__items {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: var(--dock-gap);
  margin: 0;
  padding: 0 0 var(--lift);
  list-style: none;
}

.dock__item {
  position: relative;
  display: block;
  width: var(--dock-icon);
  height: var(--dock-icon);
  outline: none;
}

.dock__icon {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
}

/* A soft contact shadow where the icon stands on the shelf. It shrinks and
   fades while the icon bounces (see dock.js). */
.dock__shadow {
  position: absolute;
  left: 8%;
  bottom: -5px;
  width: 84%;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgb(0 0 0 / 0.42), rgb(0 0 0 / 0.16) 55%, transparent);
  filter: blur(1.5px);
  pointer-events: none;
}

/* Mirrored below the icon, fading into the shelf. Pulled up into the icon box
   (behind the icon) because the artwork has ~7% empty space at the bottom,
   which mirroring doubles into a gap. */
.dock__reflection {
  position: absolute;
  top: 86%;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0.38;
  transform: scaleY(-1);
  -webkit-mask-image: linear-gradient(to top, rgb(0 0 0 / 0.75) 10%, transparent 44%);
  mask-image: linear-gradient(to top, rgb(0 0 0 / 0.75) 10%, transparent 44%);
  pointer-events: none;
}

.dock__dot {
  position: absolute;
  top: calc(100% + (var(--lift) - 6px) / 2);
  left: 50%;
  width: 6px;
  height: 6px;
  margin-left: -3px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0, #9eeaff 35%, #2fb6ff 70%);
  box-shadow: 0 0 5px 2px rgb(80 200 255 / 0.75);
  opacity: 0;
  transition: opacity 0.3s;
}

.dock__item[data-running="true"] .dock__dot {
  opacity: 1;
}

.dock__label {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  padding: 3px 12px;
  border-radius: 12px;
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
  background: rgb(28 28 28 / 0.78);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.2);
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}

@media (hover: hover) {
  .dock__item:hover .dock__label {
    opacity: 1;
  }
}

.dock__item:focus-visible .dock__label {
  opacity: 1;
}

.dock__item:active .dock__icon {
  filter: brightness(0.7);
}

/* ---------- Restart / Shut down (see src/os/power.js) ---------- */

/* Covers the whole viewport, safe areas included, above everything. */
.power {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
}

.power[hidden] {
  display: none;
}

.power__logo {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 112px;
  color: #fff;
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: opacity 0.5s, color 0.5s;
}

.power__logo svg {
  display: block;
  width: 100%;
  height: auto;
}

.power[data-state="shutdown"] .power__logo {
  color: #2b2b2b;
  opacity: 1;
}

.power[data-state="booting"] .power__logo {
  opacity: 1;
}

/* The bar and the power button share one spot near the bottom. */
.power__foot {
  position: absolute;
  left: 50%;
  bottom: calc(10% + env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  transform: translate(-50%, 50%);
}

.power__foot > * {
  grid-area: 1 / 1;
}

.power__bar {
  width: 136px;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  background: #262626;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s 0.2s;
}

.power__fill {
  height: 100%;
  border-radius: inherit;
  background: #fff;
  width: 0;
}

.power[data-state="booting"] .power__bar {
  opacity: 1;
}

.power__button {
  position: relative;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #d4d4d4;
  cursor: pointer;
  visibility: hidden;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.4s, transform 0.4s, visibility 0s 0.4s, background-color 0.15s;
}

.power__button img {
  display: block;
  width: 22px;
  height: 22px;
}

.power[data-state="shutdown"] .power__button {
  visibility: visible;
  opacity: 1;
  transform: none;
  transition: opacity 0.6s 0.3s, transform 0.6s 0.3s, visibility 0s, background-color 0.15s;
}

.power__button:hover {
  background: #f0f0f0;
}

.power__button:active {
  background: #a8a8a8;
}

.power__button:focus-visible {
  outline-offset: 3px;
}

/* ---------- Phones ---------- */

/*
 * The desktop becomes a rounded screen between the status bar and the
 * browser controls. It never touches the top or bottom edge, so iOS Safari
 * tints its bars from the black page behind it rather than the wallpaper.
 * Keep the breakpoint in sync with src/main.js.
 */
@media (max-width: 720px) {
  :root {
    --menubar-h: 30px;
    --dock-icon: min(56px, 14vw);
    --dock-gap: min(22px, 5vw);
    --dock-pad: min(34px, 7vw);
  }

  /* The shelf is short here: lower the icons less, so the dot still fits. */
  .dock {
    --lift: calc(var(--shelf-h) * 0.5 - 5px);
  }

  .os {
    top: env(safe-area-inset-top);
    bottom: calc(8px + env(safe-area-inset-bottom));
    border-radius: 22px;
  }

  /* Solid and fully opaque: Safari ignores transparent or opacity-0 strips. */
  .status-strip {
    display: block;
    position: fixed;
    inset: 0 0 auto;
    height: env(safe-area-inset-top, 0px);
    background: #000;
    pointer-events: none;
  }

  .menubar {
    padding: 0 4px;
    font-size: 13px;
  }

  .menubar__logo,
  .menubar__item {
    padding: 0 7px;
  }

  .menubar__logo {
    padding-left: 12px;
  }

  .menubar__clock {
    padding-right: 12px;
  }

  .menu {
    min-width: 180px;
  }

  .menu__item {
    min-height: 34px;
  }

  .win__grip {
    display: none;
  }

  .finder {
    padding: 18px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .menu {
    animation: none;
  }

  .win--gliding {
    transition: none;
  }
}
