/* =========================================================
   Pioneer Python — Capture the Flag page (ctf.html only)

   DESIGN CONCEPT: "live terminal in the dark, printout in the light."
   This page deliberately breaks the site's VS Code token palette — it is
   the Capture the Flag hub for a cybersecurity course, and it is supposed
   to look like the activities it links to.

   It is still THEME-AWARE, but not by washing the dark look out:
     dark  = a live terminal session (void ground, phosphor accents, glow)
     light = the declassified printout of that session (cool gray-green
             paper stock, ink-dark type, no glow, registration marks)
   Both are real looks. Neither is a fallback for the other.

   The three level accent colors are NOT invented — they are sampled from
   the three actual CtF activities this page links to:
     Level 1  ACCESS_GRANTED    emerald terminal green
     Level 2  GHOSTNET_NODE-7   brighter spring green
     Level 3  ICEBREAKER        ice cyan (the final level changes palette)
   Keep them in step with the activities if those pages are ever restyled.

   Everything is scoped under .ctf-page (or body[data-page="ctf"]) so it
   cannot leak into the shared sheets. The site header and footer are
   untouched on purpose: navigation should not change character page to page.
   ========================================================= */

/* ---- Palette + type tokens (page-scoped) --------------------------------
   Light values sit on the bare selector and dark overrides sit under
   [data-theme="dark"], matching how tokens.css is organized. The inline
   script in the page head always sets data-theme, so there is no
   prefers-color-scheme branch to maintain here. */
body[data-page="ctf"] {
  /* LIGHT — "the printout": cool gray-green stock, deliberately not cream. */
  --ctf-ground:    #E4E9E6;
  --ctf-panel:     #F2F5F3;
  --ctf-panel-2:   #E9EEEB;
  --ctf-ink:       #0F1A16;
  --ctf-ink-dim:   #4A5A54;
  --ctf-rule:      #C2CEC8;
  --ctf-l1:        #06603F;
  --ctf-l2:        #0E7A46;
  --ctf-l3:        #0A5578;
  /* Zero-blur rather than `none`: this token is substituted into the
     LENGTH slot of text-shadow/box-shadow, and `none` there produces an
     invalid declaration that the browser drops wholesale. 0 0 0 is valid
     and paints nothing, which is what the printout wants. */
  --ctf-glow:      0 0 0;
  --ctf-art-dim:   0.62;   /* screenshots sit back until hovered */
  --ctf-art-lift:  0.95;
  --ctf-scan:      0;      /* scanline sheen strength */
}

/* The theme attribute lives on <html>, set by the inline script in the page
   head before first paint. */
html[data-theme="dark"] body[data-page="ctf"] {
  /* DARK — "the session": near-black with a green cast, phosphor accents. */
  --ctf-ground:    #06090C;
  --ctf-panel:     #0B1116;
  --ctf-panel-2:   #101A20;
  --ctf-ink:       #C8D6D0;
  --ctf-ink-dim:   #6F8880;
  --ctf-rule:      #1C2A2A;
  --ctf-l1:        #00E08A;
  --ctf-l2:        #5CFF9E;
  --ctf-l3:        #5CD6FF;
  --ctf-glow:      0 0 12px;
  --ctf-art-dim:   0.42;
  --ctf-art-lift:  1;
  --ctf-scan:      1;
}

/* Type roles. Chakra Petch is squared and technical without tipping into
   retro sci-fi; IBM Plex Mono carries every piece of terminal/data text.
   Both fall back to the site stacks if the font request fails. */
body[data-page="ctf"] {
  --ctf-display: "Chakra Petch", var(--font-sans);
  --ctf-mono:    "IBM Plex Mono", var(--font-mono);

  background: var(--ctf-ground);
  color: var(--ctf-ink);
}

/* Ambient ground texture. Two different materials, one element:
     dark  = a faint terminal grid in the Level 1 green
     light = continuous-feed paper ruling (horizontal only), in ink
   Both are near-invisible by design — texture, never pattern. */
body[data-page="ctf"]::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  /* Light default: paper ruling. */
  background-image: linear-gradient(to bottom, currentColor 1px, transparent 1px);
  background-size: 100% 30px;
  color: var(--ctf-ink);
  opacity: 0.05;
}

html[data-theme="dark"] body[data-page="ctf"]::before {
  /* Dark: terminal grid. */
  background-image:
    linear-gradient(to right, currentColor 1px, transparent 1px),
    linear-gradient(to bottom, currentColor 1px, transparent 1px);
  background-size: 64px 64px;
  color: var(--ctf-l1);
  opacity: 0.045;
}

/* Content sits above the fixed ground texture. */
.ctf-page {
  position: relative;
  z-index: 1;
  color: var(--ctf-ink);
  font-family: var(--ctf-mono);
}

/* ---- Shared bits -------------------------------------------------------- */

/* Section label: "// SELECT A LEVEL". The `//` marker is the same comment
   vernacular the activities use in their own headers (// ACCESS_GRANTED),
   which ties the hub to the pages it launches. It replaced bracketed [01]
   numbering: with the course-resources section gone there is only one
   section here, and numbering a sequence of one says nothing. */
