/* study-message-card.css — Ask AI's message card (public/js/study/study-message-card.js).
   2026-09-30.

   A message Khio wrote for the user to copy and send somewhere else: a
   rounded card a shade lighter than the chat, a title with Copy and Expand
   on the right, then the message. A long one is capped, scrolls inside and
   fades out at the bottom; Expand opens it full size.

   Colours are this file's own --kmc-* tokens with a dark twin under
   html[data-theme="dark"]: the full-size view hangs off <body>, outside
   #view-deeptutor where the chat's --dt-* tokens live, so it cannot borrow
   them. The ink, muted and line values are the --dt-* ones. No orange
   anywhere; dark is the graphite ink.

   Nothing here animates: study-deeptutor.js redraws a streaming reply on
   every token, which would restart any animation each time. An unfinished
   card keeps its newest line in view with column-reverse alone.

   Phone width: the card is the bubble's width and its buttons grow to a
   thumb's size; the full-size view covers the screen inside the safe areas,
   which is also what the iPhone app (html.khio-app) gets. */

.kmc,
.kmc-dialog {
    --kmc-ink: #191a1d;
    --kmc-muted: #70747c;
    --kmc-line: rgba(22,24,28,.10);
    --kmc-hover: #f1f2f3;
    --kmc-bg: #ffffff;
}
html[data-theme="dark"] .kmc,
html[data-theme="dark"] .kmc-dialog {
    --kmc-ink: #f2f2f3;
    --kmc-muted: #a3a4aa;
    --kmc-line: rgba(255,255,255,.12);
    --kmc-hover: rgba(255,255,255,.08);
    --kmc-bg: #1f1f21;
}

/* ── The card ── */
.kmc {
    box-sizing: border-box;
    max-width: 100%;
    margin: 14px 0;
    border: 1px solid var(--kmc-line);
    border-radius: 24px;
    background: var(--kmc-bg);
    color: var(--kmc-ink);
    overflow: hidden;
}
.kmc *, .kmc-dialog * { box-sizing: border-box; }

.kmc-head {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 12px 12px 2px 22px;
}
/* A quiet label, as ChatGPT's is: the message is the thing to read. */
.kmc-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--kmc-muted);
    font-size: 14.5px;
    font-weight: 500;
    line-height: 1.3;
}
.kmc-tools { display: inline-flex; flex: 0 0 auto; gap: 2px; }

.kmc-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--kmc-ink);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
}
.kmc-btn:hover { background: var(--kmc-hover); color: var(--kmc-ink); }
.kmc-btn:focus-visible { outline: 2px solid var(--kmc-ink); outline-offset: 1px; }
.kmc-btn svg {
    flex: 0 0 auto;
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}
/* Copy swaps its icon for a check and says so for a moment. */
.kmc-btn svg + svg,
.kmc-copied,
.kmc-btn.is-copied svg:first-child { display: none; }
.kmc-btn.is-copied { color: var(--kmc-ink); }
.kmc-btn.is-copied svg + svg,
.kmc-btn.is-copied .kmc-copied { display: inline; }

/* ── The message ── */
.kmc-view { position: relative; }
.kmc-scroll {
    max-height: min(560px, 64vh);
    overflow-y: auto;
    scrollbar-width: thin;
}
.kmc-scroll:focus-visible { outline: 2px solid var(--kmc-ink); outline-offset: -2px; border-radius: 0 0 15px 15px; }
.kmc-body { padding: 8px 22px 22px; overflow-wrap: anywhere; font-size: 17px; line-height: 1.7; }
/* The message's own type, in the chat and full size alike, over the
   answer's .dt2-md rules: a list of people or jobs reads as a document, a
   heading per entry, a label per line, a rule between entries (James
   2026-09-30, next to ChatGPT's card). */
