/* Once Riff has the screen: the drawers right under him with room to scroll, and his chat folded or to the side,
   on the right (js/chatlayout.js). Nick's side, at Nick's request (2026-11-08). These sit over v2.css's state-2 rules. */

:root {
  --chat-w: clamp(300px, 25vw, 380px);
}

/* The drawers come up right under Riff instead of waiting at the bottom of the screen (chords.css already
   lets their column scroll, with room at the sides for the Moon body's shadow). */
body[data-state="riff"] .drawers {
  margin-top: 0;
}

/* The chat's two controls, at its top right. They stay put as the chat scrolls. */
.convo-tools,
.convo-fold {
  display: none;
}

body[data-state="riff"] .convo-tools {
  position: sticky;
  top: -44px;
  z-index: 2;
  display: flex;
  justify-content: flex-end;
  gap: 2px;
  height: 0;
  margin: -44px -14px 44px 0;
}

/* The controls get a band of their own at the top of the chat, so no words run under them: room for it above the
   first message, and behind the keys a strip of the panel's own colour that stays put while the chat scrolls. It is
   solid for the keys' whole height and only fades below them. (Until 2026-11-17 the strip was a phone's only and
   faded from two thirds of the way down, so a scrolled message showed through under the keys: Nick, "the corner
   buttons cover the top of his message".) */
body[data-state="riff"]:not([data-chat-fold]) .convo {
  padding-top: 48px;
}

body[data-state="riff"] .convo-tools::before {
  content: "";
  position: absolute;
  top: -4px;
  right: -8px;
  left: -22px;
  z-index: -1;
  height: 48px;
  border-radius: var(--r-card) var(--r-card) 0 0;
  background: linear-gradient(var(--panel) 40px, transparent);
  pointer-events: none;
}

.convo-tools .ibtn {
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  color: var(--dust);
}

.convo-tools .ibtn .ic {
  width: 18px;
  height: 18px;
}

@media (hover: hover) {
  .convo-tools .ibtn:hover {
    border-color: var(--line);
    color: var(--starlight);
  }
}

/* Folded: one line, Riff's latest words. */
body[data-state="riff"][data-chat-fold] .convo {
  min-height: 0;
  padding: 4px 6px;
  overflow: hidden;
}

body[data-state="riff"][data-chat-fold] .log,
body[data-state="riff"][data-chat-fold] .convo-tools {
  display: none;
}

body[data-state="riff"][data-chat-fold] .convo-fold {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 4px 8px 4px 14px;
  border: 0;
  border-radius: calc(var(--r-card) - 4px);
  background: none;
  color: var(--starlight);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.convo-fold-who {
  flex: none;
  color: var(--dust);
  font-size: 13px;
}

.convo-fold-line {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-family: var(--serif);
  font-size: 16px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.convo-fold .ic {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--dust);
}

/* To the side: wide screens only. The chat docks on the right, the height of the screen down to the play bar; the
   ask bar and the drawers move over and take the rest. It was on the left until 2026-11-17 (Nick: "we need to be
   consistent. right is probably better"). While the song builder is open Riff sits there too, asked or not
   (songbuilder.css, js/songdrawer.js), so he's beside the part you're working on. Folded wins: a folded chat sits
   above the drawers. */
@media (min-width: 1100px) {
  body[data-state="riff"]:is([data-chat-side], [data-song-open]):not([data-chat-fold]) .stage {
    padding-right: calc(var(--chat-w) + var(--gutter) * 2);
  }

  body[data-state="riff"]:is([data-chat-side], [data-song-open]):not([data-chat-fold]) .convo {
    position: fixed;
    top: 96px;
    right: var(--gutter);
    bottom: calc(var(--gutter) + 60px);
    width: var(--chat-w);
    max-height: none;
    margin: 0;
  }

  /* Beside the song he's there already: the key that moves him is put away, and so is Bigger. */
  body[data-state="riff"][data-song-open]:not([data-chat-fold]) :is(.convo-side, .convo-tall) {
    display: none;
  }
}

@media (max-width: 1099px) {
  .convo-side {
    display: none;
  }
}

/* ---------- Bigger: the chat takes the screen under the ask bar ----------
   Nick, 2026-11-11: "There needs to be an option to collapse the riff chat or expand it to mostly full screen."
   What's under it (the drawers, the Learn page) steps aside until it's made smaller, or one of them is opened. */
body[data-state="riff"][data-chat-tall]:not([data-chat-fold]) .convo {
  flex: 1 1 auto;
  max-height: none;
}

body[data-state="riff"][data-chat-tall]:not([data-chat-fold]) :is(.drawers, .learnpage) {
  display: none;
}

/* To the side it already has the height of the screen. */
@media (min-width: 1100px) {
  body[data-chat-side] .convo-tall {
    display: none;
  }
}

/* ---------- Phones: room for the chat and for what's under it ----------
   Nick, 2026-11-11: "It's currently split screen but there's only about 2 lines of the riff chat visible", and
   "we also need to maximize the vertical real estate on mobile - maybe we move the listen, learn create buttons
   to the menu." */
@media (max-width: 639px) {
  /* The chat keeps its share (what it has to say, up to a third of the screen) and doesn't give it up to a
     tall drawer; the drawers scroll in the rest. Bigger and Fold are a tap away. */
  body[data-state="riff"]:not([data-chat-fold], .rc-practicing) .convo {
    flex-shrink: 0;
    max-height: 34dvh;
  }

  /* Once Riff has the screen, the three rooms are in the Menu's sheet (js/rooms.js, v2/settings.css), and their
     row gives its place up. */
  body[data-state="riff"] .doors {
    display: none;
  }

  /* The chat's keys are thumbs' size here. */
  body[data-state="riff"] .convo-tools {
    top: -50px;
    margin: -50px -16px 50px 0;
  }

  .convo-tools .ibtn {
    width: 40px;
    height: 40px;
  }

  body[data-state="riff"]:not([data-chat-fold]) .convo {
    padding-top: 54px;
  }

  /* The strip behind the keys (above), a phone's size: solid to just under them, then a short fade. */
  body[data-state="riff"] .convo-tools::before {
    right: 0;
    left: -16px;
    height: 54px;
    background: linear-gradient(var(--panel) 46px, transparent);
  }
}

/* Riff's pick at the head of his chat: a picture only, before his voice and the chat's keys. */
.convo-pick {
  display: none;
}

body[data-state="riff"] .convo-tools .convo-pick {
  display: block;
  flex: none;
  align-self: flex-start;
  margin: 5px 0 0 4px;
}

@media (max-width: 639px) {
  body[data-state="riff"] .convo-tools .convo-pick {
    margin: 9px 0 0 0;
  }
}
