/* ============================================================================
   Nanobot Muse v3 — Dynamic Mascot Animations + Settings Studio
   ============================================================================ */

/* ==================== DYNAMIC MASCOT ENGINE (60FPS) ==================== */
.mascot-stage {
  width: var(--m-size, 64px);
  height: var(--m-size, 64px);
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto; user-select: none; -webkit-user-select: none;
}
.mascot-interactive { cursor: pointer; }
.mascot-inner {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  transform-origin: center 75%; will-change: transform;
}
.mascot-svg, .m-svg {
  width: 100%; height: 100%; overflow: visible; display: block;
  transform: scale(var(--m-scale, 1));
  filter: drop-shadow(0 6px 14px rgba(15, 23, 42, 0.08));
}
.mascot-custom-img {
  width: 100%; height: 100%; object-fit: contain; display: block;
  transform: scale(var(--m-scale, 1));
}
.mascot-mini .mascot-svg, .mascot-mini .m-svg, .topic-mascot-badge .m-svg { filter: none; }
html[data-theme="dark"] .mascot-svg, html[data-theme="dark"] .m-svg { filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.36)); }
html[data-theme="dark"] .mascot-mini .mascot-svg, html[data-theme="dark"] .mascot-mini .m-svg, html[data-theme="dark"] .topic-mascot-badge .m-svg { filter: none; }
.m-shadow { fill: #0F172A; opacity: 0.075; filter: blur(3.5px); transform-origin: 60px 111px; transition: transform 0.3s ease, opacity 0.25s ease; }
html[data-theme="dark"] .m-shadow { fill: #000000; opacity: 0.45; filter: blur(4.5px); }

/* Obsidian preset auto-inverts between Light & Dark themes */
.m-obsidian-fill { fill: #18181B; transition: fill 0.25s ease; }
.m-obsidian-eye { stroke: #FFFFFF; fill: #FFFFFF; }
.m-obsidian-eye-stroke { stroke: #FFFFFF; }
.m-obsidian-eye-fill { fill: #FFFFFF; }
html[data-theme="dark"] .m-obsidian-fill { fill: #ECEEF2; }
html[data-theme="dark"] .m-obsidian-eye-stroke { stroke: #141519; }
html[data-theme="dark"] .m-obsidian-eye-fill { fill: #141519; }

/* Eye layers & FX visibility by state */
.m-eyes-happy, .m-eyes-error, .m-fx-work, .m-fx-working, .m-fx-happy, .m-fx-error { opacity: 0; transition: opacity 0.18s ease; }
.mascot-state-happy .m-eyes-normal { opacity: 0; }
.mascot-state-happy .m-eyes-happy, .mascot-state-happy .m-fx-happy { opacity: 1; }
.mascot-state-error .m-eyes-normal { opacity: 0; }
.mascot-state-error .m-eyes-error, .mascot-state-error .m-fx-error { opacity: 1; }
.mascot-state-working .m-fx-work, .mascot-state-working .m-fx-working { opacity: 1; }
.mascot-mini .m-fx-work, .mascot-mini .m-fx-working, .mascot-mini .m-fx-happy, .mascot-mini .m-fx-error { display: none; }

/* Natural living IDLE animation: breath + periodic blink + subtle gaze */
.mascot-state-idle .mascot-inner { animation: mIdleBreath 3.8s ease-in-out infinite; }
.mascot-state-idle .m-eye-wrap {
  transform-box: fill-box; transform-origin: center center;
  animation: mIdleBlinkGaze 5.2s ease-in-out infinite;
}
.mascot-motion-subtle.mascot-state-idle .mascot-inner { animation-duration: 5.4s; }
.mascot-motion-lively.mascot-state-idle .mascot-inner { animation-duration: 2.6s; }

@keyframes mIdleBreath {
  0%, 100% { transform: translateY(0px) scale(1, 1); }
  50% { transform: translateY(-4px) scale(1.018, 0.986); }
}
@keyframes mIdleBlinkGaze {
  0%, 38%, 44%, 100% { transform: translate(0px, 0px) scaleY(1); }
  41% { transform: translate(0px, 0px) scaleY(0.1); }
  62%, 74% { transform: translate(2.8px, -1px) scaleY(1); }
  84%, 92% { transform: translate(-2px, 0.5px) scaleY(1); }
}

/* WORKING animation: energetic rhythmic lean-bounce + scanning eyes + orbiting dots */
.mascot-state-working .mascot-inner { animation: mWorkBounce 1.15s cubic-bezier(0.4, 0, 0.2, 1) infinite; }
.mascot-state-working .m-eye-wrap {
  transform-box: fill-box; transform-origin: center center;
  animation: mWorkScan 1.5s ease-in-out infinite;
}
.mascot-state-working .m-work-dot-1 { animation: mOrbitPulse 1.1s ease-in-out infinite 0s; }
.mascot-state-working .m-work-dot-2 { animation: mOrbitPulse 1.1s ease-in-out infinite 0.2s; }
.mascot-state-working .m-work-dot-3 { animation: mOrbitPulse 1.1s ease-in-out infinite 0.4s; }

@keyframes mWorkBounce {
  0%, 100% { transform: translateY(0) rotate(-3deg) scale(1.03, 0.97); }
  50% { transform: translateY(-7px) rotate(3deg) scale(0.97, 1.04); }
}
@keyframes mWorkScan {
  0%, 100% { transform: translate(-2.6px, -0.5px); }
  50% { transform: translate(2.8px, -1.2px); }
}
@keyframes mOrbitPulse {
  0%, 100% { opacity: 0.3; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-4px); }
}

/* HAPPY animation: celebratory double-hop + sparkle pop */
.mascot-state-happy .mascot-inner { animation: mHappyHop 0.95s cubic-bezier(0.22, 1.25, 0.36, 1) infinite; }
.mascot-state-happy .m-fx-happy {
  transform-box: fill-box; transform-origin: center center;
  animation: mSparklePop 0.95s ease-in-out infinite;
}
@keyframes mHappyHop {
  0%, 100% { transform: translateY(0) scale(1.05, 0.94); }
  38% { transform: translateY(-11px) scale(0.95, 1.07) rotate(-2.5deg); }
  68% { transform: translateY(-3px) scale(1.02, 0.98) rotate(2deg); }
}
@keyframes mSparklePop {
  0%, 100% { transform: scale(0.88); opacity: 0.7; }
  50% { transform: scale(1.12); opacity: 1; }
}

/* ERROR animation: gentle tilt shiver */
.mascot-state-error .mascot-inner { animation: mErrorTilt 0.65s ease-in-out infinite; }
@keyframes mErrorTilt {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  25% { transform: translateX(-3px) rotate(-4deg); }
  75% { transform: translateX(3px) rotate(4deg); }
}

/* Tap / Poke Jelly Squash-and-Stretch */
.mascot-tap .mascot-inner { animation: mJellyTap 0.58s cubic-bezier(0.22, 1.4, 0.36, 1) !important; }
@keyframes mJellyTap {
  0% { transform: scale(1, 1); }
  22% { transform: scale(1.18, 0.84) translateY(5px); }
  52% { transform: scale(0.91, 1.12) translateY(-8px); }
  76% { transform: scale(1.05, 0.96) translateY(1px); }
  100% { transform: scale(1, 1); }
}

/* Custom uploaded image mascot */
.mascot-custom-wrap {
  position: relative; width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
}
.mascot-custom-img {
  width: 100%; height: 100%; object-fit: contain; display: block;
  transform: scale(var(--m-scale, 1));
  transition: transform 0.2s ease;
}
.mascot-crop-circle .mascot-custom-img { border-radius: 50%; object-fit: cover; }
.mascot-crop-rounded .mascot-custom-img { border-radius: 26%; object-fit: cover; }

@media (prefers-reduced-motion: reduce) {
  .mascot-inner, .m-eye-wrap, .m-fx-happy, .m-work-dot-1, .m-work-dot-2, .m-work-dot-3 {
    animation: none !important;
  }
}

/* ==================== SUB-VIEW LAYOUT (SETTINGS / MEMORY / GOALS / LIB / SKILLS) ==================== */
.subview-scroll {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg-sidebar);
  padding: 16px 16px calc(36px + env(safe-area-inset-bottom, 0px));
}
.subview-inner {
  width: 100%; max-width: 680px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 16px;
}

.section-card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 20px; padding: 16px; display: flex; flex-direction: column; gap: 14px;
}
.section-card-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.section-card-title { margin: 0; font-size: 15.5px; font-weight: 650; letter-spacing: -0.015em; }
.section-card-sub { font-size: 12.5px; color: var(--text-secondary); }

/* ==================== SETTINGS: MASCOT STUDIO ==================== */
.studio-stage-box {
  position: relative; padding: 20px 16px 16px; border-radius: 16px;
  background: var(--bg-sidebar); border: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
}
.studio-stage-mascot { min-height: 126px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.studio-poke-bubble {
  padding: 5px 12px; border-radius: 999px; background: var(--bg-elevated);
  border: 1px solid var(--border-strong); font-size: 12.5px; font-weight: 500;
  box-shadow: var(--shadow-sm);
}
.studio-stage-name { font-size: 16px; font-weight: 650; letter-spacing: -0.015em; }
.studio-stage-meta { font-size: 12px; color: var(--text-secondary); }

.state-pill-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 4px; }
.state-pill {
  padding: 5px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 500;
  color: var(--text-secondary); background: var(--bg-elevated); border: 1px solid var(--border);
  transition: all 0.14s;
}
.state-pill.active { background: var(--accent); color: var(--accent-inv); border-color: transparent; }

.studio-subhead { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); margin-top: 2px; }

.preset-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.preset-card {
  padding: 12px 8px 10px; border-radius: 16px; background: var(--bg-sidebar);
  border: 1.5px solid transparent; display: flex; flex-direction: column;
  align-items: center; gap: 7px; text-align: center;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
}
.preset-card:hover { background: var(--bg-hover); }
.preset-card:active { transform: scale(0.97); }
.preset-card.active {
  background: var(--bg-elevated); border-color: var(--text);
  box-shadow: var(--shadow-sm);
}
.preset-card-preview { height: 54px; display: flex; align-items: center; justify-content: center; }
.preset-card-name { font-size: 13px; font-weight: 600; color: var(--text); }
.preset-card-tag { font-size: 11px; color: var(--text-muted); line-height: 1.25; }

/* Built-in DIY Customization Panel */
.diy-panel {
  padding: 14px; border-radius: 16px; background: var(--bg-sidebar);
  border: 1px solid var(--border); display: flex; flex-direction: column; gap: 14px;
}
.diy-row { display: flex; flex-direction: column; gap: 8px; }
.diy-row-head { display: flex; align-items: center; justify-content: space-between; }
.diy-label { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
.diy-reset-link { font-size: 12px; color: var(--text-secondary); text-decoration: underline; }
.diy-reset-link:hover { color: var(--text); }

.swatch-grid { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.swatch-btn {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  transition: transform 0.13s, box-shadow 0.13s;
}
.swatch-btn:hover { transform: scale(1.1); }
.swatch-btn.active { box-shadow: 0 0 0 2px var(--bg-elevated), 0 0 0 4px var(--text); }
.swatch-picker-wrap {
  position: relative; width: 28px; height: 28px; border-radius: 50%; overflow: hidden;
  border: 1.5px dashed var(--text-muted); display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; color: var(--text-secondary); cursor: pointer;
}
.swatch-picker { position: absolute; inset: -6px; width: 42px; height: 42px; opacity: 0; cursor: pointer; }

.diy-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.diy-chip {
  padding: 6px 13px; border-radius: 999px; font-size: 12.5px; font-weight: 500;
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-secondary);
  transition: all 0.14s;
}
.diy-chip.active { background: var(--accent); color: var(--accent-inv); border-color: transparent; }

.nickname-row { display: flex; gap: 8px; }
.nickname-input {
  flex: 1 1 auto; height: 38px; padding: 0 13px; border-radius: 12px;
  border: 1px solid var(--border-strong); background: var(--bg-elevated);
  font-size: 14px; outline: none;
}
.nickname-input:focus { border-color: var(--text); }

/* Classic & Custom Upload Accordions */
.classic-details {
  border-radius: 14px; background: var(--bg-sidebar); border: 1px solid var(--border);
  padding: 10px 12px;
}
.classic-summary {
  cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--text);
  list-style: none; display: flex; align-items: center; justify-content: space-between;
}
.classic-summary::-webkit-details-marker { display: none; }
.classic-summary::after { content: '›'; font-size: 17px; color: var(--text-muted); transition: transform 0.16s; }
.classic-details[open] .classic-summary::after { transform: rotate(90deg); }
.classic-details-body { margin-top: 12px; display: flex; flex-direction: column; gap: 12px; }

.upload-dropzone {
  position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-radius: 14px; background: var(--bg-elevated);
  border: 1px dashed var(--border-strong); cursor: pointer;
}
.upload-dropzone-text { font-size: 13px; color: var(--text-secondary); }
.upload-dropzone-text strong { color: var(--text); display: block; font-size: 13.5px; margin-bottom: 2px; }
.slot-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.slot-card {
  padding: 11px; border-radius: 14px; background: var(--bg-elevated);
  border: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px;
}
.slot-card-top { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: 600; }
.slot-thumb {
  height: 64px; border-radius: 10px; background: var(--bg-sidebar);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  font-size: 12px; color: var(--text-muted);
}
.slot-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.slot-actions { display: flex; gap: 6px; }

.range-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-secondary); }
.range-row input[type="range"] { flex: 1 1 auto; accent-color: var(--text); }

/* Segmented Control (Theme / Custom Mode / Motion) */
.seg-control {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px; border-radius: 14px; background: var(--bg-sidebar); border: 1px solid var(--border);
}
.seg-btn {
  padding: 8px 10px; border-radius: 10px; font-size: 13.5px; font-weight: 550;
  color: var(--text-secondary); text-align: center; transition: all 0.15s;
}
.seg-btn.active { background: var(--bg-elevated); color: var(--text); box-shadow: var(--shadow-sm); }

/* Settings Workspace Hub Rows (Memory / Goals / Library / Skills) */
.hub-list { display: flex; flex-direction: column; margin: -6px -4px; }
.hub-row {
  width: 100%; display: flex; align-items: center; gap: 13px;
  padding: 12px 10px; border-radius: 14px; text-align: left;
  transition: background 0.14s;
}
.hub-row:hover { background: var(--bg-subtle); }
.hub-row + .hub-row { border-top: 1px solid var(--border); border-top-left-radius: 0; border-top-right-radius: 0; }
.hub-row-icon {
  width: 38px; height: 38px; border-radius: 12px; flex: 0 0 38px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-sidebar); color: var(--text); border: 1px solid var(--border);
}
.hub-row-icon svg { width: 19px; height: 19px; }
.hub-row-text { flex: 1 1 auto; min-width: 0; }
.hub-row-title { font-size: 14.5px; font-weight: 600; color: var(--text); }
.hub-row-sub { font-size: 12.5px; color: var(--text-secondary); margin-top: 1px; }
.hub-row-chevron { font-size: 20px; color: var(--text-muted); line-height: 1; }

.kv-list { display: flex; flex-direction: column; gap: 9px; font-size: 13.5px; }
.kv-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.kv-row span:first-child { color: var(--text-secondary); }
.kv-row span:last-child { font-weight: 550; color: var(--text); text-align: right; word-break: break-all; }
.btn-danger-outline {
  width: 100%; padding: 11px 16px; border-radius: 14px;
  border: 1px solid rgba(239, 68, 68, 0.35); color: var(--danger);
  font-size: 14px; font-weight: 600; text-align: center; transition: background 0.14s;
}
.btn-danger-outline:hover { background: rgba(239, 68, 68, 0.07); }

/* ==================== SUB-VIEW SHARED CARDS & CONTROLS ==================== */
.pill-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 550;
  background: var(--bg-subtle); border: 1px solid var(--border); color: var(--text);
  transition: background 0.14s, border-color 0.14s;
}
.pill-btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.pill-btn.primary { background: var(--accent); color: var(--accent-inv); border-color: transparent; }
.pill-btn.compact-pill { padding: 6px 12px; font-size: 12.5px; }
.pill-btn.danger-text { color: var(--danger); }

.card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 18px; padding: 15px 16px; display: flex; flex-direction: column; gap: 10px;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-title { margin: 0; font-size: 15px; font-weight: 650; color: var(--text); }
.card-sub { font-size: 12.5px; color: var(--text-secondary); margin-top: 2px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.badge {
  display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; flex: 0 0 auto;
  background: var(--bg-subtle); color: var(--text-secondary);
}
.badge-ok { background: rgba(22, 198, 106, 0.13); color: #129E54; }
html[data-theme="dark"] .badge-ok { color: #34D399; }
.badge-warn { background: rgba(245, 158, 11, 0.15); color: #C27803; }
html[data-theme="dark"] .badge-warn { color: #FBBF24; }
.empty-box {
  padding: 28px 16px; border-radius: 16px; text-align: center;
  background: var(--bg-elevated); border: 1px dashed var(--border-strong);
  font-size: 13.5px; color: var(--text-secondary);
}

/* Goals / Library / Memory / Skills specifics */
.goal-hero { border-color: var(--border-strong); }
.goal-grid, .skill-list, .mem-list { display: flex; flex-direction: column; gap: 10px; }
.lib-cats, .mem-tabs { display: flex; flex-wrap: wrap; gap: 7px; }
.lib-cat, .mem-tab {
  padding: 6px 13px; border-radius: 999px; font-size: 13px; font-weight: 550;
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-secondary);
}
.lib-cat.active, .mem-tab.active { background: var(--accent); color: var(--accent-inv); border-color: transparent; }
.lib-folder-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; color: var(--text-secondary); }
.lib-crumb { padding: 4px 9px; border-radius: 8px; background: var(--bg-elevated); border: 1px solid var(--border); }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 10px; }
.lib-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 15px;
  overflow: hidden; text-align: left; display: flex; flex-direction: column;
  transition: border-color 0.14s, transform 0.12s;
}
.lib-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.lib-thumb {
  height: 112px; width: 100%; background: var(--bg-subtle);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.lib-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lib-doc-icon { font-size: 28px; color: var(--text-muted); }
.lib-card-meta { padding: 9px 10px; display: flex; flex-direction: column; gap: 2px; }
.lib-card-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-card-info { font-size: 11.5px; color: var(--text-muted); }

.mem-search-row { display: flex; gap: 8px; }
.mem-entry {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 15px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px;
}
.mem-entry-time { font-size: 11.5px; color: var(--text-muted); font-family: var(--font-mono); }
.skill-name { font-size: 14.5px; font-weight: 650; }
.skill-desc { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }

/* ==================== PROKBOT MARKDOWN (TABLES & CODE CARDS) ==================== */
.md-body { word-break: break-word; }
.md-body > :first-child { margin-top: 0; }
.md-body > :last-child { margin-bottom: 0; }
.md-body p { margin: 0 0 11px; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 {
  margin: 16px 0 8px; font-weight: 680; letter-spacing: -0.02em; line-height: 1.35;
}
.md-body h1 { font-size: 19px; } .md-body h2 { font-size: 17px; } .md-body h3 { font-size: 15.5px; }
.md-body ul, .md-body ol { margin: 0 0 11px; padding-left: 20px; }
.md-body li { margin: 4px 0; }
.md-body a { color: #1D88FF; text-decoration: none; border-bottom: 1px solid rgba(29, 136, 255, 0.35); }
.md-body blockquote {
  margin: 10px 0; padding: 8px 13px; border-left: 3px solid var(--border-strong);
  background: var(--bg-sidebar); border-radius: 0 10px 10px 0; color: var(--text-secondary);
}
.md-body hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.md-body code {
  font-family: var(--font-mono); font-size: 0.87em; padding: 2px 6px; border-radius: 6px;
  background: var(--bg-subtle); border: 1px solid var(--border);
}
.md-body .md-code-block, .md-body .code-block {
  margin: 12px 0; border-radius: 14px; overflow: hidden;
  border: 1px solid var(--border); background: var(--bg-sidebar);
}
.md-body .md-code-head, .md-body .code-block-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px; border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-secondary); font-family: var(--font-mono);
}
.md-body .code-copy-btn, .md-body .md-copy-btn {
  font-family: var(--font-sans); font-size: 12px; font-weight: 550;
  color: var(--text-secondary); padding: 2px 8px; border-radius: 6px;
}
.md-body .code-copy-btn:hover, .md-body .md-copy-btn:hover { background: var(--bg-hover); color: var(--text); }
.md-body pre {
  margin: 0; padding: 12px 14px; overflow-x: auto; font-size: 13px; line-height: 1.55;
}
.md-body pre code { background: none; border: none; padding: 0; font-size: inherit; }
.tok-kw { color: #7C3AED; font-weight: 550; }
.tok-str { color: #0F9D58; }
.tok-num { color: #D97706; }
.tok-cmt { color: var(--text-muted); font-style: italic; }
html[data-theme="dark"] .tok-kw { color: #C084FC; }
html[data-theme="dark"] .tok-str { color: #4ADE80; }
html[data-theme="dark"] .tok-num { color: #FBBF24; }

.md-table-wrap, .table-scroll {
  margin: 12px 0; overflow-x: auto; border-radius: 13px; border: 1px solid var(--border);
}
.md-body table { width: 100%; border-collapse: collapse; font-size: 14px; }
.md-body th, .md-body td {
  padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border);
}
.md-body th { font-weight: 600; background: var(--bg-sidebar); color: var(--text); }
.md-body tr:last-child td { border-bottom: none; }
.md-inline-img { max-width: 100%; border-radius: 12px; margin: 8px 0; display: block; border: 1px solid var(--border); }

/* ==================== MODAL, LIGHTBOX & TOAST ==================== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, 0.44);
  display: flex; align-items: flex-end; justify-content: center; padding: 16px;
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; } }
.modal-sheet {
  width: 100%; max-width: 580px; max-height: 85dvh;
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: 22px; box-shadow: var(--shadow-md);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 650; }
.modal-body { padding: 16px; overflow-y: auto; flex: 1 1 auto; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.code-preview-pre {
  margin: 0; padding: 12px; border-radius: 12px; background: var(--bg-sidebar);
  border: 1px solid var(--border); overflow: auto; font-family: var(--font-mono);
  font-size: 12.5px; line-height: 1.55; max-height: 60dvh; white-space: pre-wrap; word-break: break-word;
}

.lightbox {
  position: fixed; inset: 0; z-index: 80; background: rgba(10, 11, 14, 0.94);
  display: flex; flex-direction: column;
}
.lightbox-stage {
  position: relative; flex: 1 1 auto; display: flex; align-items: center; justify-content: center;
  padding: 20px; overflow: hidden;
}
.lightbox-stage img {
  max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px;
  transition: transform 0.2s ease; cursor: zoom-in;
}
.lightbox-stage img.is-zoomed { transform: scale(1.85); cursor: zoom-out; }
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.16); color: #FFF; font-size: 26px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }
.lightbox-counter { font-size: 13px; font-weight: 600; opacity: 0.9; flex: 0 0 auto; }
.lightbox-bar {
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 10px; color: #FFF;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.72), transparent);
}
.lightbox-caption { flex: 1 1 auto; font-size: 13px; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lightbox-btn {
  padding: 7px 13px; border-radius: 999px; font-size: 13px; font-weight: 550;
  background: rgba(255, 255, 255, 0.16); color: #FFF; text-decoration: none;
}

.toast {
  position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top, 0px));
  transform: translate(-50%, -14px); z-index: 95;
  padding: 8px 16px; border-radius: 999px;
  background: #18181B; color: #FFFFFF; font-size: 13px; font-weight: 550;
  box-shadow: var(--shadow-md); opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
html[data-theme="dark"] .toast { background: #F4F5F7; color: #121316; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ==================== ALIGNED V3 MASCOT / STUDIO / SUB-VIEW CLASSES ==================== */
/* Mascot SVG organic body + blink + gaze + working orbs + happy stars */
.mascot-preset, .mascot-custom-fx { position: relative; }
.m-shadow { transform-origin: 60px 104px; transition: transform 0.3s ease; }
.m-body { transform-origin: 60px 64px; }
.m-grok-shape { transition: fill 0.25s ease; }
.m-blink { transform-origin: 60px 58px; }
.m-gaze { transform-origin: 60px 58px; }
.m-fx-working { opacity: 0; transition: opacity 0.25s ease; }
.mascot-state-working .m-fx-working { opacity: 1; }
.mascot-state-idle .m-blink { animation: mascotBlink 4.6s ease-in-out infinite; }
.mascot-state-idle .m-gaze { animation: mascotGaze 7.5s ease-in-out infinite; }
.mascot-state-working .m-gaze { animation: mascotScan 1.8s ease-in-out infinite; }
.m-orb { opacity: 0.78; }
.mascot-state-working .m-orb-1 { animation: orbFloat 1.2s ease-in-out infinite; }
.mascot-state-working .m-orb-2 { animation: orbFloat 1.2s ease-in-out 0.22s infinite; }
.mascot-state-working .m-orb-3 { animation: orbFloat 1.2s ease-in-out 0.44s infinite; }
@keyframes mascotScan {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-4px, -1px); }
  75% { transform: translate(4px, -1px); }
}
@keyframes orbFloat {
  0%, 100% { transform: translateY(0) scale(0.85); opacity: 0.45; }
  50% { transform: translateY(-6px) scale(1.25); opacity: 1; }
}
.m-star { transform-box: fill-box; transform-origin: center; }
.mascot-state-happy .m-star-1 { animation: sparklePop 1.2s ease-in-out infinite; }
.mascot-state-happy .m-star-2 { animation: sparklePop 1.2s ease-in-out 0.35s infinite; }

/* Settings Hub & Mascot Studio exact classes */
.settings-bg { background: var(--bg-sidebar); }
html[data-theme="dark"] .settings-bg { background: var(--bg); }
.settings-card, .studio-card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 20px; padding: 18px; margin-bottom: 14px;
  box-shadow: var(--shadow-xs);
}
.settings-group {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 18px; overflow: hidden; margin-bottom: 14px;
}
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 4px 8px;
}
.section-head h2, .section-label {
  font-size: 12.5px; font-weight: 650; color: var(--text-tertiary);
  letter-spacing: 0.03em; margin: 14px 4px 8px;
}
.section-head h2 { margin: 0; }
.studio-preview-hit {
  display: inline-flex; flex-direction: column; align-items: center; cursor: pointer;
}
.studio-state-pills { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 8px; }
.studio-section-title {
  font-size: 13px; font-weight: 650; color: var(--text-secondary);
  margin: 16px 0 10px;
}
.preset-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.preset-name { font-size: 13px; font-weight: 600; color: var(--text); }

.diy-box {
  margin-top: 14px; padding: 14px; border-radius: 16px;
  background: var(--bg-subtle); border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 13px;
}
.diy-label-row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12.5px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px;
}
.color-palette { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.color-picker-btn {
  width: 26px; height: 26px; border-radius: 50%; overflow: hidden; cursor: pointer;
  border: 1.5px dashed var(--text-tertiary); display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; color: var(--text-secondary); position: relative;
}
.color-picker-btn input[type="color"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.nick-row { display: flex; gap: 8px; align-items: center; }
.clean-input {
  flex: 1 1 auto; height: 38px; padding: 0 13px; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--border); color: var(--text); font-size: 14px;
}
.clean-input:focus { border-color: var(--text-secondary); }
.text-link-btn { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); padding: 2px 6px; border-radius: 6px; }
.text-link-btn:hover { color: var(--text); background: var(--bg-muted); }
.muted-link { font-size: 12px; color: var(--text-tertiary); }
.muted-link:hover { color: var(--text); }
.muted { color: var(--text-secondary); font-size: 13px; }
.muted-sm { color: var(--text-tertiary); font-size: 12px; }

.studio-fold {
  margin-top: 12px; border-radius: 15px; border: 1px solid var(--border);
  background: var(--bg); overflow: hidden;
}
.studio-fold-summary {
  padding: 12px 14px; font-size: 13.5px; font-weight: 600; color: var(--text);
  cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between;
}
.studio-fold-summary::-webkit-details-marker { display: none; }
.studio-fold-summary::after { content: '›'; font-size: 18px; color: var(--text-tertiary); transition: transform 0.16s; }
.studio-fold[open] .studio-fold-summary::after { transform: rotate(90deg); }
.studio-fold-body { padding: 4px 14px 14px; border-top: 1px solid var(--border); }

.single-upload-row { display: flex; align-items: center; gap: 14px; margin: 12px 0; }
.single-upload-thumb {
  width: 68px; height: 68px; border-radius: 16px; background: var(--bg-subtle);
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex: 0 0 auto; font-size: 12px; color: var(--text-tertiary);
}
.single-upload-thumb img { width: 100%; height: 100%; object-fit: contain; }
.single-upload-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.upload-label { cursor: pointer; }
.slot-box {
  padding: 10px; border-radius: 14px; background: var(--bg-subtle); border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.slot-head { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; font-weight: 600; }
.slot-del { font-size: 12px; color: var(--danger); }
.studio-sliders { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.slider-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-secondary); }
.slider-row input[type="range"] { flex: 1 1 auto; accent-color: var(--accent); }
.studio-foot-actions { margin-top: 14px; display: flex; justify-content: flex-end; gap: 8px; }
.full-width { width: 100%; }

/* Settings Grouped Rows */
.group-row {
  width: 100%; display: flex; align-items: center; gap: 13px;
  padding: 13px 16px; text-align: left; transition: background 0.14s;
}
.group-row + .group-row { border-top: 1px solid var(--border); }
button.group-row:hover { background: var(--bg-subtle); }
.group-row-main { flex: 1 1 auto; min-width: 0; }
.group-row-title { font-size: 14.5px; font-weight: 550; color: var(--text); }
.group-row-sub { font-size: 12.5px; color: var(--text-tertiary); margin-top: 1px; }
.row-chevron { font-size: 20px; color: var(--text-tertiary); line-height: 1; flex: 0 0 auto; }
.row-ico {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
}
.row-ico svg { width: 18px; height: 18px; }
.row-ico-green { background: rgba(22, 198, 106, 0.13); color: #12A858; }
.row-ico-orange { background: rgba(255, 122, 26, 0.13); color: #E8680C; }
.row-ico-blue { background: rgba(29, 136, 255, 0.13); color: #1677E8; }
.row-ico-pink { background: rgba(255, 46, 136, 0.13); color: #E02274; }

/* Sub-views (Memory / Goals / Library / Skills) */
.card-stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.loading-box { text-align: center; padding: 36px 20px; color: var(--text-tertiary); font-size: 13.5px; }
.search-bar, .search-box {
  margin-bottom: 12px; display: flex; align-items: center; gap: 8px;
  padding: 0 14px; height: 42px; border-radius: 999px;
  background: var(--bg-elevated); border: 1px solid var(--border);
}
.search-bar svg, .search-box svg {
  width: 16px; height: 16px; flex: 0 0 auto; color: var(--text-tertiary);
}
.search-bar input, .search-box input {
  flex: 1 1 auto; min-width: 0; height: 100%; border: none; background: transparent;
  padding: 0; color: var(--text); font-size: 14px; outline: none;
}
.search-bar:focus-within, .search-box:focus-within { border-color: var(--border-strong); }
.mem-section {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 16px;
  overflow: hidden; margin-bottom: 10px;
}
.mem-summary {
  padding: 13px 16px; font-size: 14.5px; font-weight: 600; color: var(--text);
  cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center;
}
.mem-summary::-webkit-details-marker { display: none; }
.mem-body { padding: 4px 16px 15px; border-top: 1px solid var(--border); font-size: 14px; }
.timeline-list { display: flex; flex-direction: column; gap: 8px; }
.timeline-item {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px;
}
.timeline-ts { font-size: 11.5px; color: var(--text-tertiary); font-family: var(--font-mono); margin-bottom: 4px; }
.timeline-text { font-size: 13.5px; color: var(--text); line-height: 1.55; white-space: pre-wrap; }

.skill-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 16px;
  padding: 14px 16px;
}
.skill-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.filter-strip {
  display: flex; flex-wrap: nowrap; align-items: center; gap: 7px;
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  padding: 2px 0 10px;
}
.filter-strip::-webkit-scrollbar { display: none; }
.filter-strip .chip, .chip, .filter-strip .filter-pill, .filter-pill {
  flex: 0 0 auto; white-space: nowrap; word-break: keep-all;
}
.seg-btn { white-space: nowrap; padding: 7px 6px; font-size: 12.5px; }
.seg-control.compact .seg-btn { font-size: 12px; padding: 6px 4px; }
.m-shadow {
  fill: rgba(15, 23, 42, 0.085);
  filter: blur(2.4px);
}
html[data-theme="dark"] .m-shadow {
  fill: rgba(0, 0, 0, 0.34);
}
.studio-stage-box { padding: 14px 12px 12px; }
.studio-preview-card { padding: 16px; }
.preset-grid { gap: 8px; }
.preset-card { padding: 10px 6px 9px; gap: 5px; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(144px, 1fr)); gap: 10px; }
.lib-info { padding: 9px 10px; }
.lib-name { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-sub { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }
.lib-ext-tag {
  display: inline-block; padding: 3px 8px; border-radius: 8px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  font-size: 11px; font-weight: 650; color: var(--text-secondary);
}
.preview-code {
  margin: 0; padding: 14px; border-radius: 12px; background: var(--bg-subtle);
  border: 1px solid var(--border); font-family: var(--font-mono); font-size: 12.5px;
  line-height: 1.55; overflow-x: auto; white-space: pre-wrap; word-break: break-word;
}
.job-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.job-name { font-size: 15px; font-weight: 650; }
.job-msg { font-size: 13.5px; color: var(--text-secondary); line-height: 1.55; margin-bottom: 8px; }
.job-meta-grid { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 12px; color: var(--text-tertiary); margin-bottom: 10px; }
.job-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.badge.ok { background: rgba(22, 198, 106, 0.14); color: #12A858; }
.badge.warn { background: rgba(245, 158, 11, 0.14); color: #D97706; }
.badge.info { background: rgba(29, 136, 255, 0.13); color: #1D88FF; }

.field-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field-group label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.field-input, .field-textarea {
  width: 100%; padding: 10px 13px; border-radius: 12px;
  background: var(--bg-subtle); border: 1px solid var(--border); color: var(--text); font-size: 14px;
}
.field-textarea { min-height: 92px; resize: vertical; }

/* Markdown + Modal + Lightbox aligned aliases */
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px; background: var(--bg-muted); border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-secondary); font-family: var(--font-mono);
}
.inline-code {
  font-family: var(--font-mono); font-size: 0.87em; padding: 2px 5px;
  border-radius: 6px; background: var(--bg-subtle); border: 1px solid var(--border);
}
.md-img-wrap { margin: 10px 0; }
.modal-card {
  width: 100%; max-width: 540px; max-height: 85dvh;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 22px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-title { font-size: 16px; font-weight: 650; }
.lightbox-img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }

/* Classic mascot SVG states (dragon/cat/bot) */
.m-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.m-mouth-happy, .m-mouth-error { display: none; }
.mascot-state-happy .m-mouth-idle { display: none; }
.mascot-state-happy .m-mouth-happy { display: inline; }
.mascot-state-error .m-mouth-idle { display: none; }
.mascot-state-error .m-mouth-error { display: inline; }
.m-tail { transform-origin: 86px 76px; }
.mascot-state-idle .m-tail, .mascot-state-happy .m-tail { animation: mascotBreath 2.6s ease-in-out infinite; }


/* Native animated WebP/GIF custom mascots: disable idle sway, keep interactive tap/purr animations */
.mascot-native-anim .mascot-inner {
  animation: none !important;
}
.mascot-native-anim.mascot-tap .mascot-inner {
  animation: mJellyTap 0.56s cubic-bezier(0.22, 1.4, 0.36, 1) !important;
}
.mascot-purr .mascot-inner,
.mascot-native-anim.mascot-purr .mascot-inner {
  animation: mPetPurr 0.48s ease-in-out infinite !important;
}
@keyframes mPetPurr {
  0%, 100% { transform: scale(1.03, 0.97) translateY(2px) rotate(-0.8deg); }
  50% { transform: scale(0.98, 1.03) translateY(-2px) rotate(0.8deg); }
}
