/*
 * EXPERIENCE Desktop Assistant — Clippy and friends.
 *
 * Two surfaces with different jobs:
 *
 *   The CHARACTER remains an engine-owned animated sprite on the desktop.
 *   The COMPANION is a compact React speech bubble with an XP toolbar,
 *   transcript, composer and popup menu. It follows the sprite without
 *   becoming a taskbar window. Legacy balloon/window rules remain below for
 *   engine and compatibility coverage, but the companion is the live UI.
 */

/* =============================================================== character */

.clippy-agent {
  position: fixed;
  /* Above every window (1000) so the assistant is never buried, but below the
     start menu (2000) and dialogs, which must be able to cover it. */
  z-index: 1500;
  cursor: grab;
  display: none;
  touch-action: none;
  /* The sprite sheets have hard-edged transparency; a drop shadow is what
     lifts the character off the wallpaper instead of looking pasted on. */
  filter: drop-shadow(2px 4px 4px rgba(0, 0, 0, 0.35));
}

.clippy-agent.is-dragging {
  cursor: grabbing;
  /* Dropping the shadow while dragging makes the character read as picked up. */
  filter: drop-shadow(4px 8px 8px rgba(0, 0, 0, 0.4));
}

/* ================================================================= balloon */

.clippy-balloon {
  position: fixed;
  z-index: 1501;
  display: none;
  box-sizing: border-box;
  max-width: 260px;
  padding: 8px 10px;
  background: #ffffe1; /* the XP tooltip yellow */
  border: 1px solid #767676;
  border-radius: 3px;
  box-shadow: 2px 3px 6px rgba(0, 0, 0, 0.3);
  color: #000;
  cursor: default;
}

.clippy-balloon.is-visible {
  display: block;
}

.clippy-balloon-content {
  max-width: 240px;
  min-width: 110px;
  font: 11px Tahoma, "Microsoft Sans Serif", sans-serif;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/*
 * The tip. Two stacked triangles — border colour behind, fill in front — which
 * is how you get a bordered pointer without an image. `data-side` is set by
 * balloon.js to whichever corner it settled on, and each case aims the tip
 * back at the character.
 */
.clippy-balloon-tip {
  position: absolute;
  width: 0;
  height: 0;
  border: 9px solid transparent;
}

.clippy-balloon-tip::after {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border: 8px solid transparent;
}

/* Balloon above the character: tip points down. */
.clippy-balloon[data-side='top-left'] .clippy-balloon-tip,
.clippy-balloon[data-side='top-right'] .clippy-balloon-tip {
  top: 100%;
  border-top-color: #767676;
  border-bottom-width: 0;
}

.clippy-balloon[data-side='top-left'] .clippy-balloon-tip::after,
.clippy-balloon[data-side='top-right'] .clippy-balloon-tip::after {
  top: -9px;
  left: -8px;
  border-top-color: #ffffe1;
  border-bottom-width: 0;
}

/* Balloon below the character: tip points up. */
.clippy-balloon[data-side='bottom-left'] .clippy-balloon-tip,
.clippy-balloon[data-side='bottom-right'] .clippy-balloon-tip {
  bottom: 100%;
  border-bottom-color: #767676;
  border-top-width: 0;
}

.clippy-balloon[data-side='bottom-left'] .clippy-balloon-tip::after,
.clippy-balloon[data-side='bottom-right'] .clippy-balloon-tip::after {
  bottom: -9px;
  left: -8px;
  border-bottom-color: #ffffe1;
  border-top-width: 0;
}

/* The tip sits under whichever edge of the balloon is nearest the character. */
.clippy-balloon[data-side='top-left'] .clippy-balloon-tip,
.clippy-balloon[data-side='bottom-left'] .clippy-balloon-tip {
  right: 28px;
}

.clippy-balloon[data-side='top-right'] .clippy-balloon-tip,
.clippy-balloon[data-side='bottom-right'] .clippy-balloon-tip {
  left: 28px;
}

/*
 * A blinking caret while a reply streams in, so a pause between chunks reads
 * as thinking rather than as the balloon having stopped.
 */
.clippy-balloon.is-streaming .clippy-balloon-content::after {
  content: '▋';
  margin-left: 1px;
  animation: clippy-caret 1s steps(1) infinite;
}

@keyframes clippy-caret {
  50% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .clippy-balloon.is-streaming .clippy-balloon-content::after {
    animation: none;
  }
}

/* ================================================================== window */

.assistant-window-content {
  overflow: hidden;
  padding: 0;
  background: #ece9d8;
  font: 11px Tahoma, sans-serif;
}

.assistant-app {
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-sizing: border-box;
  height: 100%;
  padding: 10px;
  color: #000;
}

/* ---------------------------------------------------------- character picker */

.assistant-characters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  flex: 0 0 auto;
}

