/* writeups.css */
/* Writeups-only layout bits (theme uses your existing :root vars in index.css) */

.writeups-container {
  width: 77%;
  margin: auto;

  /* helps direct-link scroll land consistently if this (or an ancestor) is the scroller */
  scroll-padding-top: 90px;

  /* reduce browser scroll-anchoring surprises when cards expand / images load */
  overflow-anchor: none;

  /* =========================================================
     CLOSE SPEED CONTROL (adjust these)
     - --writeup-close-maxh controls the collapse speed (main one)
     - --writeup-close-pad controls how fast padding collapses
     ========================================================= */
  --writeup-close-opacity: 220ms;
  --writeup-close-maxh: 260ms; /* <- tweak this to change close time */
  --writeup-close-pad: 220ms;
}

/* =========================================================
   GAP / CENTERING FIX (scoped to writeups page)
   index.css sets:
     .main-block { min-height: 100dvh; padding-block: 5rem; justify-content:center; }
   That makes the intro consume a full viewport and pushes the list far down.

   Here, we:
   - remove the forced full-viewport height
   - add responsive top padding so the intro "starts around the middle"
   - keep bottom padding small so the list is closer
   ========================================================= */
.writeups-container .main-block {
  min-height: auto !important;

  /* approximate vertical centering without consuming a whole screen */
  padding-top: clamp(5rem, calc(50dvh - 160px), 14rem) !important;

  /* keep the gap under the intro small */
  padding-bottom: 2.00rem !important;

  margin-bottom: 0 !important;

  /* the padding controls positioning; don't add flex-centering gaps */
  justify-content: flex-start !important;
}

/* remove default bottom margin on the intro paragraph */
.writeups-container .text-block p {
  margin-bottom: 0;
}

/* List of cards */
.writeups-list {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;

  /* tighter top spacing above first card, slightly bigger bottom spacing */
  padding: 0.75rem 0 4.25rem;
  margin: 0;
}

/* Card matches your “panel” look */
.writeup-card {
  background: var(--panel-bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--panel-shadow);
  color: var(--accent);
  overflow: hidden;

  position: relative; /* needed for the absolute tiles & close button */

  /* make scrollIntoView land slightly below top (also matches JS offset) */
  scroll-margin-top: 90px;
}

/* Clickable header (condensed view) */
.writeup-head {
  cursor: pointer;
  padding: 1.2rem 1.4rem 1.1rem;
  user-select: none;
}

.writeup-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  display: inline-block;
}

