:root {
  color-scheme: light;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  --blue: #167d4d;
  --blue-strong: #000000;
  --blue-soft: #f3f9f6;
  --red: #d43b45;
  --red-strong: #b91f2b;
  --red-soft: #ffeaec;
  --ink: #202532;
  --muted: #66738b;
  --muted-light: #8c98ad;
  --line: #dce3ef;
  --line-strong: #cdd7e7;
  --chrome: #eef2f8;
  --paper: #ffffff;
  --row-hover: #f5f8ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
}

body {
  background: #e7edf6;
  color: var(--ink);
  overflow: hidden;
}

button,
summary {
  font: inherit;
}

button {
  color: inherit;
}

.motion-canvas {
  position: relative;
  display: grid;
  grid-template-rows: 96px minmax(0, 1fr) 56px;
  width: 100%;
  aspect-ratio: 1360 / 830;
  min-height: 830px;
  overflow: hidden;
  background: var(--paper);
  border: 1px solid #d5deeb;
  box-shadow: 0 18px 60px rgba(46, 63, 91, 0.13);
}

.report-toolbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  padding: 16px 28px;
  background: var(--chrome);
  border-bottom: 1px solid var(--line-strong);
}

.report-title {
  max-width: 820px;
  margin: 0;
  color: var(--ink);
  font-size: clamp(26px, 2.35vw, 32px);
  font-weight: 780;
  letter-spacing: -0.025em;
  line-height: 1.08;
}

.report-actions {
  display: flex;
  margin-left: auto;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
}

.optimize-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-width: 287px;
  height: 65px;
  padding: 0 33px;
  border: 0;
  border-radius: 12px;
  background: #006d40;
  box-shadow: 0 6px 14px rgba(0, 109, 64, 0.2);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.optimize-button:hover:not(:disabled) {
  background: #089657;
  box-shadow: 0 6px 14px rgba(0, 109, 64, 0.2);
  transform: translateY(-1px);
}

.optimize-button:active:not(:disabled) {
  transform: translateY(0);
}

.optimize-button:focus-visible {
  outline: 3px solid rgba(0, 109, 64, 0.28);
  outline-offset: 2px;
}

.group-token:focus-visible,
.group-row summary:focus-visible,
.query-context__close:focus-visible {
  outline: 3px solid rgba(22, 125, 77, 0.28);
  outline-offset: 2px;
}

.optimize-button:disabled {
  background: #006d40;
  box-shadow: 0 6px 14px rgba(0, 109, 64, 0.2);
  cursor: wait;
}

.optimize-button__icon {
  font-size: 24px;
  transition: transform 300ms ease;
}

body[data-state="tokenizing"] .optimize-button__icon,
body[data-state="grouping"] .optimize-button__icon {
  animation: icon-pulse 960ms ease-in-out infinite alternate;
}

.report-table {
  display: grid;
  min-height: 0;
  grid-template-rows: 64px minmax(0, 1fr);
}

.table-head {
  display: flex;
  min-height: 0;
  color: #5f6d86;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
  font-size: 14px;
  font-weight: 620;
}

.table-head span {
  display: flex;
  align-items: center;
  padding: 0 28px;
}

.stage-viewport {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #fff;
}