.ctf-label {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin: 0 0 1.25rem;
  font-family: var(--ctf-mono);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ctf-ink-dim);
}

.ctf-label__mark { color: var(--ctf-l1); }

.ctf-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--ctf-rule);
}

/* ---- Hero --------------------------------------------------------------- */

.ctf-hero {
  position: relative;
  border: 1px solid var(--ctf-rule);
  border-radius: var(--radius-md);
  background: var(--ctf-panel);
  padding: clamp(1.5rem, 4vw, 3rem);
  overflow: hidden;
}

/* Scanline sheen — dark only (--ctf-scan is 0 on the printout). */
.ctf-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.028) 0 1px,
    transparent 1px 3px
  );
  opacity: var(--ctf-scan);
}

.ctf-hero__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: clamp(1.5rem, 4vw, 2.5rem);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ctf-ink-dim);
}

.ctf-hero__course { color: var(--ctf-l1); }

.ctf-hero__status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

/* Pulsing session dot. The only ambient motion on the page; the rest of the
   motion budget is spent on the card hover. */
.ctf-hero__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ctf-l1);
  box-shadow: var(--ctf-glow) var(--ctf-l1);
  animation: ctf-pulse 2.4s var(--ease) infinite;
}

@keyframes ctf-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

.ctf-hero__title {
  margin: 0;
  font-family: var(--ctf-display);
  font-weight: 700;
  font-size: clamp(2.5rem, 7vw, 5.5rem);
  line-height: 0.95;
  letter-spacing: -0.02em;
  color: var(--ctf-ink);
  text-transform: uppercase;
}

/* Second line of the title takes the accent + glow, so the phrase reads as
   one object but the operative half carries the color. */
.ctf-hero__title em {
  display: block;
  font-style: normal;
  color: var(--ctf-l1);
  text-shadow: var(--ctf-glow) color-mix(in srgb, var(--ctf-l1) 45%, transparent);
}

.ctf-hero__line {
  margin: clamp(1.25rem, 3vw, 1.75rem) 0 0;
  max-width: 62ch;
  font-size: clamp(0.9rem, 1.1vw, 1.05rem);
  line-height: 1.7;
  color: var(--ctf-ink-dim);
}

.ctf-hero__line b {
  font-weight: 600;
  color: var(--ctf-ink);
}

/* Terminal caret at the end of the strapline. */
.ctf-caret {
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  margin-left: 0.15em;
  vertical-align: -0.18em;
  background: var(--ctf-l1);
  animation: ctf-blink 1.1s steps(1) infinite;
}

@keyframes ctf-blink {
  0%, 49%   { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* ---- Challenge cards ---------------------------------------------------- */

.ctf-grid {
  display: grid;
  gap: clamp(1rem, 2vw, 1.5rem);
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
}

/* Each card is one level, tinted by that level's real accent via --lv,
   set inline per card in the HTML. */
.ctf-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--ctf-panel);
  border: 1px solid var(--ctf-rule);
  border-radius: var(--radius-md);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: border-color 220ms var(--ease), transform 220ms var(--ease);
}

.ctf-card:hover,
.ctf-card:focus-visible {
  border-color: var(--lv);
  transform: translateY(-3px);
  text-decoration: none;
}

.ctf-card:focus-visible {
  outline: 2px solid var(--lv);
  outline-offset: 3px;
}

/* Accent hairline across the top of each card — the quickest read of which
   level you are looking at. */
.ctf-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: var(--lv);
  opacity: 0.55;
  transition: opacity 220ms var(--ease);
  z-index: 2;
}

.ctf-card:hover::before,
.ctf-card:focus-visible::before { opacity: 1; }

/* -- Card art: the real activity screenshot, used as a surveillance still.
      It sits back behind a scrim so the card's own labels stay dominant,
      and lifts on hover. object-position keeps each shot's title band in
      frame rather than centering on body copy. */
.ctf-card__art {
  position: relative;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: var(--ctf-panel-2);
}

.ctf-card__art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  opacity: var(--ctf-art-dim);
  filter: saturate(0.85);
  transition: opacity 320ms var(--ease), transform 420ms var(--ease),
              filter 320ms var(--ease);
}

.ctf-card:hover .ctf-card__art img,
.ctf-card:focus-visible .ctf-card__art img {
  opacity: var(--ctf-art-lift);
  transform: scale(1.04);
  filter: saturate(1);
}

/* Scrim: fades the screenshot into the card body so there is no hard seam. */
.ctf-card__art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    transparent 35%,
    color-mix(in srgb, var(--ctf-panel) 78%, transparent) 72%,
    var(--ctf-panel) 100%
  );
}

/* Corner brackets, borrowed from the panel framing on the real Level 2 and
   Level 3 pages. They extend on hover — the "target acquired" beat. */
