/* ============================================================
   Chatbot page styles
   All colors use the site theme variables (--bg-*, --text-*,
   --border-*, --input-*) defined in base.html, so light, dark
   and OLED themes all get correct colors automatically.
   ============================================================ */

/* -- Override main layout -- */
html, body { height: 100%; }

/* Chat font — picked in the settings modal. It styles the conversation column
   (messages + composer); the sidebar and the site chrome keep the site font.
   The non-mono stacks are the same families the rest of the site falls back to. */
:root { --chat-font: var(--font-mono); }

/* Fill the viewport exactly: the site-wide #content-wrapper has a -60px
   top margin (meant to tuck content under the fixed header). On this page it
   pulled the chat up behind the header — hiding the top of the conversation —
   and left a ~60px dead gap at the bottom once the footer is hidden.
   Cancelling it at every width keeps the chat column between the header and
   the bottom of the viewport. !important is required because base.html's
   inline <style> block comes AFTER this stylesheet in the cascade. */
#content-wrapper {
    min-height: calc(100vh - var(--header-height)) !important;
    min-height: calc(100dvh - var(--header-height)) !important;
    margin-top: 0 !important;
}

/* base.html adds 0.75rem of breathing room above the page on phones, so the
   wrapper's height has to subtract it too — otherwise the column is 12px taller
   than the screen and the last line of the composer caption is cut off. */
@media (max-width: 767px) {
    #content-wrapper {
        min-height: calc(100vh - var(--header-height) - 0.75rem) !important;
        min-height: calc(100dvh - var(--header-height) - 0.75rem) !important;
    }
}

main.container.py-4 {
    display: flex !important;
    flex-direction: column !important;
    padding: 0 !important;
    margin: 0 !important; /* styles.css sets main { margin: 3vh } — that dead zone shows at the bottom here */
    flex: 1;
    min-height: 0;
    overflow: hidden;
    max-width: none !important;
    width: 100%;
}

#site-footer { display: none !important; }

/* -- Layout --
   The body already provides padding-top: var(--header-height) from base.html,
   so the chat starts directly under the header — no extra top gap (it read as
   an empty background-coloured strip above the conversation).
   chat-main is centered via margin:0 auto; the sidebar is positioned
   absolutely to the left of it so the centering is unaffected.
*/
.chat-layout {
    position: relative;
    display: flex;
    flex: 1;
    min-height: 0;
    width: 100%;
    transition: padding-left .25s ease;
}
/* Signed out there is no conversations sidebar, so the desktop gutter that
   reserves its space must not apply — otherwise the login box sits off-center. */
.chat-layout.chat-layout-locked { padding-left: 0; }
.chat-main {
    /* The scrollbar belongs to the full-width message area below, while the
       reading column itself stays 880px. Keeping a max-width here put the
       scrollbar at the edge of that column instead of the window. */
    max-width: none;
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    display:flex;
    flex-direction:column;
    padding:0;
    min-width:0;
    margin: 0 auto;
    position: relative;
    font-family: var(--chat-font); /* self-hosted JetBrains Mono by default */
}