.assistant-character {
  flex: 1 1 0;
  min-width: 0;
  box-sizing: border-box;
  padding: 7px 8px;
  text-align: left;
  font: 11px Tahoma, sans-serif;
  color: #000;
  background: linear-gradient(180deg, #fff 0%, #f2f0e6 50%, #e8e5d6 100%);
  border: 1px solid #adaa9f;
  border-radius: 3px;
  cursor: pointer;
}

.assistant-character:hover {
  border-color: #6a8cc7;
  background: linear-gradient(180deg, #fff 0%, #f4f8ff 50%, #e3ecfb 100%);
}

.assistant-character.is-selected {
  /* The XP selected-item blue, so the current character reads the same way a
     selected file does elsewhere on this desktop. */
  border-color: #316ac5;
  background: linear-gradient(180deg, #eef4ff 0%, #d6e4fb 100%);
  box-shadow: inset 0 0 0 1px #fff;
}

.assistant-character-name {
  display: block;
  font-weight: bold;
  color: #003399;
}

.assistant-character-blurb {
  display: block;
  margin-top: 2px;
  line-height: 1.35;
  color: #444;
}

/* ------------------------------------------------------------- transcript */

.assistant-transcript {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 6px;
  background: #fff;
  /* The XP sunken well: dark outer, light inner. */
  border: 1px solid #7f9db9;
  box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.12);
}

.assistant-line {
  display: block;
  margin-bottom: 6px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.assistant-line:last-child {
  margin-bottom: 0;
}

.assistant-line-who {
  font-weight: bold;
  margin-right: 5px;
}

.assistant-line-user .assistant-line-who {
  color: #7a3a00;
}

.assistant-line-assistant .assistant-line-who {
  color: #003399;
}

/* --------------------------------------------------------------- composer */

.assistant-composer {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

.assistant-input {
  flex: 1 1 auto;
  min-width: 0;
  box-sizing: border-box;
  padding: 3px 4px;
  font: 11px Tahoma, sans-serif;
  background: #fff;
  border: 1px solid #7f9db9;
}

.assistant-input:focus {
  outline: 1px dotted #316ac5;
  outline-offset: -3px;
}

.assistant-input:disabled {
  background: #f0f0f0;
  color: #888;
}

.assistant-ask {
  flex: 0 0 auto;
  min-width: 72px;
  padding: 3px 12px;
  font: 11px Tahoma, sans-serif;
}

/* ----------------------------------------------------------------- status */

.assistant-status {
  flex: 0 0 auto;
  min-height: 14px;
  padding: 2px 1px;
  line-height: 1.35;
  color: #444;
}

.assistant-status[data-tone='error'] {
  color: #a10000;
}

.assistant-status[data-tone='success'] {
  color: #1a6b1a;
}

.assistant-app.is-busy .assistant-status {
  color: #003399;
}

/* -------------------------------------------------------------- narrow app */

/*
 * The picker is the first thing to run out of room. Below this width the four
 * characters stack, which keeps their names and descriptions readable instead
 * of crushing them into unreadable columns.
 */
@media (max-width: 420px) {
  .assistant-characters {
    grid-template-columns: 1fr;
  }

  .assistant-character-blurb {
    display: none;
  }
}

/* A canonical link the server supplied alongside an answer. */
.assistant-line-link {
  margin: -2px 0 6px;
  padding-left: 2px;
}

.assistant-line-link a {
  color: #0000ee;
  word-break: break-all;
}

.assistant-line-link a:visited {
  color: #551a8b;
}

/* ===================================================== companion bubble */

.assistant-companion {
  --assistant-tail-x: 30px;
  position: fixed;
  z-index: 1502;
  box-sizing: border-box;
  width: min(352px, calc(100vw - 16px));
  max-height: calc(100vh - 54px);
  padding: 0;
  color: #000;
  background: #ffffe1;
  border: 1px solid #404040;
  border-radius: 4px;
  box-shadow: 2px 3px 5px rgba(0, 0, 0, 0.35);
  font: 11px Tahoma, "Microsoft Sans Serif", sans-serif;
}

.assistant-companion-tail {
  position: absolute;
  left: var(--assistant-tail-x);
  width: 0;
  height: 0;
  margin-left: -9px;
  border: 9px solid transparent;
  pointer-events: none;
}

.assistant-companion-tail::after {
  content: '';
  position: absolute;
  left: -8px;
  width: 0;
  height: 0;
  border: 8px solid transparent;
}

.assistant-companion[data-vertical='above'] .assistant-companion-tail {
  top: 100%;
  border-top-color: #404040;
  border-bottom-width: 0;
}

.assistant-companion[data-vertical='above'] .assistant-companion-tail::after {
  top: -9px;
  border-top-color: #ffffe1;
  border-bottom-width: 0;
}

.assistant-companion[data-vertical='below'] .assistant-companion-tail {
  bottom: 100%;
  border-top-width: 0;
  border-bottom-color: #404040;
}

.assistant-companion[data-vertical='below'] .assistant-companion-tail::after {
  bottom: -9px;
  border-top-width: 0;
  border-bottom-color: #ffffe1;
}

.assistant-companion-toolbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  min-height: 27px;
  padding: 3px 3px 3px 4px;
  background: #ece9d8;
  border-bottom: 1px solid #aca899;
  border-radius: 3px 3px 0 0;
}

.assistant-companion-name {
  min-width: 0;
  margin-left: 7px;
  overflow: hidden;
  color: #003399;
  font-weight: bold;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.assistant-close-button {
  width: 20px;
  height: 20px;
  margin-left: auto;
  padding: 0 0 2px;
  color: #fff;
  background: #e04425;
  border: 1px solid #fff;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px #9b1b08, 1px 1px 0 #aca899;
  font: bold 16px/16px Tahoma, sans-serif;
  cursor: default;
}

.assistant-close-button:hover {
  background: #f45b3a;
}

.assistant-close-button:active {
  padding: 1px 0 1px 1px;
  background: #bd321c;
}

.assistant-xp-button {
  min-height: 23px;
  box-sizing: border-box;
  padding: 2px 8px;
  color: #000;
  background: #ece9d8;
  border: 1px solid #003c74;
  border-radius: 3px;
  box-shadow: inset 1px 1px 0 #fff, inset -1px -1px 0 #aca899;
  font: 11px Tahoma, "Microsoft Sans Serif", sans-serif;
  cursor: default;
}

.assistant-xp-button:hover:not(:disabled) {
  background: #f5f3eb;
  box-shadow: inset 1px 1px 0 #fff, inset -1px -1px 0 #7f9db9;
}

.assistant-xp-button:active:not(:disabled) {
  padding-top: 3px;
  padding-left: 9px;
  background: #dedbd0;
  box-shadow: inset 1px 1px 0 #808080;
}

.assistant-xp-button:disabled {
  color: #808080;
  border-color: #aca899;
  text-shadow: 1px 1px #fff;
}

.assistant-xp-button:focus-visible,
.assistant-close-button:focus-visible,
.assistant-agent-option:focus-visible,
.assistant-chat-input:focus-visible {
  outline: 1px dotted #000;
  outline-offset: -3px;
}

.assistant-swap-wrap {
  position: relative;
}

.assistant-swap-button {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 1px 6px 1px 3px;
  white-space: nowrap;
}

.assistant-menu-arrow {
  margin-left: 5px;
  font-size: 7px;
}

.assistant-agent-menu {
  position: absolute;
  top: 26px;
  left: 0;
  z-index: 5;
  width: 184px;
  padding: 2px;
  background: #fff;
  border: 1px solid #404040;
  box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.35);
}

.assistant-agent-option {
  display: grid;
  grid-template-columns: 14px 30px 1fr;
  align-items: center;
  width: 100%;
  min-height: 31px;
  padding: 1px 5px 1px 2px;
  color: #000;
  background: transparent;
  border: 0;
  border-radius: 0;
  font: 11px Tahoma, "Microsoft Sans Serif", sans-serif;
  text-align: left;
  cursor: default;
}

.assistant-agent-option:hover:not(:disabled),
.assistant-agent-option:focus-visible:not(:disabled) {
  color: #fff;
  background: #316ac5;
}

.assistant-agent-option:disabled {
  color: #808080;
}

.assistant-agent-check {
  font-weight: bold;
  text-align: center;
}

.assistant-agent-menu-separator {
  height: 1px;
  margin: 2px 3px;
  background: #aca899;
  border-bottom: 1px solid #fff;
}

.assistant-dismiss-icon {
  display: inline-grid;
  width: 16px;
  height: 16px;
  place-items: center;
  color: #fff;
  background: #c72d14;
  border: 1px solid #8f1709;
  font-weight: bold;
  line-height: 14px;
}

.assistant-agent-icon {
  position: relative;
  display: inline-block;
  width: 28px;
  height: 24px;
  overflow: hidden;
  vertical-align: middle;
}

.assistant-agent-icon-sprite {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  width: var(--assistant-icon-width);
  height: var(--assistant-icon-height);
  background-repeat: no-repeat;
  transform: translate(-50%, -50%) scale(var(--assistant-icon-scale));
  transform-origin: center;
}

.assistant-agent-icon[data-character='Clippy'] {
  --assistant-icon-width: 124px;
  --assistant-icon-height: 93px;
  --assistant-icon-scale: 0.26;
}

.assistant-agent-icon[data-character='Clippy'] .assistant-agent-icon-sprite {
  background-image: url('/assets/clippy/clippy/map.png');
}

.assistant-agent-icon[data-character='Merlin'] {
  --assistant-icon-width: 128px;
  --assistant-icon-height: 128px;
  --assistant-icon-scale: 0.19;
}

.assistant-agent-icon[data-character='Merlin'] .assistant-agent-icon-sprite {
  background-image: url('/assets/clippy/merlin/map.png');
}

.assistant-agent-icon[data-character='Rover'] {
  --assistant-icon-width: 80px;
  --assistant-icon-height: 80px;
  --assistant-icon-scale: 0.3;
}

.assistant-agent-icon[data-character='Rover'] .assistant-agent-icon-sprite {
  background-image: url('/assets/clippy/rover/map.png');
}

.assistant-agent-icon[data-character='ExperienceMascot'] {
  --assistant-icon-width: 124px;
  --assistant-icon-height: 93px;
  --assistant-icon-scale: 0.26;
}

.assistant-agent-icon[data-character='ExperienceMascot'] .assistant-agent-icon-sprite {
  background-image: url('/assets/mascot/assistant/map.png');
}

.assistant-chat-transcript {
  box-sizing: border-box;
  max-height: min(224px, calc(100vh - 145px));
  min-height: 56px;
  overflow-y: auto;
  padding: 8px 9px 5px;
  background: #ffffe1;
  scrollbar-color: #c8c6b8 #f1f0e8;
}

.assistant-chat-line {
  display: flex;
  gap: 5px;
  align-items: baseline;
  margin: 0 0 7px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.assistant-chat-line-user {
  margin-left: 28px;
  padding: 4px 5px;
  background: #fff;
  border: 1px solid #aca899;
  box-shadow: inset 1px 1px 0 #f5f5f5;
}

.assistant-chat-who {
  flex: 0 0 auto;
  color: #003399;
  font-weight: bold;
}

.assistant-chat-line-user .assistant-chat-who {
  color: #7a3a00;
}

.assistant-chat-who::after {
  content: ':';
}

.assistant-chat-text {
  min-width: 0;
  white-space: pre-wrap;
}

.assistant-chat-link {
  margin: -3px 0 7px 42px;
}

.assistant-chat-link a {
  color: #0000ee;
}

.assistant-chat-link a:visited {
  color: #551a8b;
}

.assistant-thinking {
  display: flex;
  gap: 5px;
  align-items: center;
  min-height: 18px;
  color: #555;
  font-style: italic;
}

.assistant-thinking-dots {
  display: inline-flex;
  gap: 2px;
  align-items: center;
  height: 8px;
}

.assistant-thinking-dots i {
  width: 3px;
  height: 3px;
  background: #555;
  animation: assistant-thinking-dot 900ms steps(2, end) infinite;
}

.assistant-thinking-dots i:nth-child(2) {
  animation-delay: 150ms;
}

.assistant-thinking-dots i:nth-child(3) {
  animation-delay: 300ms;
}

@keyframes assistant-thinking-dot {
  50% {
    transform: translateY(-2px);
  }
}

.assistant-inline-status {
  margin: 0 7px 4px;
  padding: 3px 5px;
  color: #003399;
  background: #fff;
  border: 1px solid #aca899;
}

.assistant-inline-status[data-tone='error'] {
  color: #a10000;
}

.assistant-composer-row {
  display: flex;
  gap: 5px;
  align-items: flex-end;
  padding: 5px;
  background: #ece9d8;
  border-top: 1px solid #aca899;
  border-radius: 0 0 3px 3px;
}

.assistant-chat-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 23px;
  max-height: 54px;
  box-sizing: border-box;
  resize: none;
  overflow-y: auto;
  padding: 3px 4px;
  color: #000;
  background: #fff;
  border: 1px solid #7f9db9;
  border-radius: 0;
  box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.12);
  font: 11px/15px Tahoma, "Microsoft Sans Serif", sans-serif;
}

.assistant-chat-input:disabled {
  color: #808080;
  background: #f1f1f1;
}

.assistant-send-button {
  flex: 0 0 auto;
  min-width: 54px;
  height: 23px;
}

@media (max-width: 420px), (max-height: 430px) {
  .assistant-companion {
    width: min(320px, calc(100vw - 12px));
    max-height: calc(100vh - 44px);
  }

  .assistant-chat-transcript {
    max-height: min(168px, calc(100vh - 135px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .assistant-thinking-dots i {
    animation: none;
  }
}