/* underline ONLY on hover */
.writeup-head:hover .writeup-title {
  text-decoration-line: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.writeup-subtitle {
  margin: 0.35rem 0 0;
  font-size: 1rem;
  line-height: 1.4rem;
  opacity: 0.95;
}

/* =========================================================
   OPEN / CLOSE (measured height) — smooth slow open + FAST close
   - Close fade-out time kept the same (220ms)
   - Close collapse is now much faster (controlled by vars above)
   ========================================================= */

.writeup-body {
  max-height: 0;
  opacity: 0;
  overflow: hidden;

  padding: 0 1.4rem 0;
  pointer-events: none;

  /* CLOSE timing (applies when .open is removed) */
  transition:
    opacity var(--writeup-close-opacity, 220ms) ease-in,
    max-height var(--writeup-close-maxh, 260ms) ease-in,
    padding var(--writeup-close-pad, 220ms) ease-in;

  text-align: center;
  transform: translateY(0);
  will-change: max-height, opacity, padding;
}

.writeup-card.open .writeup-body {
  /* open to the measured content height */
  max-height: var(--body-h, 0px);
  opacity: 1;

  /* extra bottom space so the close button doesn't cover the last line */
  padding: 0 1.4rem 3.2rem;
  pointer-events: auto;

  /* OPEN timing (applies when .open is added) — much slower */
  transition:
    max-height 2400ms cubic-bezier(0.16, 1, 0.3, 1),
    opacity 1200ms ease-out,
    padding 1400ms ease-out;

  animation: writeup-pop 900ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes writeup-pop {
  from { transform: translateY(-10px); }
  to   { transform: translateY(0); }
}

/* Bottom-right close button (only visible when open) */
.writeup-close-btn {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 5;

  width: 40px;
  height: 40px;
  border-radius: 999px;

  display: grid;
  place-items: center;

  border: 1px solid rgba(255, 138, 0, 0.55);
  background: rgba(0, 0, 0, 0.38);
  color: var(--accent);

  font-size: 1.35rem;
  line-height: 1;
  font-weight: 800;

  cursor: pointer;

  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);

  transition:
    opacity 160ms ease-out,
    transform 160ms ease-out,
    background 160ms ease-out,
    border-color 160ms ease-out;
}

.writeup-card.open .writeup-close-btn {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.writeup-close-btn:hover {
  background: rgba(0, 0, 0, 0.52);
  border-color: rgba(255, 138, 0, 0.8);
}

.writeup-close-btn:focus-visible {
  outline: 2px solid rgba(255, 138, 0, 0.85);
  outline-offset: 2px;
}

/* Paragraphs stay centered */
.writeup-body p {
  margin: 0.85rem 0 0;
  line-height: 1.8rem;
  text-align: center;
}

/* Headings inside body */
.writeup-body h4 {
  margin: 1.25rem 0 0.25rem;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-align: center;
}

/* Horizontal rule */
.writeup-body hr {
  border: none;
  border-top: 1px solid rgba(255, 138, 0, 0.35);
  margin: 1.15rem 0 0.35rem;
}

/* ---------- LEFT-ALIGNED AREAS ---------- */

/* "Description:" label at top left (but still centered container-wise) */
.writeup-body .desc-label {
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
  text-align: left;
}

/* Description block: keep the box centered, but left-align text inside */
.writeup-body blockquote.desc-area {
  max-width: 900px;
  margin: 0.8rem auto 0;
  text-align: left;
}

/* Meta row: keep it in the same centered flow, but left-align its text */
.writeup-body .writeup-meta {
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
  text-align: left;
}

/* Lists: keep block centered, but bullets + text left */
.writeup-body ul,
.writeup-body ol {
  max-width: 900px;
  margin: 0.75rem auto 0;
  padding-left: 1.35rem;
  text-align: left;
}

.writeup-body li {
  margin: 0.35rem 0;
  line-height: 1.7rem;
  text-align: left;
}

/* =========================================================
   CODE BLOCKS
   ========================================================= */

/* wrapper around long code blocks (JS inserts this only when lines > 10) */
.code-wrap {
  max-width: 900px;
  margin: 1rem auto 0;
  text-align: left;
  position: relative;
}

/* Code blocks: keep box centered, text left */
.writeup-body pre {
  max-width: 900px;
  margin: 1rem auto 0;
  text-align: left;

  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 138, 0, 0.45);
  border-radius: 0.8rem;

  padding: 1rem;
  overflow: auto;
}

/* when wrapped, the wrapper owns the margin */
.code-wrap pre {
  margin: 0;
}

/* leave room for the overlay arrow button (only for long code blocks) */
.writeup-body pre.code-toggle {
  padding: 1rem 1rem 3.2rem;
}

/* collapsed: exactly 10 lines visible (scrollable) */
.writeup-body pre.code-toggle.code-collapsed {
  max-height: calc((10 * 1.45rem) + 4.2rem);
  overflow: auto;
}

/* expanded: exactly 25 lines visible (scrollable) */
.writeup-body pre.code-toggle.code-open {
  max-height: calc((25 * 1.45rem) + 4.2rem);
  overflow: auto;
}

/* v/^ arrow button for long code blocks
   - same size + border + bg + hover as the writeup close (×) button
   - arrow is CSS-only (no characters) */
.code-toggle-btn {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 6;

  width: 40px;
  height: 40px;
  border-radius: 999px;

  display: grid;
  place-items: center;

  border: 1px solid rgba(255, 138, 0, 0.55);
  background: rgba(0, 0, 0, 0.38);
  color: var(--accent);

  cursor: pointer;

  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);

  transition:
    opacity 160ms ease-out,
    transform 160ms ease-out,
    background 160ms ease-out,
    border-color 160ms ease-out;
}

/* CSS-only chevron */
.code-toggle-btn::before {
  content: "";
  width: 12px;
  height: 12px;

  /* thickness similar to the “×” weight visually */
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;

  /* default is "down" */
  transform: rotate(45deg);
}