.magnetic-layer {
  position: absolute;
  z-index: 8;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.magnetic-token {
  position: absolute;
  top: var(--magnet-from-y);
  left: var(--magnet-from-x);
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: var(--magnet-to-width);
  height: var(--magnet-to-height);
  overflow: hidden;
  border: 1px solid #c4dfd1;
  border-radius: 8px;
  background: var(--blue-soft);
  box-shadow: 0 7px 18px rgba(22, 125, 77, 0.12);
  color: var(--blue-strong);
  font-size: 14px;
  font-weight: 620;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
  transform: translate3d(0, 0, 0);
  transform-origin: center;
  contain: layout paint;
  will-change: opacity, transform;
}

.magnetic-token--word {
  animation: word-magnet 1900ms cubic-bezier(0.45, 0, 0.25, 1) both;
  animation-delay: var(--magnet-delay);
}

.magnetic-token--group {
  animation: group-magnet 1600ms cubic-bezier(0.45, 0, 0.25, 1) both;
  animation-delay: var(--magnet-delay);
}

.stage {
  position: absolute;
  inset: 0;
  min-height: 0;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 936ms ease, transform 1224ms cubic-bezier(0.22, 1, 0.36, 1), visibility 0s linear 1224ms;
}

body[data-state="queries"] .query-stage,
body[data-state="tokenizing"] .query-stage,
body[data-state="morphing"] .query-stage,
body[data-state="morphing"] .token-stage,
body[data-state="tokens"] .token-stage,
body[data-state="grouping"] .token-stage,
body[data-state="grouping"] .group-stage,
body[data-state="groups"] .group-stage {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
  transition-delay: 0s;
}

.query-stage,
.group-stage {
  overflow-y: auto;
  scrollbar-color: #cbd5e5 transparent;
  scrollbar-width: thin;
}

.query-stage {
  z-index: 3;
}

body[data-state="morphing"] .query-stage {
  pointer-events: none;
}

body[data-state="morphing"] .query-stage,
body[data-state="grouping"] .token-stage {
  z-index: 2;
  pointer-events: none;
}

body[data-state="morphing"] .query-stage {
  animation: magnetic-query-out 2150ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

body[data-state="morphing"] .token-stage {
  z-index: 3;
  pointer-events: none;
  background: transparent;
}

body[data-state="morphing"] .stage-summary {
  animation: token-summary-in 1250ms cubic-bezier(0.22, 1, 0.36, 1) 650ms both;
}

body[data-state="grouping"] .token-stage {
  animation: magnetic-token-field-out 2650ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

body[data-state="grouping"] .group-stage {
  z-index: 3;
  pointer-events: none;
  background: transparent;
}

body[data-state="grouping"] .group-row {
  animation: magnetic-group-row-in 2200ms cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: calc(var(--group-index) * 20ms);
}

.query-row {
  display: flex;
  min-height: 58px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  content-visibility: auto;
  contain-intrinsic-block-size: 58px;
  transition: background 160ms ease, opacity 312ms ease, transform 600ms ease;
}

.query-row:hover {
  background: var(--row-hover);
}

.query-row > span {
  display: flex;
  align-items: center;
  padding: 0 28px;
  width: 100%;
}

.query-row__value {
  gap: 16px;
  color: #232936;
  font-size: 18.4px;
}

.query-row__text {
  min-width: 0;
  line-height: 1.55;
}

.query-word {
  position: relative;
  display: inline-block;
  border-radius: 4px;
  transform-origin: center;
}

.query-word-slot {
  --word-gap: 0em;
  box-sizing: content-box;
  display: inline-block;
  max-width: var(--slot-width);
  padding-right: var(--word-gap);
  overflow: hidden;
  vertical-align: bottom;
  white-space: nowrap;
}

.query-word-slot.has-separator {
  --word-gap: 0.28em;
}

.query-word-separator {
  font-size: 0;
}

.report-checkbox {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border: 2px solid #d4ddea;
  border-radius: 7px;
  background: #fff;
}

body[data-state="tokenizing"] .report-checkbox,
body[data-state="morphing"] .report-checkbox {
  opacity: 0.25;
  transition: opacity 960ms ease;
}

body[data-state="tokenizing"] .query-word.is-token-source {
  animation: word-keep 900ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: calc(3700ms + var(--row-index) * 45ms);
}

body[data-state="morphing"] .query-word.is-token-source {
  color: var(--blue-strong);
  background: var(--blue-soft);
  box-shadow: 0 0 0 3px var(--blue-soft);
  transform: translateY(-1px);
}

body[data-state="tokenizing"] .query-word-slot.is-duplicate-primary {
  animation: duplicate-slot-remove 1650ms cubic-bezier(0.4, 0, 0.2, 1) both;
  animation-delay: calc(var(--row-index) * 35ms);
}

body[data-state="tokenizing"] .query-word-slot.is-duplicate-secondary {
  animation: duplicate-slot-remove 1700ms cubic-bezier(0.4, 0, 0.2, 1) both;
  animation-delay: calc(1550ms + var(--row-index) * 35ms + var(--duplicate-wave) * 150ms);
}

body[data-state="tokenizing"] .query-word-slot.is-duplicate-primary .query-word {
  animation: duplicate-word-alert 1650ms cubic-bezier(0.4, 0, 0.2, 1) both;
  animation-delay: calc(var(--row-index) * 35ms);
}

body[data-state="tokenizing"] .query-word-slot.is-duplicate-secondary .query-word {
  animation: duplicate-word-alert 1700ms cubic-bezier(0.4, 0, 0.2, 1) both;
  animation-delay: calc(1550ms + var(--row-index) * 35ms + var(--duplicate-wave) * 150ms);
}

body[data-state="morphing"] .query-word-slot.is-removable {
  max-width: 0;
  padding-right: 0;
  opacity: 0;
  transform: scaleX(0);
}

.token-stage {
  z-index: 2;
  overflow-y: auto;
  background: #fff;
  scrollbar-color: #cbd5e5 transparent;
  scrollbar-width: thin;
}

.token-stage__content {
  min-width: 0;
  padding: 20px 28px 24px;
}

.stage-summary {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 58px;
  margin-bottom: 12px;
  padding: 8px 14px;
  border: 1px solid #cfdaef;
  border-radius: 12px;
  background: #f4f7ff;
}

.stage-summary__icon {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 10px;
  background: var(--blue);
  color: #fff;
  font-size: 14px;
  font-weight: 750;
}

.stage-summary div {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.stage-summary strong {
  font-size: 15px;
  font-weight: 650;
}

.stage-summary div span {
  color: var(--muted);
  font-size: 13px;
}

.token-grid {
  display: flex;
  align-content: flex-start;
  flex-wrap: wrap;
  gap: 6px;
}

body[data-state="morphing"] .token-cell {
  opacity: 0;
}

body[data-state="morphing"] .token-cell.is-rising-token {
  z-index: 1;
  animation: individual-token-rise var(--token-rise-duration) cubic-bezier(0.32, 0.02, 0.2, 1) var(--token-rise-delay) both;
}

body[data-state="morphing"] .token-cell.is-magnetic-target {
  z-index: 2;
  animation: magnetic-target-settle 520ms ease-out 1540ms both;
}

.token-cell {
  position: relative;
  display: flex;
  min-width: 0;
  width: auto;
  height: 34px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0 11px;
  border: 1px solid #c4dfd1;
  border-radius: 8px;
  background: var(--blue-soft);
  box-shadow: 0 2px 6px rgba(22, 125, 77, 0.05);
  color: var(--blue-strong);
  font-size: 14.95px;
  font-weight: 560;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body[data-state="grouping"] .token-stage {
  pointer-events: none;
}

body[data-state="groups"] .token-stage {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: none;
}

body[data-state="groups"] .token-cell {
  opacity: 0;
  visibility: hidden;
  animation: none;
}

.group-stage {
  z-index: 1;
  background: #fff;
}

body[data-state="grouping"] .group-stage {
  pointer-events: none;
}

.group-list {
  min-height: 100%;
}

.group-row {
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.group-row[open] {
  background: #f9fbff;
  box-shadow: inset 3px 0 0 var(--blue);
}

.group-row__summary {
  position: relative;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 118px 32px;
  align-items: center;
  min-height: 48px;
  padding: 0 24px;
  cursor: pointer;
  list-style: none;
  transition: background 160ms ease;
}

.group-row__summary::-webkit-details-marker {
  display: none;
}

.group-row__summary:hover {
  background: var(--row-hover);
}

.group-row__marker {
  color: #9aa6ba;
  font-size: 13.8px;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.group-row__title {
  font-size: 17.25px;
  font-weight: 620;
}

.group-row__count {
  color: var(--muted);
  font-size: 14.95px;
}

.group-row__toggle {
  position: relative;
  width: 26px;
  height: 26px;
  justify-self: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4f6fa;
}

.group-row__toggle::before,
.group-row__toggle::after {
  position: absolute;
  top: 12px;
  left: 7px;
  width: 10px;
  height: 2px;
  border-radius: 2px;
  background: #65728a;
  content: "";
}

.group-row__toggle::after {
  transform: rotate(90deg);
  transition: transform 180ms ease;
}

.group-row[open] .group-row__toggle {
  border-color: #b8c7f2;
  background: var(--blue-soft);
}

.group-row[open] .group-row__toggle::after {
  transform: rotate(0deg);
}

.group-row__content {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 78px 16px;
}

.group-token {
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid #cbd6eb;
  border-radius: 8px;
  background: #fff;
  color: #35415a;
  font-size: 14.95px;
  font-weight: 560;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease, transform 150ms ease;
}

.group-token:hover {
  border-color: #8fa8ef;
  background: var(--blue-soft);
  color: var(--blue-strong);
  transform: translateY(-1px);
}

.report-footer {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 24px;
  padding: 0 28px;
  border-top: 1px solid var(--line-strong);
  background: var(--chrome);
}

.process-status {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9aa6ba;
  box-shadow: 0 0 0 4px rgba(154, 166, 186, 0.14);
}

body[data-state="tokenizing"] .status-dot,
body[data-state="tokens"] .status-dot,
body[data-state="grouping"] .status-dot {
  background: var(--blue);
  box-shadow: 0 0 0 4px rgba(22, 125, 77, 0.12);
  animation: status-pulse 1080ms ease-in-out infinite alternate;
}

body[data-state="groups"] .status-dot {
  background: #3b8b72;
  box-shadow: 0 0 0 4px rgba(59, 139, 114, 0.12);
}

.query-context[hidden] {
  display: none;
}

.query-context {
  position: absolute;
  z-index: 20;
  inset: 0;
}

.query-context__backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  background: rgba(36, 44, 61, 0.24);
  backdrop-filter: blur(2px);
  cursor: default;
  animation: backdrop-in 180ms ease both;
}

.query-context__drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  width: min(650px, 52vw);
  overflow: hidden;
  border-left: 1px solid var(--line-strong);
  background: #fff;
  box-shadow: -20px 0 50px rgba(43, 56, 80, 0.16);
  animation: drawer-in 280ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.query-context__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 28px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--chrome);
}

.query-context__header span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.query-context__header h2 {
  margin: 6px 0 0;
  color: var(--blue-strong);
  font-size: 27.6px;
  line-height: 1.1;
}

.query-context__close {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  color: #56637a;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.query-context__summary {
  margin: 0;
  padding: 18px 28px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.query-context__list {
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.query-context__item {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  min-height: 64px;
  padding: 10px 28px;
  border-bottom: 1px solid var(--line);
}

.query-context__item span {
  color: #98a4b7;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.query-context__item strong {
  font-size: 16.1px;
  font-weight: 560;
}

.query-context__hint {
  margin: 0;
  padding: 16px 28px;
  color: var(--muted-light);
  border-top: 1px solid var(--line);
  background: #fbfcfe;
  font-size: 12px;
}

.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;
}

@keyframes word-keep {
  0%, 28% {
    color: inherit;
    background: transparent;
    box-shadow: 0 0 0 0 transparent;
    transform: translateY(0) scale(1);
  }
  62% {
    color: var(--blue-strong);
    background: var(--blue-soft);
    box-shadow: 0 0 0 3px var(--blue-soft);
    transform: translateY(-2px) scale(1.02);
  }
  100% {
    color: var(--blue-strong);
    background: var(--blue-soft);
    box-shadow: 0 0 0 3px var(--blue-soft);
    transform: translateY(-1px) scale(1);
  }
}

@keyframes duplicate-word-alert {
  0%, 10% {
    opacity: 1;
    color: inherit;
    background: transparent;
    box-shadow: 0 0 0 0 transparent;
    transform: scale(1);
  }
  26%, 56%, 72% {
    opacity: 1;
    color: var(--red-strong);
    background: var(--red-soft);
    box-shadow: 0 0 0 2px var(--red-soft);
    transform: translateY(-0.5px) scale(1.012);
  }
  41%, 64% {
    opacity: 0.74;
    color: var(--red);
    background: rgba(255, 234, 236, 0.62);
    box-shadow: 0 0 0 1px rgba(255, 234, 236, 0.72);
    transform: translateY(0) scale(1);
  }
  82% {
    opacity: 0.9;
    color: var(--red-strong);
    background: rgba(255, 234, 236, 0.82);
    box-shadow: 0 0 0 2px rgba(255, 234, 236, 0.82);
    transform: translateY(-0.5px) scale(1.006);
  }
  100% {
    opacity: 0;
    color: var(--red-strong);
    background: var(--red-soft);
    box-shadow: 0 0 0 1px var(--red-soft);
    transform: translateY(-2px) scale(0.94);
  }
}

@keyframes duplicate-slot-remove {
  0%, 72% {
    max-width: var(--slot-width);
    padding-right: var(--word-gap);
    opacity: 1;
    transform: translateX(0) scaleX(1);
  }
  84% {
    max-width: var(--slot-width);
    padding-right: var(--word-gap);
    opacity: 0.88;
    transform: translateX(0) scaleX(0.97);
  }
  100% {
    max-width: 0;
    padding-right: 0;
    opacity: 0;
    transform: translateX(-5px) scaleX(0);
  }
}

@keyframes word-magnet {
  0% {
    opacity: 0;
    border-color: transparent;
    border-radius: 4px;
    background: var(--blue-soft);
    box-shadow: 0 0 0 3px var(--blue-soft);
    transform: translate3d(0, 0, 0) scale(0.96);
  }
  12%, 84% {
    opacity: 1;
    border-color: #c4dfd1;
    border-radius: 8px;
    background: var(--blue-soft);
    box-shadow: 0 7px 18px rgba(22, 125, 77, 0.12);
  }
  100% {
    opacity: 0;
    border-color: #c4dfd1;
    border-radius: 8px;
    background: var(--blue-soft);
    box-shadow: 0 2px 6px rgba(22, 125, 77, 0.05);
    transform: translate3d(var(--magnet-to-x), var(--magnet-to-y), 0) scale(1);
  }
}

@keyframes group-magnet {
  0% {
    opacity: 0;
    transform: translate3d(0, 0, 0) scale(0.98);
  }
  10%, 86% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--magnet-to-x), var(--magnet-to-y), 0) scale(0.78);
  }
}

@keyframes magnetic-query-out {
  0%, 24% { opacity: 1; transform: translateY(0) scale(1); }
  72% { opacity: 0.22; transform: translateY(-2px) scale(0.997); }
  100% { opacity: 0; transform: translateY(-4px) scale(0.992); }
}

@keyframes individual-token-rise {
  0% {
    opacity: 0;
    transform: translate3d(var(--token-rise-x), var(--token-rise-y), 0) scale(0.96);
  }
  12% { opacity: 0.72; }
  26% { opacity: 1; }
  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

@keyframes magnetic-target-settle {
  0%, 22% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes token-summary-in {
  0%, 18% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes magnetic-token-field-out {
  0%, 18% { opacity: 1; transform: translateY(0) scale(1); }
  68% { opacity: 0.3; transform: translateY(-2px) scale(0.997); }
  100% { opacity: 0; transform: translateY(-5px) scale(0.992); }
}

@keyframes magnetic-group-row-in {
  0% {
    opacity: 0.08;
    border-color: transparent;
    background: rgba(244, 247, 255, 0.2);
    transform: translateY(5px);
  }
  55% {
    opacity: 0.52;
    border-color: rgba(225, 230, 239, 0.55);
    background: rgba(248, 250, 255, 0.72);
    transform: translateY(1px);
  }
  100% {
    opacity: 1;
    border-color: var(--line);
    background: #fff;
    transform: translateY(0);
  }
}

@keyframes status-pulse {
  from { opacity: 0.55; }
  to { opacity: 1; }
}

@keyframes icon-pulse {
  from { opacity: 0.65; transform: scale(0.9) rotate(-8deg); }
  to { opacity: 1; transform: scale(1.08) rotate(8deg); }
}

@keyframes drawer-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 1100px) and (min-width: 701px) {
  body {
    overflow: auto;
  }

  .motion-canvas {
    min-width: 0;
    min-height: 720px;
    aspect-ratio: 4 / 3;
  }

  .report-title {
    max-width: 560px;
    font-size: 24px;
  }

  .optimize-button {
    min-width: 245px;
    height: 58px;
    padding: 0 24px;
    font-size: 18px;
  }

  .token-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  html,
  body {
    width: 100%;
    height: 100%;
    min-width: 0;
  }

  body {
    overflow: hidden;
  }

  .motion-canvas {
    grid-template-rows: 124px minmax(0, 1fr) 52px;
    width: 100%;
    height: 100%;
    min-height: 0;
    aspect-ratio: auto;
    border: 0;
    box-shadow: none;
  }

  .report-toolbar {
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px;
  }

  .report-title {
    max-width: none;
    font-size: 18px;
    line-height: 1.12;
  }

  .report-actions {
    width: 100%;
  }

  .optimize-button {
    width: min(100%, 340px);
    min-width: 0;
    height: 44px;
    gap: 10px;
    padding: 0 18px;
    border-radius: 7px;
    font-size: 14px;
  }

  .optimize-button__icon {
    font-size: 18px;
  }

  .report-table {
    grid-template-rows: 64px minmax(0, 1fr);
  }

  .table-head {
    font-size: 12px;
  }

  .table-head span {
    padding: 0 14px;
    line-height: 1.3;
  }

  .query-row {
    min-height: 48px;
  }

  .query-row > span {
    padding: 0 14px;
  }

  .query-row__value {
    gap: 10px;
    font-size: 14.95px;
  }

  .report-checkbox {
    width: 18px;
    height: 18px;
    flex-basis: 18px;
    border-radius: 6px;
  }

  .token-stage {
    overflow-y: auto;
    scrollbar-width: thin;
  }

  .token-stage__content {
    padding: 10px 12px 14px;
  }

  .stage-summary {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 8px;
    min-height: 0;
    margin-bottom: 8px;
    padding: 8px 10px;
    border-radius: 9px;
  }

  .stage-summary__icon {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    font-size: 10px;
  }

  .stage-summary strong {
    font-size: 12px;
    line-height: 1.25;
  }

  .stage-summary div span {
    font-size: 10px;
    line-height: 1.3;
  }

  .token-grid {
    gap: 4px;
  }

  .token-cell {
    height: 30px;
    padding: 0 8px;
    border-radius: 6px;
    font-size: 12.08px;
  }

  .magnetic-token {
    border-radius: 6px;
    font-size: 11.5px;
  }

  .group-row__summary {
    grid-template-columns: 32px minmax(0, 1fr) 68px 28px;
    min-height: 44px;
    padding: 0 12px;
  }

  .group-row__marker {
    font-size: 11.5px;
  }

  .group-row__title {
    font-size: 13.8px;
  }

  .group-row__count {
    font-size: 11.5px;
  }

  .group-row__toggle {
    width: 24px;
    height: 24px;
  }

  .group-row__toggle::before,
  .group-row__toggle::after {
    top: 11px;
    left: 6px;
  }

  .group-row__content {
    gap: 5px;
    padding: 2px 44px 12px;
  }

  .group-token {
    min-height: 30px;
    padding: 0 10px;
    font-size: 12.65px;
  }

  .report-footer {
    display: flex;
    padding: 10px 12px;
  }

  .process-status {
    gap: 7px;
    min-width: 0;
    overflow: hidden;
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .status-dot {
    width: 6px;
    height: 6px;
    flex: 0 0 6px;
  }

  .query-context__drawer {
    width: 100%;
    border-left: 0;
  }

  .query-context__header {
    padding: 16px 14px 12px;
  }

  .query-context__header span {
    font-size: 10px;
  }

  .query-context__header h2 {
    font-size: 23px;
  }

  .query-context__summary,
  .query-context__hint {
    padding: 12px 14px;
    font-size: 11px;
  }

  .query-context__item {
    grid-template-columns: 30px minmax(0, 1fr);
    min-height: 54px;
    padding: 8px 14px;
  }

  .query-context__item strong {
    font-size: 13.8px;
  }
}

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

  .query-word,
  .query-word-slot {
    animation-delay: 0ms !important;
  }
}

/* Option 2: the editable heading grows above a stable, scrollable report. */
html, body { min-width: 0; min-height: 0; height: auto; }
body { background: #fff; }
.motion-canvas {
  grid-template-columns: minmax(0, 1fr);
  /* 64px table heading + 12 x 49px collapsed groups + 32px breathing room. */
  grid-template-rows: auto 684px 56px;
  min-height: 0; height: auto; aspect-ratio: auto;
  box-shadow: none; border: 0;
}
.report-toolbar.motion-heading {
  display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.35fr);
  align-items: start; gap: 36px; padding: 30px;
  min-width: 0; background: #fff; border-bottom: 1px solid #dce3e7;
}
.motion-heading .intro-context, .motion-heading .intro-guide { min-width: 0; }
.motion-heading .eyebrow {
  display: block; margin: 0 0 12px; font-size: 11px; line-height: 1.4;
  letter-spacing: .08em; text-transform: uppercase; color: #167d4d; font-weight: 700;
}
.motion-heading .report-title {
  max-width: 420px; margin: 0; font-size: 24px; line-height: 1.25;
  font-weight: 650; letter-spacing: -.025em; color: #202532;
}
.motion-heading p {
  margin: 10px 0 0; font-size: 16px; line-height: 1.5; font-weight: 400; color: #596575;
}
.motion-heading [data-heading-eyebrow], .motion-heading [data-heading-title],
.motion-heading [data-heading-description], .motion-heading [data-heading-instruction] {
  white-space: pre-wrap; overflow-wrap: anywhere; text-wrap: pretty;
}
.motion-heading [hidden] { display: none; }
.motion-heading .intro-guide { padding-left: 30px; border-left: 1px solid #dce3e7; }
.motion-heading .intro-guide > p:first-child { margin-top: 0; }
.motion-heading .report-actions { margin: 16px 0 0; min-width: 0; justify-content: flex-end; }
.motion-heading .optimize-button {
  width: auto; max-width: 100%; min-width: 0; height: auto; min-height: 46px;
  padding: 12px 20px; border-radius: 9px; font-size: 16px; line-height: 1.35;
  font-weight: 650; white-space: normal; box-shadow: none; gap: 9px;
}
.motion-heading .optimize-button__icon { font-size: 18px; flex-shrink: 0; }
.motion-heading [data-action-label] { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 700px) {
  .motion-canvas { grid-template-rows: auto 700px 52px; }
  .report-toolbar.motion-heading { grid-template-columns: minmax(0, 1fr); padding: 20px; gap: 18px; }
  .motion-heading .report-title { font-size: 21px; max-width: none; }
  .motion-heading .intro-guide { padding: 16px 0 0; border-left: 0; border-top: 1px solid #dce3e7; }
  .motion-heading .optimize-button { width: 100%; font-size: 16px; min-height: 46px; }
  .motion-heading .report-actions { width: 100%; }
}


/* The query window belongs to the page viewport, rather than the tall iframe. */
.directpro-query-modal {
  width: min(560px, calc(100% - 32px));
  max-width: none;
  max-height: min(640px, calc(100dvh - 32px));
  margin: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: #202532;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  overflow: visible;
}
.directpro-query-modal::backdrop {
  background: rgba(36, 44, 61, .32);
  backdrop-filter: blur(2px);
}
html.directpro-query-open { overflow: hidden; }
.directpro-query-modal .query-context {
  position: relative; inset: auto; max-height: inherit;
}
.directpro-query-modal .query-context[hidden],
.directpro-query-modal .query-context__backdrop { display: none; }
.directpro-query-modal .query-context__drawer {
  position: relative; inset: auto;
  display: flex; flex-direction: column;
  width: 100%; max-height: inherit; box-sizing: border-box;
  overflow: hidden; border: 1px solid #dce3e7; border-radius: 16px;
  background: #fff; box-shadow: 0 20px 60px rgba(43, 56, 80, .2);
  animation: none;
}
.directpro-query-modal .query-context__header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; flex-shrink: 0; padding: 18px 20px 14px;
  border-bottom: 1px solid #e5e9ef; background: #f3f5f9;
}
.directpro-query-modal .query-context__header > div { min-width: 0; }
.directpro-query-modal .query-context__header span {
  color: #647083; font-size: 10px; font-weight: 650;
  letter-spacing: .04em; text-transform: uppercase;
}
.directpro-query-modal .query-context__header h2 {
  margin: 6px 0 0; color: #202532; font-size: 24px; line-height: 1.2;
  overflow-wrap: anywhere;
}
.directpro-query-modal .query-context__close {
  display: grid; place-items: center; flex: 0 0 44px;
  width: 44px; height: 44px; padding: 0;
  border: 1px solid #d8dee7; border-radius: 10px;
  background: #fff; color: #56637a; font-size: 26px; line-height: 1;
  cursor: pointer;
}
.directpro-query-modal .query-context__summary,
.directpro-query-modal .query-context__hint {
  flex-shrink: 0; margin: 0; padding: 12px 20px;
  color: #647083; font-size: 12px;
}
.directpro-query-modal .query-context__summary { border-bottom: 1px solid #e5e9ef; }
.directpro-query-modal .query-context__hint {
  border-top: 1px solid #e5e9ef; background: #fbfcfe; color: #8791a0;
}
.directpro-query-modal .query-context__list {
  flex: 0 1 auto; min-height: 0; margin: 0; padding: 0;
  overflow-y: auto; overscroll-behavior: contain; list-style: none;
}
.directpro-query-modal .query-context__item {
  display: grid; grid-template-columns: 28px minmax(0, 1fr);
  align-items: center; gap: 4px; min-height: 52px;
  box-sizing: border-box; padding: 12px 20px;
  border-bottom: 1px solid #e5e9ef;
}
.directpro-query-modal .query-context__item:last-child { border-bottom: 0; }
.directpro-query-modal .query-context__item span {
  color: #98a4b7; font-size: 11px; font-variant-numeric: tabular-nums;
}
.directpro-query-modal .query-context__item strong {
  color: #000000;
  font-size: 14px; font-weight: 560; line-height: 1.45; overflow-wrap: anywhere;
}
@media (max-width: 360px) {
  .directpro-query-modal .query-context__header { padding: 14px; }
  .directpro-query-modal .query-context__summary,
  .directpro-query-modal .query-context__hint,
  .directpro-query-modal .query-context__item { padding: 10px 14px; }
}

/* A single green impulse brings attention back to the updated step heading. */
.report-toolbar.motion-heading.is-heading-updated {
  animation: motion-heading-green-pulse 1000ms ease-out both;
}
.motion-heading.is-heading-updated [data-heading-eyebrow],
.motion-heading.is-heading-updated [data-heading-title],
.motion-heading.is-heading-updated [data-heading-description],
.motion-heading.is-heading-updated [data-heading-instruction] {
  animation: motion-heading-text-in 230ms ease-out both;
}
@keyframes motion-heading-green-pulse {
  0%, 100% { background-color: #fff; }
  16%, 40% { background-color: #dbeee6; }
}
@keyframes motion-heading-text-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .report-toolbar.motion-heading.is-heading-updated,
  .motion-heading.is-heading-updated [data-heading-eyebrow],
  .motion-heading.is-heading-updated [data-heading-title],
  .motion-heading.is-heading-updated [data-heading-description],
  .motion-heading.is-heading-updated [data-heading-instruction] {
    animation: none;
  }
}
