/* tenderfoot/css/tf-pip.css - Pip's chat (js/tf-pip.js).
 *
 * The game's own materials (tf-shop.css's stone and gold, tf.css's tokens): a dark plum panel with a
 * gold hairline, Pip's portrait in a gold ring, cream bubbles for Pip and plum ones for the player,
 * a gold "Ask" button. On a computer or tablet it rises from Pip's corner, bottom left, and leaves the
 * rest of the painting in view; on a phone it is a full-screen sheet that stays above the keyboard.
 *
 * SNOOZE MODE (.is-napping): the header goes to night blue, Pip wears his nightcap (pip-sleepy.png)
 * and three z's drift up from him.
 *
 * Every size a finger touches is at least 44 CSS px, every text at least 15 px on a phone
 * (docs/platform-design-spec.md). Everything is under .tf-pip.
 */
.tf-pip {
  --tfp-gold: #F5C242;
  --tfp-gold-hi: #FFF3C4;
  --tfp-gold-lo: #B7791F;
  --tfp-parchment: #FBF3E7;
  --tfp-ink: #0B0814;
  --tfp-plum: #3A2B58;
  --tfp-plum-hi: #5C4380;
  --tfp-stone-top: #4A3568;
  --tfp-stone-mid: #2A1F42;
  --tfp-stone-low: #1B1430;
  --tfp-lavender: #C9A8F5;
  --tfp-mint: #7FE0D6;
  --tfp-muted: #B3A4D6;
  --tfp-night-top: #1F2E5C;
  --tfp-night-low: #121A38;
  --tfp-font: 'Trebuchet MS', 'Lucida Grande', Verdana, sans-serif;
  --tfp-title: 'Palatino Linotype', 'Book Antiqua', Palatino, Georgia, serif;
  --tfp-vh: 100vh;
  --tfp-top: 0px;

  position: fixed;
  left: 0;
  right: 0;
  top: var(--tfp-top);
  height: var(--tfp-vh);
  z-index: 900;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(11, 8, 20, 0);
  font-family: var(--tfp-font);
  color: var(--tfp-parchment);
  transition: background 200ms ease;
  touch-action: manipulation;
}
.tf-pip[hidden] { display: none; }
.tf-pip.is-open { background: rgba(11, 8, 20, 0.42); }

.tf-pip .tfp-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(440px, 100%);
  height: min(640px, 100%);
  border-radius: 18px;
  background: linear-gradient(180deg, var(--tfp-stone-top) 0%, var(--tfp-stone-mid) 16%, var(--tfp-stone-low) 100%);
  border: 2px solid rgba(245, 194, 66, 0.55);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  overflow: hidden;
  transform: translateY(24px) scale(0.97);
  transform-origin: bottom left;
  opacity: 0;
  transition: transform 220ms cubic-bezier(0.2, 0.9, 0.3, 1.2), opacity 180ms ease;
}
.tf-pip.is-open .tfp-panel { transform: none; opacity: 1; }