/* open state = chevron up */
.code-toggle-btn.is-open::before {
  transform: rotate(-135deg);
}

.code-toggle-btn:hover {
  background: rgba(0, 0, 0, 0.52);
  border-color: rgba(255, 138, 0, 0.8);
}

.code-toggle-btn:focus-visible {
  outline: 2px solid rgba(255, 138, 0, 0.85);
  outline-offset: 2px;
}

.writeup-body pre code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.95rem;
  line-height: 1.45rem;
  background: transparent;
  border: none;
  padding: 0;
  text-align: left;
  white-space: pre;
}

/* Inline code: keep centered paragraphs, but code itself reads cleanly */
.writeup-body :not(pre) > code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  background: rgba(0, 0, 0, 0.30);
  border: 1px solid rgba(255, 138, 0, 0.28);
  border-radius: 0.45rem;
  padding: 0.12rem 0.38rem;
  font-size: 0.95em;
}

/* ---------- KEEP THESE CENTERED ---------- */

/* Blockquotes / notes (box styling; alignment is handled above for desc-area) */
.writeup-body blockquote {
  padding: 0.9rem 1rem;
  border-left: 3px solid var(--accent);
  border-radius: 0.85rem;
  background: rgba(0, 0, 0, 0.22);
}

.writeup-body blockquote p {
  margin: 0.4rem 0 0;
}

.writeup-body blockquote p:first-child {
  margin-top: 0;
}

/* Callout stays centered */
.writeup-body .callout {
  max-width: 900px;
  margin: 0.95rem auto 0;
  padding: 0.95rem 1rem;
  border-radius: 0.85rem;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 138, 0, 0.35);
  line-height: 1.7rem;
  text-align: center;
}

.writeup-body .callout.important {
  border-left: 3px solid var(--accent);
}

/* Images stay centered */
.writeup-body .writeup-img {
  display: block;
  width: 100%;
  max-width: 800px;
  height: auto;
  margin: 1rem auto 0;
  border-radius: 0.9rem;
  border: 1px solid rgba(255, 138, 0, 0.35);
  box-shadow: 0 0.75rem 1.8rem rgba(0, 0, 0, 0.35);
}

.writeup-body .caption {
  margin-top: 1.05rem;
  opacity: 0.95;
  text-align: center;
}

/* Links */
.writeup-body a {
  color: var(--accent);
  text-decoration-line: underline;
  text-decoration-color: rgba(255, 138, 0, 0.75);
  text-underline-offset: 0.18em;
}

.writeup-body a:hover {
  text-decoration-color: var(--accent);
}

/* Small meta pill */
.writeup-body .pill {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.12rem 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 138, 0, 0.45);
  background: rgba(0, 0, 0, 0.22);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}

/* =========================================================
   Title tiles
   - Left: difficulty + category
   - Right: First Blood (Emoji CAPTCHA only via JS display)
   ========================================================= */
.writeup-badges-left {
  position: absolute;
  left: 28px;
  top: 37px;
  transform: translate3d(0, -50%, 0);

  display: flex;
  gap: 25px;
  align-items: center;

  pointer-events: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

.writeup-badges-right {
  position: absolute;
  right: 28px;
  top: 37px;
  transform: translate3d(0, -50%, 0);

  display: flex;
  gap: 25px;
  align-items: center;

  pointer-events: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

.writeup-badge {
  padding: 5px 10px;
  border: 2px solid currentColor;
  color: currentColor;

  border-radius: 10px;
  background: transparent;

  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1;
  letter-spacing: 0.02em;
}

/* Difficulty badge uses JS-provided --diff-color (easy green, hard dark red) */
.writeup-badge.writeup-diff {
  border-color: var(--diff-color, #22c55e);
  color: var(--diff-color, #22c55e);
}

/* category badge uses JS-provided --badge-color */
.writeup-badge.writeup-cat {
  border-color: var(--badge-color, currentColor);
  color: var(--badge-color, currentColor);
}

/* First Blood badge */
.writeup-badge.writeup-firstblood {
  border-color: #ef4444;
  color: #ef4444;
}