/* ============================================================
   Chess Home — Bento-grid magazine feed.
   Layered AFTER social.css + notifications.css so it can win
   the specificity war for the home feed only. Scoped to
   `.bento-feed` / `.bento-page` so it doesn't leak into club /
   thread pages. Palette references the zine tokens (paper, ink,
   forest, wood) declared in zine.css — no blue permitted.
   ============================================================ */

/* ---- 0. Page shell — single centered column ------------- */
/* We deliberately do NOT set `display: grid` on .bento-page.
   The old two-column pinned-sidebar layout was where the
   composer/sidecar collision happened; the fix is to keep the
   page as a normal block flow and put the pinned tiles inside
   the .bento-feed grid instead. */
.bento-page {
  display: block;
  position: relative;
}

/* Belt-and-suspenders: if any collab-worker `{% include %}` re-adds
   an .li-cols / .li-left / .li-right shell around .bento-page,
   neutralise it so we don't regress into a broken multi-column
   layout on the home feed. */
.bento-page.li-cols,
.li-cols.bento-page {
  display: block !important;
  grid-template-columns: none !important;
  gap: 0 !important;
}
.bento-page .li-left,
.bento-page .li-right {
  display: none !important;
}

/* ---- 1. Grid container ------------------------------------ */
.bento-feed {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-flow: dense;
  grid-auto-rows: minmax(220px, auto);
  /* Progressive enhancement: real masonry when the browser can. */
  grid-template-rows: masonry;
  margin-top: 14px;
  position: relative;
  z-index: 1;
}

