/* ============================================================================
   PAGE: SOFTWARE DEVELOPMENT (software-development.html)
   Sections: typewriter + editor hero · 3D-tilt device cards · funnel ·
             draggable sticky-note board · wireframe phone · integration
             diagram · chat thread · terminal CTA
   ============================================================================ */

@layer sections {

  /* ===================== TYPEWRITER + EDITOR HERO ===================== */
  .dev-hero {
    position: relative;
    isolation: isolate;
    overflow-x: clip;
    min-height: min(100svh, 62rem);
    display: grid;
    align-items: center;
    padding-block: calc(var(--header-h) + 3rem) clamp(3rem, 6vw, 5rem);
  }
  .dev-hero__blob {
    position: absolute;
    z-index: -1;
    inline-size: clamp(20rem, 45vw, 42rem);
    aspect-ratio: 1;
    right: -8%;
    top: 12%;
    border-radius: var(--blob);
    background: var(--grad-k);
    filter: blur(70px);
    opacity: .4;
  }
  .dev-hero__grid { display: grid; gap: clamp(3rem, 6vw, 5rem); align-items: center; }
  @media (min-width: 1000px) { .dev-hero__grid { grid-template-columns: 1.1fr .9fr; } }

  .dev-hero__title {
    font-size: clamp(2.5rem, 1.4rem + 4.4vw, 5.4rem);
    font-weight: 700;
    letter-spacing: -.045em;
    line-height: .98;
    margin-bottom: 2rem;
    min-block-size: 2em;                 /* reserves space while typing → no layout shift */
  }
  .dev-hero__lead { font-size: var(--fs-lg); line-height: 1.4; letter-spacing: -.01em; margin-bottom: 1.1rem; max-inline-size: 46ch; }
  .dev-hero__text { color: var(--ink-soft); max-inline-size: 58ch; }

  /* Typewriter: real text is in the DOM; JS reveals it char by char */
  .tw-caret {
    display: inline-block;
    inline-size: .08em;
    block-size: .9em;
    margin-left: .06em;
    vertical-align: -.05em;
    background: var(--k-orange);
  }

  .editor {
    border-radius: 22px;
    overflow: hidden;
    rotate: 2deg;
    transition: rotate .6s var(--ease-spring);
  }
  .editor:hover { rotate: 0deg; }
  .editor__bar { display: flex; gap: .45rem; padding: .9rem 1.1rem; border-bottom: 1px solid var(--glass-edge); }
  .editor__bar span { inline-size: .75rem; aspect-ratio: 1; border-radius: 50%; background: var(--k-orange); }
  .editor__bar span:nth-child(2) { background: var(--k-amber); }
  .editor__bar span:nth-child(3) { background: var(--k-magenta); }
  .editor__code { display: grid; gap: .85rem; padding: clamp(1.25rem, 3vw, 2rem); }
  .editor__code i {
    display: block;
    block-size: .7rem;
    inline-size: var(--w);
    margin-left: calc(var(--x, 0) * 1.5rem);
    border-radius: 999px;
    background: var(--ink-mute);
    transform-origin: 0 50%;
  }
  .editor__code i.is-fire { background: var(--grad-fire); }
  .editor__code i.is-k { background: var(--grad-k); }

  /* ===================== DEVICE CARDS (3D tilt) ===================== */
  .platforms__head { display: grid; gap: 1.5rem; margin-bottom: clamp(2.5rem, 5vw, 4rem); }
  @media (min-width: 960px) { .platforms__head { grid-template-columns: 1fr 1fr; gap: 5rem; align-items: end; } }
  .platforms__title { font-size: var(--fs-xl); letter-spacing: -.035em; }
  .platforms__title em { color: var(--accent); font-weight: inherit; }
  .platforms__head p { color: var(--ink-soft); }
  .platforms__lead { font-weight: 600; margin-bottom: 1.25rem; }
  .platforms__foot { margin-top: clamp(2rem, 4vw, 3rem); color: var(--ink-soft); max-inline-size: 70ch; }

  .devices { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); perspective: 900px; }
  .device {
    --rx: 0deg;
    --ry: 0deg;
    display: grid;
    gap: 1.5rem;
    padding: 1.5rem;
    border-radius: var(--radius);
    background: var(--surface-solid);
    border: 1px solid var(--ink-mute);
    box-shadow: var(--shadow-soft);
    transform: rotateX(var(--rx)) rotateY(var(--ry));
    transform-style: preserve-3d;
    transition: transform .25s ease-out;
  }
  .device p { font-weight: 500; line-height: 1.35; }
  .device__art {
    position: relative;
    block-size: 9rem;
    border-radius: 18px;
    background: var(--bg-alt);
    display: grid;
    place-items: center;
    transform: translateZ(30px);           /* art floats above the card in 3D */
  }
  /* CSS-drawn devices */
  .device__art--desktop span { block-size: 48%; aspect-ratio: 16 / 10; border: 3px solid var(--line); border-radius: 8px; background: var(--grad-k); position: relative; }
  .device__art--desktop span::after { content: ""; position: absolute; left: 35%; right: 35%; top: 100%; block-size: 14px; border: 3px solid var(--line); border-top: 0; }
  .device__art--mobile span { block-size: 68%; aspect-ratio: 9 / 18; border: 3px solid var(--line); border-radius: 12px; background: var(--grad-fire); }
  .device__art--cloud span { block-size: 38%; aspect-ratio: 2 / 1; background: var(--grad-brand); border-radius: 999px; position: relative; border: 3px solid var(--line); }
  .device__art--cloud span::before { content: ""; position: absolute; inline-size: 50%; aspect-ratio: 1; border-radius: 50%; left: 18%; bottom: 40%; background: inherit; border: 3px solid var(--line); border-bottom-color: transparent; border-right-color: transparent; rotate: 20deg; }
  .device__art--flow { grid-auto-flow: column; gap: .8rem; }
  .device__art--flow span { inline-size: 2.4rem; aspect-ratio: 1; border-radius: 30% 70% 60% 40% / 50% 40% 60% 50%; border: 3px solid var(--line); background: var(--k-amber); }
  .device__art--flow span:nth-child(2) { background: var(--k-magenta); }
  .device__art--flow span:nth-child(3) { background: var(--k-indigo); }

  /* ===================== FUNNEL ===================== */
  .problem__grid { display: grid; gap: 3rem; align-items: center; }
  @media (min-width: 960px) { .problem__grid { grid-template-columns: 1.1fr .9fr; gap: 6rem; } }
  .problem__copy { display: grid; gap: 1.1rem; color: var(--ink-soft); }
  .problem__title { color: var(--ink); font-size: var(--fs-xl); letter-spacing: -.035em; margin-bottom: .75rem; }

  .funnel { position: relative; display: grid; justify-items: center; gap: .9rem; padding-block: 2rem 5rem; }
  .funnel__band { display: block; block-size: 3.4rem; border-radius: 999px; border: 2px solid var(--line); }
  .funnel__band:nth-of-type(1) { inline-size: 100%; background: color-mix(in oklab, var(--k-amber) 70%, transparent); }
  .funnel__band:nth-of-type(2) { inline-size: 66%; background: var(--k-orange); }
  .funnel__band:nth-of-type(3) { inline-size: 34%; background: var(--k-magenta); }
  .funnel__drop { position: absolute; top: 0; inline-size: .9rem; aspect-ratio: 1; border-radius: 50%; background: var(--k-indigo); border: 2px solid var(--bg); opacity: 0; }
  .funnel__drop:nth-of-type(4) { left: 20%; }
  .funnel__drop:nth-of-type(5) { left: 50%; }
  .funnel__drop:nth-of-type(6) { left: 78%; }
  .funnel__out { position: absolute; bottom: 0; inline-size: 3.4rem; aspect-ratio: 1; border-radius: var(--blob); background: var(--grad-k); border: 2px solid var(--line); box-shadow: 6px 6px 0 var(--k-amber); }

  /* ===================== STICKY-NOTE BOARD ===================== */
  .board-sec__title { font-size: var(--fs-xl); letter-spacing: -.035em; margin-bottom: clamp(2rem, 4vw, 3rem); }
  .board-sec__title em { color: var(--accent); font-weight: inherit; }
  .board {
    position: relative;
    display: grid;
    gap: 1.5rem;
    padding: clamp(1.25rem, 4vw, 3rem);
    border-radius: var(--radius);
    border: 2px solid var(--line);
    /* dotted cork-board */
    background: radial-gradient(var(--ink-mute) 1.4px, transparent 1.6px) 0 0 / 22px 22px, var(--bg-alt);
  }
  @media (min-width: 900px) { .board { grid-template-columns: repeat(3, 1fr); gap: 2rem; padding-block: 4rem; } }
  .note {
    position: relative;
    padding: 2.4rem 1.6rem 1.8rem;
    border-radius: 6px 6px 22px 6px;
    box-shadow: 0 18px 30px -18px rgb(20 8 50 / .45);
    font-size: var(--fs-sm);
    line-height: 1.6;
    rotate: var(--tilt, -2deg);
    touch-action: pan-y;
    transition: rotate .4s var(--ease-spring), box-shadow .3s;
  }
  .note:nth-child(2) { --tilt: 2.5deg; translate: 0 1.5rem; }
  .note:nth-child(3) { --tilt: -1deg; }
  .note--amber { background: #ffd27a; color: var(--k-indigo); }
  .note--paper { background: var(--surface-solid); color: var(--ink); border: 1px solid var(--ink-mute); }
  .note--plum  { background: var(--k-plum); color: #f5eee4; }
  .note__pin {
    position: absolute;
    top: .8rem;
    left: 50%;
    translate: -50% 0;
    inline-size: 1.1rem;
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--k-orange);
    border: 2px solid var(--k-indigo);
    box-shadow: 0 3px 0 rgb(0 0 0 / .25);
  }
  /* Drag states (set by JS) */
  .board.is-draggable .note { cursor: grab; }
  .note.is-dragging { cursor: grabbing; rotate: 0deg; z-index: 5; box-shadow: 0 30px 50px -20px rgb(20 8 50 / .55); transition: none; }

  /* ===================== WIREFRAME PHONE ===================== */
  .users__grid { display: grid; gap: 3rem; align-items: center; }
  @media (min-width: 960px) { .users__grid { grid-template-columns: 1.2fr .8fr; gap: 6rem; } }
  .users__copy { display: grid; gap: 1.1rem; color: var(--ink-soft); }
  .users__title { color: var(--ink); font-size: var(--fs-xl); letter-spacing: -.035em; margin-bottom: .75rem; }
  .users__title em { color: var(--accent); font-weight: inherit; }

  .wire-phone {
    position: relative;
    justify-self: center;
    inline-size: min(70vw, 17rem);
    aspect-ratio: 9 / 18.5;
    padding: .9rem;
    border-radius: 2.6rem;
    background: var(--k-indigo);
    border: 3px solid var(--line);
    box-shadow: 14px 14px 0 var(--k-orange);
  }
  .wire-phone__screen {
    block-size: 100%;
    display: flex;
    flex-direction: column;
    gap: .75rem;
    padding: 1.4rem 1rem;
    border-radius: 1.9rem;
    background: var(--bg);
  }
  .sk { display: block; border-radius: 10px; background: var(--ink-mute); }
  .sk--head { block-size: 1.4rem; inline-size: 55%; background: var(--grad-k); }
  .sk--line { block-size: .6rem; }
  .sk--short { inline-size: 60%; }
  .sk--card { block-size: 4.5rem; border-radius: 16px; }
  .sk--btn { margin-top: auto; block-size: 2.4rem; border-radius: 999px; background: var(--grad-fire); }
  .wire-phone__cursor { position: absolute; inline-size: 2rem; fill: var(--k-amber); stroke: var(--k-indigo); stroke-width: 1.6; left: 60%; top: 70%; }

  /* ===================== INTEGRATION DIAGRAM ===================== */
  .env__grid { display: grid; gap: 3rem; align-items: center; }
  @media (min-width: 960px) { .env__grid { grid-template-columns: .9fr 1.1fr; gap: 6rem; } }
  .env__copy { display: grid; gap: 1.1rem; color: var(--ink-soft); }
  .env__title { color: var(--ink); font-size: var(--fs-xl); letter-spacing: -.035em; margin-bottom: .75rem; }
  .nodes { justify-self: center; inline-size: min(100%, 28rem); }
  .nodes__links path { stroke: var(--ink-mute); stroke-width: 3; stroke-dasharray: 2 8; stroke-linecap: round; fill: none; }
  .nodes__packets circle { fill: var(--k-orange); }
  .nodes__sat rect { fill: var(--surface-solid); stroke: var(--line); stroke-width: 2.5; }
  .nodes__core { fill: var(--k-magenta); stroke: var(--line); stroke-width: 3; }

  /* ===================== CHAT THREAD ===================== */
  .convo__grid { display: grid; gap: 2.5rem; }
  @media (min-width: 960px) { .convo__grid { grid-template-columns: 1fr 1fr; gap: 4rem; align-items: start; } }
  .convo__title { font-size: var(--fs-xl); letter-spacing: -.04em; line-height: 1; }   /* two lines on desktop */
  .convo__title em { color: var(--accent); font-weight: inherit; }
  .convo__thread { display: grid; gap: 1.25rem; }
  .bubble {
    position: relative;
    max-inline-size: 36rem;
    padding: 1.3rem 1.5rem;
    border-radius: 26px;
    line-height: 1.55;
  }
  .bubble--in  { justify-self: start; background: var(--surface-solid); border: 1px solid var(--ink-mute); border-bottom-left-radius: 6px; }
  .bubble--out { justify-self: end; background: var(--grad-k); color: #f5eee4; border-bottom-right-radius: 6px; }
  /* "typing…" dots shown before each bubble's text fades in */
  .bubble::before {
    content: "";
    position: absolute;
    left: 1.5rem;
    top: 50%;
    inline-size: 2.4rem;
    block-size: .6rem;
    translate: 0 -50%;
    background: radial-gradient(circle, currentColor 45%, transparent 50%) 0 50% / .8rem .6rem repeat-x;
    opacity: 0;
  }

  /* ===================== TERMINAL CTA ===================== */
  .terminal {
    border-radius: 20px;
    overflow: hidden;
    background: #120b25;
    color: #e8deef;
    border: 2px solid var(--line);
    box-shadow: 12px 12px 0 var(--k-magenta);
  }
  .terminal__bar { display: flex; gap: .45rem; padding: .85rem 1.1rem; background: #1d1438; }
  .terminal__bar span { inline-size: .75rem; aspect-ratio: 1; border-radius: 50%; background: #3a2c63; }
  .terminal__bar span:first-child { background: var(--k-orange); }
  .terminal__body { display: grid; gap: 1.1rem; justify-items: start; padding: clamp(1.75rem, 5vw, 4rem); }
  .terminal__title {
    font-size: clamp(1.8rem, 1.1rem + 2.8vw, 3.6rem);
    letter-spacing: -.04em;
    line-height: 1.02;
    color: #f5eee4;
    margin-bottom: .5rem;
    max-inline-size: 22ch;
  }
  .terminal__prompt { color: var(--k-amber); font-weight: 400; margin-right: .2em; }
  .terminal__caret { display: inline-block; inline-size: .5em; block-size: .9em; margin-left: .1em; vertical-align: -.08em; background: var(--k-amber); }
  .terminal__body p { max-inline-size: 64ch; color: #c8bdd9; }
  .terminal__body strong { color: #f5eee4; }
  .btn--term {
    margin-top: 1rem;
    border-radius: 10px;
    color: #120b25;
    background: var(--k-amber);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: var(--fs-sm);
  }
  .btn--term:hover { background: var(--k-orange); }
}

@layer motion {
  @keyframes caret     { 50% { opacity: 0; } }
  @keyframes code-in   { from { scale: 0 1; } to { scale: 1 1; } }
  @keyframes drop      { 0% { opacity: 0; translate: 0 0; } 15% { opacity: 1; } 80% { opacity: 1; translate: 0 13rem; } 100% { opacity: 0; translate: 0 14rem; } }
  @keyframes tap-path  {
    0%, 100% { left: 60%; top: 72%; }
    25% { left: 30%; top: 32%; }
    30% { scale: .8; }
    35% { scale: 1; }
    55% { left: 70%; top: 48%; }
    60% { scale: .8; }
    65% { scale: 1; }
    85% { left: 50%; top: 86%; }
    90% { scale: .8; }
  }
  @keyframes typing    { 0%, 100% { opacity: .9; } 50% { opacity: .3; } }
  @keyframes bubble-text { from { color: transparent; } }

  @media (prefers-reduced-motion: no-preference) {
    .tw-caret, .terminal__caret { animation: caret 1s steps(1) infinite; }
    .dev-hero__blob { animation: morph 16s ease-in-out infinite alternate; }

    /* Editor lines "write" in sequence, then loop */
    .editor__code i { animation: code-in .7s var(--ease-out) both; animation-delay: calc(var(--t) * 180ms + 400ms); }

    .funnel__drop { animation: drop 2.8s ease-in infinite; }
    .funnel__drop:nth-of-type(5) { animation-delay: .9s; }
    .funnel__drop:nth-of-type(6) { animation-delay: 1.8s; }
    .funnel__out { animation: morph 8s ease-in-out infinite alternate; }

    .wire-phone__cursor { animation: tap-path 7s ease-in-out infinite; }

    /* Chat bubbles: dots blink, then text appears (only once revealed) */
    .is-ready .bubble[data-reveal] { color: transparent; }
    .is-ready .bubble--out[data-reveal] { color: transparent; }
    .is-ready .bubble[data-reveal]::before { opacity: 1; color: var(--ink-soft); animation: typing .6s ease-in-out infinite; }
    .is-ready .bubble--out[data-reveal]::before { color: #f5eee4; }
    .is-ready .bubble.is-in { color: var(--ink); transition: opacity .9s var(--ease-out), translate 1.1s var(--ease-out), filter .9s var(--ease-out), color .5s .9s; }
    .is-ready .bubble--out.is-in { color: #f5eee4; }
    /* Stop the blink (an animation would override opacity), then fade the dots out */
    .is-ready .bubble.is-in::before { animation: none; opacity: 0; transition: opacity .2s .85s; }
  }
}
