/* bad-ai — the app's own styles, after the kit (DESIGN.md). Tokens only: no colour, size or font that isn't one
   (test/style.test.js). The one literal is the 600 px phone/wide split, as in the kit's frame. It declares no
   token of its own. The page is a chat like the familiar ones: a greeting over a large box in the middle, then the
   conversation in one column with the box at its foot. */

.ba {
  --ba-column: calc(var(--space-24) * 7);

  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 72svh;
  padding-block: var(--space-8);
  padding-inline: var(--space-4);
}

.ba.ba-started {
  justify-content: flex-start;
  padding-block-end: 0;
}

.ba-intro,
.ba-log,
.ba-form,
.ba-starters {
  width: 100%;
  max-width: var(--ba-column);
  margin-inline: auto;
}

.ba-intro[hidden],
.ba-starters[hidden] {
  display: none;
}

/* The greeting: the body face at the title's size, centred over the box. */
.ba-intro {
  margin-block-end: var(--space-6);
  text-align: center;
}

.ba-greeting {
  margin: 0;
  font-size: var(--title-size);
  line-height: var(--title-line);
  font-weight: var(--title-weight);
}

.ba-greeting:lang(ar) {
  font-size: var(--ar-title-size);
  line-height: var(--ar-title-line);
  font-weight: var(--ar-title-weight);
}

/* The suggestions: quiet controls under the box that fill it. */
.ba-starters {
  list-style: none;
  margin-block: var(--space-4) 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
}

.ba-starter {
  margin: 0;
  padding-block: var(--space-2);
  padding-inline: var(--space-3);
  border: var(--hairline) solid var(--sand);
  border-radius: var(--radius-md);
  background: none;
  color: var(--graphite);
  font: inherit;
  font-size: var(--small-size);
  line-height: var(--small-line);
  cursor: pointer;
}

.ba-starter:hover {
  border-color: var(--stone);
  color: var(--ink);
}

/* The conversation: one column that grows downward. The visitor's turns at the end side in a bubble, the bot's at
   the start side as plain text. */
.ba-log {
  list-style: none;
  margin-block: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  flex: 1;
}

.ba-log:empty {
  display: none;
}

.ba-turn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-3);
  max-width: 100%;
  scroll-margin-block: var(--space-6) calc(var(--space-24) * 2 + var(--space-16));
}

.ba-you {
  align-self: flex-end;
  max-width: 85%;
  padding-block: var(--space-2);
  padding-inline: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--bone);
}

/* Who spoke, and the box's label: for a screen reader only. */
.ba-who,
.ba-label {
  position: absolute;
  width: var(--hairline);
  height: var(--hairline);
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.ba-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ba-text:empty {
  display: none;
}

.ba-waiting .ba-text {
  color: var(--stone);
}

/* A prop that is a drawing: the file is a mask, so the lines take the theme's ink. */
.ba-drawing {
  display: block;
  width: calc(var(--space-24) + var(--space-6));
  aspect-ratio: 1;
  background: var(--ink);
  mask: center / contain no-repeat;
}

.ba-drawing-calculator {
  mask-image: url('props/calculator.svg');
}

.ba-drawing-clock {
  mask-image: url('props/clock.svg');
}

.ba-drawing-pen {
  mask-image: url('props/pen.svg');
}

/* The composer: one large box that holds the text and the one primary button. In the conversation it stays at
   the foot of the screen, the turns scrolling behind it. */
.ba-form {
  margin-block-start: var(--space-4);
}

.ba-started .ba-form {
  position: sticky;
  bottom: 0;
  padding-block: var(--space-3) calc(var(--space-4) + env(safe-area-inset-bottom));
  background: var(--paper);
}

.ba-box {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  border: var(--hairline) solid var(--stone);
  border-radius: var(--radius-md);
  background: var(--bone);
}

.ba-box:hover {
  border-color: var(--graphite);
}

.ba-box:focus-within {
  outline: var(--rule) solid var(--focus);
  outline-offset: var(--rule);
}

.ba-input {
  display: block;
  width: 100%;
  min-height: calc(var(--ar-body-line) * 3);
  max-height: calc(var(--ar-body-line) * 10);
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: var(--ar-body-size);
  line-height: var(--ar-body-line);
  field-sizing: content;
  resize: none;
}

/* The box draws the focus. */
.ba-input:focus-visible {
  outline: none;
}

/* An empty box has no text to take its direction from: it follows the page's language. */
:lang(ar) .ba-input:placeholder-shown {
  direction: rtl;
}

.ba-input::placeholder {
  color: var(--stone);
  opacity: 1;
}

.ba-input:disabled {
  color: var(--stone);
}

.ba-go {
  align-self: flex-end;
  min-height: var(--space-12);
  margin: 0;
  padding-block: var(--space-2);
  padding-inline: var(--space-6);
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-weight: var(--title-weight);
  cursor: pointer;
}

.ba-go:disabled {
  background: var(--paper);
  color: var(--stone);
  cursor: default;
}

@media (min-width: 600px) {
  .ba {
    padding-inline: var(--space-12);
  }

  .ba-drawing {
    width: calc(var(--space-24) + var(--space-16));
  }
}
