/* ==========================================================================
   shell.css — lock screen, sign-in, desktop, window chrome, taskbar, tray,
   Start menu, flyouts, toast stack, tablet mode.
   Uses tokens.css names only.
   ========================================================================== */

:root {
  --taskbar-h: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --taskbar-total: calc(var(--taskbar-h) + var(--safe-bottom));
}

html,
body {
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
}

#wallpaper {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

@keyframes shell-enter {
  from {
    opacity: 0;
    translate: 0 12px;
  }
}

@keyframes shell-fade {
  from {
    opacity: 0;
  }
}

.is-entering {
  animation: shell-enter var(--dur) var(--ease) both;
}

/* ---- Lock screen --------------------------------------------------------- */

.lock {
  position: fixed;
  inset: 0;
  z-index: var(--z-lock);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(9vh, 48px) var(--s-4) calc(var(--s-8) + var(--safe-bottom));
  color: var(--c-text);
  transform: translateY(var(--lift, 0px));
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.lock.is-leaving {
  transform: translateY(-100%);
  opacity: 0;
  transition: transform var(--dur) var(--ease-in), opacity var(--dur) var(--ease-in);
}

.lock__face {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-6);
  border: 0;
  border-radius: var(--r-lg);
  background: transparent;
  color: inherit;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.28);
}

.lock__time {
  font-family: var(--font-display);
  font-weight: var(--fw-strong);
  font-size: clamp(72px, 13vw, 136px);
  line-height: 1;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.lock__date {
  font-family: var(--font-display);
  font-weight: var(--fw-medium);
  font-size: clamp(18px, 2.4vw, 24px);
  line-height: 1.3;
}

.lock__hint {
  margin-top: auto;
  font: var(--type-body);
  color: var(--c-text-2);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.4);
  text-align: center;
}

/* ---- Sign-in ------------------------------------------------------------- */

.signin {
  position: fixed;
  inset: 0;
  z-index: var(--z-lock);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-6) var(--s-4) calc(var(--s-6) + var(--safe-bottom));
  overflow-y: auto;
  background: var(--c-overlay-light);
}

.signin__panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(360px, 100%);
  margin-bottom: 6vh;
}

.signin__avatar {
  width: clamp(112px, 22vh, 192px);
  aspect-ratio: 1;
  border-radius: 50%;
  overflow: hidden;
  background: var(--c-surface-2);
  box-shadow: 0 0 0 1px var(--c-stroke-strong);
}

.signin__avatar img {
  display: block;
  width: 100%;
  height: 100%;
}

.signin__title {
  margin-top: var(--s-5);
  font: var(--type-title);
  text-align: center;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.signin__form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--s-3);
  width: min(320px, 100%);
  margin-top: var(--s-6);
}

/* The sign-in box is the hero control: always touch-sized (≥ 44 px). */
.signin__pin {
  min-height: 48px;
  padding: 0 1px 0 0;
}

.signin__pin .input__field {
  font-size: 16px;
}

.signin__pin .input__action {
  width: 44px;
  height: 44px;
}

.signin__check {
  margin-top: calc(-1 * var(--s-2));
}

.signin__error {
  font: var(--type-body);
  color: var(--c-text);
  text-align: center;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5);
}

.signin__remember {
  align-self: center;
  min-height: 44px;
}

.signin__busy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-4);
  margin-top: var(--s-8);
  color: var(--c-text);
  --spinner-size: 40px;
}

.signin__busy.is-static .spinner-dots {
  display: none;
}

.signin__welcome {
  font: var(--type-subtitle);
  text-align: center;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

/* ---- Desktop ------------------------------------------------------------- */

.desktop {
  position: fixed;
  inset: 0;
  z-index: 1;
  animation: shell-fade var(--dur) var(--ease) both;
}

.desktop.is-entering {
  animation: shell-fade var(--dur) var(--ease) both;
}

.desk-icons {
  position: absolute;
  top: var(--s-2);
  left: var(--s-1);
  bottom: calc(var(--taskbar-total) + var(--s-2));
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(auto-fill, 104px);
  grid-auto-columns: 88px;
  gap: var(--s-1);
  margin: 0;
  padding: 0;
  list-style: none;
  z-index: var(--z-desktop);
}

.desk-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  width: 100%;
  height: 100%;
  padding: var(--s-2) var(--s-1) var(--s-1);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--c-text);
  user-select: none;
  -webkit-user-select: none;
}

