/* === RESET === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    background-color: #fff;
    color: #000;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.6;
}

/* === PAGE LOADER === */
.page-loader {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    background: rgba(255, 255, 255, 0.96);
    color: #000;
}

.page-loader .spinner {
    width: 42px;
    height: 42px;
    border: 3px solid #000;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

.page-loader .loader-title {
    font-size: 1.05rem;
    font-weight: 600;
}

.page-loader .loader-subtitle {
    font-size: 0.9rem;
    opacity: 0.7;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}



/* === CONTAINER === */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 860px;
    margin: 0 auto;
    padding-top: 1rem;
    padding-bottom: 60px; /* room for fixed input */
}

.chat-container.has-guest-topbar {
    padding-top: 5rem;
}

.guest-topbar {
    position: fixed;
    top: max(0.55rem, env(safe-area-inset-top));
    left: max(0.55rem, env(safe-area-inset-left));
    right: max(0.55rem, env(safe-area-inset-right));
    z-index: 950;
    padding: 0.36rem 0.85rem;
    border: 1px solid #bfdbfe;
    border-radius: 14px;
    background: rgba(239, 246, 255, 0.96);
    backdrop-filter: blur(14px);
    box-shadow: 0 14px 28px rgba(148, 163, 184, 0.22);
    color: #0f172a;
}

.guest-topbar-inner {
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    justify-content: space-between;
    min-height: 2.1rem;
}

.guest-topbar-copy {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.8rem;
    line-height: 1.1;
}

.guest-topbar-label {
    color: #0f172a;
    font-weight: 700;
    flex-shrink: 0;
}

.guest-topbar-detail {
    color: #475569;
    overflow: hidden;
    text-overflow: ellipsis;
}

.guest-topbar-detail-mobile {
    display: none;
}

.guest-topbar-cta,
.guest-save-prompt-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 1.95rem;
    padding: 0.32rem 0.82rem;
    border-radius: 999px;
    border: 1px solid #1d4ed8;
    background: #1d4ed8;
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.79rem;
    letter-spacing: 0.01em;
    white-space: nowrap;
    flex-shrink: 0;
    box-shadow: none;
}

.guest-topbar-cta-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.15rem;
    height: 1.15rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.96);
    color: #1d4ed8;
    font-size: 0.72rem;
    font-weight: 800;
}

.guest-topbar-cta:hover,
.guest-save-prompt-link:hover {
    background: #fff;
    color: #1d4ed8;
}

.guest-save-prompt {
    margin: 0 0 1.15rem;
    padding: 0.78rem 0.85rem;
    border: 1px solid #bfdbfe;
    border-radius: 10px;
    background: #eff6ff;
    color: #0f172a;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    font-size: 0.87rem;
    line-height: 1.35;
}

.survey-code-banner {
    margin: 0.3rem 1rem 0.2rem;
    padding: 0.38rem 0.55rem;
    border: 1px solid #d1d5db;
    border-radius: 7px;
    background: #f9fafb;
    color: #111827;
    font-size: 0.84rem;
    line-height: 1.25;
}

.survey-code-banner-copy {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
    flex-wrap: wrap;
}

.survey-code-banner code {
    padding: 0.04rem 0.28rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    font-size: 0.78rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.survey-code-note {
    margin: 0;
    font-size: 0.76rem;
    color: #6b7280;
}

/* === CHAT BOX === */
#chat-box {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding-bottom: 3rem;
}

.message {
    white-space: normal;
    word-wrap: break-word;
    padding: 1rem;
    
    background-color: #fff;
    color: #000;
}

.message.ai {
    margin-right: 0%;
    list-style: none;
}


.message.user {
    margin-left: 0%;
    text-align: right;
    border: 1px solid #000;
}

/* === FIXED INPUT AREA === */
.input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #fff;
    border-top: 1px solid #000;
    padding: 0.5rem 1rem;
}

.input-wrapper {
    max-width: 680px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap; /* keep everything on one line */
    width: 100%;
}


