:root {
  color-scheme: light;
  --brand-primary: #ef001f;
  --brand-primary-deep: #a60016;
  --brand-primary-soft: #fff0f2;
  --brand-accent: #151929;
  --brand-page: #ffffff;
  --brand-surface: #ffffff;
  --brand-text: #171923;
  --brand-muted: #696d7a;
  --header-height: 76px;
  --content-width: 1480px;
  --grid-color: rgba(23, 25, 35, 0.042);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--brand-page);
}

body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  color: var(--brand-text);
  background: var(--brand-page);
  -webkit-font-smoothing: antialiased;
}

.site-header {
  position: sticky;
  z-index: 20;
  top: 0;
  height: var(--header-height);
  background: color-mix(in srgb, var(--brand-page) 97%, transparent);
  backdrop-filter: blur(16px);
}

.site-header::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--brand-primary);
  content: "";
  transition: background-color 1s ease;
}

.brand-progress {
  position: absolute;
  top: calc(100% + 2px);
  right: 0;
  left: 0;
  display: grid;
  grid-template-columns: auto 46px minmax(120px, 360px);
  gap: 11px;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 6px 20px;
  border-bottom: 1px solid rgba(20, 23, 34, 0.08);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 18px rgba(20, 23, 34, 0.06);
  backdrop-filter: blur(12px);
  color: var(--brand-text);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.brand-progress[hidden] {
  display: none;
}

.brand-progress strong {
  text-align: right;
  color: var(--brand-primary);
  font-size: 12px;
  transition: color 1s ease;
}

.brand-progress-track {
  position: relative;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(20, 23, 34, 0.12);
}

.brand-progress-track span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: inherit;
  background: var(--brand-primary);
  transition: width 650ms ease, background-color 1s ease;
}

.brand-progress.is-failed .brand-progress-track span,
.brand-progress.is-failed strong {
  color: #9a3340;
  background: #9a3340;
}

.header-inner {
  display: flex;
  align-items: center;
  width: min(var(--content-width), calc(100% - 64px));
  height: 100%;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: 50px;
  height: 50px;
  object-fit: contain;
}

