/* "Rowdy asks" (rowdy-lessons.js): his teaching questions in a box with him in it, on the 3D farm and in the
   farm office. Also the "?" over his head on the 3D farm and the question button in his chat. Uses the
   --fh-* tokens so light and dark both work. */

.rl {
  position: fixed;
  z-index: 1150;
  left: 18px;
  bottom: 18px;
  color: var(--fh-ink, #14291e);
  font-size: 14px;
  line-height: 1.4;
}
/* The agronomist's pop-in sits in the same corner: Rowdy's question goes first. */
body.rowdy-asking .agro-pop {
  display: none !important;
}

/* ---------------------------------------------------------------- pop-in */
.rl-peek {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: min(400px, calc(100vw - 36px));
  animation: rl-in 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.rl-peek-face {
  position: relative;
  flex: none;
  width: 72px;
  height: 72px;
  padding: 0;
  border: 3px solid #b3332a;
  border-radius: 50%;
  background: #e9dcc4;
  box-shadow: 0 6px 20px #0005;
  cursor: pointer;
  animation: rl-bob 2.4s ease-in-out infinite;
}
.rl-peek-face img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.rl-peek-face i,
.rowdy-q {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #f2c230;
  color: #3a2a00;
  font:
    800 15px/1 system-ui,
    sans-serif;
  font-style: normal;
  box-shadow: 0 2px 8px #0004;
  animation: rl-pulse 1.6s ease-in-out infinite;
}
.rl-peek-bubble {
  position: relative;
  padding: 12px 14px;
  border-radius: 14px 14px 14px 4px;
  background: var(--fh-surface, #fff);
  border: 1px solid var(--fh-line-strong, #0003);
  box-shadow: 0 10px 30px #0004;
}
.rl-peek-bubble b {
  display: block;
  font-size: 12px;
  letter-spacing: 0.4px;
  color: #b3332a;
  text-transform: uppercase;
}
.rl-peek-bubble p {
  margin: 4px 0;
}
.rl-peek-bubble small {
  display: block;
  color: var(--fh-muted, #5c6b62);
}
.rl-peek-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.rl button.primary,
.rl button.secondary {
  font-size: 12px;
  padding: 7px 12px;
}

/* ---------------------------------------------------------------- the box */
.rl-open {
  display: flex;
  width: min(620px, calc(100vw - 36px));
  max-height: min(600px, calc(100vh - 36px));
  border-radius: 16px;
  overflow: hidden;
  background: var(--fh-surface, #fff);
  border: 1px solid var(--fh-line-strong, #0003);
  box-shadow: 0 18px 50px #0005;
  animation: rl-in 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
.rl-stage {
  position: relative;
  flex: none;
  width: 190px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 0 0 12px;
  background:
    radial-gradient(120% 80% at 50% 20%, #ffe9b8 0%, #f2c46e 35%, transparent 70%),
    linear-gradient(180deg, #8ec5e8 0%, #cfe6c0 62%, #6f8f3a 63%, #4f6b28 100%);
  color: #fff;
}
.rl-portrait {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 210px;
}
.rl-portrait canvas,
.rl-portrait img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.rl-portrait img {
  object-fit: cover;
  object-position: 50% 30%;
  inset: 18px 14px 0;
  width: calc(100% - 28px);
  height: calc(100% - 18px);
  border-radius: 50% 50% 12px 12px;
  transition: transform 0.2s;
}
.rl-portrait img.rl-gone {
  display: none;
}
.rl-who {
  text-align: center;
  text-shadow: 0 1px 3px #0008;
  padding: 0 8px;
}
.rl-who b {
  display: block;
  font-size: 16px;
  letter-spacing: 0.5px;
}
.rl-who small {
  font-size: 11px;
  opacity: 0.95;
}
.rl-stage .rl-icon {
  position: absolute;
  top: 8px;
  left: 8px;
  background: #0005;
  color: #fff;
}
.rl-icon {
  border: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font-size: 16px;
  cursor: pointer;
}
.rl-icon:focus-visible {
  outline: 2px solid var(--lime, #b7d64b);
}
.rl-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.rl-main header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 8px 8px 14px;
  background: #b3332a;
  color: #fff;
}
.rl-main header .eyebrow {
  color: #fff;
  font-size: 11px;
  letter-spacing: 0.8px;
}
.rl-log {
  padding: 12px 14px 4px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 210px;
}
.rl-msg {
  max-width: 92%;
  padding: 8px 11px;
  border-radius: 12px;
  font-size: 13.5px;
  animation: rl-pop 0.25s ease-out;
}
.rl-rowdy {
  align-self: flex-start;
  background: var(--fh-surface-2, #f1efe6);
  border: 1px solid var(--fh-line, #0001);
  border-bottom-left-radius: 4px;
}
.rl-rowdy.rl-ask {
  font-weight: 600;
  border-color: #b3332a66;
}
.rl-rowdy.rl-good {
  background: var(--fh-good-bg, #e3f3df);
}
.rl-rowdy.rl-bad {
  background: var(--fh-warn-bg, #fbefd6);
}
.rl-thinking {
  font-style: italic;
  color: var(--fh-muted, #5c6b62);
}
.rl-you {
  align-self: flex-end;
  background: var(--fh-accent-soft, #dfeec0);
  color: var(--fh-accent-ink, var(--fh-ink, #14291e));
  border-bottom-right-radius: 4px;
}
.rl-coach {
  align-self: stretch;
  max-width: none;
  font-size: 12.5px;
  background: var(--fh-info-bg, #e3eef8);
  color: var(--fh-ink, #14291e);
}
.rl-answer {
  padding: 6px 14px 4px;
  overflow-y: auto;
}
.rl-prompt {
  margin: 4px 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--fh-muted, #5c6b62);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.rl-warn {
  color: var(--fh-bad, #b3332a);
  text-transform: none;
}
.rl-options {
  display: grid;
  gap: 6px;
}
.rl-option {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--fh-line-strong, #0003);
  background: var(--fh-input, #fff);
  color: var(--fh-ink, #14291e);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition:
    transform 0.12s,
    border-color 0.12s,
    background 0.12s;
}
.rl-option span {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #b3332a;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}
.rl-option:hover:not(:disabled),
.rl-option:focus-visible {
  border-color: #b3332a;
  transform: translateX(3px);
}
.rl-option:disabled {
  opacity: 0.55;
  cursor: default;
}
.rl-words {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}
.rl-words label {
  font-size: 12px;
  font-weight: 600;
}
.rl-words-row {
  display: flex;
  gap: 6px;
  align-items: flex-start;
}
.rl-words textarea {
  flex: 1;
  min-width: 0;
  resize: vertical;
  font: inherit;
  font-size: 13px;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid var(--fh-line-strong, #0003);
  background: var(--fh-input, #fff);
  color: var(--fh-ink, #14291e);
}
.rl-words button[type='submit'] {
  justify-self: end;
}
.rl-mic {
  background: var(--fh-surface-2, #f1efe6);
}
.rl-mic.on {
  background: #b3332a;
  color: #fff;
  animation: rl-pulse 1.2s ease-in-out infinite;
}
.rl-result {
  margin: 6px 0;
}
.rl-result p {
  margin: 6px 0;
  font-size: 13px;
}
.rl-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.rl-chips span {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--fh-good-bg, #e3f3df);
  color: var(--fh-good, #2c6a2a);
  animation: rl-pop 0.35s ease-out both;
}
.rl-chips span:nth-child(2) {
  animation-delay: 0.12s;
}
.rl-chips .rl-promo {
  background: #f2c230;
  color: #3a2a00;
  animation-delay: 0.24s;
}
.rl-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--fh-line, #0001);
  margin-top: auto;
}
.rl-foot small {
  color: var(--fh-muted, #5c6b62);
  font-size: 12px;
}

/* ---------------------------------------------------------------- the 3D farm and his chat */
.rowdy-tag .rowdy-q {
  display: none;
  position: static;
  width: 30px;
  height: 30px;
  font-size: 18px;
  cursor: pointer;
}
.rowdy-tag.asking .rowdy-q {
  display: grid;
}
.rowdy-asks {
  margin: 0 12px 8px;
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: #f2c230;
  color: #3a2a00;
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  display: flex;
  gap: 8px;
  align-items: center;
}
.rowdy-asks[hidden] {
  display: none;
}
.rowdy-asks span {
  font-weight: 800;
}
.rowdy-asks b {
  margin-left: auto;
}
.rt-talk {
  margin: 4px 0 8px;
}

@keyframes rl-in {
  from {
    transform: translateY(30px) scale(0.92);
    opacity: 0;
  }
}
@keyframes rl-pop {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
}
@keyframes rl-bob {
  50% {
    transform: translateY(-4px) rotate(-2deg);
  }
}
@keyframes rl-pulse {
  50% {
    transform: scale(1.12);
  }
}
html[data-motion='calm'] .rl,
html[data-motion='calm'] .rl *,
html[data-motion='calm'] .rowdy-q {
  animation: none !important;
  transition: none !important;
}
@media (prefers-reduced-motion: reduce) {
  .rl,
  .rl *,
  .rowdy-q {
    animation: none !important;
    transition: none !important;
  }
}

/* Phones: Rowdy across the top of the box, the conversation under him. */
@media (max-width: 700px), (max-width: 950px) and (max-height: 500px) {
  .rl {
    left: 8px;
    right: 8px;
    bottom: 8px;
  }
  .rl-open {
    width: auto;
    flex-direction: column;
    max-height: calc(100vh - 16px);
  }
  .rl-stage {
    width: 100%;
    flex-direction: row;
    justify-content: flex-start;
    gap: 8px;
    padding: 0 12px 0 0;
    height: 110px;
  }
  .rl-portrait {
    flex: none;
    width: 110px;
    min-height: 0;
    height: 110px;
  }
  .rl-who {
    text-align: left;
  }
  .rl-stage .rl-icon {
    left: auto;
    right: 8px;
  }
  .rl-log {
    max-height: 150px;
  }
}