.ctf-card__art::before {
  content: "";
  position: absolute;
  top: 10px;
  left: 10px;
  width: 18px;
  height: 18px;
  border-top: 2px solid var(--lv);
  border-left: 2px solid var(--lv);
  opacity: 0.7;
  z-index: 1;
  transition: width 260ms var(--ease), height 260ms var(--ease),
              opacity 260ms var(--ease);
}

.ctf-card:hover .ctf-card__art::before,
.ctf-card:focus-visible .ctf-card__art::before {
  width: 34px;
  height: 34px;
  opacity: 1;
}

/* -- Card body */
.ctf-card__body {
  position: relative;
  z-index: 1;
  margin-top: -2.75rem;   /* pull the label block up over the scrim */
  padding: 0 clamp(1.1rem, 2.2vw, 1.5rem) clamp(1.1rem, 2.2vw, 1.5rem);
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 0.85rem;
}

.ctf-card__level {
  font-family: var(--ctf-display);
  font-weight: 700;
  font-size: clamp(1.6rem, 2.6vw, 2rem);
  line-height: 1;
  letter-spacing: 0.01em;
  color: var(--lv);
  text-shadow: var(--ctf-glow) color-mix(in srgb, var(--lv) 40%, transparent);
  text-transform: uppercase;
}

.ctf-card__codename {
  margin: 0.3rem 0 0;
  font-size: 0.76rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  color: var(--ctf-ink-dim);
  text-transform: uppercase;
}

/* -- THE SIGNATURE: the flag-tick meter.
      Every tick is one flag, so the bar length IS the flag count — Level 3's
      20-flag bar is visibly longer than the 12-flag bars, and a student can
      literally count them. Drawn with a repeating gradient (no 44 spans of
      markup) and sized from --flags, set per card in the HTML.
      Echoes the segmented "TARGET SYSTEM INTEGRITY" bar on the Level 3 page. */
.ctf-meter {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

/* NOTE: the unlit state is a dimmed COLOR, not opacity on the element.
   Opacity here would create a stacking context that also caps the ::after
   fill below it, so the "captured" ticks could never burn brighter than the
   empty ones — which is the entire point of the interaction. */
.ctf-meter__track {
  position: relative;
  display: block;
  width: calc(var(--flags) * 11px - 3px);
  max-width: 100%;
  height: 12px;
  background: repeating-linear-gradient(
    to right,
    color-mix(in srgb, var(--lv) 28%, transparent) 0 8px,
    transparent 8px 11px
  );
}

/* The fill sweeps left-to-right on hover, like flags being captured.
   The gradient's stops are absolute lengths measured from this box's left
   edge, which is flush with the track's, so the lit ticks land exactly on
   the unlit ones as the width grows. */
.ctf-meter__track::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 0;
  background: repeating-linear-gradient(
    to right,
    var(--lv) 0 8px,
    transparent 8px 11px
  );
  transition: width 520ms var(--ease);
}

.ctf-card:hover .ctf-meter__track::after,
.ctf-card:focus-visible .ctf-meter__track::after { width: 100%; }

.ctf-meter__count {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--ctf-ink);
  text-transform: uppercase;
  white-space: nowrap;
}

.ctf-card__brief {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--ctf-ink-dim);
}

/* Tools list — what DevTools panels that level actually exercises. */
.ctf-card__tools {
  margin: 0;
  padding-top: 0.85rem;
  border-top: 1px solid var(--ctf-rule);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.13em;
  color: var(--ctf-ink-dim);
  text-transform: uppercase;
}

/* CTA. Named "Start challenge" to match the button on the activity itself,
   so the action keeps one name across the whole flow. */
.ctf-card__cta {
  margin-top: auto;
  padding-top: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--lv);
  text-transform: uppercase;
}

.ctf-card__cta .ctf-caret {
  background: var(--lv);
  height: 0.9em;
  animation: none;
  opacity: 0;
  transition: opacity 180ms var(--ease);
}

.ctf-card:hover .ctf-card__cta .ctf-caret,
.ctf-card:focus-visible .ctf-card__cta .ctf-caret {
  opacity: 1;
  animation: ctf-blink 1.1s steps(1) infinite;
}

/* ---- Motion opt-out ----------------------------------------------------- */
/* Everything above still reaches its hover STATE; only the movement goes. */
@media (prefers-reduced-motion: reduce) {
  body[data-page="ctf"] * {
    animation: none !important;
    transition-duration: 1ms !important;
  }
  .ctf-card:hover,
  .ctf-card:focus-visible { transform: none; }
  .ctf-card:hover .ctf-card__art img,
  .ctf-card:focus-visible .ctf-card__art img { transform: none; }
  /* Scoped to the hero: the card CTA carets are meant to stay hidden until
     that card is hovered, so a blanket .ctf-caret rule would light all three. */
  .ctf-hero__dot,
  .ctf-hero__line .ctf-caret { opacity: 1; }
}

/* ---- Narrow screens ----------------------------------------------------- */
@media (max-width: 560px) {
  .ctf-hero__title { font-size: clamp(2rem, 11vw, 2.75rem); }
  .ctf-card__art { aspect-ratio: 16 / 11; }
}
