* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-family);
  background:
    radial-gradient(1200px 600px at 20% -10%, #ffffff55, transparent),
    linear-gradient(135deg, #c9d6ff, #e2e2e2);
  color: #1c1e21;
}

.stage {
  min-height: 100%;
  display: flex;
  gap: 32px;
  align-items: center;
  justify-content: center;
  padding: 40px;
  flex-wrap: wrap;
}

/* ---------- Device / chat window ----------
   Sized to the latest iPhone 16 Pro logical resolution:
   402 x 874 pt (aspect ratio ~1:2.174). The outer titanium
   frame adds the physical bezel around that screen.
   -------------------------------------------------------- */
.device {
  --screen-w: 402px;
  --screen-h: 874px;
  width: var(--screen-w);
  height: var(--screen-h);
  max-height: 92vh;
  aspect-ratio: 402 / 874;
  background: var(--color-bg);
  border-radius: 55px;               /* iPhone 16 Pro corner radius */
  box-shadow: var(--shadow-device);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 14px solid #1a1a1c;        /* titanium bezel */
}

/* Demo states toggled by the header minimize / close buttons */
.device.is-minimized .chat-log,
.device.is-minimized .composer {
  display: none;
}
.device.is-minimized {
  height: auto;
}
.device.is-closed {
  opacity: 0;
  transform: scale(0.96);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: var(--color-header);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  font-size: 22px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--color-accent) 18%, white);
}

.chat-header__meta { display: flex; flex-direction: column; }
.chat-header__name { font-weight: 600; font-size: var(--font-size-name); }
.chat-header__status {
  font-size: 12px;
  color: var(--color-status);
  display: flex;
  align-items: center;
  gap: 5px;
}
.chat-header__status::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--color-status);
}

/* ---------- Status bar (iOS style) ---------- */
.statusbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 22px 6px;
  background: var(--color-header);
  font-size: 15px;
  font-weight: 600;
  color: var(--fg-primary, #1c1e21);
}
.statusbar__time {
  min-width: 54px;
  letter-spacing: 0.2px;
}
/* Dynamic Island */
.statusbar__island {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  width: 118px;
  height: 34px;
  background: #000;
  border-radius: 20px;
}
.statusbar__icons {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--fg-primary, #1c1e21);
}
/* Signal bars */
.sb-signal {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
}
.sb-signal i {
  width: 3px;
  background: currentColor;
  border-radius: 1px;
}
.sb-signal i:nth-child(1) { height: 5px; }
.sb-signal i:nth-child(2) { height: 7px; }
.sb-signal i:nth-child(3) { height: 9px; }
.sb-signal i:nth-child(4) { height: 12px; }
/* Wi-Fi */
.sb-wifi { display: inline-flex; align-items: center; }
.sb-wifi svg { fill: currentColor; }
/* Battery */
.sb-battery {
  position: relative;
  width: 25px;
  height: 12px;
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 1.5px;
  opacity: 0.95;
}
.sb-battery::after {
  content: "";
  position: absolute;
  right: -3px;
  top: 50%;
  transform: translateY(-50%);
  width: 2px;
  height: 4px;
  background: currentColor;
  border-radius: 0 1px 1px 0;
}
.sb-battery i {
  display: block;
  width: 100%;
  height: 100%;
  background: currentColor;
  border-radius: 1px;
}