/* === MOBILE RESPONSIVE LAYOUT === */
@media (max-width: 600px) {
  .chat-container.has-guest-topbar {
    padding-top: 5.15rem;
  }

  .guest-topbar {
    top: max(0.45rem, env(safe-area-inset-top));
    left: max(0.45rem, env(safe-area-inset-left));
    right: max(0.45rem, env(safe-area-inset-right));
    padding: 0.28rem 0.42rem;
  }

  .guest-topbar-inner {
    justify-content: space-between;
    gap: 0.5rem;
    min-height: 2.35rem;
  }

  .guest-topbar-copy {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.14rem;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    font-size: 0.71rem;
    line-height: 1.18;
  }

  .guest-topbar-detail-desktop {
    display: none;
  }

  .guest-topbar-detail-mobile {
    display: block;
    overflow: visible;
    text-overflow: clip;
  }

  .guest-topbar-cta {
    min-height: 1.78rem;
    padding: 0.28rem 0.72rem;
    font-size: 0.71rem;
  }

  .guest-save-prompt {
    margin: 0 0 1rem;
    padding: 0.55rem 0.6rem;
    font-size: 0.78rem;
  }

  .guest-save-prompt-link {
    min-height: 1.9rem;
    width: auto;
  }

  .survey-code-banner {
    margin: 0.25rem 0.55rem 0.15rem;
    padding: 0.3rem 0.42rem;
    font-size: 0.78rem;
  }

  .survey-code-banner code {
    font-size: 0.72rem;
  }

  .survey-code-note {
    font-size: 0.72rem;
  }

  .input-area {
    padding: 0.6rem 0.6rem; /* slightly tighter padding */
  }

  .input-wrapper {
    gap: 0.4rem;
  }

  #question {
    font-size: 1rem;
    padding: 0.6rem 0.8rem;
    height: 3rem;
  }

  .slash-btn,
  #quiz-btn {
    height: 3rem;
    padding: 0 0.8rem;
    font-size: 1rem;
    flex-shrink: 0; /* prevent them from shrinking weirdly */
  }

  /* prevent buttons from wrapping or pushing textarea */
  .input-wrapper {
    flex-wrap: nowrap;
    overflow: hidden;
  }

  /* make textarea the flexible one */
  #question {
    flex: 1 1 auto;
    min-width: 0; /* required so it can shrink on small screens */
  }
}

/* === TEXTAREA === */
#question {
    flex: 1;
    font-family: 'monospace', serif;
    font-size: 1rem;
    padding: 0.6rem 1rem;
    border: 1px solid #000;
    background: #fff;
    color: #000;
    resize: none;
    height: 2.4rem;
}

/* === SLASH BUTTON === */
.slash-btn {
    background: #fff;
    border: 1px solid #000;
    color: #000;
    font-size: 1rem;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
}

/* === SEND BUTTON === */
.input-area > button {
    background: #000;
    color: #fff;
    border: none;
    font-size: 1rem;
    padding: 0.6rem 1rem;
    cursor: pointer;
}


.input-area > button:hover {
    opacity: 0.8; /* subtle hover effect since it's already black */
}


/* === /QUIZ BUTTON — Theme-aware throb matching index.html === */
#quiz-btn {
  border-radius: 10px;
  font-weight: 600;
  font-size: 1rem;
  padding: 0.6rem 1.4rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.3s ease;
  /* animation: pulse-glow 3s ease-in-out infinite; */
  background: #000;
  color: #fff;
}

#quiz-btn:hover {
  background: #000;
  color: #fff;
  border-color: #000;
  box-shadow: 0 0 12px rgba(0,0,0,0.3);
}

/* === Theme overrides === */

:root[data-theme="dark"] #quiz-btn {
  background: #00b4ff;
  color: #0a0f14; /* deep navy-gray for smoother contrast */
  border: 1px solid rgba(0,180,255,0.8);
  box-shadow: 0 0 16px rgba(0,180,255,0.7);
}

:root[data-theme="dark"] #quiz-btn:hover {
  background: #000 !important;
  color: #00b4ff !important;
  border-color: #00b4ff !important;
  box-shadow: 0 0 18px rgba(0,180,255,0.8) !important;
}

