:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f3f4f6;
  color: #111827;
}

body {
  margin: 0;
  display: flex;
  min-height: 100vh;
  justify-content: center;
  align-items: center;
  padding: 24px;
}

/* 1. Let the whole app fill the viewport height */
.app {
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.12);
  max-width: 960px;
  width: 100%;
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 0;
  /* overflow: hidden;   <-- remove or comment this out */
  /*height: 100vh;         /* new */  
}

/* 2. Make the left column sticky */
.expert-panel {
  background: #111827;
  color: #e5e7eb;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  row-gap: 16px;

  position: sticky;  /* new */
  top: 0;            /* new */
  align-self: flex-start; /* helps in grid layouts */
}

.sprite-frame {
  position: relative;
  overflow: hidden;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  width: 300px;   /* will be updated by JS to exact tile size */
  height: 300px;  /* will be updated by JS to exact tile size */
}

.sprite-frame img {
  display: block;
  object-fit: none;
  object-position: 0 0;
  position: absolute;
  top: 0;
  left: 0;
}

.expert-name {
  font-weight: 600;
  font-size: 1.05rem;
}

.expert-role {
  font-size: 0.85rem;
  opacity: 0.8;
}

.expression-label {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #9ca3af;
}

.expression-value {
  font-size: 0.9rem;
  font-weight: 500;
  color: #e5e7eb;
}

.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

button {
  border-radius: 999px;
  border: none;
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  background: #10b981;
  color: #ecfdf5;
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.35);
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

button.secondary {
  background: #374151;
  color: #e5e7eb;
  box-shadow: none;
}

button:active {
  transform: translateY(1px);
  box-shadow: 0 3px 10px rgba(16, 185, 129, 0.45);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
  box-shadow: none;
}

/* Right panel – chat */
.chat-panel {
  padding: 24px 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-header {
  margin-bottom: 4px;
}

.chat-header h1 {
  margin: 0;
  font-size: 1.25rem;
}

.chat-header p {
  margin: 2px 0 0;
  font-size: 0.9rem;
  color: #6b7280;
}

.chat-window {
  flex: 1;
  background: #f9fafb;
  border-radius: 12px;
  padding: 16px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
}

.message-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.message-row.expert {
  justify-content: flex-start;
}

.message-row.user {
  justify-content: flex-end;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar.expert {
  background: #111827;
  color: #f9fafb;
  font-size: 0.8rem;
  font-weight: 600;
}

.avatar.user {
  background: #e5e7eb;
  color: #4b5563;
}

/* Simple head-and-shoulders silhouette */
/* The container for the silhouette icon */
.user-silhouette {
  position: relative;   /* allows absolute-positioned head + body inside */
  width: 18px;          /* overall icon width */
  height: 20px;         /* overall icon height (slightly taller than before) */
}

/* Shared base style for both head (before) and torso (after) */
.user-silhouette::before,
.user-silhouette::after {
  content: "";                  /* generates the pseudo-elements */
  position: absolute;           /* position relative to .user-silhouette */
  left: 50%;                    /* start centered horizontally */
  transform: translateX(-50%);  /* correct the centering exactly */
  background: #4b5563;          /* dark grey silhouette color */
}

/* HEAD + HAIR shape */
.user-silhouette::before {
  top: 1px;                     /* small gap from top for nicer balance */
  width: 12px;                  /* head width */
  height: 12px;                 /* head height */
  border-radius: 50%;           /* circular head */

  /* creates “hair volume” under the head by adding a shadow block */
  box-shadow: 0 4px 0 0 #4b5563;  /* downward shadow = hair covering neck */
}

/* SHOULDERS + UPPER TORSO */
.user-silhouette::after {
  bottom: 0;                    /* sit at the bottom of the container */
  width: 14px;                  /* slightly narrower shoulders than male silhouette */
  height: 9px;                  /* torso/shoulder height */
  border-radius: 999px 999px 4px 4px;  
  /* rounded top corners (shoulders), 
     slightly flatter bottom corners for a natural torso shape */
}

.bubble {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.4;
  position: relative;
}

.message-row.expert .bubble {
  background: #111827;
  color: #e5e7eb;
  border-bottom-left-radius: 4px;
}

.message-row.user .bubble {
  background: #e5e7eb;
  color: #111827;
  border-bottom-right-radius: 4px;
}

.status-line {
  font-size: 0.75rem;
  color: #6b7280;
  margin-top: 4px;
  min-height: 1em;
}

.bubble p {
  margin: 0 0 6px;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble ul {
  margin: 0 0 6px 16px;
  padding-left: 12px;
}

.bubble code {
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.85em;
}

.bubble pre {
  background: rgba(0, 0, 0, 0.08);
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.85em;
}

.bubble.loading {
  min-width: 48px;
}

.loading-ellipsis {
  display: inline-flex;
  gap: 3px;
}

.loading-ellipsis span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.4;
  animation: ellipsis-blink 1.2s infinite;
}

.loading-ellipsis span:nth-child(2) {
  animation-delay: 0.2s;
}

.loading-ellipsis span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes ellipsis-blink {
  0%, 20% { opacity: 0.2; transform: translateY(0); }
  40% { opacity: 0.9; transform: translateY(-2px); }
  60% { opacity: 0.6; transform: translateY(0); }
  100% { opacity: 0.2; transform: translateY(0); }
}

.bubble h1,
.bubble h2,
.bubble h3 {
  margin: 0 0 6px;
  line-height: 1.2;
}

.bubble h1 { font-size: 1.2rem; }
.bubble h2 { font-size: 1.1rem; }
.bubble h3 { font-size: 1rem; }

.legend {
  margin-top: 12px;
  font-size: 0.75rem;
  color: #9ca3af;
}

.legend span {
  font-family: "Fira Code", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  background: #111827;
  color: #e5e7eb;
  border-radius: 6px;
  padding: 2px 6px;
  margin-right: 4px;
  font-size: 0.7rem;
}

.input-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.input-row textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid #d1d5db;
  padding: 10px 12px;
  font-size: 0.95rem;
  resize: vertical;
  min-height: 84px;
  font-family: inherit;
}

.input-actions {
  display: flex;
  justify-content: flex-end;
}

@media (max-width: 780px) {
  .app {
    grid-template-columns: 1fr;
  }

  .expert-panel {
    flex-direction: row;
    justify-content: flex-start;
    column-gap: 16px;
  }

  .expert-panel-inner {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
}

/* Reusable hidden helper */
.hidden {
  display: none !important;
}

/* Full-screen overlay banner */
.rotate-banner {
  position: fixed;
  inset: 0;
  background: #111827;
  color: #f9fafb;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.rotate-banner-content {
  max-width: 600px;
  border-radius: 16px;
  border: 2px dashed #f9fafb;
  padding: 24px 32px;
  font-size: 3rem;
  font-weight: 700;
  line-height: 1.4;
}


/* Removes the old shape-making CSS if it still exists */
.user-silhouette {
  display: none;
}

/* New female silhouette image */
.user-silhouette-img {
  width: 18px;               /* same width as old silhouette */
  height: 18px;              /* same height */
  object-fit: cover;         /* ensures the image fills the circle nicely */
  border-radius: 50%;        /* makes the image circular */
  background: #b3cbec;       /* fallback circle color if PNG has transparency */
  padding: 2px;              /* optional: adds a small margin inside circle */
  display: block;            /* avoids weird inline-gap spacing */
}
