/* ============================================================
   Design tokens — from Figma "Personalise Your Agents" (light)
   ============================================================ */
:root {
  --surface: #ffffff;
  --surface-secondary: #f5f5f7;
  --surface-tertiary: #e8e8ed;
  --border: #d1d1d6;

  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #a1a1a6;
  --text-on-accent: #ffffff;

  --accent: #007aff;
  --accent-subtle: #e8f0fe;
  --danger: #ff3b30;
  --success: #34c759;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 999px;

  --space-4: 4px;
  --space-8: 8px;
  --space-12: 12px;
  --space-16: 16px;
  --space-20: 20px;
  --space-24: 24px;
  --space-32: 32px;
  --space-48: 48px;
  --space-64: 64px;

  /* Effect/Shadow SM · MD · LG */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
  --shadow-modal: var(--shadow-lg);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* Figma artboard — full desktop frame */
  --desktop-w: 1512px;
  --desktop-h: 982px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: #2e2e33;
  min-height: 100vh;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 24px;
}

/* ============================================================
   Desktop canvas (1512 × 982) — matches Figma artboard
   ============================================================ */
.desktop {
  position: relative;
  width: var(--desktop-w);
  height: var(--desktop-h);
  flex-shrink: 0;
  background: url("Desktop.png") no-repeat;
  background-size: var(--desktop-w) var(--desktop-h);
  overflow: hidden;
}