:root[data-theme="red"] #quiz-btn {
  background: #f70072;
  color: #fef3fa;
  border: 1px solid rgba(247, 0, 114, 0.8);
  box-shadow: 0 0 16px rgba(247, 0, 114, 0.7);
}

:root[data-theme="red"] #quiz-btn:hover {
  background: #000 !important;
  color: #f70072 !important;
  border-color: #f70072 !important;
  box-shadow: 0 0 18px rgba(247, 0, 114, 0.8) !important;
}

/* === Pulse keyframes (imported from index.html for consistency) === */
@keyframes pulse-glow {
  0%   { box-shadow: 0 0 6px rgba(0,0,0,0.2); transform: scale(1); }
  50%  { box-shadow: 0 0 16px rgba(0,0,0,0.35); transform: scale(1.02); }
  100% { box-shadow: 0 0 6px rgba(0,0,0,0.2); transform: scale(1); }
}

@keyframes pulse-blue {
  0%   { box-shadow: 0 0 6px rgba(0,180,255,0.6); transform: scale(1); }
  50%  { box-shadow: 0 0 12px rgba(0,180,255,0.9); transform: scale(1.03); }
  100% { box-shadow: 0 0 6px rgba(0,180,255,0.6); transform: scale(1); }
}

@keyframes pulse-red {
  0%   { box-shadow: 0 0 6px rgba(255,40,40,0.6); transform: scale(1); }
  50%  { box-shadow: 0 0 12px rgba(255,40,40,0.9); transform: scale(1.03); }
  100% { box-shadow: 0 0 6px rgba(255,40,40,0.6); transform: scale(1); }
}

/* === INLINE QUIZ BUTTONS === */
.chat-btn {

    width: 100%;
    text-align: left;
    font-size: 1rem;
    font-family: 'monospace', serif;
    background: #fff;
    color: #000;
    border: 1px solid #000;
    padding: 0.75rem 1rem;
    margin-top: 0.8rem;
    cursor: pointer;
}

.message.ai .chat-btn:last-of-type {
    margin-bottom: 1rem;
}

.chat-btn sup {
    font-size: 0.72em;
    line-height: 0;
    vertical-align: super;
}

.chat-btn.selected {
    font-weight: bold;
    background: #000;
    color: #fff;
}


.chat-btn:hover {
    background: #000;
    color: #fff;
}

.chat-btn:disabled,
.chat-btn[aria-disabled="true"] {
    background: #f3f4f6;
    border-color: #d1d5db;
    color: #6b7280;
    opacity: 1;
    cursor: not-allowed;
}

.chat-inline-command {
    color: inherit;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    opacity: 0.84;
    cursor: pointer;
}

.chat-inline-command:hover {
    opacity: 1;
}

.slash-command-btn .slash-cmd-name {
    display: block;
}

.slash-command-btn .slash-cmd-help {
    display: block;
    margin-top: 0.2rem;
    font-size: 0.78rem;
    line-height: 1.25;
    font-weight: 400;
    opacity: 0.68;
}

