/* ===========================================================================
   Codium landing — codium.cc
   Terminal-UI, built on the same stack as the app (app.codium.cc):
   WebTUI + the Osmium theme (light + dark), Hack as the monospace voice.
   Light theme is the default; a single header button toggles dark.
   Layer order is declared first so WebTUI's base < utils < components
   interleave predictably, with our page rules layered last so they win.
   =========================================================================== */
@layer base, utils, components, page;

@import "vendor/hack.css";
@import "vendor/webtui.css";
@import "vendor/osmium.css";
@import "vendor/osmium-light.css";

@layer base {
  :root {
    /* Hack is the brand voice; the app's Nerd/JetBrains stack is the fallback. */
    --font-family: "Hack", ui-monospace, "SF Mono", SFMono-Regular, Menlo,
      Consolas, "Liberation Mono", monospace;
    --font-size: 15px;
    --line-height: 1.4;

    /* landing layout tokens */
    --maxw: 68rem;
    --gutter: 2ch;
  }

  /* Box borders follow the active theme's surface scale (osmium-light already
     sets this; mirror it for dark so borders aren't the bright foreground). */
  [data-webtui-theme="osmium"] {
    --box-border-color: var(--surface3);
  }

  /* WebTUI's terminal `break-all` hurts prose; the app makes the same fix. */
  body,
  html {
    word-break: normal;
  }

  body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  main {
    flex: 1;
  }

  a {
    color: var(--blue-fg);
  }
}