.tool-launch {
  display: inline-flex;
  gap: 9px;
  align-items: center;
  min-height: 42px;
  margin-left: auto;
  padding: 0 16px;
  border: 1px solid color-mix(in srgb, var(--brand-primary) 24%, transparent);
  border-radius: 999px;
  color: var(--brand-text);
  background: color-mix(in srgb, var(--brand-page) 92%, var(--brand-primary-soft));
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  transition: transform 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

.tool-launch:hover,
.tool-launch:focus-visible {
  border-color: var(--brand-primary);
  background: var(--brand-primary-soft);
  transform: translateY(-1px);
}

.tool-launch svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.conversation-stage {
  position: relative;
  isolation: isolate;
  min-height: calc(100svh - var(--header-height));
  overflow: hidden;
  background:
    linear-gradient(var(--grid-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-color) 1px, transparent 1px),
    radial-gradient(circle at 33% 40%, color-mix(in srgb, var(--brand-primary-soft) 42%, transparent) 0, transparent 35%),
    linear-gradient(112deg, #fcfcfb 0%, var(--brand-page) 46%, #fafafa 100%);
  background-position: -1px -1px, -1px -1px, 0 0, 0 0;
  background-size: 48px 48px, 48px 48px, auto, auto;
}

.conversation-stage::after {
  position: absolute;
  z-index: -1;
  top: 12%;
  left: 50%;
  width: 70%;
  height: 72%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.73);
  filter: blur(48px);
  content: "";
  transform: translateX(-50%);
}

.stage-inner {
  display: grid;
  grid-template-columns: minmax(430px, 0.9fr) minmax(500px, 1fr);
  gap: clamp(18px, 2vw, 36px);
  align-items: center;
  width: min(1320px, calc(100% - 80px));
  min-height: calc(100svh - var(--header-height));
  margin: 0 auto;
  padding: 36px 0 44px;
}

.robot-area {
  position: relative;
  align-self: stretch;
  min-height: 620px;
}

.robot-halo {
  position: absolute;
  top: 46%;
  left: 50%;
  width: min(530px, 88%);
  aspect-ratio: 1;
  border: 1px solid color-mix(in srgb, var(--brand-primary) 13%, transparent);
  border-radius: 50%;
  opacity: 0.7;
  transform: translate(-50%, -50%);
}

.robot-halo::before,
.robot-halo::after {
  position: absolute;
  border: 1px solid color-mix(in srgb, var(--brand-primary) 10%, transparent);
  border-radius: inherit;
  content: "";
  inset: 9%;
}

.robot-halo::after {
  inset: 22%;
}

.robot-canvas {
  position: absolute;
  z-index: 1;
  inset: 0 -110px 0 0;
}

.robot-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.robot-loading {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.robot-loading span {
  display: block;
  width: 24px;
  height: 24px;
  border: 2px solid color-mix(in srgb, var(--brand-primary) 18%, transparent);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.chat-column {
  position: relative;
  z-index: 3;
  width: 100%;
  visibility: hidden;
  opacity: 0;
  transform: translateY(18px);
  transition:
    opacity 520ms ease,
    transform 620ms cubic-bezier(0.2, 0.75, 0.2, 1),
    visibility 0s linear 620ms;
}

.chat-column.is-visible {
  visibility: visible;
  opacity: 1;
  transform: translateY(-3px);
  transition-delay: 0s;
}

.chat-card {
  position: relative;
  width: 100%;
  min-height: 535px;
  border: 1px solid rgba(20, 23, 34, 0.1);
  border-radius: 25px;
  background: var(--brand-surface);
  box-shadow:
    0 2px 4px rgba(22, 24, 35, 0.08),
    15px 19px 0 rgba(22, 24, 35, 0.105);
  transform: perspective(1300px) translateX(-32px) rotateY(-2.2deg) rotateX(0.8deg);
  transform-origin: left center;
}

.chat-card::after {
  position: absolute;
  z-index: -1;
  right: 6%;
  bottom: -30px;
  left: 8%;
  height: 30px;
  border-radius: 50%;
  background: rgba(20, 23, 34, 0.2);
  content: "";
  filter: blur(3px);
  transform: perspective(300px) rotateX(68deg);
}

.chat-title {
  display: flex;
  gap: 13px;
  align-items: center;
  margin: 0 0 18px -20px;
  color: var(--brand-text);
  font-size: clamp(25px, 2.15vw, 36px);
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1;
}

.chat-title::before {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--brand-primary);
  content: "";
}

.chat-body {
  display: flex;
  flex-direction: column;
  min-height: 435px;
  max-height: 500px;
  padding: 34px 34px 30px;
  overflow-y: auto;
}

.message-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
}

.message-row + .message-row {
  margin-top: 16px;
}

.message-row.is-user {
  justify-content: flex-end;
}

.message-row.is-user .message-bubble {
  width: auto;
  max-width: 82%;
  min-height: 0;
  border-radius: 20px 8px 20px 20px;
  color: white;
  background: var(--brand-primary);
  box-shadow: none;
  transition: background-color 1s ease;
}

.message-avatar {
  display: grid;
  flex: 0 0 30px;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-top: 4px;
  border-radius: 9px;
  color: white;
  background: var(--brand-primary);
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 6px 14px color-mix(in srgb, var(--brand-primary) 18%, transparent);
  transition: background-color 1s ease, box-shadow 1s ease;
}

.message-bubble {
  width: min(470px, calc(100% - 42px));
  min-height: 96px;
  margin: 0;
  padding: 19px 21px;
  border: 1px solid rgba(22, 24, 35, 0.045);
  border-radius: 8px 20px 20px 20px;
  color: var(--brand-text);
  background: #f4f4f6;
  box-shadow: 0 12px 25px rgba(22, 24, 35, 0.045);
  font-size: 18px;
  line-height: 1.62;
}

.typing-caret {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 3px;
  vertical-align: -0.12em;
  background: var(--brand-primary);
  animation: caret 700ms steps(1) infinite;
}

.typing-caret.is-finished {
  animation-iteration-count: 3;
}

.message-bubble.is-waiting {
  width: auto;
  min-height: 0;
  padding: 17px 20px;
}

.waiting-dots {
  display: inline-flex;
  gap: 5px;
}

.waiting-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand-muted);
  animation: waiting-dot 900ms ease-in-out infinite;
}

