/* ============================================================================
   Sophie the Explorer Guide — chat UI styles
   Expedition palette: Paper #F5F1E8, Ink #1F1A14, Deep Field #1B3A2F,
   Expedition Gold #C8A24B, Rust #A8432A, Sky #6B8CAE, Soft Cream #EEE6D3
   ============================================================================ */

:root {
  --sophie-paper: #f5f1e8;
  --sophie-ink: #1f1a14;
  --sophie-deep: #1b3a2f;
  --sophie-gold: #c8a24b;
  --sophie-rust: #a8432a;
  --sophie-sky: #6b8cae;
  --sophie-cream: #eee6d3;
}

/* ---------- Floating Sophie button (FAB) ---------- */
#sophie-fab {
  position: fixed;
  bottom: 1.25rem;
  left: 1.25rem;
  width: 76px;
  height: 76px;
  border: 3px solid var(--sophie-gold);
  background: var(--sophie-paper);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35),
    0 0 0 4px rgba(200, 162, 75, 0.2);
  z-index: 9998;
  padding: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: sophie-bob 3s ease-in-out infinite;
}
#sophie-fab:hover {
  transform: scale(1.06);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45),
    0 0 0 6px rgba(200, 162, 75, 0.3);
}
#sophie-fab img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  pointer-events: none;
}
#sophie-fab .sophie-coin-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border-radius: 14px;
  background: var(--sophie-gold);
  color: var(--sophie-ink);
  font-family: "Source Sans 3", system-ui, sans-serif;
  font-weight: 700;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--sophie-paper);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
@keyframes sophie-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* Hide FAB while panel open on small screens */
.sophie-open #sophie-fab { display: none; }
@media (min-width: 700px) {
  .sophie-open #sophie-fab { display: flex; opacity: 0.5; }
}

