/*
  Learn AI Here — cards, "Night Shift" style: everything Views/Shared/_ContentCard.cshtml renders (tip, news and video
  cards, the compact share controls, the on-demand YouTube player) and the three-bar level meter.

  Loaded by the public layout after site.css, and by the admin and import previews (whose "In the feed" card sits in a
  .content-detail-layout wrapper, so content.css supplies the dark ground, links, code and labels there). Every colour
  follows site.css's tokens where site.css is loaded and falls back to the same values where it is not (admin).
  Selectors use only the card, card-list and player class names, so this file cannot restyle the admin chrome.
*/

/* ---------- Lists of cards ---------- */

/* One column of raised cards, capped at the reading measure (listings, search, topic hubs). */
.card-list {
  display: grid;
  gap: 1rem;
  max-width: var(--measure, 70ch);
  margin: 0 0 1.5rem;
  padding: 0;
  list-style: none;
}

/* With no ad unit between them (ads off), the two listing groups read as one list. */
.card-list:has(+ .card-list--continued) {
  margin-bottom: 1rem;
}

/* A responsive grid: three columns on a desktop, two on a tablet, one on a phone (home videos). */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 18.75rem), 1fr));
  gap: 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

/*
  One row of cards that scrolls sideways (home tips): three across on a desktop, two on a tablet, and one on a phone
  with the next card peeking in. Readers swipe, use a trackpad or Shift+wheel, or Tab through the cards (a focused link
  scrolls into view); carousel.js adds Previous/Next buttons. The scrollbar is hidden: the peek and the buttons show
  there is more. The row is the containing block of the cards' absolutely positioned, visually hidden labels, so those
  scroll and clip with it instead of widening the page.
*/
.card-carousel {
  position: relative;
  display: grid;
  grid-auto-columns: 85%;
  grid-auto-flow: column;
  gap: 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.card-carousel::-webkit-scrollbar {
  display: none;
}

.card-carousel > .card {
  scroll-snap-align: start;
}

@media (min-width: 40rem) {
  .card-carousel {
    grid-auto-columns: calc((100% - 1rem) / 2);
  }
}

@media (min-width: 60rem) {
  .card-carousel {
    grid-auto-columns: calc((100% - 2rem) / 3);
  }
}

/*
  The Previous/Next buttons keep their space but stay invisible (and out of the tab order) until carousel.js finds
  more cards than fit, so showing them never moves the page.
*/
.card-carousel__controls {
  display: flex;
  gap: 0.5rem;
  visibility: hidden;
}

.card-carousel__controls--active {
  visibility: visible;
}

.card-carousel__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid var(--color-control-border, #6b7382);
  border-radius: var(--radius, 8px);
  background: var(--color-surface, #161a21);
  color: var(--color-text, #e8eaed);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.card-carousel__button:hover {
  border-color: var(--color-accent, #b5f23d);
  color: var(--color-accent, #b5f23d);
}

/* At either end: still focusable (focus never drops to the page), but dimmed and inert. */
.card-carousel__button[aria-disabled="true"],
.card-carousel__button[aria-disabled="true"]:hover {
  border-color: var(--color-rule-strong, #3a414d);
  color: var(--color-subtle, #8b93a1);
  cursor: default;
}

/* Ruled rows without boxes (home news). */
.card-list--ruled {
  gap: 0;
  border-top: 1px solid var(--color-rule, #272d38);
}

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

.card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--color-rule, #272d38);
  border-radius: var(--radius-card, 12px);
  background: var(--color-surface, #161a21);
  color: var(--color-text, #e8eaed);
  overflow-wrap: break-word;
}

.card-list--ruled > .card {
  padding: 1.1rem 0;
  border: 0;
  border-bottom: 1px solid var(--color-rule, #272d38);
  border-radius: 0;
  background: none;
}

.card--pinned {
  border-color: var(--color-accent, #b5f23d);
}

.card > * {
  margin: 0;
}

/* Pinned mark, type chip, topic tag and level above the title. */
.card__tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 1rem;
  color: var(--color-muted, #a0a7b4);
  font-family: var(--font-mono, "IBM Plex Mono", ui-monospace, monospace);
  font-size: 0.8rem;
}

.card__pin {
  color: var(--color-accent, #b5f23d);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.card__topic a {
  color: var(--color-accent, #b5f23d);
  font-weight: 500;
  text-decoration: none;
}

.card__topic a:hover {
  color: var(--color-accent-hover, #cdf779);
  text-decoration: underline;
}

.card__level {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-transform: lowercase;
}

.card__title {
  margin: 0;
  color: var(--color-heading, #f5f6f7);
  font-size: 1.1875rem;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.card__title a {
  color: var(--color-heading, #f5f6f7);
  text-decoration: none;
}

.card__title a:hover {
  color: var(--color-accent, #b5f23d);
  text-decoration: underline;
}

/* The tip text and video description (sanitised Markdown). */
.card__text {
  color: var(--color-text, #e8eaed);
  font-size: 1rem;
  line-height: 1.6;
}

.card__text > * {
  margin: 0 0 0.75em;
}

.card__text > :last-child {
  margin-bottom: 0;
}

.card__text :is(ul, ol) {
  padding-left: 1.25rem;
}

/*
  A code block's "Copy code" button (share.js) sits in a strip across the top of the block, which is there from the
  start, and share.js's wrapper takes the block's place in the card's spacing, so adding the button never moves the
  page. The copy status shows below the block only once there is something to say.
*/
.card__text pre {
  max-width: 100%;
  overflow-x: auto;
  padding-top: 2.9rem;
}

.card__text .code-block {
  position: relative;
}

.card__text .code-block > pre {
  margin: 0;
}

.card__text .code-block__toolbar {
  position: absolute;
  top: 0.45rem;
  right: 0.5rem;
}

.card__text .code-block__button {
  min-height: 2rem;
  padding: 0.25rem 0.7rem;
  font-family: var(--font-mono, "IBM Plex Mono", ui-monospace, monospace);
  font-size: 0.78rem;
  font-weight: 500;
}

.card__text .code-block__status {
  display: block;
  margin-top: 0.4rem;
  color: var(--color-muted, #a0a7b4);
  font-size: 0.85rem;
}

.card__text .code-block__status:empty {
  display: none;
}

.card__summary {
  color: var(--color-text, #e8eaed);
  font-size: 0.975rem;
  line-height: 1.6;
}

.card__summary li + li {
  margin-top: 0.25em;
}

.card__more a,
.card__source {
  color: var(--color-accent, #b5f23d);
  font-weight: 600;
  text-decoration: none;
}

.card__more a:hover,
.card__source:hover {
  color: var(--color-accent-hover, #cdf779);
  text-decoration: underline;
}

/* Date and share controls (tips), the date (news) or channel, duration and date (videos), at the bottom of a grid card. */
.card__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-rule, #272d38);
}

.card-list--ruled .card__foot {
  padding-top: 0;
  border-top: 0;
}

.card__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem 0;
  margin: 0;
  color: var(--color-muted, #a0a7b4);
  font-family: var(--font-mono, "IBM Plex Mono", ui-monospace, monospace);
  font-size: 0.8rem;
}

.card__meta > * + *::before {
  content: "·";
  margin: 0 0.5rem;
  color: var(--color-subtle, #8b93a1);
}

/* ---------- Compact share controls (tip cards) ---------- */

.card-share {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.card-share__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.card-share__actions[hidden] {
  display: none;
}

.card-share__button {
  min-height: 2rem;
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--color-control-border, #6b7382);
  border-radius: var(--radius, 8px);
  background: transparent;
  color: var(--color-text, #e8eaed);
  font-family: var(--font-mono, "IBM Plex Mono", ui-monospace, monospace);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
}

.card-share__button:hover {
  border-color: var(--color-accent, #b5f23d);
  color: var(--color-accent, #b5f23d);
}

.card-share__button[hidden] {
  display: none;
}

.card-share__status {
  margin: 0;
  color: var(--color-muted, #a0a7b4);
  font-family: var(--font-mono, "IBM Plex Mono", ui-monospace, monospace);
  font-size: 0.8rem;
}

.card-share__status:empty {
  display: none;
}

.card-share__status[data-state="success"] {
  color: var(--color-success, #8ee0a4);
}

.card-share__status[data-state="error"] {
  color: var(--color-error, #ff8f87);
}

.card-share__fallback {
  flex-basis: 100%;
}

.card-share__fallback label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.85rem;
}

.card-share__fallback textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--color-input-border, #6b7382);
  border-radius: var(--radius, 8px);
  background: var(--color-bg, #0f1115);
  color: var(--color-text, #e8eaed);
  font-family: var(--font-mono, "IBM Plex Mono", ui-monospace, monospace);
  font-size: 0.85rem;
}

/* ---------- Level meter: one, two or three lime bars ---------- */

/* Decorative (aria-hidden); the level's name is always written beside it. */
.level-meter {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
}

.level-meter__bar {
  width: 4px;
  height: 12px;
  border-radius: 1px;
  background: var(--color-meter-off, #3a414d);
}

.level-meter__bar:nth-child(1) {
  height: 6px;
}

.level-meter__bar:nth-child(2) {
  height: 9px;
}

.level-meter__bar:first-child,
.level-meter--intermediate .level-meter__bar:nth-child(2),
.level-meter--advanced .level-meter__bar {
  background: var(--color-accent, #b5f23d);
}

/* ---------- Video: the on-demand player, or a link to YouTube when embedding is off ---------- */

.video-player__stage,
.video-link {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 16 / 9;
  padding: 0.75rem;
  border: 1px solid var(--color-rule, #272d38);
  border-radius: 10px;
  background: var(--color-surface-raised, #1d222b);
  color: var(--color-text, #e8eaed);
}

.video-player[data-video-state="playing"] .video-player__stage {
  overflow: hidden;
}

.video-cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.video-player__controls,
.video-link__label {
  position: relative;
}

.video-player__play {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.5rem 1.25rem;
  border: 2px solid var(--color-accent, #b5f23d);
  border-radius: 999px;
  background: var(--color-accent, #b5f23d);
  color: var(--color-on-accent, #0f1115);
  font: inherit;
  font-weight: 600;
  box-shadow: 0 2px 12px rgb(0 0 0 / 40%);
  cursor: pointer;
}

.video-player__play:hover {
  border-color: var(--color-accent-hover, #cdf779);
  background: var(--color-accent-hover, #cdf779);
}

.video-player__play:focus-visible {
  outline: 3px solid var(--color-heading, #f5f6f7);
  outline-offset: 3px;
}

.video-player__disclosure {
  margin: 0.4rem 0 0;
  color: var(--color-muted, #a0a7b4);
  font-size: 0.8rem;
  line-height: 1.45;
}

.video-player__frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 10px;
}

.video-link {
  font-weight: 600;
  text-decoration: none;
}

.video-link:hover {
  border-color: var(--color-accent, #b5f23d);
  color: var(--color-accent, #b5f23d);
}

.video-link__label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  background: var(--color-on-accent, #0f1115);
  color: inherit;
}

/* High-contrast modes draw no backgrounds: keep the lime bars and the play marks visible as outlines. */
@media (forced-colors: active) {
  .level-meter__bar,
  .video-link__label {
    border: 1px solid CanvasText;
  }
}

/* Print: no players or share buttons on paper; the links and the text remain. */
@media print {
  .card {
    break-inside: avoid;
    background: none;
  }

  .card-share,
  .video-player,
  .video-link {
    display: none !important;
  }
}