/* ---------- Header / top navigation ---------- */
.chat-header {
  justify-content: space-between;
  padding: 14px 20px 16px;
  border-bottom: 1px solid var(--header-border, rgba(0, 0, 0, 0.08));
}
.chat-header__title {
  font-size: var(--font-size-name, 16px);
  font-weight: 500;
  color: var(--fg-primary, #1c1e21);
}
.chat-header__actions {
  display: flex;
  align-items: center;
  gap: 14px;
}
.chat-header__btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  color: var(--fg-tertiary, #6b7280);
  border-radius: 6px;
  transition: color 0.15s ease, background 0.15s ease;
}
.chat-header__btn:hover {
  color: var(--fg-primary, #1c1e21);
  background: var(--state-primary-subtle, rgba(0, 0, 0, 0.05));
}
.chat-header__btn svg {
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  fill: none;
}

/* ---------- Intro headline (scrolls with the messages) ---------- */
.chat-intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding: 8px 24px 18px;
}
.chat-intro__text {
  margin: 0;
  max-width: 30ch;
  font-size: 11px;
  line-height: 1.45;
  color: var(--fg-tertiary, #6b7280);
}
/* The "Powered by AI…" line only shows once the user starts typing */
.chat-intro { display: none; }
.device.is-composing .chat-intro { display: flex; }

/* ---------- Welcome / starting screen ---------- */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
  min-height: 100%;
  padding: 12px 4px 4px;
}
.welcome__title {
  margin: 0 0 14px;
  font-size: 30px;
  line-height: 38px;
  font-weight: 400;
  color: var(--fg-primary, #1c1e21);
}
.welcome__subtitle {
  margin: 0;
  font-size: 16px;
  line-height: 24px;
  color: var(--fg-tertiary, #6b7280);
}
.welcome__suggestions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}
.suggestion {
  max-width: 100%;
  padding: 13px 20px;
  border: 1px solid var(--suggestion-border, rgba(0, 0, 0, 0.18));
  border-radius: 999px;
  background: var(--suggestion-bg, transparent);
  color: var(--suggestion-text, var(--fg-primary, #1c1e21));
  font-family: inherit;
  font-size: 16px;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.08s ease;
}
.suggestion:hover { background: var(--state-primary-subtle, rgba(0, 0, 0, 0.05)); }
.suggestion:active { transform: scale(0.98); }
/* Hidden once the conversation begins */
.device.is-started .welcome { display: none; }

/* ---------- Message log ---------- */
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 18px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: var(--gap-messages);
  scroll-behavior: smooth;
}

.msg {
  max-width: 78%;
  padding: var(--space-bubble-y) var(--space-bubble-x);
  border-radius: var(--radius-bubble);
  font-size: var(--font-size-msg);
  line-height: var(--line-height-msg);
  box-shadow: var(--shadow-bubble);
  word-wrap: break-word;
  animation: pop var(--anim-enter-ms) var(--anim-ease) both;
}

/* Centered timestamp divider (e.g. "Today 08:34") */
.timestamp {
  align-self: center;
  padding: 4px 0 2px;
  font-size: 13px;
  color: var(--fg-tertiary, #6b7280);
  animation: pop var(--anim-enter-ms) var(--anim-ease) both;
}

/* Consecutive messages from the same sender sit closer together.
   The log uses `gap: var(--gap-messages)`, so pull grouped
   messages up by the difference to reach --gap-messages-grouped. */
.msg--grouped {
  margin-top: calc(var(--gap-messages-grouped, 4px) - var(--gap-messages));
}
/* Also apply the tighter gap to the loader and feedback blocks
   when they follow an assistant message. */
.thinking.msg--grouped,
.feedback.msg--grouped {
  margin-top: calc(var(--gap-messages-grouped, 4px) - var(--gap-messages));
}

.msg--bot {
  align-self: flex-start;
  background: var(--bubble-bot-bg);
  color: var(--bubble-bot-text);
  border-bottom-left-radius: 6px;
}

.msg--user {
  align-self: flex-end;
  background: var(--bubble-user-bg);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 6px;
}

/* ---------- Rich content blocks (inside a bot bubble) ---------- */
.msg--rich {
  max-width: 88%;
  padding: 16px 18px;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg--rich .m-heading {
  font-size: var(--font-size-heading);
  font-weight: 400;
  font-variation-settings: "wght" 400;
  font-synthesis: none;
  line-height: var(--line-height-heading);
  margin: 0;
}
.msg--rich .m-text { margin: 0; }
.msg--rich ol,
.msg--rich ul {
  margin: 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg--rich li { padding-left: 4px; line-height: var(--line-height-msg); }
.msg--rich ol { list-style: decimal; }
.msg--rich ul { list-style: disc; }

/* Action button (with external-link glyph) */
.m-action {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  margin-top: 2px;
  border: none;
  border-radius: 999px;
  background: var(--action-bg, rgba(0, 0, 0, 0.06));
  color: var(--action-text, var(--bubble-bot-text));
  font-family: inherit;
  font-size: var(--font-size-msg);
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.08s ease;
}
.m-action:hover { filter: brightness(0.95); }
.m-action:active { transform: scale(0.98); }
.m-action .m-action__icon {
  font-size: 0.9em;
  opacity: 0.85;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Typing indicator */
.typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 5px;
  padding: 12px 16px;
  background: var(--bubble-bot-bg);
  border-radius: var(--radius-bubble);
  border-bottom-left-radius: 6px;
}
.typing span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Thinking / loading state (spinner + label) */
.thinking {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--thinking-bg, var(--bubble-bot-bg));
  color: var(--thinking-text, var(--fg-primary, #1c1e21));
  animation: pop var(--anim-enter-ms) var(--anim-ease) both;
}
.thinking__spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--thinking-track, rgba(0, 0, 0, 0.15));
  border-top-color: var(--thinking-accent, var(--fg-primary, #1c1e21));
  animation: spin 0.7s linear infinite;
}
.thinking__label {
  font-size: var(--font-size-msg, 15px);
  font-weight: 500;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Feedback component ---------- */
/* Question shown as a normal bot bubble, but full-width-ish */
.feedback__question {
  align-self: flex-start;
}
.feedback {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  flex: none;                       /* never let flex collapse it */
  min-height: 0;
  border-radius: 16px;
  overflow: hidden;
  background: var(--feedback-bg, var(--fg-always_white, #ffffff));
  border: 1px solid var(--feedback-border, rgba(0, 0, 0, 0.12));
  color: var(--feedback-text, var(--fg-primary, #1c1e21));
  animation: pop var(--anim-enter-ms) var(--anim-ease) both;
}
.feedback__option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: var(--font-size-msg, 16px);
  line-height: var(--line-height-msg, 24px);
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.feedback__text { flex: 1; }
/* Checkmark is hidden until the option is selected */
.feedback__check {
  width: 18px;
  display: inline-flex;
  justify-content: center;
  opacity: 0;
  font-size: 15px;
}
.feedback__option + .feedback__option {
  border-top: 1px solid var(--feedback-divider, rgba(0, 0, 0, 0.10));
}
.feedback__option:disabled { cursor: default; }
.feedback__option:hover:not(:disabled) {
  background: var(--state-primary-subtle, rgba(0, 0, 0, 0.04));
}

/* Selected: solid dark row with a white checkmark */
.feedback__option.is-selected {
  background: var(--feedback-selected-bg, var(--elevation-highlight-neutral, #101014));
  color: var(--feedback-selected-text, var(--fg-inverted, #ffffff));
}
.feedback__option.is-selected .feedback__check { opacity: 1; }
/* Round the selected row's corners when it's first/last */
.feedback__option.is-selected:first-child {
  border-top-left-radius: 15px;
  border-top-right-radius: 15px;
}
.feedback__option.is-selected:last-child {
  border-bottom-left-radius: 15px;
  border-bottom-right-radius: 15px;
}

/* ---------- Composer ---------- */
.composer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: var(--composer-bg, var(--color-header));
  border-top: 1px solid var(--composer-border, rgba(0, 0, 0, 0.08));
}

.composer__field {
  flex: 1;
  min-height: 24px;
  font-size: var(--composer-font-size, 15px);
  line-height: 1.4;
  color: var(--composer-text, var(--fg-primary, #1c1e21));
  white-space: pre-wrap;
  word-break: break-word;
  outline: none;
}

/* Placeholder (shown when field is empty) */
.composer__field:empty::before {
  content: attr(data-placeholder);
  color: var(--composer-placeholder, var(--fg-tertiary, #9aa1ad));
}

/* Blinking caret at the end while "typing" for the demo */
.composer__field.is-typing::after {
  content: "";
  display: inline-block;
  width: 1px;
  height: 1.1em;
  margin-left: 1px;
  vertical-align: text-bottom;
  background: var(--composer-text, var(--fg-primary, #1c1e21));
  animation: caret-blink 1s steps(1) infinite;
}
@keyframes caret-blink {
  50% { opacity: 0; }
}

/* Send button: gray & disabled when empty, solid when there's text */
.composer__send {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background: var(--send-bg-idle, #c7c9cc);
  color: var(--send-icon-idle, #ffffff);
  cursor: default;
  transition: background 0.18s ease, color 0.18s ease, transform 0.08s ease;
}
.composer__send-icon {
  font-size: 18px;
  line-height: 1;
}
.composer__send:not([disabled]) {
  background: var(--send-bg-active, var(--elevation-highlight-neutral, #101014));
  color: var(--send-icon-active, var(--fg-inverted, #ffffff));
  cursor: pointer;
}
.composer__send:not([disabled]):hover { transform: scale(1.05); }
.composer__send:not([disabled]):active { transform: scale(0.95); }

/* ---------- Presenter controls ---------- */
.controls {
  width: 340px;
  background: #ffffffcc;
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.35);
  align-self: stretch;
  max-height: 88vh;
  overflow-y: auto;
}
.controls__title { margin: 0 0 16px; font-size: 18px; }
.controls__row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.btn {
  padding: 9px 14px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: #fff;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn--primary { background: var(--color-accent); color: var(--color-accent-contrast); border-color: transparent; }
.btn--ghost { background: transparent; }

.speed {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-left: auto;
}
.speed input { width: 90px; }

.panel {
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  padding: 10px 14px;
  margin-top: 12px;
}
.panel summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.hint { font-size: 12px; color: #666; }

.token-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0;
}
.token {
  display: flex;
  flex-direction: column;
  font-size: 11px;
  color: #555;
  gap: 4px;
}
.token input[type="color"] {
  width: 100%; height: 30px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: none;
  cursor: pointer;
}
.token input[type="range"] { width: 100%; }

#scriptBox {
  width: 100%;
  height: 180px;
  margin: 8px 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 10px;
  resize: vertical;
}

/* ---------- Phone-only embed mode ----------
   Activated by adding `?phoneOnly=1` (or `#phoneOnly`) to the URL.
   Hides the presenter controls and centers the device — ideal for
   embedding in Notion, Figma, docs, etc. */
.phone-only html,
.phone-only body { background: #ffffff !important; }
.phone-only .controls { display: none !important; }
/* Caption only shows in embed mode */
.phone-caption { display: none; }
.phone-only .phone-caption { display: block; }
.phone-only .stage {
  padding: 0;
  gap: 0;
  min-height: 100vh;
  flex-wrap: nowrap;
  flex-direction: column;
  align-items: center;       /* center horizontally */
  justify-content: flex-start; /* pin to the top */
  overflow: hidden;
  background: #ffffff !important;
}
.phone-only .phone-caption {
  font-family: var(--font-family);
  font-size: 13px;
  line-height: 1.4;
  color: #6b7280;
  text-align: center;
  margin-top: 12px;
  padding: 0 16px;
}
/* Render the device at its native 402x874 and scale to fill the
   iframe height, so it always touches top & bottom (no gap).
   `zoom` shrinks the element's layout box too. */
.phone-only .device {
  flex: none;
  zoom: calc(100vh / 874px);
}
