/* ══════════════════════════════════════════════════════════════════
   Pevra — Plus aesthetics
   Themed Scenes · Editorial reading mode · Premium content rendering
   · Living presence orb. Layered on top of styles.css / premium.css.
══════════════════════════════════════════════════════════════════ */

/* ════════════════════════════════════════════════
   THEMED SCENES — full "worlds", not just colours.
   #scene-layer is a fixed backdrop shown only for scene skins.
════════════════════════════════════════════════ */
#scene-layer {
  position: fixed; inset: 0; z-index: -2; pointer-events: none;
  opacity: 0; transition: opacity .8s var(--ease-out, ease);
}
html[data-skin="aurora"] #scene-layer,
html[data-skin="noir"]   #scene-layer,
html[data-skin="sunrise"] #scene-layer,
html[data-skin="paper"]  #scene-layer { opacity: 1; }

/* ── Aurora (dark): drifting northern-lights mesh ──
   NOTE: theme-studio.css sets a WARM-LIGHT palette unconditionally at :root
   (its comment: "Loaded LAST so it wins the cascade"), and only its own
   [data-theme="dark"] activates a dark companion — which app.js never sets
   (it only ever sets data-theme="light" or removes it). So every dark scene
   MUST fully re-declare fg/line/glass/accent-d/-l/-ink/grad-accent itself,
   or those properties silently fall through to theme-studio's light values —
   producing dark text on a dark background (unreadable) and a wrong-coloured
   (orange, via --grad-accent) avatar regardless of the scene's accent. */
html[data-skin="aurora"] {
  --accent: #46d3a6; --accent-d: #2fb488; --accent-l: #6be3c0;
  --accent-glow: rgba(70,211,166,.45); --accent-wash: rgba(70,211,166,.14);
  --accent-ink: #04140f;
  --ink-0: #04070c; --ink-1: #070b12; --ink-2: #0c121d; --ink-3: #121a28; --ink-4: #1a2436; --ink-5: #24304a;
  --fg: #eef6f2; --fg-2: #b9c8c2; --fg-3: #85978f; --fg-4: #56655f;
  --line: rgba(170,230,210,.08); --line-2: rgba(170,230,210,.13);
  --line-3: rgba(170,230,210,.22); --line-4: rgba(170,230,210,.32);
  --c-chat: #46d3a6;
  --grad-accent: linear-gradient(135deg,#46d3a6 0%,#6be3c0 50%,#2fb488 100%);
  --glass-bg: rgba(12,18,29,.68); --glass-bg-2: rgba(18,26,40,.6); --glass-line: rgba(170,230,210,.1);
  --elev-1: 0 1px 2px rgba(0,0,0,.4);
  --elev-2: 0 6px 22px -8px rgba(0,0,0,.55), 0 1px 3px rgba(0,0,0,.4);
  --elev-3: 0 20px 48px -14px rgba(0,0,0,.65), 0 4px 12px -6px rgba(0,0,0,.5);
  --shadow: 0 4px 32px rgba(0,0,0,.5);
  --bg-hover: var(--ink-4);
}
html[data-skin="aurora"] body { background: var(--ink-1); }
html[data-skin="aurora"] #scene-layer {
  background:
    radial-gradient(60% 45% at 20% 15%, rgba(70,211,166,.22), transparent 60%),
    radial-gradient(55% 40% at 80% 10%, rgba(120,110,255,.20), transparent 60%),
    radial-gradient(70% 50% at 60% 90%, rgba(60,160,255,.16), transparent 65%),
    #070b12;
  background-size: 200% 200%, 200% 200%, 200% 200%, 100% 100%;
  animation: auroraDrift 26s ease-in-out infinite alternate;
}
@keyframes auroraDrift {
  0%   { background-position: 0% 0%, 100% 0%, 50% 100%, 0 0; }
  100% { background-position: 40% 30%, 60% 20%, 40% 70%, 0 0; }
}