.waiting-dots span:nth-child(2) { animation-delay: 120ms; }
.waiting-dots span:nth-child(3) { animation-delay: 240ms; }

.chat-composer {
  display: grid;
  grid-template-columns: 1fr 45px;
  gap: 10px;
  align-items: center;
  margin: 0 24px 22px;
  padding: 7px 8px 7px 17px;
  border: 1px solid rgba(22, 24, 35, 0.13);
  border-radius: 16px;
  background: var(--brand-surface);
  box-shadow: inset 0 1px 2px rgba(22, 24, 35, 0.035);
}

.chat-composer:focus-within {
  border-color: color-mix(in srgb, var(--brand-primary) 55%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-primary) 9%, transparent);
}

.chat-composer input {
  min-width: 0;
  height: 42px;
  padding: 0;
  border: 0;
  outline: 0;
  color: var(--brand-text);
  background: transparent;
  caret-color: var(--brand-primary-deep);
  font: inherit;
  font-size: 16px;
}

.chat-composer input::placeholder {
  color: color-mix(in srgb, var(--brand-muted) 72%, transparent);
}

.chat-composer button {
  display: grid;
  place-items: center;
  width: 45px;
  height: 45px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--brand-primary-deep) 62%, #3f0008);
  border-radius: 14px;
  color: white;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.22), transparent 35%),
    linear-gradient(180deg, var(--brand-primary) 0%, var(--brand-primary-deep) 100%);
  box-shadow:
    inset 0 2px 1px rgba(255, 255, 255, 0.38),
    inset 0 -2px 2px rgba(62, 0, 9, 0.34),
    0 5px 11px color-mix(in srgb, var(--brand-primary-deep) 32%, transparent);
  font: inherit;
  font-size: 21px;
  cursor: pointer;
  transition: box-shadow 120ms ease, transform 120ms ease;
}

.chat-composer button svg {
  width: 25px;
  height: 25px;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 1px 0 rgba(65, 0, 8, 0.45));
}

.chat-composer button:hover {
  filter: saturate(1.08) brightness(1.04);
}

.chat-composer button:active {
  box-shadow:
    inset 0 1px 2px rgba(62, 0, 9, 0.36),
    0 2px 6px color-mix(in srgb, var(--brand-primary-deep) 24%, transparent);
  transform: translateY(1px);
}

.chat-composer button:disabled,
.chat-composer input:disabled {
  cursor: wait;
  opacity: 0.62;
}

.brand-inspector {
  position: fixed;
  z-index: 12;
  top: calc(var(--header-height) + 54px);
  right: 18px;
  width: min(340px, calc(100vw - 36px));
  max-height: calc(100svh - var(--header-height) - 76px);
  overflow: hidden;
  border: 1px solid rgba(20, 23, 34, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 42px rgba(20, 23, 34, 0.14);
  backdrop-filter: blur(16px);
}

.brand-inspector-heading {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 17px 18px 14px;
  border-bottom: 1px solid rgba(20, 23, 34, 0.08);
}

.brand-inspector-heading span {
  display: block;
  margin-bottom: 4px;
  color: var(--brand-primary);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.14em;
}

.brand-inspector-heading h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
}

.brand-inspector-heading strong {
  max-width: 128px;
  padding: 6px 8px;
  border-radius: 999px;
  color: var(--brand-muted);
  background: #f0f1f3;
  font-size: 9px;
  line-height: 1.25;
  text-align: center;
}

.brand-inspector-content {
  max-height: calc(100svh - var(--header-height) - 150px);
  padding: 16px 18px 22px;
  overflow-y: auto;
  color: var(--brand-muted);
  font-size: 12px;
  line-height: 1.5;
}

