/* Interactive demo, shared by index.html and demo.html. */
.demo-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 7px 20px rgba(15, 23, 42, 0.07);
  padding: 1.1rem 1.2rem 1.2rem;
}

.demo-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem 1rem;
}

.demo-field label,
.demo-field .demo-label {
  display: block;
  font-family: 'Google Sans', 'Noto Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  color: #4b5563;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.3rem;
}

.demo-field select {
  width: 100%;
  font-family: inherit;
  font-size: 0.86rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  color: #111827;
}

/* Ad intensity knob: slider modeled on the control in the method overview figure */
.knob {
  --thumb: 22px;
  position: relative;
  padding-top: 0.15rem;
}

.knob input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: var(--thumb);
  margin: 0;
  background: transparent;
  cursor: pointer;
}

.knob input[type="range"]:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 3px;
  border-radius: 6px;
}

.knob input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #cfe1f4, #2f6db5 70%, #1d4a8f);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.2);
}

.knob input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #cfe1f4, #2f6db5 70%, #1d4a8f);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.2);
}

.knob input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: var(--thumb);
  height: var(--thumb);
  margin-top: calc((8px - var(--thumb)) / 2);
  border-radius: 50%;
  border: 2px solid #fff;
  background: radial-gradient(circle at 35% 30%, #8fbcec, #2f6db5 55%, #1d4a8f);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.45);
}

.knob input[type="range"]::-moz-range-thumb {
  width: var(--thumb);
  height: var(--thumb);
  border-radius: 50%;
  border: 2px solid #fff;
  background: radial-gradient(circle at 35% 30%, #8fbcec, #2f6db5 55%, #1d4a8f);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.45);
}

.knob-ticks {
  position: relative;
  height: 2.1rem;
  margin-top: 0.2rem;
}

.knob-ticks button {
  position: absolute;
  top: 0;
  left: calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--i) / 3);
  transform: translateX(-50%);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
  font-family: 'Google Sans', 'Noto Sans', sans-serif;
  font-size: 0.78rem;
  color: #6b7280;
}

.knob-ticks button:first-child {
  transform: translateX(-11px);
  text-align: left;
}

.knob-ticks button:last-child {
  transform: translateX(calc(-100% + 11px));
  text-align: right;
}

.knob-ticks button.active {
  color: #1d4a8f;
  font-weight: 700;
}

.knob-ticks small {
  display: block;
  font-size: 0.68rem;
  font-weight: 400;
  color: #9ca3af;
}

.threshold-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.threshold-row input[type="range"] {
  flex: 1 1 auto;
  accent-color: #2563eb;
}

.threshold-value {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 0.8rem;
  color: #111827;
  min-width: 4.6rem;
  text-align: right;
}

.threshold-reset {
  font-size: 0.74rem;
  color: #2563eb;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.84rem;
  color: #374151;
  margin-top: 0.35rem;
}

.chat {
  margin-top: 1.1rem;
  border-top: 1px solid #e5e7eb;
  padding-top: 1rem;
}

.chat-row {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.chat-role {
  flex: 0 0 7.2rem;
  font-family: 'Google Sans', 'Noto Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  color: #6b7280;
  padding-top: 0.45rem;
}

.chat-bubble {
  flex: 1 1 auto;
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  font-size: 0.88rem;
  line-height: 1.6;
  min-width: 0;
}

.chat-bubble.user,
.chat-bubble.advertiser {
  background: #f3f4f6;
}

.chat-bubble.provider {
  background: #fff;
  border: 1px dashed #d1d5db;
  color: #4b5563;
}

.chat-bubble.assistant {
  background: #fff;
  border: 1px solid #e5e7eb;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.control-token {
  display: inline-block;
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 0.76rem;
  padding: 0 0.35rem;
  border-radius: 5px;
  color: #fff;
  vertical-align: 1px;
}

.ad-sent {
  background: #d9f2d9;
  border-radius: 3px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  padding: 0 1px;
}

.ad-tag {
  display: inline-block;
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 0.66rem;
  font-weight: 700;
  color: #fff;
  background: #2f8f4e;
  border-radius: 4px;
  padding: 0 0.28rem;
  margin-right: 0.25rem;
  vertical-align: 1px;
  line-height: 1.5;
}

.chat-bubble.assistant {
  min-height: 7rem;
}

.generating {
  color: #6b7280;
  font-style: italic;
}

.generating .dots span {
  animation: dot-blink 1.2s infinite;
}

.generating .dots span:nth-child(2) { animation-delay: 0.2s; }
.generating .dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-blink {
  0%, 80%, 100% { opacity: 0.15; }
  40% { opacity: 1; }
}

.caret {
  display: inline-block;
  width: 0.5em;
  height: 1.05em;
  margin-left: 1px;
  vertical-align: -0.18em;
  background: #374151;
  animation: caret-blink 1s steps(1) infinite;
}

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

.control-token.pop {
  animation: token-pop 0.5s cubic-bezier(0.2, 1.5, 0.4, 1);
}

@keyframes token-pop {
  from { opacity: 0; transform: scale(0.3); }
  to { opacity: 1; transform: scale(1); }
}

.ad-sent.fresh {
  animation: ad-fade 0.7s ease-out;
}

.ad-sent.fresh .ad-tag {
  animation: tag-pop 0.45s ease-out;
}

@keyframes ad-fade {
  from { background-color: transparent; }
  to { background-color: #d9f2d9; }
}

@keyframes tag-pop {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1); }
}

.demo-skip {
  font-size: 0.76rem;
  color: #2563eb;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin-left: 0.3rem;
}

.demo-skip[hidden] {
  display: none;
}

.demo-meta {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: #6b7280;
  margin-top: 0.3rem;
}

.demo-note {
  font-size: 0.78rem;
  color: #6b7280;
  text-align: center;
  margin-top: 0.8rem;
}

@media screen and (max-width: 768px) {
  .demo-controls {
    grid-template-columns: 1fr;
  }

  .chat-row {
    flex-direction: column;
    gap: 0.2rem;
  }

  .chat-role {
    flex: none;
    padding-top: 0;
  }
}