.desk-icon:hover {
  background: rgba(255, 255, 255, 0.08);
}

.desk-icon:focus {
  background: rgba(96, 205, 255, 0.16);
  border-color: rgba(96, 205, 255, 0.32);
}

.desk-icon__img {
  width: 44px;
  height: 44px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
  pointer-events: none;
}

.desk-icon__label {
  font: var(--type-caption);
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85), 0 0 8px rgba(0, 0, 0, 0.4);
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

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

.workarea {
  position: absolute;
  inset: 0 0 var(--taskbar-total) 0;
  z-index: 1;
  pointer-events: none;
}

.win {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--w, 760px);
  height: var(--h, 560px);
  transform: translate3d(var(--x, 0px), var(--y, 0px), 0);
  z-index: calc(var(--z-window) + var(--z, 1));
  display: flex;
  flex-direction: column;
  background: var(--c-surface-1);
  border: 1px solid var(--c-stroke-surface);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-window-inactive);
  overflow: hidden;
  pointer-events: auto;
  contain: layout paint;
}

.win.is-active {
  box-shadow: var(--shadow-window);
}

.win.is-max {
  transform: none;
  width: 100%;
  height: 100%;
  border-radius: 0;
  border-width: 0;
}

.win.is-opening {
  animation: win-open 160ms var(--ease) both;
}

@keyframes win-open {
  from {
    opacity: 0;
    scale: 0.96;
  }
}

.win.is-dragging {
  user-select: none;
  -webkit-user-select: none;
}

/* Focus lands on the window container itself only programmatically; the
   active-window styling (shadow, title colour) already shows where it is. */
.win:focus-visible {
  outline: none;
}

.win__bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: 40px;
  padding-left: var(--s-4);
  background: var(--c-surface-3);
  border-bottom: 1px solid var(--c-stroke);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.win__icon {
  width: 16px;
  height: 16px;
  flex: none;
  pointer-events: none;
}

.win__title {
  flex: 1;
  min-width: 0;
  font: var(--type-caption);
  font-weight: var(--fw-regular);
  color: var(--c-text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.win.is-active .win__title {
  color: var(--c-text);
}

.win__caption {
  display: flex;
  align-self: stretch;
  flex: none;
}

.win__cap,
.win__back {
  display: grid;
  place-items: center;
  width: 46px;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--c-text);
  transition: background-color var(--dur-fast) linear;
}

.win__cap:hover,
.win__back:hover {
  background: var(--c-fill-subtle-hover);
}

.win__cap:active,
.win__back:active {
  background: var(--c-fill-subtle-pressed);
}

.win__cap--close:hover {
  background: #c42b1c;
}

.win__cap--close:active {
  background: #c83c31;
}

.win__cap-icon,
.win__back-icon {
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.win:not(.is-active) .win__cap-icon {
  opacity: 0.55;
}

.win__cap:focus-visible,
.win__back:focus-visible {
  outline-offset: -2px;
}

.win__back {
  display: none;
}

.win__body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.app {
  flex: 1;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  container-type: inline-size;
  container-name: app;
}

.app__failed {
  padding: var(--s-6);
}

/* ---- Taskbar ------------------------------------------------------------- */

.taskbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-taskbar);
  height: var(--taskbar-total);
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: center;
  background: var(--c-taskbar);
  border-top: 1px solid var(--c-stroke);
  -webkit-backdrop-filter: var(--blur-acrylic);
  backdrop-filter: var(--blur-acrylic);
}

.taskbar__center {
  position: absolute;
  left: 50%;
  top: 0;
  height: var(--taskbar-h);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--s-1);
}

.taskbar__apps {
  display: flex;
  align-items: center;
  gap: var(--s-1);
}

.tb-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 40px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--c-text);
  transition: background-color var(--dur-fast) linear;
}

.tb-btn:hover {
  background: var(--c-fill-subtle-hover);
  border-color: var(--c-stroke);
}

.tb-btn:active img {
  scale: 0.9;
}

.tb-btn img {
  width: 24px;
  height: 24px;
  pointer-events: none;
  transition: scale var(--dur-fast) var(--ease);
}

.tb-start__logo {
  width: 22px;
  height: 22px;
}

.tb-btn[aria-expanded="true"],
.tb-app.is-active {
  background: var(--c-control);
  border-color: var(--c-stroke-control);
}