.window {
  position: absolute;
  /* centred within the 1512×982 artboard (Figma: x 276, y 131) */
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  width: 960px;
  height: 720px;
  background: var(--surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.window.dragged { translate: none; }

.navbar {
  position: absolute;
  inset: 0 0 auto 0;
  height: 36px;
  background: var(--surface-secondary);
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 2;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.navbar.dragging { cursor: grabbing; }

.traffic-lights { display: flex; gap: 8px; }
.light { width: 11px; height: 11px; border-radius: 50%; }
.light.red { background: #ff5f57; }
.light.yellow { background: #febc2e; }
.light.green { background: #28c840; }

.sidebar-icon {
  margin-left: 18px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 2px;
  border-radius: 4px;
}
.sidebar-icon:hover { background: rgba(0, 0, 0, 0.05); }

/* ============================================================
   Ask-me-anything input bar
   ============================================================ */
.input-bar {
  position: absolute;
  left: 18px;
  right: 18px;
  top: 658px;
  height: 42px;
  background: var(--surface-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  padding: 0 12px 0 18px;
  gap: 14px;
  z-index: 2;
}

.plus {
  /* Typography/H3 */
  font-size: 18px;
  font-weight: 600;
  line-height: 24px;
  letter-spacing: -0.2px;
  color: var(--text-secondary);
}

.ask-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-family: var(--font);
  /* Typography/Caption */
  font-size: 13px;
  line-height: 18px;
  color: var(--text-primary);
}
.ask-input::placeholder { color: var(--text-tertiary); }

.model-label {
  /* Typography/Caption */
  font-size: 13px;
  line-height: 18px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.mic-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 2px;
}

/* ============================================================
   Scrim + modal shell
   ============================================================ */
.scrim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 3;
}
.scrim.visible { opacity: 1; pointer-events: auto; }

.modal {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  width: 360px;
  height: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: flex-start;
  z-index: 4;
}
.modal[hidden] { display: none; }

.close-btn {
  position: absolute;
  top: 11px;
  right: 12px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--surface-tertiary);
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.close-btn:hover { background: var(--border); }

.spacer { flex: 1; }

/* Progress dots */
.progress {
  width: 320px;
  height: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}
.dot.active { background: var(--accent); }
.dot.completed { background: var(--success); }
.rule { width: 90px; height: 1px; background: var(--border); flex-shrink: 0; }

/* Typography */
.modal-hero {
  font-size: 22px;
  font-weight: 700;
  line-height: 28px;
  letter-spacing: -0.3px;
  text-align: center;
}
.modal-title {
  font-size: 17px;
  font-weight: 600;
  line-height: 24px;
  letter-spacing: -0.2px;
}

/* Buttons */
.btn {
  height: 42px;
  padding: 0 24px;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  line-height: 20px;
  cursor: pointer;
  transition: filter 0.15s ease, background 0.15s ease;
}
.btn-primary {
  background: var(--accent);
  border: none;
  color: var(--text-on-accent);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled {
  opacity: 0.45;
  cursor: default;
  filter: none;
}
.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
}
.btn-secondary:hover { background: var(--surface-secondary); }

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 320px;
}

/* ============================================================
   01 Welcome
   ============================================================ */
.modal-welcome {
  align-items: center;
  justify-content: center;
  gap: 40px;
}

.branding-box {
  width: 160px;
  height: 160px;
  background: var(--surface-tertiary);
  border-radius: 25.5px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.branding-box p {
  /* Typography/H3 */
  font-size: 18px;
  font-weight: 600;
  line-height: 24px;
  letter-spacing: -0.2px;
  color: var(--text-tertiary);
  text-align: center;
}

/* ============================================================
   02 Name
   ============================================================ */
.field-group {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.field-label {
  font-size: 12px;
  font-weight: 600;
  line-height: 16px;
  color: var(--text-secondary);
}
.text-field {
  height: 44px;
  width: 100%;
  background: var(--surface-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  font-family: var(--font);
  /* Typography/Overlay/Body */
  font-size: 14px;
  line-height: 20px;
  color: var(--text-primary);
  outline: none;
}
.text-field::placeholder { color: var(--text-tertiary); }
.text-field:focus { border-color: var(--accent); }
.char-count {
  font-size: 12px;
  line-height: 16px;
  color: var(--text-tertiary);
}
.char-count.at-max { color: var(--danger); }

.field-error {
  font-size: 12px;
  line-height: 16px;
  color: var(--danger);
}
.field-error[hidden] { display: none; }

/* ============================================================
   03 Avatar
   ============================================================ */
.avatars {
  display: flex;
  gap: 12px;
  width: 320px;
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  overscroll-behavior-x: contain;
}
.avatars::-webkit-scrollbar { display: none; }

.avatar-item {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--surface-tertiary);
  border: 1.5px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  background-size: cover;
  background-position: center;
}
.avatar-item:hover { border-color: var(--text-tertiary); }
.avatar-item.selected { border: 2px solid var(--accent); }

.avatar-emoji { font-size: 28px; line-height: 1; }

.avatar-check {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  display: none;
  align-items: center;
  justify-content: center;
}
.avatar-item.selected .avatar-check { display: flex; }

.upload-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 320px;
}
.upload-panel[hidden] { display: none; }
.upload-panel-wide .btn-block,
.upload-panel-change .btn-block { width: 100%; }

.btn-block {
  width: 100%;
  justify-content: center;
}

.upload-helper {
  font-size: 11px;
  line-height: 1.2;
  color: var(--text-tertiary);
  text-align: center;
  width: 100%;
}

.upload-error {
  font-size: 11px;
  line-height: 1.2;
  color: var(--danger);
  text-align: center;
}
.upload-error[hidden] { display: none; }

.avatar-custom {
  background-color: var(--surface-tertiary);
}

/* Crop modal (upload sub-flow) */
.modal-crop {
  gap: 10px;
}
.modal-crop .actions {
  margin-top: auto;
}

.crop-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 320px;
}

.crop-title {
  /* Typography/H3 */
  font-size: 18px;
  font-weight: 600;
  line-height: 24px;
  letter-spacing: -0.2px;
  color: var(--text-primary);
}

.crop-subtitle {
  /* Typography/Overlay/Caption */
  font-size: 12px;
  line-height: 16px;
  color: var(--text-tertiary);
}

.crop-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 320px;
}

.crop-viewport {
  position: relative;
  width: 320px;
  height: 200px;
  border-radius: var(--radius-md);
  /* Figma crop placeholder hue (#8cb8e0) */
  background: #8cb8e0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.crop-viewport.dragging { cursor: grabbing; }

.crop-image {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: center center;
  pointer-events: none;
  max-width: none;
}

.crop-mask {
  position: absolute;
  inset: 0;
  pointer-events: none;
  /* Circular cutout: 140px diameter, centered in 320×200 — blue-tinted dim */
  background: radial-gradient(
    circle 70px at 50% 50%,
    transparent 69px,
    rgba(40, 90, 140, 0.4) 70px
  );
}
.crop-mask::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 140px;
  height: 140px;
  translate: -50% -50%;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.9);
  box-sizing: border-box;
}

.crop-zoom-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 320px;
  height: 24px;
}

.crop-zoom-btn {
  background: none;
  border: none;
  padding: 0;
  width: 16px;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1;
  color: var(--text-tertiary);
  cursor: pointer;
}
.crop-zoom-btn:hover { color: var(--text-secondary); }

.crop-zoom {
  flex: 1;
  height: 14px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
.crop-zoom::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    var(--accent-subtle) 0%,
    var(--accent-subtle) var(--fill, 0%),
    var(--surface-tertiary) var(--fill, 0%),
    var(--surface-tertiary) 100%
  );
}
.crop-zoom::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.crop-zoom::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: var(--surface-tertiary);
}
.crop-zoom::-moz-range-progress {
  height: 3px;
  border-radius: 2px;
  background: var(--accent-subtle);
}
.crop-zoom::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* ============================================================
   04 Tone
   ============================================================ */
.tone-presets {
  display: flex;
  gap: 6px;
  width: 320px;
}
.chip {
  width: 90px;
  height: 34px;
  border-radius: var(--radius-full);
  background: var(--surface-tertiary);
  border: 1px solid transparent;
  font-family: var(--font);
  /* Typography/Overlay/Caption (unselected) */
  font-size: 12px;
  font-weight: 400;
  line-height: 16px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover { background: var(--border); }
.chip.selected {
  background: var(--accent-subtle);
  border-color: var(--accent);
  color: var(--accent);
  /* Typography/Overlay/Button (selected) */
  font-weight: 500;
  line-height: 20px;
}

.slider-group {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  line-height: 16px;
}
.label-strong { font-weight: 600; color: var(--text-secondary); }
.label-soft { font-weight: 400; color: var(--text-tertiary); }

.tone-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 14px;
  background: transparent;
  cursor: default;
  pointer-events: none;
  --fill: 50%;
}
.tone-slider::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    var(--accent-subtle) 0%,
    var(--accent-subtle) var(--fill),
    var(--surface-tertiary) var(--fill),
    var(--surface-tertiary) 100%
  );
}
.tone-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-top: -5.5px;
}
.tone-slider::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: var(--surface-tertiary);
}
.tone-slider::-moz-range-progress {
  height: 3px;
  border-radius: 2px;
  background: var(--accent-subtle);
}
.tone-slider::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* ============================================================
   05 Confirmation
   ============================================================ */