.oops-flag-wrap {
    margin-top: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.oops-flag-btn {
    -webkit-appearance: none;
    appearance: none;
    border: 0 !important;
    background: transparent !important;
    color: #676767;
    font-family: 'monospace', serif;
    font-size: 0.78rem;
    letter-spacing: 0.01em;
    line-height: 1.2;
    padding: 0.1rem 0.2rem;
    cursor: pointer;
    border-radius: 0;
    opacity: 0.78;
    text-decoration: underline;
    text-underline-offset: 0.14em;
    transition: color 0.2s ease, opacity 0.2s ease;
}

.oops-flag-btn:hover {
    background: transparent !important;
    border: 0 !important;
    color: #2a2a2a;
    opacity: 1;
}

.oops-flag-btn.flagged {
    background: transparent !important;
    border: 0 !important;
    color: #111;
    font-weight: 600;
    opacity: 1;
}

.oops-flag-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.oops-flag-status {
    font-size: 0.78rem;
    opacity: 0.7;
    color: #6f6f6f;
}

.calc-chat-prompt {
    margin-top: 0.7rem;
}

.calc-chat-hint {
    font-size: 0.92rem;
    opacity: 0.72;
}

.calc-chat-example {
    margin-top: 0.2rem;
    font-size: 0.86rem;
    opacity: 0.62;
}

.calc-chat-example span {
    font-family: monospace;
}

.calc-chat-status {
    margin-top: 0.18rem;
    font-size: 0.8rem;
    opacity: 0.72;
}

.oops-note-wrap {
    margin-top: 0.55rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

html.superuser-notes-hidden .oops-note-wrap {
    display: none !important;
}

.oops-note-label {
    font-size: 0.8rem;
    opacity: 0.8;
}

.oops-note-input {
    width: 100%;
    max-width: 560px;
    border: 1px solid #000;
    padding: 0.5rem;
    font-family: monospace;
    font-size: 0.9rem;
    background: #fff;
    color: #000;
    resize: vertical;
}

.oops-note-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.oops-note-save-btn {
    border: 1px solid #000;
    background: #fff;
    color: #000;
    font-family: monospace;
    font-size: 0.85rem;
    padding: 0.35rem 0.65rem;
    cursor: pointer;
}

.oops-note-save-btn:hover {
    background: #000;
    color: #fff;
}

.oops-note-save-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.oops-note-status {
    font-size: 0.82rem;
    opacity: 0.75;
}

/* === COMMAND SUGGESTIONS === */
.command-suggestions {
    position: absolute;
    bottom: 110%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #000;
    font-family: monospace;
    font-size: 0.9rem;
    z-index: 10;
}

.command-suggestions.hidden {
    display: none;
}

.command-suggestion-item {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #000;
    cursor: pointer;
}

.command-suggestion-item.active {
    background: #000;
    color: #fff;
}


.input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #fff;
    border-top: 1px solid #000;
    padding: 0.9rem 1.2rem; /* increased vertical padding */
}

.input-wrapper {
    max-width: 680px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 0.75rem; /* slightly more spacing between elements */
}

.input-wrapper {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 0.5rem;
}

/* Make textarea fill remaining space */
/* === TEXTAREA === */
#question {
    flex: 1;
    height: 3.4rem;          /* consistent height with buttons */
    padding: 1rem 1.2rem;    /* comfortable vertical space */
    font-family: monospace, serif;
    font-size: 1.2rem;       /* larger, readable text */
    border: 1px solid #000;
    background: #fff;
    color: #000;
    resize: none;
}

/* === SLASH & QUIZ BUTTONS === */
.slash-btn,
#quiz-btn {
    height: 3.4rem;          /* perfectly matches textarea */
    padding: 0 1.2rem;
    background: #fff;
    border: 1px solid #000;
    color: #000;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.25s ease;
}

/* === Hover Effects === */
.slash-btn:hover,
#quiz-btn:hover {
    background: #000;
    color: #fff;
}

/* Send button */
.input-area > button {
    margin-left: 0.5rem;
    height: 2.4rem;
    padding: 0 1rem;
    background: #000;
    color: #fff;
    border: none;
    font-size: 1rem;
    cursor: pointer;
}

textarea,
.slash-btn,
.input-wrapper > button:last-child {
    /* height: 2.6rem; */
    padding: 0.5rem 0.75rem;
    line-height: 1.2;
}

.hidden {
    display: none;
}

div.message ul {
    list-style: disc;       /* keep bullets */
    padding-left: 1.5rem;   /* standard bullet indent */
}

div.message ul li {
    margin-left: 0.5rem;    /* extra space if you want more indent */
}

div.message ol {
    padding-left:1.5rem;
}

div.message ul li ul {
    list-style: circle;     /* keep your nested list style */
    margin-left: 1.5rem;    /* nested list indentation */
}

.message.user {
    white-space: unset;
}

.thinking-dots::after {
  content: "";
  animation: thinking-dots 1.2s steps(4, end) infinite;
}

@keyframes thinking-dots {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%  { content: "..."; }
  100% { content: ""; }
}

