/* -------------------------------------------------------------------- */
/*  Tokens                                                               */
/* -------------------------------------------------------------------- */
:root {
  --cream:        #FBF3E7;
  --cream-deep:    #F3E5D3;
  --paper:        #FFFDF9;
  --ink:          #3A2E4D;
  --ink-soft:     #6C5E82;

  --plum-deep:    #241A38;
  --plum-deeper:  #180F29;
  --plum-glow:    #372A54;

  --pink:         #F3A9C4;
  --pink-deep:    #E8799F;
  --mint:         #8FE0C2;
  --mint-deep:    #57BE9C;
  --lilac:        #B9A6F2;
  --lilac-deep:   #9276E8;
  --gold:         #F0C869;

  --font-display: "Fredoka", sans-serif;
  --font-body:    "Nunito", sans-serif;
  --font-mono:    "JetBrains Mono", "Fira Code", monospace;

  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 10px;

  --shadow-soft: 0 18px 40px -18px rgba(58, 46, 77, 0.35);
  --shadow-pop:  0 10px 24px -10px rgba(58, 46, 77, 0.3);
}

/* -------------------------------------------------------------------- */
/*  Reset-ish base                                                      */
/* -------------------------------------------------------------------- */
* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--cream);
  background-image:
    radial-gradient(circle at 8% 8%, rgba(243, 169, 196, 0.25), transparent 42%),
    radial-gradient(circle at 92% 18%, rgba(185, 166, 242, 0.25), transparent 45%),
    radial-gradient(circle at 50% 100%, rgba(143, 224, 194, 0.18), transparent 50%);
  line-height: 1.6;
}

a { color: inherit; }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Reduced motion respect ------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* -------------------------------------------------------------------- */
/*  Ambient sparkles (decorative, aria-hidden)                          */
/* -------------------------------------------------------------------- */
.page-sparkles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(circle, var(--gold) 1.5px, transparent 1.6px),
    radial-gradient(circle, var(--pink) 1.5px, transparent 1.6px),
    radial-gradient(circle, var(--lilac) 1.5px, transparent 1.6px);
  background-size: 220px 220px, 260px 260px, 300px 300px;
  background-position: 20px 40px, 140px 180px, 60px 260px;
  opacity: 0.5;
}

/* -------------------------------------------------------------------- */
/*  Header / footer                                                     */
/* -------------------------------------------------------------------- */
.site-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  max-width: 900px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 0.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--ink);
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 2.1rem; height: 2.1rem;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: var(--shadow-pop);
}

.lang-switch {
  display: flex;
  gap: 0.4rem;
}

.lang-pill {
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-soft);
  box-shadow: var(--shadow-pop);
  transition: transform 0.15s ease, color 0.15s ease;
}

.lang-pill:hover { transform: translateY(-2px); }

.lang-pill.is-active {
  background: var(--ink);
  color: var(--paper);
}

.site-footer {
  position: relative;
  z-index: 2;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
  padding: 2.5rem 1.5rem 3rem;
}

main { position: relative; z-index: 1; }

/* -------------------------------------------------------------------- */
/*  Hero + TOC (table of contents page)                                 */
/* -------------------------------------------------------------------- */
.hero {
  max-width: 720px;
  margin: 3.5rem auto 3rem;
  padding: 0 1.5rem;
  text-align: center;
}

.hero-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--lilac-deep);
  margin: 0 0 0.75rem;
}