@media (max-width: 1024px) {
  .bento-feed {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .bento-feed {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }
}

/* ---- 2. Tile shapes --------------------------------------- */
.bento-tile {
  position: relative;
  background: var(--cream, #fbf7ef);
  border: 1px solid var(--rule-soft, #d8ceb6);
  padding: 0;
  overflow: hidden;
  min-width: 0;
  transition:
    transform 0.22s ease,
    box-shadow 0.28s ease;
  /* Every tile alternates rounding by nth-child (see below);
     defaults for tiles that aren't in the .bento-feed grid. */
  border-radius: 22px 4px 22px 4px;
}

/* Odd position: 22px top-left / bottom-right. */
.bento-feed > .bento-tile:nth-child(odd) {
  border-radius: 22px 4px 22px 4px;
}
/* Even position: mirrored corners. */
.bento-feed > .bento-tile:nth-child(even) {
  border-radius: 4px 22px 4px 22px;
}

/* Grid spans per bento kind. */
.bento-tile.bento-standard {
  grid-column: span 1;
  grid-row: span 1;
}
.bento-tile.bento-wide {
  grid-column: span 2;
  grid-row: span 1;
}
.bento-tile.bento-tall {
  grid-column: span 1;
  grid-row: span 2;
}
.bento-tile.bento-hero {
  grid-column: span 2;
  grid-row: span 2;
  border-radius: 28px 6px 28px 6px;
}

/* Full-width banner (onboarding nudge, empty-state, etc.). */
.bento-tile.bento-banner {
  grid-column: 1 / -1;
  grid-row: span 1;
  border-radius: 22px 22px 22px 22px;
}

/* Narrow viewports collapse to a single column — kinds stop
   claiming extra columns, but keep organic corners. */
@media (max-width: 1024px) {
  .bento-feed > .bento-tile.bento-hero,
  .bento-feed > .bento-tile.bento-wide {
    grid-column: span 2;
  }
}
@media (max-width: 640px) {
  .bento-feed > .bento-tile,
  .bento-feed > .bento-tile.bento-hero,
  .bento-feed > .bento-tile.bento-wide,
  .bento-feed > .bento-tile.bento-tall {
    grid-column: 1 / -1;
    grid-row: auto;
  }
}

/* ---- 3. Hover — gentle lift + wood-grain shadow ---------- */
.bento-tile:hover {
  transform: translateY(-2px);
  box-shadow:
    0 1px 0 rgba(120, 80, 40, 0.10),
    0 6px 12px rgba(120, 80, 40, 0.14),
    0 18px 32px rgba(90, 55, 25, 0.10),
    0 2px 0 rgba(217, 185, 138, 0.35) inset;
}

/* ---- 4. Category ribbon (top-right diagonal) ------------- */
.bento-ribbon {
  position: absolute;
  top: 14px;
  right: -34px;
  transform: rotate(35deg);
  transform-origin: center;
  background: var(--wood-a, #8b5a2b);
  color: var(--cream, #fbf7ef);
  font-family: "Fraunces", "Iowan Old Style", Georgia, serif;
  font-weight: 600;
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 4px 40px;
  box-shadow:
    0 2px 4px rgba(60, 35, 15, 0.22),
    inset 0 -1px 0 rgba(0, 0, 0, 0.12);
  pointer-events: none;
  z-index: 3;
  transition: transform 0.22s ease;
}

.bento-tile:hover .bento-ribbon {
  transform: rotate(37deg);
}

/* Ribbon variants per post kind. */
.bento-ribbon.rib-event      { background: var(--forest, #2a5f3a); }
.bento-ribbon.rib-pgn        { background: var(--ink, #1a1512); }
.bento-ribbon.rib-video      { background: var(--sienna, #b45a2b); }
.bento-ribbon.rib-study      { background: var(--wood-a, #8b5a2b); }
.bento-ribbon.rib-discussion { background: var(--wood-a-hi, #a56b34); }
.bento-ribbon.rib-post       { background: var(--wood-a, #8b5a2b); }
/* Pinned-tile ribbons — reuse the same palette so nothing new
   is introduced. */
.bento-ribbon.rib-puzzle     { background: var(--ink, #1a1512); }
.bento-ribbon.rib-upcoming   { background: var(--forest, #2a5f3a); }
.bento-ribbon.rib-discover   { background: var(--sienna, #b45a2b); }

/* ---- 5. Reshape post_card content inside a bento tile ---- */
/* The reused .post-card lives inside .bento-tile — we suppress
   its own frame and repaint the interior for a magazine feel. */
.bento-tile .post-card {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  margin: 0;
  padding: 18px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  min-height: 220px;
}

/* Hide the LinkedIn-style top head — author moves to bottom. */
.bento-tile .post-card > .post-head {
  display: none;
}

/* Titles: Fraunces, larger on hero. */
.bento-tile .post-card .post-title {
  font-family: "Fraunces", "Iowan Old Style", Georgia, serif;
  font-weight: 600;
  font-size: 20px;
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 4px 0 6px;
  color: var(--ink, #1a1512);
}
.bento-tile.bento-hero .post-card .post-title {
  font-size: 30px;
  line-height: 1.05;
}
.bento-tile.bento-wide .post-card .post-title {
  font-size: 24px;
}

/* Body: clamped previews so tiles don't blow out. */
.bento-tile .post-card .post-body {
  font-family: "Inter", -apple-system, sans-serif;
  color: var(--ink-soft, #3a2f27);
  font-size: 14.5px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  margin: 0;
  flex: 1 1 auto;
}
.bento-tile.bento-wide .post-card .post-body,
.bento-tile.bento-hero .post-card .post-body {
  -webkit-line-clamp: 5;
  font-size: 15px;
}

/* Reactions + like counters slide to the bottom-right, small. */
.bento-tile .post-card .post-stats,
.bento-tile .post-card .rx-row {
  margin-top: auto;
  font-size: 12px;
  color: var(--ink-mute, #6a5d52);
}
.bento-tile .post-card .post-stats {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Actions bar slimmed down and moved to a subtle inline strip. */
.bento-tile .post-card .post-actions {
  border-top: 1px dashed var(--rule-soft, #d8ceb6);
  padding-top: 8px;
  margin-top: 4px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.bento-tile .post-card .post-actions .act {
  font-size: 12.5px;
  padding: 4px 8px;
}

/* PGN board fills tile width; games are always tall. */
.bento-tile.bento-tall .post-card .post-game {
  margin: 0 -4px;
}
.bento-tile .post-card .post-media img,
.bento-tile .post-card .post-media-item {
  border-radius: 8px;
}
.bento-tile.bento-hero .post-card .post-media,
.bento-tile.bento-wide .post-card .post-media {
  margin: -18px -18px 8px;
  border-radius: 0;
}
.bento-tile.bento-hero .post-card .post-media img,
.bento-tile.bento-wide .post-card .post-media img {
  border-radius: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Video posts — muted preview reveals on hover. */
.bento-tile .post-card .post-media-video video {
  width: 100%;
  border-radius: 8px;
  background: #000;
}
.bento-tile.bento-tall .post-card .post-media-video {
  margin: -18px -18px 8px;
}

/* ---- 6. Bottom byline (author moves here) ---------------- */
.bento-byline {
  position: absolute;
  left: 14px;
  bottom: 12px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 2;
  font-family: "Inter", sans-serif;
  font-size: 11.5px;
  color: var(--ink-mute, #6a5d52);
  pointer-events: none;
}
.bento-byline .avatar {
  width: 22px;
  height: 22px;
  font-size: 10px;
  line-height: 22px;
  border-radius: 50%;
  display: inline-block;
  text-align: center;
  color: var(--cream);
  font-weight: 600;
}
.bento-byline .b-name {
  font-weight: 600;
  color: var(--ink-soft, #3a2f27);
  text-decoration: none;
  pointer-events: auto;
}
.bento-byline .b-flag { font-size: 12px; }
.bento-byline .b-time { color: var(--ink-mute, #6a5d52); }
.bento-byline .b-dot::before {
  content: "·";
  margin: 0 2px;
  color: var(--rule, #b7ac93);
}
.bento-byline .b-replies {
  margin-left: auto;
  background: var(--paper-2, #ede4d1);
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--ink-soft, #3a2f27);
  font-weight: 500;
  pointer-events: auto;
}

/* Reserve bottom padding on post-card so the byline doesn't clip content. */
.bento-tile .post-card {
  padding-bottom: 46px;
}

/* ---- 7. Pinned tiles (puzzle / upcoming / discover) ------ */
/* These are first-class .bento-tile children — they share the
   same shell, ribbon, hover, and border-radius rules as post
   tiles. The rules below only style the inner text since pinned
   tiles do NOT wrap a .post-card (no byline, no reactions). */
.bento-tile.bento-pinned {
  /* Restate every base .bento-tile shell rule with a slightly
     higher specificity so even if a legacy stylesheet or a stale
     browser cache tries to flatten these tiles, the shell (cream
     bg, organic corners, border, padding-0 shell) still lands.
     This is deliberately defensive — the base .bento-tile rule
     already provides these, but pinned tiles are the most likely
     regression surface. */
  display: block;
  position: relative;
  background: var(--cream, #fbf7ef);
  border: 1px solid var(--rule-soft, #d8ceb6);
  border-radius: 22px 4px 22px 4px;
  padding: 0;
  overflow: hidden;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  /* feed.js prepends new posts with `insertBefore(post, firstChild)`,
     which would otherwise push pinned tiles down the DOM. Grid
     honours `order`, so pinned tiles stay visually first without
     us having to touch feed.js. */
  order: -1;
}
/* Even-position mirror still applies via .bento-feed > :nth-child, but
   pinned tiles are always at DOM positions 1/2/3 → odd/even/odd. */

/* Stretched-link pattern: an anchor inside a pinned tile can
   opt-in to covering the entire tile so the whole card is
   clickable (used by the Daily Puzzle tile). Sits above the
   card background but below the ribbon so hover still works. */
.bento-tile.bento-pinned .pinned-stretched-link {
  color: inherit;
  text-decoration: none;
}
.bento-tile.bento-pinned .pinned-stretched-link::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}
.bento-tile.bento-pinned .pinned-stretched-link:hover {
  color: var(--forest, #2a5f3a);
}
/* Ribbon + inner content float above the stretched link so their
   own hover / focus states still respond. */
.bento-tile.bento-pinned .bento-ribbon { z-index: 3; }
.bento-tile.bento-pinned .pinned-inner { position: relative; z-index: 2; }
/* Inner links inside the events / discover tiles must stay
   clickable — bump them above the stretched-link overlay. */
.bento-tile.bento-pinned .pinned-list-link,
.bento-tile.bento-pinned .pinned-more { position: relative; z-index: 2; }
.bento-tile.bento-pinned .pinned-inner {
  padding: 18px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  min-height: 220px;
}
.bento-tile.bento-pinned .pinned-eyebrow {
  font-family: "Fraunces", "Iowan Old Style", Georgia, serif;
  font-weight: 600;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--wood-a, #8b5a2b);
}
.bento-tile.bento-pinned .pinned-title {
  font-family: "Fraunces", "Iowan Old Style", Georgia, serif;
  font-weight: 600;
  font-size: 20px;
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 2px 0 4px;
  color: var(--ink, #1a1512);
}
.bento-tile.bento-pinned.bento-wide .pinned-title {
  font-size: 24px;
}
.bento-tile.bento-pinned .pinned-body {
  font-family: "Inter", -apple-system, sans-serif;
  color: var(--ink-soft, #3a2f27);
  font-size: 14.5px;
  line-height: 1.5;
  margin: 0;
}
.bento-tile.bento-pinned .pinned-meta {
  margin-top: auto;
  font-family: "Inter", sans-serif;
  font-size: 12.5px;
  color: var(--ink-mute, #6a5d52);
}
.bento-tile.bento-pinned .pinned-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 auto;
  overflow: hidden;
}
.bento-tile.bento-pinned .pinned-list li {
  padding: 6px 0;
  border-top: 1px dashed var(--rule-soft, #d8ceb6);
}
.bento-tile.bento-pinned .pinned-list li:first-child {
  border-top: 0;
  padding-top: 2px;
}
.bento-tile.bento-pinned .pinned-list-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--ink, #1a1512);
  text-decoration: none;
  line-height: 1.35;
}
.bento-tile.bento-pinned .pinned-list-link strong {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 14.5px;
  color: var(--ink, #1a1512);
}
.bento-tile.bento-pinned .pinned-list-link:hover strong {
  color: var(--forest, #2a5f3a);
}
.bento-tile.bento-pinned .pinned-list-meta {
  font-family: "Inter", sans-serif;
  font-size: 12px;
  color: var(--ink-mute, #6a5d52);
}
.bento-tile.bento-pinned .pinned-more {
  margin-top: 6px;
  font-family: "Inter", sans-serif;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--forest, #2a5f3a);
  text-decoration: none;
  align-self: flex-start;
}
.bento-tile.bento-pinned .pinned-more:hover { text-decoration: underline; }

/* Any legacy .club-card that a template drops inside the grid
   (e.g. Discover cards from clubs.py) must NOT keep its old
   absolute positioning or LinkedIn drop-shadow. Reset it. */
.bento-feed .club-card,
.bento-page .club-card {
  position: static;
  margin: 0 0 8px;
}

/* ---- 8. Composer — full-width band, isolated above grid --- */
/* The composer lives OUTSIDE .bento-feed. That guarantees it can
   never overlap with a grid tile. We also give it an opaque cream
   background + a positive z-index so any absolutely-positioned
   ribbon / byline from a tile below can't bleed through. */
.bento-composer {
  position: relative;
  z-index: 5;
  background: var(--cream, #fbf7ef);
  border: 1px solid var(--rule, #b7ac93);
  border-radius: 22px 4px 22px 4px;
  padding: 6px 10px;
  box-shadow:
    0 1px 0 rgba(120, 80, 40, 0.08),
    0 8px 20px rgba(90, 55, 25, 0.06);
  margin: 14px 0 6px;
  isolation: isolate;
}
.bento-composer .li-composer {
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 6px 6px 4px;
}

/* ---- 9. Skeleton tiles ----------------------------------- */
.bento-skeleton {
  background: linear-gradient(
    100deg,
    var(--paper-2, #ede4d1) 20%,
    var(--paper-3, #e2d6bc) 40%,
    var(--paper-2, #ede4d1) 60%
  );
  background-size: 200% 100%;
  animation: bento-shimmer 1.4s linear infinite;
  border: 1px solid var(--rule-soft, #d8ceb6);
}
@keyframes bento-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---- 10. Empty state — magazine cover -------------------- */
.bento-empty-cover {
  grid-column: 1 / -1;
  min-height: 380px;
  padding: 48px 36px;
  border: 1px solid var(--rule, #b7ac93);
  border-radius: 22px 4px 22px 4px;
  background:
    radial-gradient(circle at 15% 20%, rgba(217, 185, 138, 0.35), transparent 40%),
    radial-gradient(circle at 90% 90%, rgba(42, 95, 58, 0.10), transparent 45%),
    var(--cream, #fbf7ef);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.bento-empty-cover .cover-eyebrow {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--wood-a, #8b5a2b);
}
.bento-empty-cover .cover-title {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  font-size: 48px;
  line-height: 1.02;
  letter-spacing: -0.02em;
  color: var(--ink, #1a1512);
  margin: 24px 0;
  text-wrap: balance;
  max-width: 18ch;
}
.bento-empty-cover .cover-dateline {
  font-family: "Inter", sans-serif;
  font-size: 13px;
  color: var(--ink-mute, #6a5d52);
}
.bento-empty-cover .cover-piece {
  position: absolute;
  right: 24px;
  bottom: 20px;
  font-size: 180px;
  line-height: 1;
  color: rgba(120, 80, 40, 0.08);
  font-family: "Fraunces", Georgia, serif;
  pointer-events: none;
  user-select: none;
}
.bento-empty-cover .cover-cta {
  align-self: flex-start;
  background: var(--forest, #2a5f3a);
  color: var(--cream, #fbf7ef);
  padding: 10px 16px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 600;
  font-size: 13.5px;
}
.bento-empty-cover .cover-cta:hover { background: var(--forest-hi, #3a7a4c); }

/* Analyze pill for PGN tiles. */
.bento-tile.bento-tall .post-game-actions {
  position: absolute;
  bottom: 40px;
  right: 12px;
  z-index: 2;
}
.bento-tile.bento-tall .post-game-actions .btn {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 999px;
}
