/* PTutor chat page (Pythaverse2026#613). Works full-page and inside the IDE drawer (about 360-480px wide). */
:root {
  --bg: #f6f7fb; --panel: #ffffff; --ink: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --brand: #2563eb; --brand-ink: #ffffff; --brand-soft: #eff4ff; --me: #2563eb; --me-ink: #ffffff;
  --warn: #b45309; --warn-soft: #fff7ed; --err: #b91c1c; --err-soft: #fef2f2; --code-bg: #f6f8fa;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --panel: #111827; --ink: #e5e7eb; --muted: #9ca3af; --line: #1f2937;
    --brand: #3b82f6; --brand-soft: #172554; --me: #2563eb; --code-bg: #0b1220;
    --warn: #fbbf24; --warn-soft: #2a1d07; --err: #f87171; --err-soft: #2a0f10;
    color-scheme: dark;
  }
  .hljs { background: transparent; color: #c9d1d9; }
  .hljs-keyword, .hljs-built_in, .hljs-type { color: #ff7b72; }
  .hljs-string { color: #a5d6ff; }
  .hljs-number, .hljs-literal { color: #79c0ff; }
  .hljs-comment { color: #8b949e; }
  .hljs-title, .hljs-title.function_ { color: #d2a8ff; }
  .hljs-meta { color: #79c0ff; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.pt { position: relative; display: flex; flex-direction: column; height: 100%; max-width: 820px; margin: 0 auto; background: var(--panel); }
@media (min-width: 821px) { .pt { border-left: 1px solid var(--line); border-right: 1px solid var(--line); } }

.pt-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.pt-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.pt-logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); font-weight: 800; }
.pt-head-actions { display: flex; align-items: center; gap: 4px; }
.pt-usage { font-size: 12px; color: var(--muted); padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px; white-space: nowrap; }
.pt-usage.low { color: var(--warn); border-color: currentColor; }
.pt-icon, .pt-lang { border: 0; background: transparent; border-radius: 8px; padding: 6px; line-height: 0; }
.pt-lang { line-height: 1; font-size: 12px; font-weight: 600; padding: 6px 8px; color: var(--muted); }
.pt-icon:hover, .pt-lang:hover, .pt-icon:focus-visible, .pt-lang:focus-visible { background: var(--brand-soft); outline: none; }

.pt-main { flex: 1; overflow-y: auto; padding: 12px; }
.pt-state { max-width: 420px; margin: 12vh auto 0; text-align: center; }
.pt-state h2 { font-size: 18px; margin: 0 0 8px; }
.pt-state p { color: var(--muted); margin: 0 0 14px; }
.pt-btn { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 10px; padding: 9px 16px; background: var(--brand); color: var(--brand-ink); font-weight: 600; text-decoration: none; }
.pt-btn.secondary { background: transparent; color: var(--brand); border: 1px solid var(--brand); }
.pt-btn + .pt-btn { margin-left: 6px; }

.pt-welcome { padding: 8px 4px 4px; }
.pt-welcome h2 { font-size: 17px; margin: 4px 0; }
.pt-welcome p { color: var(--muted); margin: 0 0 12px; }
.pt-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pt-chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 12px; font-size: 13px; text-align: left; }
.pt-chip:hover, .pt-chip:focus-visible { border-color: var(--brand); color: var(--brand); outline: none; }

/* Pythaverse2026#627: the lesson the IDE is on (a link back to learn), the lesson chips and the link under answers */
.pt-lesson { display: flex; flex-direction: column; gap: 2px; padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--brand-soft); font-size: 13px; }
.pt-lesson-link { color: var(--brand); font-weight: 600; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pt-lesson-link:hover, .pt-lesson-link:focus-visible { text-decoration: underline; outline: none; }
.pt-lesson-note { color: var(--muted); font-size: 12px; }
.pt-chip.lesson { border-color: var(--brand); color: var(--brand); }
a.pt-chip { display: inline-block; text-decoration: none; }
.pt-lesson-back { display: inline-block; margin: 2px 2px 0; color: var(--brand); font-size: 13px; font-weight: 600; text-decoration: none; }
.pt-lesson-back:hover, .pt-lesson-back:focus-visible { text-decoration: underline; outline: none; }

.pt-thread { display: flex; flex-direction: column; gap: 12px; }
.pt-msg { max-width: 100%; }
.pt-msg.me { align-self: flex-end; max-width: 88%; }
.pt-bubble-me { background: var(--me); color: var(--me-ink); border-radius: var(--radius) var(--radius) 4px var(--radius); padding: 8px 12px; white-space: pre-wrap; word-wrap: break-word; }
.pt-me-mode { display: block; font-size: 11px; opacity: .8; margin-bottom: 2px; text-transform: uppercase; letter-spacing: .03em; }
.pt-me-code { margin-top: 6px; font: 12px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; background: rgba(255,255,255,.15); border-radius: 8px; padding: 6px 8px; max-height: 120px; overflow: auto; white-space: pre; }
.pt-msg.bot .pt-md { padding: 2px 2px; overflow-wrap: anywhere; }
.pt-md p { margin: 0 0 8px; }
.pt-md h1, .pt-md h2, .pt-md h3, .pt-md h4 { font-size: 15px; margin: 12px 0 6px; }
.pt-md ul, .pt-md ol { margin: 0 0 8px; padding-left: 20px; }
.pt-md code { font: 13px ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--code-bg); border-radius: 5px; padding: 1px 5px; }
.pt-md table { border-collapse: collapse; font-size: 13px; margin: 0 0 8px; display: block; overflow-x: auto; }
.pt-md th, .pt-md td { border: 1px solid var(--line); padding: 4px 8px; }
.pt-codeblock { margin: 6px 0 10px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--code-bg); }
.pt-codebar { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 4px 6px 4px 10px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.pt-codebar-actions { display: flex; gap: 4px; }
.pt-codebar button { border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 2px 8px; font-size: 12px; }
.pt-codebar button:hover, .pt-codebar button:focus-visible { border-color: var(--brand); color: var(--brand); outline: none; }
.pt-codeblock pre { margin: 0; padding: 10px; overflow-x: auto; }
.pt-codeblock pre code { background: none; padding: 0; font-size: 13px; line-height: 1.45; }
.pt-cursor::after { content: "▍"; animation: pt-blink 1s steps(2) infinite; color: var(--brand); }
@keyframes pt-blink { to { visibility: hidden; } }
.pt-thinking { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.pt-dots { display: inline-flex; gap: 3px; }
.pt-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); animation: pt-bounce 1.2s infinite ease-in-out; }
.pt-dots i:nth-child(2) { animation-delay: .15s; } .pt-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes pt-bounce { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.pt-note { font-size: 13px; border-radius: 10px; padding: 8px 10px; }
.pt-note.warn { background: var(--warn-soft); color: var(--warn); }
.pt-note.err { background: var(--err-soft); color: var(--err); }

.pt-composer { border-top: 1px solid var(--line); padding: 8px 10px 6px; background: var(--panel); }
.pt-modes { display: flex; gap: 4px; margin-bottom: 6px; overflow-x: auto; }
.pt-modes button { flex: 0 0 auto; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 11px; font-size: 13px; }
.pt-modes button[aria-checked="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.pt-code { margin-bottom: 6px; border: 1px solid var(--line); border-radius: 10px; }
.pt-code summary { cursor: pointer; padding: 5px 10px; font-size: 13px; color: var(--muted); list-style: none; }
.pt-code summary::-webkit-details-marker { display: none; }
.pt-code summary::before { content: "▸ "; } .pt-code[open] summary::before { content: "▾ "; }
.pt-code-meta { font-size: 12px; }
.pt-code textarea { display: block; width: 100%; border: 0; border-top: 1px solid var(--line); padding: 8px 10px; resize: vertical; min-height: 80px; max-height: 40vh;
  font: 12.5px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--code-bg); color: var(--ink); outline: none; tab-size: 2; }
.pt-code-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 3px 10px; border-top: 1px solid var(--line); }
.pt-link { border: 0; background: none; color: var(--brand); font-size: 12px; padding: 2px 0; }
.pt-input { display: flex; align-items: flex-end; gap: 6px; }
.pt-input textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; min-height: 40px; max-height: 160px;
  font: inherit; background: var(--panel); color: var(--ink); outline: none; }
.pt-input textarea:focus, .pt-code textarea:focus { border-color: var(--brand); }
.pt-send { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; }
.pt-send:disabled { opacity: .45; cursor: default; }
.pt-stop { background: var(--ink); color: var(--panel); }
.pt-foot { margin: 4px 2px 0; font-size: 11px; color: var(--muted); text-align: center; }

.pt-history { position: absolute; inset: 49px 0 0 0; z-index: 5; background: var(--panel); display: flex; flex-direction: column; }
.pt-history-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.pt-history ul { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; }
.pt-history li { display: flex; align-items: center; gap: 4px; padding: 0 6px 0 12px; }
.pt-history li button.open { flex: 1; text-align: left; border: 0; background: none; padding: 9px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pt-history li small { color: var(--muted); font-size: 11px; white-space: nowrap; }
.pt-history li:hover { background: var(--brand-soft); }

.pt-toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: var(--panel); padding: 6px 12px; border-radius: 8px; font-size: 13px; z-index: 10; }

/* Leanbot toolkit bar (standalone page only): the bar is fixed at the top and adds html.ptv-toolkit-ready once it has
   rendered, so a missing or killed bar leaves this page as it was. Its EN/VI switch replaces PTutor's own button here. */
html.ptv-toolkit-ready body { padding-top: var(--ptv-bar-h, 44px); }
html.ptv-toolkit-ready .pt-lang { display: none; }
