/* The floating chat (js/ui/chat.js): a button at the bottom right and a panel; a full-screen sheet on a phone */

#chat-root[hidden], #chat-root [hidden] { display: none !important; }

/* The player can drag it (js/ui/chat.js): it rests on the left or right edge, at the distance from the bottom that
   #chat-root carries in --fab-bottom, never lower than --fab-min (above the bottom bar on a phone) nor off the top */
.chat-fab {
  --fab-min: calc(16px + env(safe-area-inset-bottom));
  position: fixed; z-index: 150; /* above the bars (100), under everything that takes the screen: stories (200), modals (1000), the menu, search */
  touch-action: none; user-select: none; -webkit-user-select: none;
  right: calc(16px + env(safe-area-inset-right)); bottom: clamp(var(--fab-min), var(--fab-bottom, 0px), calc(100dvh - 72px));
  width: 56px; height: 56px; border: none; border-radius: 50%; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--gradient-brand); color: #0a0a14; box-shadow: var(--shadow-btn), var(--shadow-card);
  transition: transform 0.15s ease;
}
#chat-root[data-side="left"] .chat-fab { right: auto; left: calc(16px + env(safe-area-inset-left)); }
.chat-fab.dragging { transition: none; cursor: grabbing; transform: scale(1.08); }
/* Above the bottom bar of a phone (css/navbar.css) */
@media (max-width: 640px) { .chat-fab { --fab-min: calc(72px + env(safe-area-inset-bottom)); } }
.chat-fab:hover { transform: scale(1.06); }
.chat-fab:focus-visible, .chat-icon-btn:focus-visible, .chat-chip:focus-visible, .chat-send:focus-visible { outline: 2px solid var(--accent-teal); outline-offset: 2px; }

/* On a phone it is the visual viewport, which the keyboard shrinks (js/ui/chat.js sets --chat-top and --chat-height) */
.chat-panel {
  position: fixed; z-index: 160; top: var(--chat-top, 0); left: 0; right: 0; display: flex; flex-direction: column;
  height: var(--chat-height, 100dvh); background: var(--bg-surface); animation: chat-in 0.18s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (max-width: 599px) { body.chat-open { overflow: hidden; } }
@keyframes chat-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

@media (min-width: 600px) {
  .chat-panel {
    inset: auto; right: calc(20px + env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom));
    width: 380px; height: min(560px, calc(100dvh - 40px));
    border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); overflow: hidden;
  }
}

.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: none;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px 16px; border-bottom: 1px solid var(--border);
}
@media (min-width: 600px) { .chat-head { padding-top: 10px; } }
.chat-head strong { font-size: 1.05rem; background: var(--gradient-brand); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.chat-head-actions { display: inline-flex; gap: 2px; }
.chat-icon-btn {
  width: 40px; height: 40px; border: none; border-radius: 50%; background: none; cursor: pointer; font-size: 1.1rem;
  color: var(--text-secondary); display: inline-flex; align-items: center; justify-content: center;
}
.chat-icon-btn:hover { color: var(--text-primary); background: var(--bg-card-hover); }

.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 14px 6px; display: flex; flex-direction: column; gap: 8px; overscroll-behavior: contain; }
.chat-msg { max-width: 88%; padding: 9px 13px; border-radius: var(--radius-md); font-size: 0.94rem; line-height: 1.45; overflow-wrap: anywhere; }
.chat-me { align-self: flex-end; white-space: pre-wrap; background: rgba(61, 217, 179, 0.16); border: 1px solid var(--border-accent); border-bottom-right-radius: 4px; }
.chat-bot { align-self: flex-start; background: var(--bg-card); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-bot > :is(p, ul, ol) + :is(p, ul, ol) { margin-top: 6px; } /* between the blocks of an answer, not the dots of the typing indicator */
.chat-bot ul, .chat-bot ol { padding-left: 20px; }
.chat-bot code { padding: 1px 5px; border-radius: 5px; background: rgba(255, 255, 255, 0.08); font-size: 0.9em; }
.chat-error { align-self: flex-start; color: #fca5a5; background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.35); }

.chat-welcome { color: var(--text-secondary); font-size: 0.94rem; }
.chat-welcome strong { color: var(--text-primary); }
.chat-suggestions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: 12px; }
.chat-chip {
  max-width: 100%; padding: 7px 12px; border: 1px solid var(--border-accent); border-radius: var(--radius-pill);
  background: none; color: var(--accent-teal); font: inherit; font-size: 0.88rem; text-align: left; cursor: pointer;
}
.chat-chip:hover { background: rgba(61, 217, 179, 0.1); }

.chat-typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.chat-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-secondary); animation: chat-dot 1s infinite ease-in-out; }
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-dot { 0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .chat-panel, .chat-typing span { animation: none; } .chat-fab { transition: none; } }

.chat-form { flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid var(--border); }
.chat-input {
  flex: 1; min-width: 0; resize: none; max-height: 120px; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-card); color: var(--text-primary); font: inherit; font-size: 1rem; line-height: 1.4;
}
.chat-input:focus { outline: none; border-color: var(--accent-teal); }
.chat-send {
  flex: none; width: 42px; height: 42px; border: none; border-radius: 50%; cursor: pointer; font-size: 1rem;
  background: var(--gradient-brand); color: #0a0a14;
}
.chat-send:disabled, .chat-input:disabled { opacity: 0.5; cursor: default; }

/* The game guide: a card on the game page that reuses the chat's bubbles and box */
.gd-card { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.gd-intro { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.gd-levels { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; border: none; padding: 0; margin: 0; }
.gd-level { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.gd-log { flex: none; max-height: 420px; padding: 4px 0; }
.gd-form { padding: 0; border-top: none; }
.gd-reset { align-self: flex-start; }
.gd-modal .gd-log { max-height: 50vh; }
/* The way into the guide from the running timer: an outlined pill in the accent colour, on its own line under the start time */
.timer-guide-btn {
  display: flex; width: fit-content; align-items: center; gap: 7px; margin-top: 12px; padding: 7px 14px;
  border: 1px solid var(--border-accent); border-radius: var(--radius-pill); background: rgba(61, 217, 179, 0.06);
  color: var(--accent-teal); font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer;
}
.timer-guide-btn:hover { background: rgba(61, 217, 179, 0.14); }
.timer-guide-btn[hidden] { display: none; }
@media (max-width: 640px) { .timer-guide-btn { margin-inline: auto; } }