/* ── Noir (dark): high-contrast mono, sharp ── */
html[data-skin="noir"] {
  --accent: #f5f5f5; --accent-d: #cfcfcf; --accent-l: #ffffff;
  --accent-glow: rgba(255,255,255,.25); --accent-wash: rgba(255,255,255,.10);
  --accent-ink: #0a0a0b;
  --ink-0: #050505; --ink-1: #0a0a0b; --ink-2: #101012; --ink-3: #16161a; --ink-4: #202024; --ink-5: #2a2a30;
  --fg: #f5f5f5; --fg-2: #c4c4c8; --fg-3: #8f8f96; --fg-4: #5c5c62;
  --line: rgba(255,255,255,.07); --line-2: rgba(255,255,255,.12);
  --line-3: rgba(255,255,255,.2); --line-4: rgba(255,255,255,.3);
  --c-chat: #f5f5f5;
  --grad-accent: linear-gradient(135deg,#ffffff 0%,#d8d8d8 100%);
  --glass-bg: rgba(16,16,18,.7); --glass-bg-2: rgba(22,22,26,.62); --glass-line: rgba(255,255,255,.1);
  --elev-1: 0 1px 2px rgba(0,0,0,.4);
  --elev-2: 0 6px 22px -8px rgba(0,0,0,.55), 0 1px 3px rgba(0,0,0,.4);
  --elev-3: 0 20px 48px -14px rgba(0,0,0,.65), 0 4px 12px -6px rgba(0,0,0,.5);
  --shadow: 0 4px 32px rgba(0,0,0,.5);
  --bg-hover: var(--ink-4);
}
html[data-skin="noir"] body { background: var(--ink-1); }
html[data-skin="noir"] #scene-layer {
  background:
    radial-gradient(80% 60% at 50% 0%, rgba(255,255,255,.05), transparent 60%),
    repeating-linear-gradient(0deg, #0a0a0b 0 3px, #090909 3px 4px);
}
html[data-skin="noir"] .send-btn { background: #f5f5f5; color: #0a0a0b; }
html[data-skin="noir"] .msg.assistant .msg-body { border-color: rgba(255,255,255,.14); }

/* ── Sunrise (light): warm gradient tracking a calm dawn ── */
html[data-skin="sunrise"] {
  --accent: #e0602f; --accent-d: #c04c22; --accent-l: #ee7a4d;
  --accent-glow: rgba(224,96,47,.4); --accent-wash: rgba(224,96,47,.12);
  --accent-ink: #ffffff;
  --ink-0: #f9e9db; --ink-1: #fdf3ea; --ink-2: #fff8f1; --ink-3: #fbeadd; --ink-4: #f3ddc9; --ink-5: #e9cbb0;
  --fg: #3a2a20; --fg-2: #6a5142; --fg-3: #9a8272; --fg-4: #c2ac96;
  --line: rgba(120,80,50,.10); --line-2: rgba(120,80,50,.16);
  --line-3: rgba(120,80,50,.24); --line-4: rgba(120,80,50,.34);
  --c-chat: #e0602f;
  --grad-accent: linear-gradient(135deg,#e0602f 0%,#ee7a4d 100%);
  --glass-bg: rgba(255,248,241,.72); --glass-bg-2: rgba(255,243,230,.8); --glass-line: rgba(120,80,50,.1);
  --bg-hover: var(--ink-4);
}
html[data-skin="sunrise"] #scene-layer {
  background:
    radial-gradient(70% 55% at 50% 0%, rgba(255,196,140,.55), transparent 62%),
    radial-gradient(60% 50% at 85% 20%, rgba(255,150,170,.30), transparent 60%),
    linear-gradient(180deg, #fff3e6, #fce7d6 60%, #f6ddce);
  animation: sunriseBreathe 30s ease-in-out infinite alternate;
}
@keyframes sunriseBreathe { to { filter: hue-rotate(-8deg) saturate(1.08); } }

/* ── Paper (light): calm editorial off-white ── */
html[data-skin="paper"] {
  --accent: #9a5b3f; --accent-d: #7e4830; --accent-l: #b57454;
  --accent-glow: rgba(154,91,63,.32); --accent-wash: rgba(154,91,63,.10);
  --accent-ink: #ffffff;
  --ink-0: #efece3; --ink-1: #f6f4ee; --ink-2: #fbfaf5; --ink-3: #efece3; --ink-4: #e6e2d6; --ink-5: #d9d3c3;
  --fg: #2c2822; --fg-2: #5a5349; --fg-3: #8a8276; --fg-4: #b6afa0;
  --line: rgba(40,35,25,.08); --line-2: rgba(40,35,25,.13);
  --line-3: rgba(40,35,25,.21); --line-4: rgba(40,35,25,.3);
  --c-chat: #9a5b3f;
  --grad-accent: linear-gradient(135deg,#9a5b3f 0%,#b57454 100%);
  --glass-bg: rgba(251,250,245,.72); --glass-bg-2: rgba(246,244,238,.8); --glass-line: rgba(40,35,25,.08);
  --bg-hover: var(--ink-4);
}
html[data-skin="paper"] #scene-layer {
  background:
    radial-gradient(120% 120% at 50% 0%, #fbfaf5, #f2efe7 70%);
}
html[data-skin="paper"] .msg.assistant .msg-content { font-family: Georgia, "Times New Roman", serif; font-size: 15.5px; line-height: 1.7; }

/* Scene preview chips in Settings */
.sk-prev.sc-aurora  { background: linear-gradient(135deg,#0a1420 40%,#164a3e); }
.sk-prev.sc-noir    { background: linear-gradient(135deg,#0a0a0b 55%,#242428); }
.sk-prev.sc-sunrise { background: linear-gradient(135deg,#ffd9b0 45%,#ff9fb0); }
.sk-prev.sc-paper   { background: linear-gradient(135deg,#faf8f2 55%,#e9e4d7); }

/* ════════════════════════════════════════════════
   PREMIUM CONTENT RENDERING
════════════════════════════════════════════════ */
/* Code as a little window with a copy affordance */
.code-card {
  margin: 12px 0; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--glass-line, var(--line-2));
  background: #0d1117; box-shadow: 0 6px 20px -12px rgba(0,0,0,.5);
}
.code-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: rgba(255,255,255,.04);
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.code-dots { display: flex; gap: 6px; }
.code-dots i { width: 11px; height: 11px; border-radius: 50%; display: block; }
.code-dots i:nth-child(1) { background: #ff5f57; }
.code-dots i:nth-child(2) { background: #febc2e; }
.code-dots i:nth-child(3) { background: #28c840; }
.code-lang { font-size: 11px; color: #8b95a5; font-family: var(--mono, monospace); letter-spacing: .04em; text-transform: uppercase; }
.code-copy {
  margin-left: auto; background: rgba(255,255,255,.06); border: none; cursor: pointer;
  color: #c9d1d9; font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 7px;
  transition: background .15s, color .15s;
}
.code-copy:hover { background: rgba(255,255,255,.12); color: #fff; }
.code-copy.copied { background: rgba(40,200,64,.18); color: #4ade80; }
.code-card pre { margin: 0; padding: 14px 16px; overflow-x: auto; background: transparent; }
.code-card pre code { color: #d6deeb; font-size: 13px; line-height: 1.6; font-family: var(--mono, monospace); }

/* Elegant tables */
.msg .msg-content table {
  border-collapse: collapse; margin: 12px 0; width: 100%;
  border: 1px solid var(--line-2); border-radius: 10px; overflow: hidden; font-size: 13.5px;
}
.msg .msg-content table td { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.msg .msg-content table tr:first-child td { background: var(--ink-3); font-weight: 600; color: var(--fg); }
.msg .msg-content table tr:last-child td { border-bottom: none; }

/* Callout blockquotes */
.msg .msg-content blockquote {
  margin: 12px 0; padding: 10px 16px; border-left: 3px solid var(--accent);
  background: var(--accent-wash); border-radius: 0 10px 10px 0;
  color: var(--fg-2); font-style: normal;
}

/* Inline + display math (lightweight, dependency-free) */
.math-inline { font-family: "Cambria Math", Georgia, serif; font-style: italic; padding: 0 1px; }
.math-block {
  display: block; text-align: center; margin: 14px auto; padding: 12px 16px;
  font-family: "Cambria Math", Georgia, serif; font-style: italic; font-size: 16px;
  background: var(--ink-3); border-radius: 10px; overflow-x: auto;
}

/* ════════════════════════════════════════════════
   EDITORIAL READING MODE
════════════════════════════════════════════════ */
.read-btn {
  display: inline-flex; align-items: center; gap: 5px; margin-top: 8px;
  background: var(--ink-3); border: 1px solid var(--line-2); color: var(--fg-2);
  font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 999px; cursor: pointer;
  transition: background .15s, color .15s, transform .15s;
}
.read-btn:hover { background: var(--accent-wash); color: var(--accent); transform: translateY(-1px); }

.reader-overlay {
  position: fixed; inset: 0; z-index: 400; display: none;
  background: color-mix(in srgb, var(--ink-1) 78%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  overflow-y: auto; padding: 40px 20px 80px;
}
.reader-overlay.open { display: block; animation: readerFade .3s var(--ease-out, ease); }
@keyframes readerFade { from { opacity: 0; } }
.reader-close {
  position: fixed; top: 18px; right: 20px; z-index: 2;
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line-2);
  background: var(--ink-2); color: var(--fg-2); font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.reader-close:hover { color: var(--fg); }
.reader-doc {
  max-width: 720px; margin: 0 auto; animation: readerRise .45s var(--ease-out, ease) both;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--fg); font-size: 19px; line-height: 1.75;
}
@keyframes readerRise { from { opacity: 0; transform: translateY(18px); } }
.reader-kicker { font-family: var(--sans); font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin-bottom: 10px; }
.reader-doc h1, .reader-doc h2, .reader-doc h3 { font-family: Georgia, serif; line-height: 1.2; margin: 28px 0 12px; }
.reader-doc h1 { font-size: 34px; letter-spacing: -.01em; }
.reader-doc h2 { font-size: 25px; }
.reader-doc h3 { font-size: 20px; }
.reader-doc p { margin: 0 0 18px; }
/* Drop cap on the opening paragraph */
.reader-doc > p:first-of-type::first-letter {
  float: left; font-size: 62px; line-height: .82; padding: 6px 10px 0 0; color: var(--accent); font-weight: 700;
}
.reader-doc blockquote {
  margin: 22px 0; padding: 4px 0 4px 22px; border-left: 3px solid var(--accent);
  font-size: 22px; font-style: italic; color: var(--fg-2);
}
.reader-doc pre { font-family: var(--mono, monospace); font-size: 14px; background: var(--ink-3); padding: 14px 16px; border-radius: 10px; overflow-x: auto; }
.reader-doc code { font-family: var(--mono, monospace); font-size: .82em; background: var(--ink-3); padding: 1px 5px; border-radius: 5px; }
.reader-doc a { color: var(--accent); }
.reader-doc ul, .reader-doc ol { margin: 0 0 18px; padding-left: 26px; }
.reader-doc li { margin-bottom: 8px; }
.reader-doc table { width: 100%; border-collapse: collapse; margin: 18px 0; font-family: var(--sans); font-size: 15px; }
.reader-doc table td { padding: 9px 12px; border-bottom: 1px solid var(--line); }
.reader-foot { max-width: 720px; margin: 40px auto 0; padding-top: 18px; border-top: 1px solid var(--line); font-family: var(--sans); font-size: 12.5px; color: var(--fg-3); }

/* ════════════════════════════════════════════════
   LIVING PRESENCE ORB — a small, always-alive Pevra mark
════════════════════════════════════════════════ */
#pevra-presence {
  position: fixed; right: 18px; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; display: none;
  background: radial-gradient(120% 120% at 30% 25%, #1d1810, #111009 70%);
  box-shadow: 0 6px 20px -6px var(--accent-glow), 0 0 0 1px rgba(255,255,255,.06) inset;
  animation: presenceBreathe 5.5s var(--ease-in-out, ease) infinite;
}
body.is-plus #pevra-presence { display: block; }
#pevra-presence svg { width: 100%; height: 100%; display: block; }
@keyframes presenceBreathe {
  0%,100% { transform: scale(1); box-shadow: 0 6px 20px -8px var(--accent-glow), 0 0 0 1px rgba(255,255,255,.06) inset; }
  50%     { transform: scale(1.06); box-shadow: 0 8px 26px -6px var(--accent-glow), 0 0 0 1px rgba(255,255,255,.10) inset; }
}
#pevra-presence.thinking { animation: presenceThink 1.5s var(--ease-in-out, ease) infinite; }
@keyframes presenceThink {
  0%,100% { box-shadow: 0 6px 20px -8px var(--accent-glow), 0 0 0 1px rgba(255,255,255,.06) inset; }
  50%     { box-shadow: 0 6px 26px -2px var(--accent-glow), 0 0 0 2px var(--accent-wash) inset; }
}
#pevra-presence.thinking .pr-core { animation: prCoreSpin 1.5s linear infinite; transform-box: fill-box; transform-origin: center; }
@keyframes prCoreSpin { to { transform: rotate(360deg); } }
#pevra-presence.speaking { animation: presenceSpeak .5s var(--ease-in-out, ease) infinite; }
@keyframes presenceSpeak { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }

@media (prefers-reduced-motion: reduce) {
  #scene-layer, #pevra-presence { animation: none !important; }
  .reader-doc, .reader-overlay.open { animation: none; }
}
@media (max-width: 640px) {
  #pevra-presence { bottom: calc(120px + env(safe-area-inset-bottom, 0px)); right: 12px; width: 30px; height: 30px; }
  .reader-doc { font-size: 17px; }
  .reader-doc h1 { font-size: 27px; }
}

/* ════════════════════════════════════════════════
   HIGHLIGHTER — ==text== marks in responses (theme-aware).
   Translucent tint behind normal --fg text, so it stays readable on every
   theme, light or dark. Semantic variants for good / caution / risk.
════════════════════════════════════════════════ */
.msg-content mark.hl, .reader-doc mark.hl, .amt-content mark.hl {
  background: var(--accent-wash);                                 /* fallback */
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: inherit; padding: .5px 3px; border-radius: 3px;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.msg-content mark.hl-warn, .reader-doc mark.hl-warn, .amt-content mark.hl-warn {
  background: rgba(217,138,43,.22);
  background: color-mix(in srgb, var(--warn, #D98A2B) 26%, transparent);
}
.msg-content mark.hl-good, .reader-doc mark.hl-good, .amt-content mark.hl-good {
  background: rgba(47,158,107,.22);
  background: color-mix(in srgb, var(--pos, #2F9E6B) 24%, transparent);
}
.msg-content mark.hl-bad, .reader-doc mark.hl-bad, .amt-content mark.hl-bad {
  background: rgba(209,69,69,.22);
  background: color-mix(in srgb, var(--neg, #D14545) 24%, transparent);
}
