/* ============================================================
   RobiOS CMS — shared card ("окошко"), info window and Markdown body.
   Consumed by apps.html, learn/article pages, the home marketplace grid
   and the admin live preview. Tokens only (css/tokens.css).
   ============================================================ */

/* ------------------------------ card ------------------------------ */

.cms-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--grid-gap);
}

.cms-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-radius: var(--radius-card-lg);
  cursor: pointer;
  transition: transform var(--dur-med) var(--ease-pop);
  outline: none;
}
.cms-card:hover { transform: translateY(-3px); }
.cms-card:focus-visible { box-shadow: var(--ring-accent); border-radius: var(--radius-card-lg); }

.cms-cover {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius-card-lg);
  background:
    radial-gradient(120% 120% at 78% 12%, hsl(var(--cms-hue) 70% 22% / .55) 0%, transparent 62%),
    linear-gradient(150deg, #23262A 0%, #14161A 100%);
  box-shadow: var(--inset-highlight);
  display: grid;
  place-items: center;
}
.cms-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--card-glass-sheen);
  pointer-events: none;
}

.cms-art {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

/* Uploaded photo/video cover — fills the frame, generated art steps aside. */
.cms-cover-media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.cms-card.has-cover .cms-cover { background: #0c0d10; }
.cms-card.has-cover .cms-word { display: none; }
.cms-card.has-cover .cms-cover-media { transition: transform var(--dur-slow) var(--ease-glide); }
.cms-card.has-cover:hover .cms-cover-media { transform: scale(1.04); }
.cms-motif {
  width: 46%;
  max-width: 120px;
  color: hsl(var(--cms-hue) 85% 62% / .5);
  transition: transform var(--dur-slow) var(--ease-glide), color var(--dur-fast) var(--ease-ui);
}
.cms-card:hover .cms-motif { transform: scale(1.06); color: hsl(var(--cms-hue) 90% 66% / .75); }

.cms-word {
  position: absolute;
  left: 12px;
  bottom: 10px;
  max-width: calc(100% - 24px);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  line-height: 1.05;
  letter-spacing: var(--ls-display);
  text-transform: uppercase;
  color: var(--text-primary);
  opacity: .92;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cms-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  padding: 3px 7px;
  border-radius: var(--radius-badge);
  background: var(--accent-20);
  color: var(--accent);
  font-size: var(--fs-badge);
  font-weight: var(--fw-badge);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.cms-open {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity var(--dur-fast) var(--ease-ui), transform var(--dur-med) var(--ease-pop);
  pointer-events: none;
}
.cms-card:hover .cms-open,
.cms-card:focus-visible .cms-open { opacity: 1; transform: translateY(0); }

.cms-foot { display: flex; align-items: center; gap: 8px; padding: 0 2px; }

.cms-chip {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: hsl(var(--cms-hue) 80% 65%);
  box-shadow: var(--inset-highlight-soft);
}
.cms-chip svg { width: 18px; height: 18px; }

.cms-info { min-width: 0; }
.cms-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-size: var(--fs-card-title);
  font-weight: var(--fw-card-title);
  letter-spacing: var(--ls-display);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cms-dot {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}
.cms-stats {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-meta);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cms-dotsep { opacity: .45; }

.cms-empty {
  padding: 40px 0;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

/* --------------------------- info window --------------------------- */

body.cms-modal-open { overflow: hidden; }

.cms-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(6, 8, 10, .72);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-ui);
}
.cms-modal-overlay.in { opacity: 1; }

.cms-modal {
  position: relative;
  width: min(560px, 100%);
  max-height: min(80vh, 720px);
  overflow-y: auto;
  padding: 24px;
  border-radius: var(--radius-card-lg);
  background:
    radial-gradient(120% 90% at 88% -10%, hsl(var(--cms-hue, 78) 70% 24% / .4) 0%, transparent 60%),
    var(--bg-card);
  box-shadow: var(--shadow-card-xl), var(--inset-highlight);
  transform: translateY(8px) scale(.985);
  transition: transform var(--dur-med) var(--ease-pop);
}
.cms-modal-overlay.in .cms-modal { transform: translateY(0) scale(1); }

.cms-modal-x {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: var(--bg-white-5);
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1;
  transition: background var(--dur-fast) var(--ease-ui), color var(--dur-fast) var(--ease-ui);
}
.cms-modal-x:hover { background: var(--bg-white-10); color: var(--text-primary); }

.cms-modal-cover {
  margin: -4px 0 18px;
  border-radius: var(--radius-card);
  overflow: hidden;
  background: #0c0d10;
  box-shadow: var(--inset-highlight);
}
.cms-modal-cover-media {
  display: block;
  width: 100%;
  max-height: 340px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.cms-modal-head { display: flex; align-items: center; gap: 12px; padding-right: 36px; }
.cms-modal-chip {
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-card);
  background: var(--bg-elevated);
  color: hsl(var(--cms-hue, 78) 82% 66%);
  box-shadow: var(--inset-highlight-soft);
}
.cms-modal-chip svg { width: 26px; height: 26px; }

.cms-modal-kind {
  font-size: var(--fs-meta);
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent);
}
.cms-modal-title {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: var(--ls-display);
  color: var(--text-primary);
}

.cms-modal-summary {
  margin: 14px 0 0;
  font-size: 15px;
  line-height: 22px;
  color: var(--text-secondary);
}

.cms-modal-stats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.cms-modal-stat {
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  background: var(--bg-white-5);
  font-family: var(--font-mono);
  font-size: var(--fs-meta);
  color: var(--text-muted);
}

.cms-modal-body { margin-top: 16px; }

.cms-modal-foot {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--bg-white-5);
}
.cms-modal-cta { text-decoration: none; }