.brand-inspector-content > p:first-child { margin-top: 0; }
.brand-inspector-section + .brand-inspector-section { margin-top: 18px; }
.brand-inspector-section h3 { margin: 0 0 8px; color: var(--brand-text); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.brand-inspector-section p { margin: 5px 0; overflow-wrap: anywhere; }
.brand-inspector-logo { display: block; max-width: 100%; max-height: 90px; margin: 8px auto 10px; object-fit: contain; }
.brand-inspector-source { color: var(--brand-primary-deep); font-size: 10px; text-decoration: none; }
.brand-inspector-palette { display: grid; gap: 7px; }
.brand-inspector-color { display: grid; grid-template-columns: 24px 68px 1fr; gap: 8px; align-items: center; }
.brand-inspector-swatch { width: 24px; height: 24px; border: 1px solid rgba(20, 23, 34, 0.15); border-radius: 7px; }
.brand-inspector-color code { color: var(--brand-text); font-size: 10px; }
.brand-inspector-color small { font-size: 9px; line-height: 1.25; }
.brand-inspector-list { margin: 7px 0; padding-left: 17px; }
.brand-inspector-list li + li { margin-top: 4px; }
.brand-inspector-debug { margin-top: 8px; border: 1px solid rgba(20, 23, 34, 0.1); border-radius: 8px; background: rgba(245, 246, 248, 0.7); }
.brand-inspector-debug summary { padding: 8px 10px; color: var(--brand-text); font-weight: 700; cursor: pointer; }
.brand-inspector-debug ol { margin: 0; padding: 0 10px 10px 28px; }
.brand-inspector-debug li { margin-top: 5px; overflow-wrap: anywhere; font-size: 9px; line-height: 1.35; }

@media (min-width: 1181px) {
  .has-brand-inspector .stage-inner {
    width: min(1120px, calc(100% - 410px));
    margin-left: clamp(24px, 3vw, 58px);
  }
}

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

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

@keyframes waiting-dot {
  0%, 60%, 100% { opacity: 0.32; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

@media (max-width: 980px) {
  .stage-inner {
    grid-template-columns: minmax(340px, 0.88fr) minmax(430px, 1fr);
    gap: 26px;
    width: min(900px, calc(100% - 40px));
  }

  .robot-area {
    min-height: 550px;
  }

  .chat-card {
    min-height: 480px;
  }

  .chat-body {
    min-height: 380px;
    padding: 56px 26px 26px;
  }

  .chat-title { margin-left: 0; }
}

@media (max-width: 760px) {
  :root {
    --header-height: 68px;
  }

  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .header-inner {
    width: calc(100% - 30px);
  }

  .brand-progress {
    grid-template-columns: auto 40px minmax(80px, 1fr);
    gap: 7px;
    padding: 6px 14px;
    font-size: 9px;
  }

  .brand-inspector {
    display: none;
  }

  .brand-logo {
    width: 44px;
    height: 44px;
  }

  .conversation-stage {
    height: calc(100svh - var(--header-height));
    min-height: 0;
    overflow: hidden;
  }

  .stage-inner {
    position: relative;
    display: block;
    width: min(560px, calc(100% - 28px));
    height: 100%;
    min-height: 0;
    padding: 0;
  }

  .robot-area {
    position: absolute;
    inset: 0;
    min-height: 0;
  }

  .robot-canvas {
    inset: 0;
  }

  .chat-card {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    border-radius: 21px;
    transform: none;
  }

  .chat-column {
    position: absolute;
    z-index: 5;
    top: clamp(190px, 31svh, 255px);
    right: 0;
    bottom: 14px;
    left: 0;
    display: flex;
    flex-direction: column;
    transform: translateY(18px);
  }

  .chat-column.is-visible {
    transform: none;
  }

  .chat-card::after {
    bottom: -30px;
  }

  .chat-body {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    padding: 28px 20px 30px;
  }

  .chat-title {
    margin: 0 0 14px 2px;
    font-size: clamp(23px, 8vw, 31px);
  }

  .chat-composer {
    margin: 0 18px 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (max-width: 560px) {
  .header-inner {
    width: calc(100% - 32px);
  }

  .tool-launch {
    min-height: 38px;
    padding: 0 12px;
    font-size: 12px;
  }
}