.tb-app__ind {
  position: absolute;
  left: 50%;
  bottom: 1px;
  width: 0;
  height: 3px;
  border-radius: 2px;
  background: var(--c-text-tertiary);
  transform: translateX(-50%);
  transition: width var(--dur) var(--ease), background-color var(--dur) linear;
}

.tb-app.is-open .tb-app__ind {
  width: 6px;
}

.tb-app.is-active .tb-app__ind {
  width: 16px;
  background: var(--c-accent);
}

.tb-app__badge {
  position: absolute;
  top: 1px;
  right: 1px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--r-pill);
  background: var(--c-accent);
  color: var(--c-accent-text);
  font: var(--fw-strong) 10px/16px var(--font-ui);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.tray {
  position: absolute;
  right: var(--s-2);
  top: 4px;
  height: 40px;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 0 var(--s-2) 0 var(--s-3);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--c-text);
  transition: background-color var(--dur-fast) linear;
}

.tray:hover,
.tray[aria-expanded="true"] {
  background: var(--c-fill-subtle-hover);
  border-color: var(--c-stroke);
}

.tray__status {
  position: relative;
  display: grid;
  place-items: center;
}

.tray__icon {
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.tray__badge {
  display: none;
  position: absolute;
  top: -7px;
  right: -9px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: var(--r-pill);
  background: var(--c-accent);
  color: var(--c-accent-text);
  font: var(--fw-strong) 10px/15px var(--font-ui);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.tray.is-out .tray__badge {
  background: var(--c-error);
}

.tray__runs {
  font: var(--type-caption);
  color: var(--c-text-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.tray.is-out .tray__runs {
  color: var(--c-error);
}

.tray__runs:empty {
  display: none;
}

.tray__clock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font: var(--type-caption);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---- Start menu and flyouts ---------------------------------------------- */

.start,
.flyout {
  position: absolute;
  z-index: var(--z-flyout);
  bottom: calc(var(--taskbar-total) + var(--s-3));
  background: var(--c-acrylic);
  -webkit-backdrop-filter: var(--blur-acrylic);
  backdrop-filter: var(--blur-acrylic);
  border: 1px solid var(--c-stroke-surface);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-flyout);
  color: var(--c-text);
}

.start.is-entering,
.flyout.is-entering {
  animation: menu-rise var(--dur) var(--ease) both;
}

@keyframes menu-rise {
  from {
    opacity: 0;
    translate: 0 24px;
  }
}

.start {
  left: 50%;
  transform: translateX(-50%);
  width: min(640px, calc(100vw - 24px));
  max-height: min(720px, calc(100dvh - var(--taskbar-total) - 24px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.start__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--s-6) var(--s-8) var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
}

.start__heading {
  font: var(--type-body-strong);
  margin-bottom: var(--s-3);
  padding-left: var(--s-2);
}

.start__pinned {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: var(--s-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.start-app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  width: 100%;
  min-height: 84px;
  padding: var(--s-3) var(--s-1);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--c-text);
  transition: background-color var(--dur-fast) linear;
}

.start-app:hover,
.start-recent:hover {
  background: var(--c-fill-subtle-hover);
  border-color: var(--c-stroke);
}

.start-app__icon {
  width: 32px;
  height: 32px;
  pointer-events: none;
}

.start-app__label {
  font: var(--type-caption);
  text-align: center;
}

.start__recent {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--s-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.start-recent {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-height: 52px;
  padding: var(--s-2) var(--s-3);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--c-text);
  text-align: left;
  transition: background-color var(--dur-fast) linear;
}

.start-recent__icon {
  width: 24px;
  height: 24px;
  flex: none;
  pointer-events: none;
}

.start-recent__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.start-recent__title {
  font: var(--type-body);
  font-family: var(--font-mono);
}

.start-recent__meta {
  font: var(--type-caption);
  color: var(--c-text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.start__empty {
  padding-left: var(--s-2);
  font: var(--type-body);
  color: var(--c-text-tertiary);
}

.start__footer {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  min-height: 64px;
  padding: var(--s-2) var(--s-8);
  background: rgba(0, 0, 0, 0.16);
  border-top: 1px solid var(--c-stroke);
}

.start__account {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-width: 0;
}

.start__avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--c-accent-strong);
  color: #ffffff;
  font: var(--fw-strong) 13px/1 var(--font-ui);
  letter-spacing: 0.02em;
}

.start__who {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.start__team {
  font: var(--type-body-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.start__runs {
  font: var(--type-caption);
  color: var(--c-text-2);
}

.start__power {
  flex: none;
  gap: var(--s-2);
  min-height: 44px;
}

.start__power img {
  width: 16px;
  height: 16px;
}

.flyout {
  right: var(--s-3);
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100dvh - var(--taskbar-total) - 24px);
  overflow-y: auto;
  padding: var(--s-5) var(--s-6);
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

.flyout__title {
  font: var(--type-body-strong);
}

.flyout__date {
  font: var(--type-caption);
  color: var(--c-text-tertiary);
  padding-top: var(--s-3);
  border-top: 1px solid var(--c-stroke);
}

/* ---- Toast stack --------------------------------------------------------- */

.toasts {
  position: absolute;
  right: var(--s-3);
  bottom: calc(var(--taskbar-total) + var(--s-3));
  z-index: var(--z-toast);
  width: min(364px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  pointer-events: none;
}

.toasts > * {
  pointer-events: auto;
}

.toast__app-icon {
  width: 16px;
  height: 16px;
}

/* ---- Narrow screens: taskbar flows left to right ------------------------- */

@media (max-width: 599.98px) {
  .taskbar {
    justify-content: space-between;
    padding: 0 var(--s-1) var(--safe-bottom);
  }

  .taskbar__center {
    position: static;
    transform: none;
    gap: 0;
  }

  .taskbar__apps {
    gap: 0;
  }

  .tray {
    position: static;
    height: 44px;
    gap: var(--s-2);
    padding: 0 var(--s-2);
  }

  .tray__runs,
  .tray__date {
    display: none;
  }

  .tray__badge {
    display: block;
  }

  .start {
    left: 0;
    right: 0;
    width: auto;
    transform: none;
  }

  .toasts {
    left: var(--s-2);
    right: var(--s-2);
    width: auto;
  }
}

/* ---- Tablet mode (narrow or coarse pointer) ------------------------------ */

.is-tablet .tb-btn {
  width: 44px;
  height: 44px;
}

.is-tablet .tray {
  top: 2px;
  height: 44px;
}

.is-tablet .desk-icons {
  inset: var(--s-4) var(--s-3) calc(var(--taskbar-total) + var(--s-4));
  grid-auto-flow: row;
  grid-template-rows: none;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  grid-auto-rows: 108px;
  grid-auto-columns: auto;
  align-content: start;
  justify-items: center;
}

.is-tablet .desk-icon {
  width: 88px;
}

.is-tablet .desk-icon__img {
  width: 48px;
  height: 48px;
}

.is-tablet .win,
.is-tablet .win.is-max {
  transform: none;
  width: 100%;
  height: 100%;
  border-radius: 0;
  border-width: 0;
  box-shadow: none;
}

.is-tablet .win.is-covered {
  visibility: hidden;
}

.is-tablet .win__bar {
  height: 48px;
  padding-left: 0;
  gap: var(--s-2);
  touch-action: auto;
}

.is-tablet .win__back {
  display: grid;
  width: 48px;
}

.is-tablet .win__title {
  font: var(--type-body-strong);
  color: var(--c-text);
}

.is-tablet .win__cap--min,
.is-tablet .win__cap--max {
  display: none;
}

.is-tablet .win__cap {
  width: 48px;
}

.is-tablet .start {
  left: 0;
  right: 0;
  bottom: var(--taskbar-total);
  width: auto;
  transform: none;
  max-height: min(80dvh, calc(100dvh - var(--taskbar-total)));
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  border-bottom-width: 0;
}

.is-tablet .start__body {
  padding: var(--s-5) var(--s-4) var(--s-3);
}

.is-tablet .start__footer {
  padding: var(--s-2) var(--s-4);
}

.is-tablet .start-recent {
  min-height: 56px;
}

.is-tablet .flyout {
  left: var(--s-2);
  right: var(--s-2);
  width: auto;
  bottom: calc(var(--taskbar-total) + var(--s-2));
}

@media (min-width: 600px) {
  .is-tablet .start {
    left: 50%;
    right: auto;
    width: min(640px, 100vw);
    transform: translateX(-50%);
  }

  .is-tablet .flyout {
    left: auto;
    right: var(--s-2);
    width: 360px;
  }
}