/* Jump-to-bottom button — floats above the messages, appears when scrolled up */
.jump-bottom-btn {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 8.5rem; /* JS keeps this above the composer */
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: .85rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, color .15s, border-color .15s;
    z-index: 5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
.jump-bottom-btn.visible { opacity: 1; pointer-events: auto; }
.jump-bottom-btn:hover { color: var(--accent-color, #0d6efd); border-color: var(--accent-color, #0d6efd); }

/* -- Sidebar (desktop): a proper fixed left sidebar, like modern chat apps.
   Collapsible — the collapsed state is driven by body.chat-sidebar-collapsed. */
.convo-sidebar {
    position: fixed;
    left: 0;
    top: var(--header-height);
    bottom: 0;
    width: 260px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: .75rem .5rem;
    z-index: 999; /* below the site sidebar (#sidebar, z-index 1000) so it slides BEHIND it */
    transition: transform .25s ease, left .25s ease;
}
body.chat-sidebar-collapsed .convo-sidebar { left: 0 !important; transform: translateX(-100%); }

/* OLED: raise the conversations panel above the true-black page background
   (--bg-secondary is #0a0a0a there and barely reads as a panel). */
[data-theme="oled"] .convo-sidebar {
    background: var(--bg-tertiary);
}

/* Reopen button — floating at the left edge, only visible when collapsed */
.sidebar-reopen-btn {
    position: fixed;
    left: .75rem;
    top: calc(var(--header-height) + .75rem);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent-color, #0d6efd);
    color: #fff;
    border: none;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 999; /* below the site sidebar (#sidebar, z-index 1000) */
    font-size: .95rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    transition: transform .15s, left .25s ease;
}
.sidebar-reopen-btn:hover { transform: scale(1.08); }
body.chat-sidebar-collapsed .sidebar-reopen-btn { display: flex; }

.convo-sidebar-header {
    padding: 0 0.5rem 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 0.3rem;
}
.convo-sidebar-header h6 {
    flex: 1;
    margin: 0;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.convo-sidebar-header .btn-sm {
    width: 26px;
    height: 26px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.65rem;
    border: none;
    background: color-mix(in srgb, var(--accent-color, #0d6efd) 12%, transparent);
    color: var(--accent-color, #0d6efd);
    transition: background 0.15s, transform 0.12s;
}
.convo-sidebar-header .btn-sm:hover {
    background: color-mix(in srgb, var(--accent-color, #0d6efd) 22%, transparent);
    transform: scale(1.1);
}

/* The conversations overview is the scroll region. The panel keeps its height
   (its header and Settings footer are flex-shrink:0) and the list scrolls
   inside it, so any number of conversations stays reachable.
   `overflow-y: auto` is also what lets the list give up height at all: it
   zeroes this flex item's automatic minimum size, which would otherwise be its
   content height and would hold the panel open. */
.convo-list {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain; /* reaching the end of the list doesn't chain to the page */
    padding: 0 0.25rem 0.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    scrollbar-width: none; /* still scrollable — just no visible bar */
}
.convo-list::-webkit-scrollbar { display: none; }

/* Settings entry pinned to the bottom of the sidebar. It fills the footer, its
   label sits on the chat rows' left edge, and the gear is centred in a fixed
   column so the label lines up with the text column. */
.convo-sidebar-footer {
    flex-shrink: 0;
    display: flex;
    padding: 0.4rem 0.25rem 0.1rem;
    margin-top: 0.35rem;
    border-top: 1px solid var(--border-color);
}
.convo-settings-btn {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.45rem 0.7rem;
    border-radius: 0.6rem;
    font-size: 0.86rem;
    color: var(--text-muted);
    text-align: left;
    transition: background 0.12s, color 0.12s;
}
.convo-settings-btn:hover { background: var(--hover-bg); color: var(--text-color); }
/* The gear and the label are flex items, so `align-items: center` centres their
   boxes — but only boxes of the same shape line up. The icon's box is its 1em
   em-square (its glyph fills it), while a text box is as tall as the element's
   line-height, and the text sits inside that box according to the font's
   ascent/descent. Leaving the label on the inherited 1.5 line-height made its
   box ~1.3x the glyphs and pushed the visible text below the gear. Giving both
   the same line-height makes the two boxes equivalent:
   measured in Chromium, the centres land within 0.01px, the same in Arial,
   Consolas and Courier New, and at both 260px and full width. */
.convo-settings-btn i {
    display: block;
    font-size: 0.95rem;
    line-height: 1;
    width: 1.25rem;
    flex-shrink: 0;
    text-align: center;
}
.convo-settings-btn span {
    display: block;
    line-height: 1;
}
/* One fixed-size row per conversation, so the overview keeps an even rhythm
   whatever the title is (long titles ellipsise on a single line) and whichever
   row is active. `flex: 0 0 auto` pins that height: a flex item's default
   `flex-shrink: 1` would otherwise let a list that outgrows its box compress
   the rows instead of scrolling — which is exactly what happened before, down
   to ~16px per row with a long conversation list.
   2.5rem is the height these rows already had when they weren't compressed (a
   24px options button plus 0.5rem padding top and bottom). */
.convo-item {
    flex: 0 0 auto;
    height: 2.5rem;
    padding: 0 0.7rem;
    cursor: pointer;
    font-size: 0.81rem;
    line-height: 1.35;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: background 0.12s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-radius: 0.6rem;
}
.convo-item:hover { background: var(--hover-bg); }
.convo-item.active {
    background: color-mix(in srgb, var(--accent-color, #0d6efd) 12%, transparent);
    color: var(--accent-color, #0d6efd);
    font-weight: 600;
}
.convo-item .convo-title { flex:1; overflow:hidden; text-overflow:ellipsis; }
.convo-item .convo-menu-btn {
    opacity:0; font-size:.85rem; width:24px; height:24px; border-radius:50%;
    color:var(--text-muted); border:none; cursor:pointer; background:transparent;
    flex-shrink:0; display:flex; align-items:center; justify-content:center;
    transition:opacity .12s,background .12s; padding:0;
}
.convo-item:hover .convo-menu-btn { opacity:0.75; }
.convo-item .convo-menu-btn:hover { opacity:1; background:var(--hover-bg); }
.convo-item.active .convo-menu-btn { opacity:0.85; }

/* Per-conversation status dot, between the title and the options button:
   pulsing while that conversation's turn runs, solid once a reply arrived there
   while another conversation was on screen. */
.convo-item .convo-status {
    flex: 0 0 auto;
    width: .45rem;
    height: .45rem;
    border-radius: 50%;
    background: var(--accent-color, #0d6efd);
    display: none;
}
.convo-item.busy .convo-status {
    display: block;
    animation: convo-working 1.1s ease-in-out infinite;
}
.convo-item.unread:not(.busy) .convo-status {
    display: block;
    background: var(--bs-success, #198754);
}
@keyframes convo-working {
    0%, 100% { opacity: .25; transform: scale(.75); }
    50%      { opacity: 1;   transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
    .convo-item.busy .convo-status { animation: none; opacity: 1; }
}

/* "..." dropdown menu for conversation options (Rename / Delete) */
.convo-menu {
    position:fixed;
    z-index:2000;
    min-width:150px;
    background:var(--card-bg, var(--bg-secondary));
    border:1px solid var(--border-color);
    border-radius:.6rem;
    box-shadow:0 6px 24px rgba(0,0,0,.25);
    padding:.3rem;
    display:none;
    flex-direction:column;
    gap:.15rem;
}
.convo-menu.open { display:flex; }
.convo-menu-item {
    display:flex; align-items:center;
    width:100%; text-align:left;
    background:none; border:none; cursor:pointer;
    padding:.45rem .6rem; border-radius:.4rem;
    font-size:.82rem; color:var(--text-color);
    transition:background .12s;
}
.convo-menu-item:hover { background:var(--hover-bg); }
.convo-menu-item-danger { color:var(--bs-danger,#dc3545); }
.convo-menu-item-danger:hover { background:color-mix(in srgb, var(--bs-danger,#dc3545) 10%, transparent); }


.chat-logo { width:44px; height:44px; vertical-align:middle; object-fit:contain; margin-right:0.25rem; }

/* -- Welcome block (empty conversation only) -- */
.chat-welcome {
    margin: auto; /* center in the messages area */
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-color);
}
.chat-welcome .chat-logo {
    width: 56px;
    height: 56px;
    margin: 0 auto .75rem;
    display: block;
}
.chat-welcome h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: .25rem;
    letter-spacing: -0.01em;
}
/* The wordmark, so the "beta" tag can hang off its top-right corner as a
   superscript without pulling "Scrambly" off center. */
.chat-welcome-title {
    position: relative;
    display: inline-block;
}
.chat-beta-tag {
    position: absolute;
    left: 100%;
    top: -0.12em;
    margin-left: .4rem;
    padding: .2rem .5rem .25rem;
    border: 1px solid rgba(var(--accent-color-rgb, 13, 110, 253), .45);
    border-radius: 999px;
    background: rgba(var(--accent-color-rgb, 13, 110, 253), .12);
    color: var(--accent-color, #0d6efd);
    font-size: .6rem;
    font-weight: 600;
    line-height: 1;
    letter-spacing: .08em;
    text-transform: uppercase;
    white-space: nowrap;
}
.chat-welcome > p {
    font-size: .82rem;
    color: var(--text-muted);
    margin-bottom: .25rem;
}
.chat-welcome .chat-welcome-hint {
    font-style: italic;
    font-size: .88rem;
    margin-top: .9rem;
    opacity: .85;
}

/* One-tap starters under the welcome hint. Each one sends a complete question,
   and the middle two are built from the solver's own data (their first 3x3
   reconstruction, the next algorithm on their list), so a press does real work
   instead of asking the coach to guess. */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .45rem;
    max-width: 40rem;
    margin: 1.15rem auto .1rem;
}
.chat-suggestion {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    max-width: 100%;
    padding: .45rem .8rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-secondary);
    color: var(--text-color);
    font-family: inherit;
    font-size: .78rem;
    line-height: 1.3;
    text-align: left;
    cursor: pointer;
    transition: border-color .15s, background .15s, transform .1s;
}
.chat-suggestion:hover {
    border-color: var(--accent-color, #0d6efd);
    background: var(--hover-bg);
}
.chat-suggestion:active { transform: scale(.98); }
.chat-suggestion:focus-visible {
    outline: none;
    border-color: var(--accent-color, #0d6efd);
    box-shadow: 0 0 0 2px rgba(var(--accent-color-rgb, 13, 110, 253), .25);
}
.chat-suggestion i {
    flex-shrink: 0;
    font-size: .74rem;
    color: var(--accent-color, #0d6efd);
}
.chat-suggestion-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* What the suggestion will actually be about: the solve's name or its time, the
   algorithm set and case. Kept quiet so the label still leads. */
.chat-suggestion-hint {
    color: var(--text-muted);
    font-size: .72rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 13rem;
}

/* The privacy note under the empty-state welcome: what is stored where, and by
   whom. Deliberately quiet — it is information, not a warning banner — but
   readable without hunting for it. */
.chat-privacy {
    display: flex;
    align-items: flex-start;
    gap: .55rem;
    text-align: left;
    max-width: 33rem;
    margin: 1.4rem auto 0;
    padding: .7rem .85rem;
    border: 1px solid var(--border-color);
    border-radius: .75rem;
    background: var(--bg-secondary);
    color: var(--text-muted);
}
.chat-privacy > i {
    flex-shrink: 0;
    margin-top: .16rem;
    font-size: .78rem;
    opacity: .75;
}
.chat-privacy p {
    margin: 0;
    font-size: .72rem;
    line-height: 1.5;
    opacity: .95;
}

/* -- Messages -- */
.chat-messages {
    flex:1; min-height:0; overflow-y:auto; overflow-x:hidden;
    /* Full width so the scrollbar sits at the window's right edge; the padding
       keeps the conversation itself in an 880px reading column. */
    padding:.5rem max(.5rem, calc((100% - 880px) / 2));
    display:flex; flex-direction:column; gap:.55rem;
    /* The standard scrollbar is styled globally; the gutter keeps the text
       column from jumping when it appears. */
    scrollbar-gutter: stable;
}

.message {
    max-width:100%;
    padding:0;
    line-height:1.5;
    overflow-wrap:break-word;
    font-size:.92rem;
    display:flex;
    flex-direction:column;
}
.message.user { align-self:flex-end; max-width:82%; } /* 82% of the messages area, not of the shrink-wrapped bubble */
.message.user .msg-body {
    background:var(--accent-color,#0d6efd);
    color:#fff;
    padding:.5rem .85rem;
    border-radius:1.2rem;
    border-bottom-right-radius:.35rem;
    width:auto; /* grow with content — no more squeezed bubbles that split short words */
    max-width:35rem;
    align-self:flex-end;
}
/* A message with a context note gets the width of that note, with the bubble
   itself still hugging its text on the right. */
.message.user.has-context { width:100%; max-width:min(82%, 35rem); }
.message.user .chat-context { width:100%; margin-top:.35rem; align-self:flex-end; }

/* The quiet "Context: …" line under a user message: collapsed it is one
   ellipsised line with a chevron on the right; opening it shows the algorithm or
   the scramble + solution and a cube player. */
.chat-context {
    border: 1px solid var(--border-color);
    border-radius: .7rem;
    background: var(--bg-secondary);
    overflow: hidden;
}
.chat-context-toggle {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    padding: .42rem .6rem;
    background: transparent;
    border: 0;
    color: var(--text-muted);
    font: inherit;
    font-size: .72rem;
    line-height: 1.4;
    text-align: left;
    cursor: pointer;
}
.chat-context-toggle:hover { background: var(--hover-bg); }
.chat-context-summary {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-context-prefix { color: var(--text-muted); }
.chat-context-value {
    color: var(--text-color);
    font-family: var(--moves-font-mono);
}
.chat-context-chevron {
    flex: 0 0 auto;
    font-size: .64rem;
    transition: transform .15s ease;
}
.chat-context-toggle[aria-expanded="true"] .chat-context-chevron { transform: rotate(180deg); }
.chat-context-body {
    padding: .65rem .7rem .7rem;
    border-top: 1px solid var(--border-color);
}
.chat-context-block + .chat-context-block { margin-top: .55rem; }
.chat-context-label {
    margin-bottom: .2rem;
    color: var(--text-muted);
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
}
.chat-context-sequence {
    color: var(--text-color);
    font-family: var(--moves-font-mono);
    font-size: .8rem;
    line-height: 1.65;
    overflow-wrap: anywhere;
}
.chat-context-sequence .sequence-comment { color: var(--text-muted); }
.chat-context-cube {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    margin-top: .6rem;
}
.message.user .msg-header {
    text-align:right;
    padding:.35rem 0 .1rem 0;
}
/* Assistant messages fill the column instead of shrink-wrapping to their text:
   an analysis comparison has to use the whole chat width, and the prose reads
   better on a consistent measure. (User bubbles keep hugging their content.) */
.message.assistant { align-self: stretch; }
.message.assistant .msg-body {
    width:100%;
}
.message .msg-header {
    font-size:.72rem;
    color:var(--text-muted);
    padding:.35rem 0 .1rem 0;
    font-weight:500;
}
.message .msg-body {
    width:100%;
    color:var(--text-color);
}
.message .msg-body p { margin-bottom:.4rem; }
.message .msg-body p:last-child { margin-bottom:0; }
/* Two-digit ordered-list markers ("10.", "11.") need more room than 1.4rem;
   leave enough padding that they are never clipped by the message column. */
.message .msg-body ul, .message .msg-body ol { margin-bottom:.4rem; padding-left:2.4rem; }
.message .msg-body li { padding-left:.15rem; }

/* Links (trainers, tools, features) follow the user's chosen accent colour
   instead of Bootstrap's fixed theme blue. */
.message .msg-body a { color:var(--accent-color,#0d6efd); }
.message .msg-body a:hover { color:var(--accent-color-dark,#0a58ca); }

.message .msg-body table { border-collapse:collapse; margin:.5rem 0; width:100%; font-size:.85em; }
.message .msg-body th,.message .msg-body td { border:1px solid var(--border-color); padding:.35rem .6rem; text-align:left; }
.message .msg-body th { background:var(--hover-bg); font-weight:600; }

.message .msg-body code { background:var(--bg-tertiary); padding:.08em .35em; border-radius:.3rem; font-size:.88em; font-family:var(--moves-font-mono); }
.message .msg-body pre { background:var(--bg-tertiary); padding:.45rem .65rem; border-radius:.5rem; overflow-x:auto; font-family:var(--moves-font-mono); font-size:.82rem; margin-bottom:.4rem; }
.message .msg-body pre code { background:none; padding:0; }

.message.error {
    align-self:center; background:var(--danger-bg); color:var(--danger-color);
    border:1px solid color-mix(in srgb, var(--danger-color) 30%, transparent);
    font-size:.85rem; text-align:center; max-width:100%; border-radius:.75rem;
    padding:.5rem .85rem;
}

/* -- Alg pills -- */
/* Clickable algorithms use the accent colour — the option the user picked in
   the header's theme dropdown, which base.html exposes as --accent-color. */
.alg-tag {
    display:inline-block; background:color-mix(in srgb, var(--accent-color,#0d6efd) 10%, transparent);
    color:var(--accent-color,#0d6efd);
    border:1px solid color-mix(in srgb, var(--accent-color,#0d6efd) 25%, transparent);
    border-radius:.4rem; padding:.08em .45em;
    font-family:var(--moves-font-mono); font-size:.88em; cursor:pointer;
    transition:background .12s,border-color .12s; white-space:nowrap;
}
.alg-tag:hover { background:color-mix(in srgb, var(--accent-color,#0d6efd) 18%, transparent); border-color:var(--accent-color,#0d6efd); }

/* -- Typing -- */
.typing-indicator { display:flex; flex-direction:row; gap:.35rem; align-items:center; padding:.7rem .5rem; min-height:32px; }
.typing-indicator span:nth-child(-n+3) { width:8px; height:8px; background:var(--text-muted); border-radius:50%; animation:typing 1.4s infinite both; }
.typing-indicator span:nth-child(2) { animation-delay:.2s; }
.typing-indicator span:nth-child(3) { animation-delay:.4s; }
@keyframes typing { 0%,80%,100% { opacity:.25; transform:scale(.8); } 40% { opacity:1; transform:scale(1); } }
.typing-indicator .typing-status { font-size:.78rem; color:var(--text-muted); margin-left:.3rem; white-space:nowrap; }

/* -- Input -- */
.chat-input-wrap {
    flex-shrink:0; padding:.15rem .75rem .1rem; position:relative; z-index:1031;
    background:var(--bg-color); max-width:880px; width:100%; margin:0 auto;
}

.chat-disclaimer {
    font-size:0.7rem;
    color:var(--text-muted);
    text-align:center;
    padding:0.3rem 0.75rem 0.35rem;
    flex-shrink:0;
    opacity:0.65;
    line-height:1.3;
}

/* Composer box: a clean rounded "area" container in the style of modern
   chat UIs — subtle background, hairline border, focus glow on the box. */
.chat-box {
    display:flex;
    flex-direction:column;
    background:var(--bg-secondary);
    border:1px solid var(--input-border);
    border-radius:1rem;
    padding:.55rem .85rem .4rem;
    transition:border-color .15s, box-shadow .15s, background .15s;
}
.chat-box:focus-within {
    border-color:var(--accent-color,#0d6efd);
    background:var(--bg-color);
    box-shadow:0 0 0 3px rgba(var(--accent-color-rgb, 13, 110, 253), 0.15);
}
/* The textarea itself is fully transparent and borderless — the box is the
   visual container. !important beats the site-wide textarea rules in base.html. */
.chat-box textarea {
    width:100%; resize:none; min-height:46px; max-height:130px; overflow:hidden;
    background-color:transparent !important; border:none !important; box-shadow:none !important;
    padding:.15rem .1rem .35rem !important;
    color:var(--text-color) !important; font-size:.92rem; line-height:1.45;
    scrollbar-width:none;
}
.chat-box textarea:focus {
    background-color:transparent !important;
    border-color:transparent !important;
    box-shadow:none !important;
    outline:none;
}
.chat-box textarea::-webkit-scrollbar { display:none; }
.chat-box textarea::placeholder { color:var(--text-muted); opacity:.8; }

.chat-box-footer {
    display:flex;
    align-items:center;
    justify-content:flex-end; /* keeps the arrow button on the right on phones, where the hint is hidden */
    gap:.6rem;
    padding-top:.3rem;
    border-top:1px solid color-mix(in srgb, var(--border-color) 55%, transparent);
    margin-top:.15rem;
}
.chat-hint {
    flex:1;
    min-width:0;
    font-size:.68rem;
    color:var(--text-muted);
    opacity:.75;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
}
.char-count { display:none; font-size:.68rem; color:var(--text-muted); white-space:nowrap; }
.char-count.countdown { display:inline-block; color:var(--bs-danger,#dc3545) !important; font-weight:700; }

.send-inner-btn {
    width:30px; height:30px; border-radius:50%; border:none; flex-shrink:0;
    background:var(--accent-color,#0d6efd); color:#fff;
    display:flex; align-items:center; justify-content:center; cursor:pointer;
    transition:opacity .15s,transform .15s,background .15s; font-size:.72rem; padding:0;
}
.send-inner-btn:disabled { opacity:.35; cursor:default; transform:none !important; }
.send-inner-btn:not(:disabled):hover { transform:scale(1.08); background:var(--accent-color-dark,#0a58ca); }

/* -- "Replied in another conversation" toast --
   A turn runs in the background (see pendingTurns in chatbot.js), so a reply
   that lands in a hidden conversation announces itself here. It sits just above
   the composer, where the eye already is, and clicking it opens that chat. */
.chat-toast {
    position: fixed;
    left: 50%;
    transform: translate(-50%, .5rem);
    z-index: 1040; /* above the composer (1031), below the modals (1055) */
    display: flex;
    align-items: center;
    gap: .5rem;
    max-width: min(92vw, 26rem);
    padding: .55rem .95rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-secondary);
    color: var(--text-color);
    font-size: .8rem;
    font-family: var(--chat-font);
    box-shadow: 0 8px 26px rgba(0, 0, 0, .28);
    cursor: pointer;
    opacity: 0;
    transition: opacity .2s ease, transform .2s ease;
}
.chat-toast.show { opacity: 1; transform: translate(-50%, 0); }
.chat-toast:hover { border-color: var(--accent-color, #0d6efd); }
.chat-toast i { color: var(--accent-color, #0d6efd); flex-shrink: 0; }
.chat-toast span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-toast strong {
    font-weight: 600;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* -- Premium locked -- */
/* The signed-out state is the only child of the full-height chat column.
   Vertical auto margins center it in the viewport; horizontal margins must
   stay 0 so the flex item still stretches and long lines wrap on phones. */
.premium-locked { text-align:center; margin:auto 0; padding:3rem 1rem; }
.premium-locked i { font-size:3rem; color:var(--text-muted); margin-bottom:1rem; }
.premium-locked h3 { margin-bottom:.75rem; }

/* -- Alg modal -- */
/* Every dialog on this page caps its width, and Bootstrap only auto-centres a
   dialog from 576px up — below that it applies a flat 0.5rem side margin, which
   reads as centred only because a dialog normally fills the width. So on a phone
   wider than ~436px the algorithm modal (420px), the settings modal (380px) and
   the export/import modal (460px) each sat against the left edge with all the
   slack on the right. Auto side margins centre them at every width; the vertical
   margins are left as Bootstrap set them.
   The explicit width keeps that 0.5rem inset on phones too narrow for the cap to
   bite: with `width: auto` the dialog fills the line and auto margins collapse
   to 0, which would push it flush against both screen edges. */
.alg-player-modal .modal-dialog,
.chat-settings-modal .modal-dialog,
.chat-transfer-modal .modal-dialog {
    width: calc(100% - 1rem);
    margin-left: auto;
    margin-right: auto;
}
.alg-player-modal .modal-dialog { max-width:420px; }
.alg-player-modal .modal-content { border-radius:1rem; overflow:hidden; } /* keep the rounded top corners visible */
.alg-player-modal .modal-body { padding:.25rem .5rem; text-align:center; }
.alg-player-container { width:100%; max-width:340px; margin:0 auto; aspect-ratio:1; position:relative; z-index:1; transform:translateZ(0); max-height:340px; }
.alg-player-container :is(.nxn-player-container,.pyraminx-player-container,.skewb-player-container,.square1-player-container,.megaminx-player-container,.clock-player-container) { width:100% !important; height:100% !important; display:block; }
.alg-player-container canvas.cube3d-canvas { position:relative; z-index:1060; }
.alg-scramble-text {
    font-family:var(--moves-font-mono);
    font-size:.72rem;
    color:var(--text-muted);
    text-align:left;
    padding:.2rem .75rem .15rem;
    word-break:break-word;
}
.alg-scramble-label { color:var(--text-color); font-weight:600; }
.alg-solution-label {
    font-family:var(--moves-font-mono);
    font-size:.72rem;
    font-weight:600;
    color:var(--text-color);
    text-align:left;
    padding:.3rem .75rem .1rem;
}
.alg-display-text {
    font-family:var(--moves-font-mono);
    font-size:.78rem;
    color:var(--text-color);
    text-align:left;
    padding:.15rem .75rem .5rem;
    white-space:pre-wrap; /* keep the solution structured as sent, line by line */
    word-break:break-word;
    max-height:150px;
    overflow-y:auto;
    scrollbar-width:none;
}
.alg-display-text::-webkit-scrollbar { display:none; }

/* -- Played-move highlight in the alg modal --
   The moves use the same markup, classes and look as the timer's scramble line
   (see timer.css); the mark itself is the app-wide `is-current-move`, styled in
   played-move.css. */
.alg-display-text .timer-scramble-move {
    display:inline;
    padding:1px 2px;
    border-radius:3px;
    transition:background-color .08s ease, opacity .08s ease;
}
.alg-display-text .timer-scramble-gap { padding:1px 0; }
/* A comment in a written solution is not a move and is never marked. */
.alg-display-text .sequence-comment { color:var(--text-muted,#8a8f98); }

/* Alternatives for the case an algorithm belongs to (from the algorithm tool) */
.alg-solutions {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    padding: .1rem .6rem .5rem;
    max-height: 190px;
    overflow-y: auto;
    scrollbar-width: none;
}
.alg-solutions::-webkit-scrollbar { display: none; }
.alg-solution-item {
    display: flex;
    flex-direction: column;
    gap: .1rem;
    width: 100%;
    text-align: left;
    cursor: pointer;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: .5rem;
    padding: .35rem .55rem;
    color: var(--text-color);
    transition: border-color .12s, background .12s;
}
.alg-solution-item:hover { border-color: var(--accent-color, #0d6efd); background: var(--hover-bg); }
.alg-solution-item.active {
    border-color: var(--accent-color, #0d6efd);
    background: color-mix(in srgb, var(--accent-color, #0d6efd) 12%, transparent);
}
.alg-solution-text {
    font-family: var(--moves-font-mono);
    font-size: .76rem;
    line-height: 1.4;
    word-break: break-word;
}
.alg-solution-meta { font-size: .64rem; color: var(--text-muted); }
.alg-solution-item.active .alg-solution-meta { color: var(--text-color); opacity: .75; }
.toggle-stickers-btn { font-size:.75rem; padding:.1rem .6rem; margin:.15rem auto; display:inline-flex; align-items:center; gap:.3rem; }
.toggle-stickers-btn:hover { opacity:.85; }

/* -- Chat settings modal -- */
.chat-settings-modal .modal-dialog { max-width: 380px; }
.chat-settings-modal .modal-content { border-radius: 1rem; }
.chat-settings-modal .modal-header { border-bottom: 1px solid var(--border-color); }
.chat-settings-modal .modal-title { font-size: 1rem; font-weight: 600; }
.chat-settings-modal .modal-body { padding: .9rem 1.1rem 1.15rem; }

/* Settings are grouped by what they affect (appearance, playback, analysis). */
.chat-settings-group + .chat-settings-group { margin-top: 1.35rem; }
.chat-settings-group-title {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 0 0 .7rem;
    padding-bottom: .35rem;
    border-bottom: 1px solid var(--border-color);
}

.chat-setting + .chat-setting { margin-top: 1.15rem; }
.chat-setting-row { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.chat-setting-label {
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-color);
    margin: 0 0 .3rem;
    display: block;
}
.chat-setting-row .chat-setting-label { margin-bottom: 0; }
.chat-setting-value {
    font-family: var(--moves-font-mono);
    font-size: .8rem;
    color: var(--text-muted);
}
.chat-setting .form-range { margin: .35rem 0 0; }
.chat-setting .form-select { font-size: .82rem; }
.chat-setting-hint { font-size: .7rem; color: var(--text-muted); margin-top: .3rem; }

/* -- First-message privacy warning -- */
.chat-privacy-modal .modal-dialog { max-width: 520px; }
.chat-privacy-modal .modal-content { border-radius: 1rem; }
.chat-privacy-modal .modal-header { border-bottom: 1px solid var(--border-color); }
.chat-privacy-modal .modal-title { font-size: 1rem; font-weight: 600; }
.chat-privacy-modal .modal-body { padding: 1rem 1.15rem; }
.chat-privacy-modal .chat-privacy-warning {
    margin: 0 0 .85rem;
    font-size: .84rem;
    line-height: 1.55;
    color: var(--text-color);
}
.chat-privacy-modal .chat-privacy-hint {
    margin: 0;
    padding-top: .85rem;
    border-top: 1px solid var(--border-color);
    font-size: .78rem;
    line-height: 1.5;
    color: var(--text-muted);
}
.chat-privacy-modal .modal-footer {
    gap: .5rem;
    padding: .15rem 1.15rem 1rem;
    border-top: 0;
}

/* -- Mobile conversations button -- */
.mobile-convo-btn {
    display: none;
    position: fixed;
    left: 1rem; /* top-left, clear of the centered chat header */
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent-color, #0d6efd);
    color: #fff;
    border: none;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
    cursor: pointer;
    z-index: 9999; /* above the chat header (1028) and navbar (1030) */
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: transform 0.15s, box-shadow 0.15s, left 0.25s ease, opacity 0.2s ease;
}
.mobile-convo-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}
/* While a modal is up the FAB would float over it — it sits at z-index 9999 to
   clear the header and navbar, well above the modal's 1055 — which put the
   bubble on top of the conversations sheet on phones. Bootstrap marks the open
   state itself: `show` when the dialog starts appearing, and `modal-open` on
   <body> a frame later. It clears both only once the dialog has finished
   closing, so the FAB comes back on its own, timed with the modal's own fade.
   It fades out rather than vanishing: fading means the button must stay in the
   layout, so `visibility: hidden` takes it out of the tab order and the
   accessibility tree once the fade is over (the delayed transition here), while
   `pointer-events: none` stops it swallowing taps on the modal during the
   fade-out. Coming back, this rule no longer matches, so the base transition
   above fades it in and visibility returns at once.
   The two selectors are separate rules on purpose: a browser without :has()
   drops a rule whose selector list it can't parse, which would take the
   body.modal-open rule down with it. */
body.modal-open .mobile-convo-btn {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}
body:has(.modal.show) .mobile-convo-btn {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

/* -- Convo modal (phone) -- */
/* Same deal as the desktop sidebar, with slightly taller rows for touch: the
   list — not the modal — is the scroll region, and it is capped so it always
   fits the visible sheet.
   dvh is the height of the area actually on screen, so the cap doesn't extend
   the list under the phone's browser chrome the way vh (the tall viewport) can;
   the vh line is the fallback for browsers without dvh. */
.convo-modal-list {
    max-height: 60vh;
    max-height: 60dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    scrollbar-width: none;
}
.convo-modal-list::-webkit-scrollbar { display: none; }
.convo-modal-list .convo-item {
    border-radius: 0.65rem;
    height: 2.75rem; /* the row's natural height (~43px), i.e. a full touch target */
    padding: 0 0.8rem;
}
.convo-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1rem 0.5rem;
}
.convo-modal-header h6 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}
.convo-modal-header button {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: var(--accent-color, #0d6efd);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.9rem;
}
.convo-modal-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* -- Export / import chats modal -- */
.chat-transfer-modal .modal-dialog { max-width: 460px; }
.chat-transfer-modal .modal-content { border-radius: 1rem; overflow: hidden; }
.chat-transfer-modal .modal-body { padding: .75rem 1rem; }
.chat-transfer-modal .modal-footer {
    border-top: 1px solid var(--border-color);
    padding: .6rem .9rem;
    gap: .5rem;
    justify-content: space-between;
}

.chat-transfer-menu { display: flex; flex-direction: column; gap: .5rem; }
.chat-transfer-option {
    display: flex;
    align-items: center;
    gap: .8rem;
    width: 100%;
    text-align: left;
    cursor: pointer;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: .75rem;
    padding: .7rem .85rem;
    color: var(--text-color);
    transition: border-color .15s, background .15s;
}
.chat-transfer-option:hover {
    border-color: var(--accent-color, #0d6efd);
    background: var(--hover-bg);
}
.chat-transfer-option > i {
    font-size: 1.05rem;
    width: 1.4rem;
    text-align: center;
    flex-shrink: 0;
    color: var(--accent-color, #0d6efd);
}
.chat-transfer-option-text { display: flex; flex-direction: column; min-width: 0; }
.chat-transfer-option-title { font-size: .9rem; font-weight: 600; }
.chat-transfer-option-desc { font-size: .72rem; color: var(--text-muted); }

.chat-transfer-label {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    font-weight: 700;
    color: var(--text-muted);
    margin: .1rem 0 .5rem;
}
.chat-transfer-choice {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .55rem .7rem;
    margin-bottom: .4rem;
    border-radius: .6rem;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    font-size: .85rem;
    color: var(--text-color);
    cursor: pointer;
    transition: background .12s, border-color .12s;
}
.chat-transfer-choice:hover { background: var(--hover-bg); }
.chat-transfer-choice:has(input:checked) {
    border-color: var(--accent-color, #0d6efd);
    background: color-mix(in srgb, var(--accent-color, #0d6efd) 10%, transparent);
}
.chat-transfer-choice input { margin: 0; flex-shrink: 0; accent-color: var(--accent-color, #0d6efd); }
.chat-transfer-choice input:disabled + span { opacity: .5; }

.chat-transfer-hint { font-size: .74rem; color: var(--text-muted); margin-top: .45rem; text-align: center; }
.chat-transfer-error {
    font-size: .78rem;
    color: var(--bs-danger, #dc3545);
    background: color-mix(in srgb, var(--bs-danger, #dc3545) 10%, transparent);
    border-radius: .5rem;
    padding: .45rem .6rem;
    margin-top: .5rem;
}

.chat-import-toolbar {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin: .65rem 0 .4rem;
    flex-wrap: wrap;
}
/* Matches the Select Cases action row in alg_trainer2 */
.chat-import-toolbar .btn {
    font-size: .75rem;
    padding: .3rem .6rem;
    border-radius: 6px;
}
.chat-import-spacer { flex: 1; }
.chat-import-selected-count { font-size: .8125rem; color: var(--text-muted); white-space: nowrap; }
.chat-import-list {
    max-height: 45vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: .3rem;
}
.chat-import-item {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .5rem .65rem;
    border-radius: .55rem;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    font-size: .82rem;
    color: var(--text-color);
    cursor: pointer;
}
.chat-import-item:hover { background: var(--hover-bg); }
.chat-import-item input { margin: 0; flex-shrink: 0; accent-color: var(--accent-color, #0d6efd); }
.chat-import-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-import-count { font-size: .7rem; color: var(--text-muted); white-space: nowrap; }
.chat-import-item.existing .chat-import-name { color: var(--text-color); }
.chat-import-item.existing .chat-import-count { color: var(--bs-warning, #ffc107); }

.chat-transfer-warning {
    display: flex;
    align-items: flex-start;
    gap: .65rem;
    font-size: .84rem;
    line-height: 1.45;
    color: var(--text-color);
    background: color-mix(in srgb, var(--bs-warning, #ffc107) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--bs-warning, #ffc107) 45%, transparent);
    border-radius: .65rem;
    padding: .7rem .75rem;
}
.chat-transfer-warning > i { color: var(--bs-warning, #ffc107); font-size: 1rem; margin-top: .1rem; flex-shrink: 0; }
.chat-transfer-warning-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .75rem; }

/* -- Responsive: desktop — the open conversations drawer pushes the chat
   slightly right; when collapsed the chat is fully centered. -- */
@media (min-width: 768px) {
    .chat-layout { padding-left: 260px; }
    body.chat-sidebar-collapsed .chat-layout { padding-left: 0; }
}

/* -- Responsive: medium desktop — narrower sidebar -- */
@media (max-width: 1100px) and (min-width: 768px) {
    .convo-sidebar { width: 220px; }
    .chat-layout { padding-left: 220px; }
}

/* -- Site-wide sidebar (base.html #sidebar) integration --
   When it opens, #content-wrapper gets margin-left: var(--sidebar-width),
   which pushes the in-flow page (chat column) right. Our fixed elements
   must follow along, or they'd stay glued to the viewport edge. */
#content-wrapper.sidebar-open .convo-sidebar { left: var(--sidebar-width); }
#content-wrapper.sidebar-open .sidebar-reopen-btn { left: calc(var(--sidebar-width) + .75rem); }
#content-wrapper.sidebar-open .mobile-convo-btn { left: calc(var(--sidebar-width) + 1rem); }

/* -- Responsive: small screens -> hide sidebar, show mobile button + modal -- */
@media (max-width: 767px) {
    .convo-sidebar { display: none !important; }
    .sidebar-reopen-btn { display: none !important; }
    .mobile-convo-btn { display: flex !important; top: calc(var(--header-height) + 0.5rem); }
    .chat-main { max-width: 100%; padding: 0; }
    .message { max-width:100%; font-size:.88rem; }
    /* Keep the composer clear of the home indicator / gesture bar. */
    .chat-input-wrap {
        padding-left: 1rem;
        padding-right: 1rem;
        padding-bottom: calc(.1rem + env(safe-area-inset-bottom, 0px));
    }
    /* iOS zooms the whole page when a focused field is under 16px. */
    .chat-box textarea { font-size: 16px; }
    .chat-welcome { padding: 1.25rem .25rem; }
    .chat-welcome h1 { font-size: 1.45rem; }
    .chat-suggestions { gap: .4rem; margin-top: 1rem; }
    .chat-suggestion { padding: .4rem .7rem; font-size: .76rem; }
    .chat-suggestion-hint { max-width: 9rem; }
    .chat-privacy { margin-top: 1.1rem; }
}

@media (max-width: 480px) {
    .chat-hint { display: none; }
    .chat-box { padding:.5rem .7rem .35rem; }
}


/* -- Analysis two-cube display -- */
.analysis-cmp { margin:.5rem 0; }
.analysis-cubes { display:flex; gap:.5rem; }
.analysis-cube {
    flex:1; min-width:0; max-width:50%;
    background:var(--bg-tertiary); border:1px solid var(--border-color);
    border-radius:8px; padding:.5rem;
    text-align:center; display:flex; flex-direction:column;
}
/* Both columns carry exactly one title line — the cube's role on the left,
   "Alt x of y" on the right — styled identically and pinned to a single line,
   so the two players start at the same height. */
.analysis-cube-label,
.analysis-alt-label {
    font-size:.78rem; font-weight:600; color:var(--text-color);
    margin-bottom:.15rem;
    /* Exactly one line of the label font, so the two titles are always the same
       height; longer text is clipped rather than pushing the cube down. */
    line-height:1.2; height:1.2em; overflow:hidden;
}
/* The comparison cubes now sit in a full-width column, so give each one the
   room to be drawn at a readable size rather than the small canvas the
   shrink-wrapped message used to allow. */
.analysis-cube-container { min-height:225px; flex-shrink:0; }
/* The line between the title and the cube: how long each solution is, so the
   two can be compared at a glance. Same fixed height on both sides. */
.analysis-cube-subtitle {
    font-size:.72rem; color:var(--text-muted);
    line-height:1.2; height:1.2em; overflow:hidden;
    margin-bottom:.1rem;
}
.analysis-cube-metrics { font-size:.7rem; color:var(--text-muted); margin-top:.25rem; word-break:break-all; font-family:var(--moves-font-mono); }
.analysis-cube-metrics > div { line-height:1.35; }
.analysis-step-label { font-family:inherit; font-size:.66rem; opacity:.85; }

/* -- Played-move highlight --
   The moves use the same markup, classes and look as the timer's scramble line
   (see timer.css); the mark itself is the app-wide `is-current-move`, styled in
   played-move.css. */
.analysis-cube-metrics .timer-scramble-move,
.suggestion-card-metrics .timer-scramble-move,
.chat-context-sequence .timer-scramble-move {
    display:inline;
    padding:1px 2px;
    border-radius:3px;
    transition:background-color .08s ease, opacity .08s ease;
}
.analysis-cube-metrics .timer-scramble-gap,
.suggestion-card-metrics .timer-scramble-gap,
.chat-context-sequence .timer-scramble-gap {
    /* The same vertical padding as the moves, so the line keeps one height. */
    padding:1px 0;
}
.analysis-cube-with-arrows,
.suggestion-card-with-arrows { display:flex; align-items:center; gap:0; }
.analysis-cube-with-arrows .analysis-cube-container,
.suggestion-card-with-arrows .suggestion-card-cube { flex:1; min-width:0; }
.analysis-cube-with-arrows .analysis-prev,
.analysis-cube-with-arrows .analysis-next,
.suggestion-card-with-arrows .suggestion-prev,
.suggestion-card-with-arrows .suggestion-next {
    background:none; border:none; font-size:2rem; cursor:pointer;
    color:var(--text-muted); padding:0.35rem; line-height:1; flex-shrink:0;
}
.analysis-cube-with-arrows .analysis-prev:hover,
.analysis-cube-with-arrows .analysis-next:hover,
.suggestion-card-with-arrows .suggestion-prev:hover,
.suggestion-card-with-arrows .suggestion-next:hover { color:var(--accent-color,#0d6efd); }
.analysis-arrow-placeholder {
    width:2.7rem; flex-shrink:0; visibility:hidden;
}

/* Combined Play both / Next move controls under a comparison */
.analysis-controls {
    display:flex; flex-wrap:wrap; gap:.4rem; justify-content:center; margin-top:.5rem;
}
.analysis-controls button {
    background:var(--bg-tertiary); border:1px solid var(--border-color); color:var(--text-color);
    border-radius:6px; font-size:.78rem; line-height:1.2; padding:.22rem .6rem; cursor:pointer;
    display:inline-flex; align-items:center; gap:.35rem;
}
.analysis-controls button:hover:not(:disabled) {
    border-color:var(--accent-color); color:var(--accent-color);
}
.analysis-controls button:disabled { opacity:.55; cursor:default; }

@media(max-width:500px) {
    .analysis-cubes { flex-wrap:wrap; }
    .analysis-cube { min-width:130px; max-width:100%; }
}

/* -- Step suggestion cards (the chat's suggest_steps tool) --
   One centered card per start: which colour the solution is on and how long it
   is above a cube with its own play controls, and the written solution
   underneath, marked move by move as it plays (the highlight rules above). A
   start with several solutions keeps the one card and cycles through them with
   the arrows either side of the cube, the way a comparison cycles through its
   alternatives; the card is the same surface as a comparison cube, so the two
   read as one piece of UI. */
.suggestions-block { margin:.6rem 0; }
.suggestions-head {
    display:flex; align-items:baseline; justify-content:center; gap:.5rem;
    margin-bottom:.3rem;
}
.suggestions-title { font-size:.8rem; font-weight:600; color:var(--text-color); }
.suggestions-count { font-size:.72rem; color:var(--text-muted); }
.suggestions-cards {
    display:flex; flex-wrap:wrap; gap:.5rem; justify-content:center; align-items:flex-start;
}
.suggestion-card {
    /* Wide enough for the cube plus an arrow either side, which is what the card
       is: the arrows keep the cube centered whether or not there are any. */
    flex:0 1 auto; width:min(100%, 300px);
    background:var(--bg-tertiary); border:1px solid var(--border-color);
    border-radius:8px; padding:.5rem;
    text-align:center; display:flex; flex-direction:column;
}
.suggestion-card-label {
    font-size:.78rem; font-weight:600; color:var(--text-color);
    line-height:1.2;
}
/* The line between the title and the cube: the colour it is on and how long it
   is, so two solutions can be compared at a glance. */
.suggestion-card-subtitle {
    font-size:.72rem; color:var(--text-muted);
    line-height:1.2; margin-bottom:.15rem;
    overflow-wrap:anywhere;
}
/* A fixed height, so cycling through solutions never shifts the card. */
.suggestion-card-cube { min-height:200px; flex-shrink:0; }
.suggestion-card-metrics {
    font-size:.7rem; color:var(--text-muted); margin-top:.25rem;
    word-break:break-all; font-family:var(--moves-font-mono);
    line-height:1.35;
}

@media(max-width:380px) {
    .suggestion-card { width:min(100%, 300px); }
}

/* ── Shared renderer canvas — chatbot needs high z-index ── */
canvas.global-renderer-canvas {
    z-index: 1026;
}
.cube-player-container {
    z-index: 1061;
}

/* ── Breakdown cards (the chat's breakdown_algorithm tool) ──
   The same shape as the /test-breakdown cards: the algorithm being learned on
   top, the one or two it is matched with underneath, and the card stretched to
   the width of the reply so a pair of cubes has room. */
.breakdown-host { width:100%; }
.breakdown-block { width:100%; }
.breakdown-card { width:100%; max-width:none; }
.breakdown-card .suggestion-card-with-arrows { width:100%; }
.breakdown-stage { flex:1; min-width:0; display:flex; flex-direction:column; gap:.5rem; }
.breakdown-stage .analysis-cubes { width:100%; }
/* The algorithm being learned sits alone on its row; the pair shares one. */
.breakdown-stage .analysis-cubes > .analysis-cube:only-child { max-width:100%; }
.breakdown-cubes-row .analysis-cube { max-width:50%; }
.breakdown-chart { text-align:center; font-family:var(--font-mono); }
.breakdown-lines { text-align:center; white-space:pre; overflow-x:auto; }
/* The brackets that mark the runs each algorithm accounts for. Bootstrap gives
   every `mark` its own padding, and the browser paints it yellow with black text
   — the chat has none of the breakdown page's `.tb-page` rules, so a mark that is
   only stripped of its padding keeps that yellow. They wear the played-move tint
   instead (see the highlight above): the secondary colour as text, over a wash of
   it, so a marked run reads the same way a run of played moves does. */
.breakdown-lines mark {
    padding:0;
    background:color-mix(in srgb, var(--accent-color,#0d6efd) 18%, transparent);
    color:var(--accent-color,#0d6efd);
}
/* A sum is read for its join: the moves the two algorithms cancel through where
   they meet are what the brackets are there for, and nothing else on the lines is
   in question. So only the cancelling bracket wears the tint — the run each
   algorithm brings to the join stays plain text, brackets and all, exactly as the
   cubes below mark it (see drawPairs). A cover has no join: every stretch it
   marks there is one of the two algorithms' own, so all of them stay tinted. */
.breakdown-lines--exact mark.tb-combo-alg1,
.breakdown-lines--exact mark.tb-combo-alg2 {
    background:none;
    color:inherit;
}