/* Fade-in for AI messages */
.message.ai {
  animation: ai-fade-in 0.5s ease-out;
}

@keyframes ai-fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.dark-mode {
    background-color: #121212;
    color: #e0e0e0;
}

.dark-mode .message {
    background-color: #1e1e1e;
    border-color: #333;
}

#chat-box {
    overflow-y: auto;
    scroll-behavior: smooth;
    padding-right: 6px;
    transition: scrollbar-color 0.5s ease, opacity 0.5s ease;
}

/* WebKit browsers (Chrome, Edge, Safari) */
#chat-box::-webkit-scrollbar {
    width: 8px;
}

#chat-box::-webkit-scrollbar-track {
    background: transparent;
}

#chat-box::-webkit-scrollbar-thumb {
    background: rgba(120, 120, 120, 0.5);
    border-radius: 4px;
    transition: background 0.3s;
}

#chat-box::-webkit-scrollbar-thumb:hover {
    background: rgba(150, 150, 150, 0.8);
}

/* Firefox */
#chat-box {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

/* Hide scrollbar by default */
#chat-box.hide-scrollbar::-webkit-scrollbar-thumb {
    background: transparent;
}
#chat-box.hide-scrollbar {
    scrollbar-color: transparent transparent;
}

/* Keep the list on top of everything, even when the keyboard shifts layout */
#command-list {
  position: fixed;            /* avoid reflow jumps near the keyboard */
  z-index: 9999;
  max-height: 40dvh;          /* dynamic viewport units handle mobile keyboards */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Make taps easier to hit */
#command-list [data-cmd] {
  min-height: 44px;           /* Apple HIG tap target */
  display: flex;
  align-items: center;
  padding: 10px 14px;
}

/* === CALCULATION TOGGLE === */
.calculation-wrapper {
  margin-top: 1rem;
  margin: 0;
}

.toggle-calc-btn {
  display: block;
  width: 100%;
  text-align: left;
  font-size: 1rem;
  font-family: 'monospace', serif;
  background: #fff;
  color: #000;
  border: 1px solid #000;
  padding: 0.75rem 1rem;
  margin: 0.75rem 0;
  cursor: pointer;
}

/* Hide calculation toggle button in AI responses */
.message.ai .toggle-calc-btn {
  display: none;
}

.toggle-calc-btn:hover {
  background: #000;
  color: #fff;
}

.calculation-block {
  font-family: 'monospace', serif;
  font-size: 1rem;
  white-space: pre-wrap;
  margin: 0;              /* remove default browser pre margins */
  padding: 0.75rem 1rem;
  margin: 0.75rem 0;
  border: 1px solid #000;
  background: #fff;
}

.continue-quiz-wrapper {
  margin-top: 2px;   /* much tighter spacing */
}

.continue-quiz-wrapper .chat-btn {
  margin-top: 0;
  background: #f4f4f4;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 0.9em;
  cursor: pointer;
  transition: background 0.2s;
}

.continue-quiz-wrapper .chat-btn:hover {
  background: #e6e6e6;
}

/* === FORCE STYLE OVERRIDE FOR USER MESSAGES === */
/* === FINAL OVERRIDE (any element with both classes) === */
.message.user {
    background: #fff;
    color: #000;
    border: 1px solid #000;
    border-radius: 6px;
    padding: 0.75rem 1rem;
    display: inline-block;
    text-align: right;
    margin-left: auto;
    max-width: 80%;
    line-height: 1.5;
}

/* === CONTINUE QUIZ BUTTON: FORCE SAME STYLE AS chat-btn === */
.continue-quiz-wrapper .chat-btn {
    width: 100%;
    text-align: left;
    font-size: 1rem;
    font-family: 'monospace', serif;
    background: #fff;
    color: #000;
    border: 1px solid #000;
    padding: 0.75rem 1rem;
    margin-top: 0.8rem;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
}

.continue-quiz-wrapper .chat-btn:hover {
    background: #000;
    color: #fff;
}

.message.ai.continue-quiz {
  padding: 0 !important;
  margin-top: -1.5rem !important;
  margin-bottom: -1.5rem !important;
}