.kmc .kmc-body > :first-child,
.kmc-dialog .kmc-body > :first-child { margin-top: 0; }
.kmc .kmc-body > :last-child,
.kmc-dialog .kmc-body > :last-child { margin-bottom: 0; }
.kmc .kmc-body p,
.kmc-dialog .kmc-body p { margin: 0 0 12px; }
.kmc .kmc-body h1,
.kmc-dialog .kmc-body h1 { margin: 6px 0 14px; font-size: 27px; font-weight: 700; line-height: 1.2; letter-spacing: -.01em; }
.kmc .kmc-body h2,
.kmc-dialog .kmc-body h2 { margin: 20px 0 10px; font-size: 21px; font-weight: 650; line-height: 1.25; }
.kmc .kmc-body h3,
.kmc .kmc-body h4,
.kmc-dialog .kmc-body h3,
.kmc-dialog .kmc-body h4 { margin: 18px 0 10px; font-size: 20px; font-weight: 650; line-height: 1.3; }
.kmc .kmc-body strong,
.kmc-dialog .kmc-body strong { font-weight: 700; }
.kmc .kmc-body ul,
.kmc .kmc-body ol,
.kmc-dialog .kmc-body ul,
.kmc-dialog .kmc-body ol { margin: 4px 0 14px; padding-left: 22px; }
.kmc .kmc-body li,
.kmc-dialog .kmc-body li { margin: 5px 0; }
.kmc .kmc-body hr,
.kmc-dialog .kmc-body hr { border: 0; border-top: 1px solid var(--kmc-line); margin: 22px 0; }

.kmc-view::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 64px;
    background: linear-gradient(to bottom, transparent, var(--kmc-bg));
    pointer-events: none;
    opacity: 0;
}
.kmc.is-clipped:not(.is-end) .kmc-view::after { opacity: 1; }

/* Still being written: newest line in view, the fade at the top, and no
   buttons until there is a whole message to copy. */
.dt2-answer.streaming .kmc.is-open .kmc-scroll { display: flex; flex-direction: column-reverse; }
.dt2-answer.streaming .kmc.is-open .kmc-view::after {
    top: 0;
    bottom: auto;
    background: linear-gradient(to top, transparent, var(--kmc-bg));
}
.dt2-answer.streaming .kmc.is-open .kmc-tools { visibility: hidden; }

/* ── Full size ── */
.kmc-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background: rgba(10,10,12,.46);
}
.kmc-dialog {
    display: flex;
    flex-direction: column;
    width: min(760px, 100%);
    max-height: 100%;
    border: 1px solid var(--kmc-line);
    border-radius: 18px;
    background: var(--kmc-bg);
    color: var(--kmc-ink);
    /* The chat answer's own face (.dt2-answer); out here nothing passes it down. */
    font-family: Manrope, Inter, -apple-system, BlinkMacSystemFont, sans-serif;
    box-shadow: 0 24px 64px rgba(0,0,0,.28);
    overflow: hidden;
}
.kmc-dialog .kmc-head { padding: 10px 10px 10px 22px; border-bottom: 1px solid var(--kmc-line); }
.kmc-dialog .kmc-title { font-size: 15px; }
.kmc-dialog .kmc-scroll { flex: 1 1 auto; max-height: none; overscroll-behavior: contain; }
.kmc-dialog .kmc-scroll:focus-visible { border-radius: 0; }
.kmc-dialog .kmc-body { padding: 20px 26px 30px; }
.kmc-dialog .kmc-body a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.kmc-dialog .kmc-body blockquote { margin: 10px 0; padding: 2px 0 2px 14px; border-left: 3px solid var(--kmc-line); color: var(--kmc-muted); }

@media (max-width: 640px) {
    .kmc-btn { min-width: 40px; height: 40px; }
    .kmc-backdrop { padding: 0; }
    .kmc-dialog {
        width: 100%;
        height: 100%;
        border: 0;
        border-radius: 0;
        padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
    }
    .kmc-dialog .kmc-head { padding-left: 18px; }
    .kmc-dialog .kmc-body { padding: 16px 18px 28px; }
}

/* Read aloud, never shown: "Copied". */
.kmc-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}