@layer page {
  /* ---- shared rhythm --------------------------------------------------- */
  .wrap {
    max-width: var(--maxw);
    margin-inline: auto;
    padding-inline: var(--gutter);
  }

  section {
    padding-block: clamp(2.5lh, 6vw, 4.5lh);
  }

  /* Suppress WebTUI's terminal list markers ("- " on ul, decimals on ol) for
     the landing's custom lists — they carry their own glyphs / numbering. */
  .idea-grid,
  .ladder,
  .steps {
    list-style: none;
  }
  .idea-grid li::before,
  .ladder li::before,
  .steps li::before {
    content: none;
  }

  .eyebrow {
    color: var(--green-fg);
    letter-spacing: 0.1ch;
    margin-bottom: 1lh;
  }
  .eyebrow::before {
    content: "// ";
    color: var(--foreground2);
  }

  h1,
  h2,
  h3 {
    color: var(--green-fg);
    font-weight: var(--font-weight-bold);
    line-height: 1.15;
  }
  h1 {
    font-size: clamp(1.9rem, 4.6vw, 3rem);
    margin-bottom: 1lh;
  }
  h2 {
    font-size: clamp(1.4rem, 3vw, 2rem);
  }

  .muted {
    color: var(--foreground1);
  }
  .dim {
    color: var(--foreground2);
  }

  /* ---- header (mirrors the app's top bar) ------------------------------ */
  .app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2ch;
    padding: 0.5lh 2ch;
    border-bottom: 1px solid var(--background2);
    background-color: var(--background1);
  }
  .brand {
    color: var(--foreground0);
    font-weight: var(--font-weight-bold);
    text-decoration: none;
    font-size: 1.05rem;
    white-space: nowrap;
  }
  .brand .prompt {
    color: var(--green-fg);
    margin-right: 0.3ch;
  }
  .brand:hover {
    text-decoration: none;
  }
  .cursor {
    display: inline-block;
    width: 1ch;
    color: var(--green-fg);
    animation: blink 1.2s steps(1) infinite;
  }
  @keyframes blink {
    50% {
      opacity: 0;
    }
  }

  .header-controls {
    display: flex;
    align-items: center;
    gap: 2ch;
  }
  .header-nav {
    display: flex;
    gap: 2ch;
  }
  .header-nav a {
    color: var(--foreground1);
    text-decoration: none;
  }
  .header-nav a:hover {
    color: var(--foreground0);
    text-decoration: underline;
  }
  /* icon-only theme toggle, like the app's */
  .theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 3ch;
  }
  .theme-toggle span {
    font-size: 1.15em;
    line-height: 1;
  }

  /* Anchors styled as WebTUI buttons: the osmium `a` rule (components layer)
     would otherwise paint them link-blue and underlined. Restore the button's
     own text colour and drop the underline (this page layer wins by order). */
  [is-~="button"] {
    text-decoration: none;
  }
  a[is-~="button"],
  a[is-~="button"]:hover {
    color: var(--button-secondary);
    text-decoration: none;
  }

  /* ---- hero ------------------------------------------------------------ */
  .hero {
    display: grid;
    grid-template-columns: 1.05fr 0.95fr;
    gap: clamp(2ch, 5vw, 6ch);
    align-items: center;
  }
  .hero__lede {
    color: var(--foreground1);
    font-size: 1.05rem;
    margin-bottom: 1.5lh;
    max-width: 46ch;
  }
  .hero__lede em {
    color: var(--foreground0);
    font-style: normal;
    border-bottom: 1px solid var(--green-fg-dim);
  }
  .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5ch;
    margin-bottom: 1.5lh;
  }
  .hero__meta {
    color: var(--foreground2);
    display: flex;
    align-items: center;
    gap: 1ch;
    flex-wrap: wrap;
  }
  .hero__meta .ok {
    color: var(--green-fg);
  }

  /* ---- flip card (signature) ------------------------------------------- */
  .flashcard {
    all: unset;
    display: block;
    width: 100%;
    max-width: 40ch;
    aspect-ratio: 3 / 2;
    cursor: pointer;
    perspective: 1400px;
  }
  .flashcard:focus-visible {
    outline: var(--focus-ring-width, 1px) solid var(--blue-fg);
    outline-offset: 4px;
  }
  .flashcard__inner {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    transition: transform 0.65s cubic-bezier(0.22, 0.61, 0.36, 1);
    transform-style: preserve-3d;
  }
  .flashcard.is-flipped .flashcard__inner {
    transform: rotateY(180deg);
  }
  .flashcard__face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    gap: 1lh;
    padding: 1lh 2ch;
    border: 1px solid var(--box-border-color);
    background-color: var(--background1);
  }
  .flashcard__face--back {
    transform: rotateY(180deg);
    border-color: var(--green-fg-dim);
  }
  .flashcard__caption {
    display: flex;
    justify-content: space-between;
    gap: 1ch;
    color: var(--foreground2);
    border-bottom: 1px solid var(--background2);
    padding-bottom: 0.25lh;
  }
  .flashcard__body {
    flex: 1;
    display: block;
    margin-block: auto;
    font-size: 1.05rem;
    line-height: 1.5;
  }
  .flashcard__hint {
    color: var(--green-fg);
    align-self: flex-end;
  }
  .flashcard__rate {
    display: flex;
    gap: 1ch;
    flex-wrap: wrap;
  }
  /* Rating chips coloured with accent tokens that exist in both osmium themes
     (the theme-specific badge variant names differ between light and dark). */
  .rate {
    border: 1px solid currentColor;
    padding: 0 1ch;
    line-height: 1lh;
  }
  .rate--again {
    color: var(--red-fg);
  }
  .rate--hard {
    color: var(--yellow-fg);
  }
  .rate--good {
    color: var(--blue-fg);
  }
  .rate--easy {
    color: var(--green-fg);
  }
  .flashcard__note {
    margin-top: 1lh;
    text-align: center;
    color: var(--foreground2);
  }

  /* ---- idea grid ------------------------------------------------------- */
  .section-head {
    max-width: 60ch;
    margin-bottom: 2lh;
  }
  .section-head p {
    color: var(--foreground1);
    margin-top: 0.5lh;
  }
  .idea-grid {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(19ch, 1fr));
    gap: 2ch;
  }
  .idea {
    border: 1px solid var(--box-border-color);
    background-color: var(--background1);
    padding: 1lh 2ch;
    transition: border-color 0.15s ease;
  }
  .idea:hover {
    border-color: var(--green-fg-dim);
  }
  .idea__glyph {
    color: var(--green-fg);
    font-size: 1.3rem;
  }
  .idea h3 {
    font-size: 1.05rem;
    margin-block: 0.5lh 0.25lh;
  }
  .idea p {
    color: var(--foreground1);
  }

  /* ---- interval ladder (signature #2) ---------------------------------- */
  .ladder {
    list-style: none;
    display: flex;
    gap: 1ch;
    align-items: flex-end;
    overflow-x: auto;
    padding-bottom: 0.5lh;
  }
  .ladder__step {
    flex: 1;
    min-width: 13ch;
    border: 1px solid var(--box-border-color);
    border-bottom: 2px solid var(--green-fg);
    background-color: var(--green-bg);
    /* each rung climbs higher than the last — the interval visibly grows */
    padding: calc(0.75lh + var(--i) * 1lh) 1.5ch 0.75lh;
    position: relative;
  }
  .ladder__step::after {
    content: "→";
    position: absolute;
    right: -1.1ch;
    bottom: 0.6lh;
    color: var(--green-fg);
    z-index: 1;
  }
  .ladder__step:last-child::after {
    content: "";
  }
  .ladder__when {
    display: block;
    color: var(--foreground0);
    font-weight: var(--font-weight-bold);
    font-size: 1.05rem;
  }
  .ladder__label {
    display: block;
    color: var(--foreground2);
    margin-top: 0.25lh;
  }
  .ladder__foot {
    color: var(--foreground1);
    margin-top: 1lh;
    max-width: 60ch;
  }

  /* ---- how it works: a terminal transcript ----------------------------- */
  .steps {
    list-style: none;
    border: 1px solid var(--box-border-color);
    background-color: var(--background1);
  }
  .step {
    display: grid;
    grid-template-columns: 5ch 1fr;
    gap: 2ch;
    padding: 1lh 2ch;
  }
  .step + .step {
    border-top: 1px solid var(--background2);
  }
  .step__num {
    color: var(--green-fg);
    font-weight: var(--font-weight-bold);
  }
  .step h3 {
    font-size: 1rem;
    margin-bottom: 0.25lh;
  }
  .step p {
    color: var(--foreground1);
  }

  /* ---- cta ------------------------------------------------------------- */
  .cta {
    text-align: center;
    padding: 2lh 2ch;
  }
  .cta p {
    color: var(--foreground1);
    margin-block: 0.5lh 1.5lh;
  }

  /* ---- footer / status bar (mirrors the app's bottom bar) -------------- */
  .app-statusbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: 3ch;
    row-gap: 0.25lh;
    padding: 0.5lh 2ch;
    border-top: 1px solid var(--background2);
    background-color: var(--background1);
    color: var(--foreground1);
  }
  .app-statusbar a {
    color: var(--foreground1);
    text-decoration: none;
  }
  .app-statusbar a:hover {
    color: var(--foreground0);
  }
  .app-statusbar .sep {
    color: var(--foreground2);
  }
  .app-statusbar .right {
    margin-left: auto;
    display: flex;
    gap: 3ch;
    flex-wrap: wrap;
  }

  /* ---- skip link ------------------------------------------------------- */
  .skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 100;
    background-color: var(--green-fg);
    color: var(--background0);
    padding: 0.25lh 1ch;
  }
  .skip-link:focus {
    left: 0;
  }

  /* ---- reveal-on-scroll ------------------------------------------------ */
  .reveal {
    opacity: 0;
    transform: translateY(1lh);
    transition:
      opacity 0.5s ease,
      transform 0.5s ease;
    transition-delay: calc(var(--reveal-delay, 0) * 80ms);
  }
  .reveal.is-in {
    opacity: 1;
    transform: none;
  }

  /* ---- responsive ------------------------------------------------------ */
  @media (max-width: 52rem) {
    .hero {
      grid-template-columns: 1fr;
    }
    .hero__card {
      order: -1;
    }
    .header-nav {
      display: none;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .reveal {
      opacity: 1;
      transform: none;
    }
    .flashcard__inner {
      transition: none;
    }
    .cursor {
      animation: none;
    }
  }
}