.modal-confirm {
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.avatar-hero {
  width: 96px;
  height: 96px;
  cursor: default;
}
.avatar-hero .avatar-emoji { font-size: 42px; }
.avatar-hero .avatar-check {
  width: 27px;
  height: 27px;
  right: 0;
  bottom: 0;
}
.avatar-hero.selected { border-width: 2px; }
.avatar-item[hidden] { display: none; }

.closing-text {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  text-align: center;
}
.confirm-line {
  font-size: 14px;
  line-height: 20px;
  color: var(--text-secondary);
}
.confirm-countdown {
  font-size: 12px;
  line-height: 16px;
  color: var(--text-tertiary);
}

/* ============================================================
   06 / 07 / 08 — Chat layer
   ============================================================ */
.chat-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
}
.chat-layer[hidden] { display: none; }

/* 08 — generic silhouette avatar; clicking it resumes personalisation */
.avatar-generic {
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  border-radius: 50%;
  line-height: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.avatar-generic:hover {
  transform: scale(1.05);
  box-shadow: 0 0 0 3px var(--accent-subtle), 0 4px 14px rgba(0, 0, 0, 0.12);
}
.avatar-generic[hidden] { display: none; }
.avatar-hero[hidden] { display: none; }

.upgrade-pill {
  position: absolute;
  left: 50%;
  top: 55px;
  translate: -50% 0;
  height: 28px;
  padding: 0 13px 0 12px;
  background: var(--surface-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-family: var(--font);
  font-size: 12px;
  line-height: 16px;
  color: var(--text-tertiary);
  cursor: pointer;
}
.upgrade-pill:hover { background: var(--surface-tertiary); }

.chat-center {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  width: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 11px;
}

.chat-hero {
  /* Typography/H1 — First Chat */
  font-size: 32px;
  font-weight: 700;
  line-height: 40px;
  letter-spacing: -0.5px;
  text-align: center;
  color: var(--text-primary);
}
.chat-sub {
  /* Typography/Body — First Chat */
  font-size: 15px;
  line-height: 22px;
  color: var(--text-secondary);
  text-align: center;
}

.chip-btn {
  position: absolute;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font);
  /* Typography/Overlay/Label */
  font-size: 12px;
  font-weight: 600;
  line-height: 16px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s ease;
}
.chip-btn:hover { background: var(--surface-tertiary); }
.chip-btn span:last-child { font-weight: 600; }
.chip-glyph { font-weight: 400; }

.quick-actions { left: 105px; top: 193px; }
.add-context { left: 616px; top: 526px; }

.context-bubble {
  position: absolute;
  background: var(--surface-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  font-size: 12px;
  line-height: 16px;
  color: var(--text-primary);
}
.context-bubble[hidden] { display: none; }

.bubble-morning { left: 186px; top: 442px; white-space: nowrap; }
.bubble-date { left: 673px; top: 224px; width: 168px; }

/* ---- Context bubble motion ----
   Bubbles pop in with a stagger when the chat appears, then drift
   gently up and down forever, each on its own rhythm. */
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes bubble-float {
  from { transform: translateY(0); }
  to   { transform: translateY(-5px); }
}

.chat-layer:not([hidden]) .context-bubble {
  animation:
    bubble-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both,
    bubble-float 3.6s ease-in-out 1s infinite alternate;
}
.chat-layer:not([hidden]) .bubble-morning { animation-delay: 0.25s, 1s; }
.chat-layer:not([hidden]) .bubble-date {
  animation-delay: 0.45s, 1.4s;
  animation-duration: 0.45s, 4.4s;
}

@media (prefers-reduced-motion: reduce) {
  .chat-layer:not([hidden]) .context-bubble { animation: none; }
}

/* ============================================================
   Prototype screen switcher (demo aid)
   ============================================================ */
.proto-nav {
  position: fixed;
  bottom: 16px;
  left: 50%;
  translate: -50% 0;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(20, 20, 22, 0.85);
  backdrop-filter: blur(10px);
  padding: 8px 12px;
  border-radius: var(--radius-full);
  z-index: 100;
}
.proto-nav[hidden] { display: none; }
.proto-label {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
  margin-right: 4px;
}
.proto-nav button {
  width: 34px;
  height: 26px;
  border-radius: var(--radius-full);
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.8);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}
.proto-nav button:hover { background: rgba(255, 255, 255, 0.25); }
.proto-nav button.current { background: var(--accent); color: #fff; }