.hero-title {
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  line-height: 1.05;
  background: linear-gradient(100deg, var(--ink) 20%, var(--lilac-deep) 55%, var(--pink-deep) 85%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-tagline {
  margin-top: 1rem;
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--ink-soft);
  min-height: 1.6em;
}

.tw-caret {
  display: inline-block;
  color: var(--pink-deep);
  animation: caret-blink 1s steps(1) infinite;
}

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

.toc {
  max-width: 720px;
  margin: 0 auto 5rem;
  padding: 0 1.5rem;
}

.toc-heading {
  font-size: 1.2rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 1.25rem;
}

.toc-list {
  list-style: none;
  margin: 0; padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.toc-card {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  text-decoration: none;
  color: var(--ink);
  background: var(--paper);
  border-radius: var(--radius-md);
  padding: 1.1rem 1.3rem;
  box-shadow: var(--shadow-pop);
  border: 1px solid rgba(58, 46, 77, 0.06);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.toc-card:hover,
.toc-card:focus-visible {
  transform: translateY(-3px) rotate(-0.3deg);
  box-shadow: var(--shadow-soft);
  border-color: var(--pink);
}

.toc-number {
  flex: none;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--paper);
  background: linear-gradient(160deg, var(--lilac-deep), var(--pink-deep));
  width: 2.6rem; height: 2.6rem;
  display: grid; place-items: center;
  border-radius: 50%;
}

.toc-copy { flex: 1; min-width: 0; }

.toc-title {
  display: block;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
}

.toc-excerpt {
  display: block;
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin-top: 0.2rem;
}

.toc-arrow {
  flex: none;
  font-size: 1.3rem;
  color: var(--mint-deep);
  transform: rotate(-90deg);
}

/* -------------------------------------------------------------------- */
/*  Chapter console                                                     */
/* -------------------------------------------------------------------- */
.console-wrap {
  max-width: 760px;
  margin: 2.5rem auto 5rem;
  padding: 0 1.25rem;
}

.console {
  position: relative;
  background: radial-gradient(circle at 20% -10%, var(--plum-glow), var(--plum-deep) 55%, var(--plum-deeper) 100%);
  border-radius: var(--radius-lg);
  padding: 1.6rem 1.8rem 2.1rem;
  box-shadow: var(--shadow-soft);
  color: #EFE7FB;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.console-topbar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1.1rem;
}

.console-dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  display: inline-block;
}
.dot-pink  { background: var(--pink); }
.dot-mint  { background: var(--mint); }
.dot-lilac { background: var(--lilac); }

.console-chip {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: rgba(239, 231, 251, 0.6);
  background: rgba(255, 255, 255, 0.06);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
}

.console-title {
  font-size: clamp(1.35rem, 4vw, 1.7rem);
  color: #FBF3E7;
  margin-bottom: 1rem;
}

.console-progress {
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-bottom: 1.4rem;
}

.console-progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--pink), var(--lilac), var(--mint));
  transition: width 0.2s ease;
}

.chapter-source,
.chapter-output {
  font-family: var(--font-mono);
  font-size: 1.02rem;
  line-height: 1.85;
  color: #F4EEFC;
}

.chapter-source p,
.chapter-output p {
  margin: 0 0 1.2em;
}

.chapter-output p:last-child { margin-bottom: 0; }

.chapter-output .tw-cursor {
  display: inline-block;
  margin-left: 1px;
  color: var(--gold);
  animation: caret-blink 0.9s steps(1) infinite;
}

/* When JS is active, hide the plain source; output takes over.
   (site.js also removes [hidden] from #chapter-output, so this rule
   only matters for the brief instant before that happens / no-JS.) */
.js-ready .chapter-source { display: none; }

.console-controls {
  margin-top: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.console-hint {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: rgba(239, 231, 251, 0.55);
}

.console-buttons {
  display: flex;
  gap: 0.6rem;
}

.console-btn {
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 0.82rem;
  border: none;
  cursor: pointer;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--pink), var(--lilac));
  color: var(--plum-deeper);
  box-shadow: 0 8px 18px -8px rgba(0,0,0,0.5);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.console-btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.console-btn:active { transform: translateY(0); }

.console-btn.is-active {
  background: linear-gradient(135deg, var(--mint), var(--lilac));
}

.console-btn-ghost {
  background: rgba(255,255,255,0.08);
  color: #F4EEFC;
  box-shadow: none;
  border: 1px solid rgba(255,255,255,0.16);
}

.typing-catcher {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
  background: transparent;
}

/* Focus styling lands on the console itself so keyboard users can see it */
.console:focus-within {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.chapter-nav {
  margin-top: 1.8rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  animation: nav-in 0.5s ease both;
}

@keyframes nav-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chapter-nav-link {
  flex: 1 1 220px;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #F4EEFC;
  border-radius: var(--radius-sm);
  padding: 0.8rem 1rem;
  transition: transform 0.15s ease, background 0.15s ease;
}

.chapter-nav-link:not(.is-disabled):hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.13);
}

.chapter-nav-link.is-disabled { opacity: 0.35; }

.chapter-nav-next { justify-content: flex-end; text-align: right; }

.chapter-nav-arrow {
  font-size: 1.4rem;
  color: var(--gold);
  line-height: 1;
}

.chapter-nav-copy { display: flex; flex-direction: column; min-width: 0; }

.chapter-nav-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(239, 231, 251, 0.5);
}

.console-below-hint {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.85rem;
}

.console-below-hint a {
  text-decoration: none;
  color: var(--ink-soft);
  font-weight: 700;
}
.console-below-hint a:hover { color: var(--pink-deep); }

/* -------------------------------------------------------------------- */
/*  Responsive                                                          */
/* -------------------------------------------------------------------- */
@media (max-width: 560px) {
  .console { padding: 1.25rem 1.1rem 1.6rem; }
  .console-controls { flex-direction: column; align-items: stretch; }
  .console-buttons { justify-content: center; }
  .chapter-nav-next { justify-content: flex-start; text-align: left; }
}