.message.ai.continue-quiz .chat-btn {
  margin: 0 !important;
}

/* === USER MESSAGE ALIGNMENT === */
.message.user {
    background: #fff;
    color: #000;
    border: 1px solid #000;
    border-radius: 6px;
    padding: 0.75rem 1rem;
    display: inline-block;
    text-align: right;
    margin-left: auto;          /* pushes it to the right */
    margin-right: 1rem;         /* align with chat content's right padding */
    max-width: 80%;
    line-height: 1.5;
}

/* --- Prevent blue Markdown headings from AI messages --- */
.message.ai h1,
.message.ai h2,
.message.ai h3,
.message.ai h4,
.message.ai h5,
.message.ai h6 {
  color: #000 !important;     /* force black text */
  font-size: 1.2rem;            /* normal text size */
  font-weight: 600;           /* slightly bold, like a section title */
  margin: 0.75rem 0 0.25rem;  /* tidy spacing */
}

/* === Ensure AI message headings match body text === */
.message.ai h1,
.message.ai h2,
.message.ai h3,
.message.ai h4,
.message.ai h5,
.message.ai h6 {
  color: inherit !important;     /* ✅ inherit the same color as normal text */
  font-weight: 600;              /* consistent emphasis, not bold blue */
  margin: 0.6rem 0 0.25rem;      /* tidy spacing */
  font-size: 1.1rem;             /* slightly larger, not huge */
  line-height: 1.4;
}

/* === Center all chat messages symmetrically === */
#chat-box {
  display: flex;
  flex-direction: column;
  align-items: center; /* ✅ ensures both AI and user messages are centered logically */
  padding-left: 1rem;
  padding-right: 1rem;
}

/* AI messages: left-aligned within centered column */
.message.ai {
  align-self: flex-start;
  margin-left: 0;
  margin-right: 0;
  width: 100%;
}

/* User messages: right-aligned within centered column, perfectly symmetrical */
.message.user {
  align-self: flex-end;
  margin-right: 0;
  margin-left: 0;
  max-width: 80%;
  text-align: right;
}

/* === LIGHT THEME: subtle container contrast (parity with dark mode cards) === */
:root:not([data-theme="dark"]):not([data-theme="red"]) .message.ai {
  background: #fcfcfd;
  border: 1px solid #d7dbe3;
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04), 0 4px 14px rgba(15, 23, 42, 0.04);
}

:root:not([data-theme="dark"]):not([data-theme="red"]) .message.user {
  background: #ffffff;
  border: 1px solid #b7bfcc;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.05);
}

#quiz-btn.disabled {
  opacity: 0.5;
  pointer-events: none;
  cursor: not-allowed;
}

/* Paired summary card (compact, touch-friendly, theme-aware) */
:root {
  --paired-surface: #ffffff;
  --paired-surface-soft: #f8fafc;
  --paired-border: #cfd6e3;
  --paired-border-soft: #e5e7eb;
  --paired-text: #111827;
  --paired-muted: #4b5563;
  --paired-chip-bg: #ffffff;
  --paired-chip-text: #111827;
  --paired-chip-border: #94a3b8;
  --paired-chip-active-bg: #111827;
  --paired-chip-active-text: #ffffff;
  --paired-meter-bg: #e5e7eb;
  --paired-focus-ring: rgba(37, 99, 235, 0.38);
  --paired-ok: #16a34a;
  --paired-bad: #dc2626;
}

:root[data-theme="dark"] {
  --paired-surface: #10151f;
  --paired-surface-soft: #131b27;
  --paired-border: #334155;
  --paired-border-soft: #334155;
  --paired-text: #e5e7eb;
  --paired-muted: #94a3b8;
  --paired-chip-bg: #10151f;
  --paired-chip-text: #e5e7eb;
  --paired-chip-border: #64748b;
  --paired-chip-active-bg: #e2e8f0;
  --paired-chip-active-text: #0f172a;
  --paired-meter-bg: #334155;
  --paired-focus-ring: rgba(56, 189, 248, 0.42);
  --paired-ok: #4ade80;
  --paired-bad: #f87171;
}

