/* Kalima Academy: mobile layout polish + gentle motion. CSS only, loaded after language.css.
   Every animation sits behind prefers-reduced-motion: no-preference. */

/* ---------- Mobile layout ---------- */
@media (max-width:620px){
  /* Bottom row of the header becomes one clear segmented bar with icon-over-label tabs */
  .navwrap{padding-bottom:10px}
  .navwrap nav,html[lang=en] .navwrap nav{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:3px;width:100%;
    padding:4px;border:1px solid var(--line);border-radius:14px;background:var(--soft)}
  .navwrap nav a,html[lang=en] .navwrap nav a{flex-direction:column;justify-content:center;gap:2px;min-height:50px;padding:5px 2px;
    border-radius:10px;font-size:12.5px;line-height:1.3;text-align:center;white-space:normal}
  .navwrap nav a .ico,html[lang=en] .navwrap nav a .ico{width:19px;height:19px}
  nav [aria-current]{background:var(--white);box-shadow:0 1px 2px #143f3714,0 3px 10px #143f3712}

  /* Section titles: the "all rooms" link no longer breaks over two lines */
  .sectionhead{flex-wrap:wrap;align-items:flex-end;row-gap:6px}
  .sectionhead>div{flex:1 1 220px;min-width:0}
  .sectionhead .link{white-space:nowrap}

  /* Home: the three rooms become a swipeable row that peeks at the next card */
  main:has(.theme-hero) .cards{display:grid;grid-auto-flow:column;grid-template-columns:none;grid-auto-columns:80%;gap:12px;
    overflow-x:auto;overscroll-behavior-x:contain;scroll-snap-type:x mandatory;scrollbar-width:none;
    margin-inline:-4vw;padding:4px 4vw 14px;scroll-padding-inline:4vw}
  main:has(.theme-hero) .cards::-webkit-scrollbar{display:none}
  main:has(.theme-hero) .cards>.card{scroll-snap-align:start;display:flex;flex-direction:column}
  main:has(.theme-hero) .cards .cardtext{flex:1}

  /* Room and lesson cards elsewhere: shorter pictures so a whole card fits on screen */
  .cover{aspect-ratio:2}
  .cardtext h3{font-size:22px}

  /* Pressing a card or button gives instant feedback on touch */
  :is(.card,.button,.outline,.choice,.sample-tabs button,nav a):active{transform:scale(.97)}
  :is(.card,.button,.outline,.choice,.sample-tabs button,nav a){transition:transform .15s ease,background-color .2s,box-shadow .2s;-webkit-tap-highlight-color:transparent}

  /* Footer: stacked and centred */
  footer{flex-direction:column;align-items:center;gap:6px;text-align:center}
}

/* ---------- Motion ---------- */
@media (prefers-reduced-motion:no-preference){
  @keyframes km-rise{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:none}}
  @keyframes km-fade{from{opacity:0}to{opacity:1}}
  @keyframes km-zoom{from{transform:scale(1.12)}to{transform:scale(1)}}
  @keyframes km-drift{0%,100%{transform:scale(1) translateY(0)}50%{transform:scale(1.035) translateY(-1.5%)}}
  @keyframes km-float{0%,100%{transform:translateY(0) rotate(0)}50%{transform:translateY(-3px) rotate(-8deg)}}
  @keyframes km-shine{from{background-position:120% 0}to{background-position:-20% 0}}

  /* Each page (route) eases in when it is drawn */
  main>*:not(.theme-hero){animation:km-rise .5s cubic-bezier(.2,.7,.2,1) both}
  main>*:nth-child(2){animation-delay:.08s}
  main>*:nth-child(3){animation-delay:.16s}
  main>*:nth-child(4){animation-delay:.24s}
  main>*:nth-child(n+5){animation-delay:.3s}

  /* Hero: the picture settles from a slow zoom, then breathes; the words arrive one after another */
  .theme-art img{animation:km-zoom 1.6s cubic-bezier(.2,.7,.2,1) both,km-drift 18s ease-in-out 1.6s infinite}
  .theme-copy>*{animation:km-rise .6s cubic-bezier(.2,.7,.2,1) both}
  .theme-copy>:nth-child(1){animation-delay:.12s}
  .theme-copy>:nth-child(2){animation-delay:.22s}
  .theme-copy>:nth-child(3){animation-delay:.32s}
  .theme-copy>:nth-child(4){animation-delay:.42s}
  .sample-caption{animation:km-rise .6s .7s both}

  /* The main call to action gets a soft light sweep once */
  .theme-copy .button{background-image:linear-gradient(100deg,#fff0 35%,#ffffff59 50%,#fff0 65%);background-size:250% 100%;
    background-repeat:no-repeat;animation:km-rise .6s .42s cubic-bezier(.2,.7,.2,1) both,km-shine 1.4s 1.3s ease-in-out both}

  /* Cards come in one by one */
  .cards>*{animation:km-rise .55s cubic-bezier(.2,.7,.2,1) both}
  .cards>:nth-child(1){animation-delay:.12s}
  .cards>:nth-child(2){animation-delay:.22s}
  .cards>:nth-child(3){animation-delay:.32s}
  .cards>:nth-child(n+4){animation-delay:.4s}
  .card img{transition:transform .5s ease}
  .card:hover img{transform:scale(1.04)}

  /* Below the fold, cards and panels reveal as they scroll into view (where the browser supports it) */
  @supports (animation-timeline:view()){
    main:not(:has(.theme-hero)) .cards>*,.prompt,.panel,.row,.post,.roomhead,.level-card{
      animation:km-rise linear both;animation-timeline:view();animation-range:entry 0% entry 55%;animation-delay:0s}
  }

  /* Small touches */
  .prompt .round .ico{animation:km-float 3.2s ease-in-out infinite}
  nav a{transition:background-color .25s,box-shadow .25s,transform .15s}
  .sample-tabs button{transition:background-color .25s,color .25s,transform .15s}
  .link .ico,.cardfoot>.ico:last-child{transition:transform .2s}
  :is(.link,.card):hover .ico:last-child{transform:translateX(-4px)}
  html[lang=en] :is(.link,.card):hover .ico:last-child{transform:scaleX(-1) translateX(-4px)}
  .choice.correct,.choice.wrong{animation:km-fade .35s both}
  dialog[open]{animation:km-rise .3s cubic-bezier(.2,.7,.2,1) both}
  dialog[open]::backdrop{animation:km-fade .3s both}
}

/* ---------- Placement test ---------- */
.placement-step{font-size:13px;font-weight:700;color:var(--green);letter-spacing:.02em}
.placement-intro ol{margin:14px 0;padding-inline-start:22px;display:grid;gap:10px}
.placement-intro li strong{display:block}
.placement-intro li span{color:var(--muted)}
.placement-self>h2,.placement-result h2{margin:4px 0 6px}
.placement-can{border-top:1px solid var(--line);padding-top:14px;margin-top:16px}
.placement-can legend{font-size:1.05rem;text-align:start;float:left;width:100%;margin-bottom:8px}
.placement-can legend+*{clear:both}
.placement-scale{grid-template-columns:repeat(3,minmax(0,1fr));margin:0}
.placement-scale .choice{text-align:start;justify-content:center;align-items:center;padding:9px 10px;font-size:14.5px;line-height:1.3}
.placement-scale .choice:has(:checked),.placement .choice:has(:checked){border-color:var(--green);box-shadow:inset 0 0 0 1px var(--green)}
.placement-progress{appearance:none;-webkit-appearance:none;display:block;width:100%;height:8px;margin:6px 0 14px;border:0;border-radius:8px;background:var(--line);overflow:hidden;color:var(--green)}
.placement-progress::-webkit-progress-bar{background:var(--line);border-radius:8px}
.placement-progress::-webkit-progress-value{background:var(--green);border-radius:8px;transition:width .35s ease}
.placement-progress::-moz-progress-bar{background:var(--green);border-radius:8px}
.placement-line{display:block}
.placement-line+.placement-line{margin-top:4px}
.placement-result h2 small,.placement-table small{font:600 .6em/1 "Segoe UI",Arial,sans-serif;color:var(--muted);margin-inline-start:.4em}
.placement-sessions{color:var(--ink);font-weight:600}
.placement-table-wrap{overflow-x:auto}
.placement-table{width:100%;border-collapse:collapse;margin:10px 0;font-size:15px}
.placement-table th,.placement-table td{padding:9px 8px;border-bottom:1px solid var(--line);text-align:start;white-space:nowrap}
.placement-table thead th{font-size:13px;color:var(--muted);font-weight:650;white-space:normal;vertical-align:bottom}
.placement-mark{display:inline-grid;place-items:center;width:22px;height:22px;border-radius:50%;font-size:13px;margin-inline-start:6px}
.placement-mark.is-pass{background:var(--green);color:var(--action-ink)}
.placement-mark.is-miss{background:var(--soft);color:var(--muted)}
@media (max-width:620px){
  .placement-scale{gap:6px}
  .placement-scale .choice{padding:10px 4px;font-size:14px;gap:.4em}
}
@media (prefers-reduced-motion:no-preference){
  .placement .panel{animation:km-rise .45s cubic-bezier(.2,.7,.2,1) both}
  .placement-result h2{animation:km-rise .6s .15s cubic-bezier(.2,.7,.2,1) both}
}