/* ---- the header ------------------------------------------------------------------------ */
.tf-pip .tfp-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 10px 14px;
  background: linear-gradient(180deg, rgba(92, 67, 128, 0.9), rgba(42, 31, 66, 0.9));
  border-bottom: 1px solid rgba(245, 194, 66, 0.35);
  transition: background 400ms ease;
}
.tf-pip .tfp-face {
  position: relative;
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #4A3568, #1B1430);
  border: 3px solid var(--tfp-gold);
  box-shadow: 0 0 18px rgba(245, 194, 66, 0.35);
}
.tf-pip .tfp-face-img {
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 58px;
  height: auto;
  transform: translateX(-50%);
  pointer-events: none;
  user-select: none;
}
.tf-pip .tfp-titles { position: relative; flex: 1 1 auto; min-width: 0; }
.tf-pip .tfp-title {
  margin: 0;
  font-family: var(--tfp-title);
  font-size: 24px;
  font-weight: bold;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #FFD86B;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}
.tf-pip .tfp-sub { margin: 2px 0 0; font-size: 13px; color: var(--tfp-muted); }

.tf-pip .tfp-toggle {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(201, 168, 245, 0.6);
  background: rgba(11, 8, 20, 0.35);
  color: var(--tfp-lavender);
  font: bold 13px var(--tfp-font);
  cursor: pointer;
}
.tf-pip .tfp-toggle[aria-pressed="true"] { border-color: rgba(127, 224, 214, 0.75); color: var(--tfp-mint); }
.tf-pip .tfp-close {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--tfp-gold);
  background: radial-gradient(circle at 50% 35%, #5C4380, #2A1F42);
  color: var(--tfp-gold-hi);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}
.tf-pip .tfp-close-x { font-size: 26px; line-height: 1; margin-top: -2px; }
.tf-pip button:focus-visible, .tf-pip .tfp-input:focus-visible { outline: 3px solid var(--tfp-mint); outline-offset: 2px; }

.tf-pip .tfp-status {
  margin: 0;
  padding: 6px 16px;
  font-size: 12.5px;
  color: var(--tfp-muted);
  background: rgba(11, 8, 20, 0.35);
  border-bottom: 1px solid rgba(201, 168, 245, 0.14);
}
.tf-pip .tfp-status.is-ai { color: var(--tfp-mint); }

/* ---- the conversation ------------------------------------------------------------------ */
.tf-pip .tfp-log {
  flex: 1 1 auto;
  margin: 0;
  padding: 14px 12px 8px;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(201, 168, 245, 0.35) transparent;
}
.tf-pip .tfp-msg { display: flex; align-items: flex-end; gap: 8px; margin: 0 0 12px; }
.tf-pip .tfp-msg.is-player { justify-content: flex-end; }
.tf-pip .tfp-avatar {
  flex: 0 0 auto;
  width: 34px;
  height: auto;
  margin-bottom: -2px;
  pointer-events: none;
  user-select: none;
}
.tf-pip .tfp-bubble {
  position: relative;
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 15.5px;
  line-height: 1.42;
}
.tf-pip .is-pip .tfp-bubble {
  background: var(--tfp-parchment);
  color: #1A1026;
  border: 2px solid rgba(245, 194, 66, 0.85);
  border-bottom-left-radius: 4px;
}
.tf-pip .is-player .tfp-bubble {
  background: linear-gradient(180deg, var(--tfp-plum-hi), var(--tfp-plum));
  color: var(--tfp-parchment);
  border: 1px solid rgba(201, 168, 245, 0.45);
  border-bottom-right-radius: 4px;
}
.tf-pip .tfp-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.tf-pip .tfp-tag {
  display: inline-block;
  margin-top: 6px;
  font-size: 11.5px;
  font-style: italic;
  color: #7A6A99;
}
.tf-pip .tfp-action {
  display: block;
  margin-top: 8px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 2px solid var(--tfp-gold-lo);
  background: linear-gradient(180deg, #FFE08A, var(--tfp-gold));
  color: #2A1600;
  font: bold 14px var(--tfp-font);
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}
.tf-pip .tfp-action:hover { filter: brightness(1.06); }

.tf-pip .is-typing .tfp-bubble { display: flex; gap: 6px; align-items: center; padding: 14px 16px; }
.tf-pip .tfp-dot {
  width: 9px;
  height: 11px;
  border-radius: 50% 50% 45% 45%;
  background: radial-gradient(circle at 40% 35%, #FFF3C4, var(--tfp-gold) 60%, var(--tfp-gold-lo));
  animation: tfp-bob 900ms ease-in-out infinite;
}
.tf-pip .tfp-dot:nth-of-type(2) { animation-delay: 150ms; }
.tf-pip .tfp-dot:nth-of-type(3) { animation-delay: 300ms; }
@keyframes tfp-bob { 0%, 100% { transform: translateY(0); opacity: 0.55; } 40% { transform: translateY(-6px); opacity: 1; } }

/* ---- quick questions and the box ------------------------------------------------------ */
.tf-pip .tfp-chips {
  display: flex;
  gap: 8px;
  padding: 8px 12px 4px;
  overflow-x: auto;
  touch-action: pan-x;
  scrollbar-width: none;
  flex: 0 0 auto;
}
.tf-pip .tfp-chips::-webkit-scrollbar { display: none; }
.tf-pip .tfp-chip {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid rgba(245, 194, 66, 0.55);
  background: rgba(11, 8, 20, 0.45);
  color: var(--tfp-gold-hi);
  font: 14px var(--tfp-font);
  white-space: nowrap;
  cursor: pointer;
}
.tf-pip .tfp-chip:hover { background: rgba(92, 67, 128, 0.7); }
.tf-pip .tfp-form {
  display: flex;
  gap: 8px;
  padding: 8px 12px 12px;
  flex: 0 0 auto;
}
.tf-pip .tfp-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 2px solid rgba(201, 168, 245, 0.5);
  background: rgba(11, 8, 20, 0.55);
  color: var(--tfp-parchment);
  font: 16px var(--tfp-font);         /* 16 px: iOS does not zoom the page into the box */
}
.tf-pip .tfp-input::placeholder { color: rgba(201, 168, 245, 0.7); }
.tf-pip .tfp-send {
  flex: 0 0 auto;
  min-width: 76px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 12px;
  border: 2px solid var(--tfp-gold-lo);
  background: linear-gradient(180deg, #FFE08A, var(--tfp-gold));
  color: #2A1600;
  font: bold 17px var(--tfp-font);
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}
.tf-pip .tfp-send:disabled { opacity: 0.55; cursor: default; }
.tf-pip .tfp-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- snooze mode ------------------------------------------------------------------------- */
.tf-pip.is-napping .tfp-head { background: linear-gradient(180deg, var(--tfp-night-top), var(--tfp-night-low)); }
.tf-pip.is-napping .tfp-face { box-shadow: 0 0 14px rgba(120, 160, 255, 0.35); border-color: #9DB8FF; }
.tf-pip.is-napping .tfp-status { color: #9DB8FF; }
/* The z's drift up and to the right from just outside the ring, clear of his (pale) nightcap. */
.tf-pip .tfp-zzz { position: absolute; left: 62px; top: -8px; width: 40px; height: 40px; pointer-events: none; display: none; }
.tf-pip.is-napping .tfp-zzz { display: block; }
.tf-pip .tfp-z {
  position: absolute;
  font-family: var(--tfp-title);
  font-weight: bold;
  color: #DDE8FF;
  text-shadow: 0 0 2px #0B0814, 0 0 3px #0B0814, 0 0 8px rgba(157, 184, 255, 0.9);
  opacity: 0;
  animation: tfp-z 3s ease-in infinite;
}
.tf-pip .tfp-z1 { left: 0; bottom: 0; font-size: 14px; }
.tf-pip .tfp-z2 { left: 9px; bottom: 12px; font-size: 18px; animation-delay: 1s; }
.tf-pip .tfp-z3 { left: 18px; bottom: 24px; font-size: 23px; animation-delay: 2s; }
@keyframes tfp-z { 0% { opacity: 0; transform: translate(0, 6px) rotate(-8deg); } 25% { opacity: 1; } 100% { opacity: 0; transform: translate(10px, -18px) rotate(12deg); } }

/* ---- phones: a full sheet above the keyboard ------------------------------------------ */
@media (max-width: 560px), (max-height: 500px) {
  .tf-pip { padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); justify-content: center; }
  .tf-pip .tfp-panel { width: min(760px, 100%); height: 100%; border-radius: 14px; }
  .tf-pip .tfp-head { padding: 6px 8px 6px 10px; gap: 10px; }
  .tf-pip .tfp-face { width: 48px; height: 48px; }
  .tf-pip .tfp-face-img { width: 44px; }
  .tf-pip .tfp-title { font-size: 20px; }
  .tf-pip .tfp-zzz { left: 52px; top: -10px; }
  .tf-pip .tfp-sub { font-size: 13px; }
  .tf-pip .tfp-toggle { min-height: 44px; font-size: 15px; }
  .tf-pip .tfp-status { padding: 4px 12px; font-size: 13px; }
  .tf-pip .tfp-log { padding: 10px 10px 6px; }
  .tf-pip .tfp-bubble { font-size: 16px; max-width: 86%; }
  .tf-pip .tfp-chip { min-height: 44px; font-size: 15px; }
  .tf-pip .tfp-form { padding: 6px 8px 8px; }
  .tf-pip .tfp-send { min-height: 48px; }
  .tf-pip .tfp-action { min-height: 44px; font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .tf-pip, .tf-pip .tfp-panel { transition: none; }
  .tf-pip .tfp-dot, .tf-pip .tfp-z { animation: none; }
  .tf-pip.is-napping .tfp-z { opacity: 0.8; }
}
@media (forced-colors: active) {
  .tf-pip .tfp-bubble, .tf-pip .tfp-panel, .tf-pip button { border: 1px solid CanvasText; }
}