/* -------------------------- markdown body -------------------------- */

.md-body {
  font-size: 15px;
  line-height: 24px;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}
.md-body > :first-child { margin-top: 0; }
.md-body h2, .md-body h3, .md-body h4, .md-body h5, .md-body h6 {
  margin: 22px 0 8px;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: var(--ls-display);
  color: var(--text-primary);
}
.md-body h2 { font-size: 20px; }
.md-body h3 { font-size: 17px; }
.md-body h4, .md-body h5, .md-body h6 { font-size: 15px; }
.md-body p { margin: 0 0 12px; }
.md-body ul, .md-body ol { margin: 0 0 12px; padding-left: 20px; }
.md-body li { margin-bottom: 5px; }
.md-body a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-24); }
.md-body a:hover { border-bottom-color: var(--accent); }
.md-body strong { color: var(--text-primary); font-weight: 600; }
.md-body code {
  padding: 2px 5px;
  border-radius: var(--radius-badge);
  background: var(--bg-white-5);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
}
.md-body .md-pre {
  position: relative;
  margin: 0 0 14px;
  padding: 14px 16px;
  overflow-x: auto;
  border-radius: var(--radius-card);
  background: var(--bg-terminal);
  box-shadow: var(--inset-highlight-soft);
}
.md-body .md-pre code {
  padding: 0;
  background: none;
  color: var(--text-primary);
  font-size: 13px;
  line-height: 20px;
}
.md-body .md-pre[data-lang]::after {
  content: attr(data-lang);
  position: absolute;
  top: 8px;
  right: 10px;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-faint);
}
.md-body blockquote {
  margin: 0 0 14px;
  padding: 8px 14px;
  border-left: 2px solid var(--accent);
  background: var(--accent-05);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}
.md-body hr { margin: 20px 0; border: 0; border-top: 1px solid var(--bg-white-10); }
.md-body img { max-width: 100%; border-radius: var(--radius-card); margin: 6px 0 14px; }
.md-body .md-video {
  display: block;
  width: 100%;
  max-height: 70vh;
  border-radius: var(--radius-card);
  margin: 6px 0 14px;
  background: #000;
}

/* ---------------------------- responsive ---------------------------- */

@media (max-width: 1100px) {
  .cms-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .cms-grid { grid-template-columns: minmax(0, 1fr); }
  .cms-modal { padding: 20px 16px; max-height: 88vh; }
  .cms-modal-overlay { padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .cms-card, .cms-motif, .cms-open, .cms-modal, .cms-modal-overlay { transition: none !important; }
  .cms-card:hover { transform: none; }
}