/* ---------- Chat panel ---------- */
#sophie-panel {
  position: fixed;
  bottom: 1.25rem;
  left: 1.25rem;
  width: min(380px, calc(100vw - 2.5rem));
  height: min(560px, calc(100vh - 2.5rem));
  background: var(--sophie-paper);
  border: 2px solid var(--sophie-deep);
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  z-index: 9999;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: "Source Sans 3", system-ui, sans-serif;
  color: var(--sophie-ink);
  animation: sophie-pop 0.25s ease;
}
.sophie-open #sophie-panel { display: flex; }
@keyframes sophie-pop {
  from { transform: translateY(20px) scale(0.95); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

/* Mobile fullscreen */
@media (max-width: 540px) {
  #sophie-panel {
    inset: 0;
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    border: none;
  }
}

/* ---------- Header ---------- */
.sophie-header {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.8rem 1rem;
  background: var(--sophie-deep);
  color: var(--sophie-paper);
  border-bottom: 3px solid var(--sophie-gold);
}
.sophie-header-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--sophie-gold);
  background: var(--sophie-paper);
  overflow: hidden;
  flex-shrink: 0;
}
.sophie-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}
.sophie-header-text {
  flex: 1;
  min-width: 0;
}
.sophie-header-name {
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.1;
}
.sophie-header-rank {
  font-size: 0.78rem;
  color: var(--sophie-gold);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 2px;
}
.sophie-coin-pill {
  background: var(--sophie-gold);
  color: var(--sophie-ink);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.sophie-close {
  background: transparent;
  border: none;
  color: var(--sophie-paper);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}
.sophie-close:hover { background: rgba(255, 255, 255, 0.1); }

/* ---------- Message list ---------- */
.sophie-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem 0.9rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  background: var(--sophie-paper);
  scroll-behavior: smooth;
}
.sophie-msg {
  max-width: 85%;
  padding: 0.65rem 0.85rem;
  border-radius: 14px;
  font-size: 0.95rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.sophie-msg.sophie {
  align-self: flex-start;
  background: var(--sophie-cream);
  border: 1px solid rgba(27, 58, 47, 0.15);
  border-bottom-left-radius: 4px;
  position: relative;
}
.sophie-msg.user {
  align-self: flex-end;
  background: var(--sophie-deep);
  color: var(--sophie-paper);
  border-bottom-right-radius: 4px;
}
.sophie-msg.system {
  align-self: center;
  background: rgba(200, 162, 75, 0.18);
  color: var(--sophie-deep);
  font-size: 0.82rem;
  padding: 0.4rem 0.8rem;
  border-radius: 12px;
  font-style: italic;
}
.sophie-msg-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.4rem;
}
.sophie-msg-actions button {
  background: transparent;
  border: 1px solid var(--sophie-deep);
  color: var(--sophie-deep);
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.sophie-msg-actions button:hover {
  background: var(--sophie-deep);
  color: var(--sophie-paper);
}
.sophie-msg-actions button:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* Typing indicator */
.sophie-typing {
  display: inline-flex;
  gap: 4px;
  padding: 0.65rem 0.85rem;
  background: var(--sophie-cream);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  border: 1px solid rgba(27, 58, 47, 0.15);
}
.sophie-typing span {
  width: 7px;
  height: 7px;
  background: var(--sophie-deep);
  border-radius: 50%;
  animation: sophie-dot 1.2s infinite ease-in-out both;
}
.sophie-typing span:nth-child(2) { animation-delay: 0.15s; }
.sophie-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes sophie-dot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ---------- Input ---------- */
.sophie-input-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.7rem 0.8rem;
  background: var(--sophie-cream);
  border-top: 1px solid rgba(27, 58, 47, 0.2);
}
.sophie-input-row input {
  flex: 1;
  padding: 0.65rem 0.85rem;
  border: 2px solid rgba(27, 58, 47, 0.25);
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  background: var(--sophie-paper);
  color: var(--sophie-ink);
  outline: none;
  transition: border-color 0.15s;
}
.sophie-input-row input:focus { border-color: var(--sophie-gold); }
.sophie-input-row button {
  background: var(--sophie-deep);
  color: var(--sophie-paper);
  border: none;
  border-radius: 12px;
  padding: 0 1rem;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s;
}
.sophie-input-row button:hover { background: #0f2820; }
.sophie-input-row button:disabled { opacity: 0.5; cursor: wait; }

/* ---------- Suggestion chips ---------- */
.sophie-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 0.9rem 0.6rem;
}
.sophie-chips button {
  background: var(--sophie-paper);
  border: 1px solid var(--sophie-gold);
  color: var(--sophie-deep);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.82rem;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.sophie-chips button:hover {
  background: var(--sophie-gold);
}

/* ---------- Coin pop animation ---------- */
.sophie-coin-pop {
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 800;
  color: var(--sophie-gold);
  font-size: 1.4rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
  animation: sophie-coin-rise 1.4s ease-out forwards;
}
@keyframes sophie-coin-rise {
  0% { transform: translateY(0) scale(0.8); opacity: 0; }
  20% { transform: translateY(-10px) scale(1.1); opacity: 1; }
  100% { transform: translateY(-80px) scale(1); opacity: 0; }
}

/* ---------- Rank-up toast ---------- */
.sophie-toast {
  position: fixed;
  top: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--sophie-deep);
  color: var(--sophie-paper);
  border: 2px solid var(--sophie-gold);
  border-radius: 14px;
  padding: 0.9rem 1.4rem;
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 700;
  font-size: 1.05rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 10001;
  animation: sophie-toast 4s ease forwards;
  text-align: center;
  max-width: 90vw;
}
.sophie-toast small {
  display: block;
  font-family: "Source Sans 3", sans-serif;
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--sophie-gold);
  margin-top: 4px;
  letter-spacing: 0.05em;
}
@keyframes sophie-toast {
  0% { transform: translate(-50%, -30px); opacity: 0; }
  10%, 85% { transform: translate(-50%, 0); opacity: 1; }
  100% { transform: translate(-50%, -30px); opacity: 0; }
}
