/* grok.online — rendered Markdown, code blocks and message layout (chat app, tool widget, share view). Needs tokens.css. */

/* Fallback copy of the "Event horizon" site tokens (assets/css/tokens.css, same names). Layered, so the unlayered
   tokens.css always wins; only tokens it lacks fall through to these values. Dark is the default theme. */
@layer cg-fallback {
  :root, [data-theme="dark"] {
    color-scheme: dark;
    --teal: #8B9CFF; --coral: #E0A458; --coral-soft: rgba(224, 164, 88, .14); --teal-soft: rgba(139, 156, 255, .12);
    --bg: #0A0A0C; --bg-soft: #0E0E11; --surface: #121216; --surface-2: #18181D;
    --border: rgba(255, 255, 255, .08); --border-strong: rgba(255, 255, 255, .15);
    --text: #F4F4F5; --text-soft: #D4D4D8; --muted: #A1A1AA;
    --accent: #FFFFFF; --accent-hover: #E4E4E7; --accent-2: #8B9CFF; --accent-ink: #AFC0FF; --accent-soft: rgba(139, 156, 255, .12);
    --accent-grad: linear-gradient(135deg, #FFFFFF 0%, #E8ECFF 100%); --on-accent: #0A0A0C;
    --horizon: radial-gradient(closest-side, rgba(232, 236, 255, .22), rgba(139, 156, 255, .10) 55%, transparent);
    --success: #5BBF8A; --danger: #F87171;
    --radius-sm: 10px; --radius: 14px; --radius-lg: 16px; --radius-pill: 999px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px -10px rgba(0, 0, 0, .7);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, .4), 0 30px 70px -20px rgba(0, 0, 0, .85);
    --ring: 0 0 0 3px rgba(175, 192, 255, .45);
    --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
    --font-display: "Space Grotesk", var(--font);
    --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    --ease: cubic-bezier(.2, .7, .2, 1);
  }
  [data-theme="light"] {
    color-scheme: light;
    --teal: #3346C9; --coral: #A35C0A; --coral-soft: #FBEEDC; --teal-soft: #E9ECFB;
    --bg: #FAFAF9; --bg-soft: #F3F3F1; --surface: #FFFFFF; --surface-2: #F1F1EF;
    --border: rgba(11, 11, 14, .09); --border-strong: rgba(11, 11, 14, .17);
    --text: #0B0B0E; --text-soft: #2E2E36; --muted: #5B5B66;
    --accent: #0B0B0E; --accent-hover: #26262C; --accent-2: #5B6CE0; --accent-ink: #3346C9; --accent-soft: rgba(51, 70, 201, .08);
    --accent-grad: linear-gradient(135deg, #1C1C22 0%, #0B0B0E 100%); --on-accent: #FFFFFF;
    --horizon: radial-gradient(closest-side, rgba(139, 156, 255, .20), rgba(139, 156, 255, .07) 55%, transparent);
    --success: #1E7F4F; --danger: #C42B2B;
    --shadow-sm: 0 1px 2px rgba(11, 11, 14, .06);
    --shadow: 0 1px 2px rgba(11, 11, 14, .05), 0 8px 24px -10px rgba(11, 11, 14, .16);
    --shadow-lg: 0 2px 6px rgba(11, 11, 14, .05), 0 26px 60px -20px rgba(11, 11, 14, .26);
    --ring: 0 0 0 3px rgba(51, 70, 201, .3);
  }
}

:root { --cg-fs: 16px; --cg-code-bg: #0E0E12; --cg-code-head: #16161B; --cg-code-text: #E8E8EC; --cg-bubble: #1C1C22; }
:root[data-cg-font="s"] { --cg-fs: 15px; }
:root[data-cg-font="l"] { --cg-fs: 17.5px; }
[data-theme="light"] { --cg-code-bg: #121216; --cg-code-head: #1B1B21; --cg-bubble: #EFEFEC; }

.cg-sr { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- markdown ---------- */
.cg-md { font-size: var(--cg-fs); line-height: 1.72; color: var(--text); overflow-wrap: anywhere; min-width: 0; }
.cg-md > :first-child { margin-top: 0; }
.cg-md > :last-child { margin-bottom: 0; }
.cg-md p, .cg-md ul, .cg-md ol, .cg-md blockquote, .cg-md .cg-table, .cg-md .cg-code { margin: 0 0 .95em; }
.cg-md h1, .cg-md h2, .cg-md h3, .cg-md h4, .cg-md h5, .cg-md h6 { font-weight: 650; line-height: 1.3; letter-spacing: -.012em; margin: 1.5em 0 .55em; color: var(--text); }
.cg-md h1 { font-size: 1.5em; }
.cg-md h2 { font-size: 1.3em; }
.cg-md h3 { font-size: 1.14em; }
.cg-md h4, .cg-md h5, .cg-md h6 { font-size: 1em; }
.cg-md ul, .cg-md ol { padding-inline-start: 1.5em; }
.cg-md li { margin: .3em 0; }
.cg-md li > p { margin: .3em 0; }
.cg-md li > ul, .cg-md li > ol { margin: .25em 0; }
.cg-md li::marker { color: var(--muted); }
.cg-md ol > li::marker { font-variant-numeric: tabular-nums; }
.cg-md strong { font-weight: 650; }
.cg-md a { color: var(--accent-ink); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent-ink) 35%, transparent); text-underline-offset: 2px; }
.cg-md a:hover { text-decoration-color: currentColor; }
.cg-md hr { border: 0; height: 1px; background: var(--border); margin: 1.6em 0; }
.cg-md blockquote { padding: .1em 0; padding-inline-start: 1em; border-inline-start: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); color: var(--text-soft); }
.cg-md :not(pre) > code { font-family: var(--font-mono); font-size: .875em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: .08em .38em; }
.cg-md input[type="checkbox"] { margin-inline-end: .45em; vertical-align: -1px; accent-color: var(--accent); }
.cg-md li:has(> input[type="checkbox"]) { list-style: none; margin-inline-start: -1.3em; }
.cg-md-raw { white-space: pre-wrap; }

/* tables */
.cg-table { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; -webkit-overflow-scrolling: touch; }
.cg-md table { border-collapse: collapse; width: 100%; font-size: .93em; line-height: 1.5; }
.cg-md th, .cg-md td { padding: 9px 14px; text-align: start; vertical-align: top; border-bottom: 1px solid var(--border); }
.cg-md th { background: var(--bg-soft); font-weight: 600; white-space: nowrap; }
.cg-md tr:last-child td { border-bottom: 0; }
.cg-md td + td, .cg-md th + th { border-inline-start: 1px solid var(--border); }

/* code blocks */
.cg-code { background: var(--cg-code-bg); border-radius: 12px; overflow: hidden; border: 1px solid rgba(255, 255, 255, .08); direction: ltr; text-align: left; }
.cg-code-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 6px 5px 14px; background: var(--cg-code-head); color: #A1A1AA; font: 500 12px/1.4 var(--font-mono); border-bottom: 1px solid rgba(255, 255, 255, .06); }
.cg-code-lang { text-transform: lowercase; }
.cg-code-copy { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: #C4C4CC; font: 500 12px var(--font); cursor: pointer; }
.cg-code-copy:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.cg-code-copy.is-done { color: #5BBF8A; }
.cg-code-copy:focus-visible { outline: 2px solid #AFC0FF; outline-offset: 1px; }
.cg-code pre { margin: 0; padding: 14px 16px 16px; overflow-x: auto; font: 13.5px/1.65 var(--font-mono); color: var(--cg-code-text); tab-size: 4; -webkit-overflow-scrolling: touch; }
.cg-code pre code { font: inherit; background: none; border: 0; padding: 0; white-space: pre; }

/* highlight.js tokens (dark code surface in both themes) */
.hljs-comment, .hljs-quote { color: #7A7A85; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-doctag, .hljs-section, .hljs-name { color: #AFC0FF; }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-meta .hljs-string { color: #B8E0A8; }
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-link { color: #F0C08A; }
.hljs-title, .hljs-title.function_, .hljs-selector-id { color: #E8ECFF; }
.hljs-title.class_, .hljs-type, .hljs-built_in, .hljs-class .hljs-title { color: #C9B8FF; }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable, .hljs-selector-class, .hljs-property { color: #9FD3E8; }
.hljs-params { color: #E4E4E7; }
.hljs-meta, .hljs-meta .hljs-keyword { color: #A1A1AA; }
.hljs-deletion { color: #FF8A8F; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

/* ---------- messages (shared by chat + share view) ---------- */
.cg-thread { display: flex; flex-direction: column; gap: 30px; }
.cg-msg { position: relative; }
.cg-msg-user { display: flex; flex-direction: column; align-items: flex-end; }
.cg-bubble { max-width: min(85%, 640px); padding: 10px 16px; border-radius: 16px 16px 4px 16px; background: var(--cg-bubble); border: 1px solid var(--border); color: var(--text); font-size: var(--cg-fs); line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
[dir="rtl"] .cg-bubble { border-radius: 16px 16px 16px 4px; }
.cg-uimg { margin: 0 0 6px; max-width: min(85%, 300px); }
.cg-uimg img { display: block; max-width: 100%; height: auto; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); }
.cg-actions-static { opacity: 1; }
.cg-msg-ai { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 14px; align-items: start; }
.cg-msg-ai:not(:has(.cg-avatar)) { grid-template-columns: minmax(0, 1fr); }
.cg-avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border); color: var(--text); margin-top: 1px; }
.cg-avatar { --bg: var(--surface); }
.cg-avatar .cg-mark { width: 20px; height: 20px; }
.cg-msg-body { min-width: 0; }
.cg-share-thread { max-width: 760px; margin: 0 auto; }

/* Promo panels shared by the chat dialogs and the tool widget (core.js limitPanel / imageCard): text, GOPromo 'modal'
   blocks (assets/js/promo.js draws them; white or colourful on purpose), the bonus button with its countdown. */
.cg-lim-title { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 16px; font-weight: 660; color: var(--text); }
.cg-lim-title .cg-i { color: var(--accent-ink); }
.cg-lim-text { margin: 0 0 14px; font-size: 14.5px; line-height: 1.55; color: var(--text-soft); }
.cg-lim-promos { display: grid; gap: 10px; }
.cg-lim-promos:empty { display: none; }
.cg-lim-promo { min-width: 0; }
.cg-lim-promo > * { max-width: 100%; }
.cg-lim-acts { display: flex; justify-content: center; margin-top: 16px; }
.cg-lim-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 24px; border: 0; border-radius: var(--radius-pill, 999px); background: var(--accent-grad, var(--accent)); color: var(--on-accent, #0A0A0C); font: inherit; font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; cursor: pointer; transition: transform .12s, opacity .15s; }
.cg-lim-btn:hover:not(:disabled) { transform: translateY(-1px); }
.cg-lim-btn:disabled { opacity: .5; cursor: default; }
.cg-lim-btn.is-busy { opacity: .7; cursor: progress; }
.cg-lim-btn:focus-visible { outline: none; box-shadow: var(--ring, 0 0 0 3px rgba(139, 156, 255, .5)); }
.cg-lim-err { margin: 10px 0 0; text-align: center; font-size: 13.5px; color: var(--danger, #F87171); }
.cg-imgno { display: grid; gap: 10px; max-width: 560px; }
.cg-imgno-text { display: flex; align-items: flex-start; gap: 9px; margin: 0; font-size: var(--cg-fs, 15px); line-height: 1.6; color: var(--text); }
.cg-imgno-text .cg-i { flex: none; margin-top: 3px; color: var(--accent-ink); }
@media (max-width: 640px) { .cg-lim-btn { width: 100%; } }