:root[data-theme="red"] {
  --paired-surface: #fff8fb;
  --paired-surface-soft: #fff1f6;
  --paired-border: #f2bad2;
  --paired-border-soft: #f7d7e5;
  --paired-text: #3f1024;
  --paired-muted: #6a2743;
  --paired-chip-bg: #fff8fb;
  --paired-chip-text: #3f1024;
  --paired-chip-border: #d94681;
  --paired-chip-active-bg: #d94681;
  --paired-chip-active-text: #fff7fb;
  --paired-meter-bg: #f4d3e2;
  --paired-focus-ring: rgba(217, 70, 129, 0.35);
  --paired-ok: #16a34a;
  --paired-bad: #dc2626;
}

.paired-summary-card {
  border: 1px solid var(--paired-border);
  border-radius: 10px;
  padding: 0.55rem 0.6rem;
  background: var(--paired-surface);
  color: var(--paired-text);
  line-height: 1.25;
}

.paired-summary-head {
  font-size: 0.98rem;
  margin-bottom: 0.35rem;
}

.paired-summary-scope {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.82rem;
  color: var(--paired-muted);
}

.paired-summary-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.26rem;
  margin: 0.2rem 0 0.45rem;
  font-size: 0.75rem;
}

.paired-summary-controls > span {
  color: var(--paired-muted);
  margin-right: 0.2rem;
}

.message.ai .chat-btn.paired-chip {
  font-size: 0.77rem;
  font-weight: 600;
  padding: 0.4rem 0.62rem;
  min-height: 2rem;
  margin: 0;
  border-radius: 999px;
  line-height: 1;
  border: 1px solid var(--paired-chip-border);
  background: var(--paired-chip-bg);
  color: var(--paired-chip-text);
  width: auto;
  touch-action: manipulation;
}

.message.ai .chat-btn.paired-chip.active {
  background: var(--paired-chip-active-bg);
  color: var(--paired-chip-active-text);
  border-color: var(--paired-chip-active-bg);
}

.message.ai .chat-btn.paired-chip:hover {
  background: var(--paired-chip-active-bg);
  color: var(--paired-chip-active-text);
}

.message.ai .chat-btn.paired-chip:focus-visible {
  outline: 2px solid var(--paired-focus-ring);
  outline-offset: 1px;
}

.paired-summary-viz {
  margin: 0.15rem 0 0.45rem;
  display: grid;
  gap: 0.32rem;
}

.paired-meter-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.18rem;
}

.paired-meter-label {
  font-size: 0.78rem;
  color: var(--paired-muted);
}

.paired-meter {
  width: 100%;
  height: 0.4rem;
  border-radius: 999px;
  background: var(--paired-meter-bg);
  overflow: hidden;
}

.paired-meter-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
}

.paired-meter-fill.acc {
  background: linear-gradient(90deg, #0ea5e9, #2563eb);
}

.paired-meter-fill.focus {
  background: linear-gradient(90deg, #22c55e, #16a34a);
}

.paired-stack {
  width: 100%;
  height: 0.44rem;
  border-radius: 999px;
  background: var(--paired-meter-bg);
  overflow: hidden;
  display: flex;
}

.paired-stack-ok {
  background: var(--paired-ok);
  height: 100%;
}

.paired-stack-bad {
  background: var(--paired-bad);
  height: 100%;
}

.paired-summary-strip-wrap {
  margin: 0.15rem 0 0.38rem;
}

.paired-summary-strip-label {
  display: block;
  font-size: 0.76rem;
  color: var(--paired-muted);
  margin-bottom: 0.2rem;
}

.paired-summary-strip {
  display: grid;
  grid-template-columns: repeat(18, minmax(0, 1fr));
  gap: 0.12rem;
}

.paired-strip-cell {
  height: 0.34rem;
  border-radius: 999px;
  background: #cbd5e1;
}

.paired-strip-cell.ok {
  background: var(--paired-ok);
}

.paired-strip-cell.bad {
  background: var(--paired-bad);
}

.paired-summary-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.22rem;
  margin-bottom: 0.34rem;
}

.paired-summary-kpis span {
  font-size: 0.78rem;
  border: 1px solid var(--paired-border-soft);
  border-radius: 7px;
  padding: 0.22rem 0.3rem;
  text-align: center;
  white-space: nowrap;
}

.paired-summary-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  flex-wrap: wrap;
  font-size: 0.77rem;
  color: var(--paired-muted);
  margin-bottom: 0.28rem;
}

.paired-summary-attempts-title {
  font-size: 0.8rem;
  font-weight: 600;
  margin: 0.15rem 0 0.22rem;
}

.paired-attempts-scroll {
  max-height: 8.8rem;
  overflow-y: auto;
  border: 1px solid var(--paired-border-soft);
  border-radius: 7px;
  padding: 0.2rem 0.25rem;
  background: var(--paired-surface-soft);
}

.paired-attempt-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.32rem;
  padding: 0.17rem 0.1rem;
  border-bottom: 1px solid var(--paired-border-soft);
  align-items: center;
}

.paired-attempt-row:last-child {
  border-bottom: 0;
}

.message.ai .chat-btn.paired-attempt-btn {
  width: 100%;
  margin: 0;
  border: 0;
  border-bottom: 1px solid var(--paired-border-soft);
  border-radius: 6px;
  background: transparent;
  color: var(--paired-text);
  text-align: left;
  padding: 0.26rem 0.12rem;
  min-height: 2.2rem;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.message.ai .chat-btn.paired-attempt-btn:last-child {
  border-bottom: 0;
}

.message.ai .chat-btn.paired-attempt-btn:hover {
  background: rgba(148, 163, 184, 0.14);
  color: var(--paired-text);
}

.message.ai .chat-btn.paired-attempt-btn:focus-visible {
  outline: 2px solid var(--paired-focus-ring);
  outline-offset: 1px;
}

.paired-attempt-row-static {
  opacity: 0.92;
}

.paired-attempt-meta {
  font-size: 0.74rem;
  color: var(--paired-muted);
  white-space: nowrap;
}

.paired-attempt-meta.ok {
  color: var(--paired-ok);
}

.paired-attempt-meta.bad {
  color: var(--paired-bad);
}

.paired-attempt-topic {
  font-size: 0.76rem;
  color: var(--paired-text);
  line-height: 1.2;
  min-width: 0;
}

.paired-summary-back-wrap {
  margin: 0.35rem 0;
}

.message.ai .chat-btn.paired-back-btn {
  margin: 0;
  width: auto;
  min-height: 2rem;
  border-radius: 999px;
  border: 1px solid var(--paired-chip-border);
  background: var(--paired-chip-bg);
  color: var(--paired-chip-text);
  padding: 0.38rem 0.76rem;
  font-size: 0.8rem;
  font-weight: 600;
  touch-action: manipulation;
}

.message.ai .chat-btn.paired-back-btn:hover {
  background: var(--paired-chip-active-bg);
  color: var(--paired-chip-active-text);
}

.message.ai .chat-btn.paired-back-btn:focus-visible {
  outline: 2px solid var(--paired-focus-ring);
  outline-offset: 1px;
}

.paired-summary-empty,
.paired-summary-empty-mini {
  font-size: 0.8rem;
  color: var(--paired-muted);
}

@media (max-width: 480px) {
  .paired-summary-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .paired-summary-controls {
    gap: 0.3rem;
  }

  .paired-summary-controls > span {
    width: 100%;
    margin-right: 0;
    margin-top: 0.06rem;
  }

  .message.ai .chat-btn.paired-chip {
    min-height: 2.25rem;
    font-size: 0.81rem;
    padding: 0.5rem 0.7rem;
  }

  .paired-attempt-row {
    grid-template-columns: 1fr;
    gap: 0.08rem;
  }

  .message.ai .chat-btn.paired-attempt-btn {
    min-height: 2.45rem;
    padding-top: 0.34rem;
    padding-bottom: 0.34rem;
  }

  .message.ai .chat-btn.paired-back-btn {
    min-height: 2.25rem;
    font-size: 0.84rem;
  }
}
