/* Phone layout (pilot feedback: text squeezed and too much scrolling). Loaded last so it wins over the desktop rules. */
.m-ch-toggle,.m-fold-btn,.m-only,.m-subbar{display:none}
@media (max-width:640px){
  /* header: one compact row + the feature row; it stays on screen, and anything that sticks or jumps below it uses its height */
  .top{padding:6px 10px;gap:6px;transition:box-shadow .3s}
  .gate-card{top:calc(var(--top-h,110px) + 8px)}
  .hx-sticky{top:calc(var(--top-h,110px) + 8px)}
  .brand{font-size:0;gap:0}
  .brand .logo-face{width:34px;height:34px}
  /* the tabs (Study, Progress, Ask teacher, Profile) and Sign out stay on one line and slide sideways when they do not fit */
  .top-actions{gap:6px;flex:1 1 auto;min-width:0;justify-content:flex-start;overflow-x:auto;scrollbar-width:none;-webkit-overflow-scrolling:touch}
  .top-actions::-webkit-scrollbar{display:none}
  .top-actions>*{flex:0 0 auto;white-space:nowrap}
  .top-actions>:first-child{margin-left:auto} /* right-aligned when there is room; scrollable from the start when there is not */
  .top-actions .tab,#auth{padding:7px 11px;font-size:.88rem}
  #theme{padding:7px 9px}
  .subnav{padding-top:4px}
  .subnav button{padding:5px 10px;font-size:.82rem}

  /* welcome banner: text only */
  .hero{padding:16px;margin:8px 8px 0;border-radius:18px;gap:0}
  .hero .mascot-img,.hero-art{display:none}
  .hero h1{font-size:1.45rem;line-height:1.15;margin:6px 0}
  .hero p{font-size:.9rem;margin:0}

  /* wider reading column: less padding around boxes inside boxes */
  .layout{padding:0 8px;margin:10px auto;gap:10px}
  .side,.card{padding:14px 12px;border-radius:16px}
  .banner{padding:14px;gap:12px;border-radius:16px;min-height:118px}
  .banner .ico{width:42px;height:42px}
  .banner h2{font-size:1.3rem}
  .card p.lead{font-size:.95rem;line-height:1.55}
  .omap{gap:8px}
  .omap>li{padding:10px 11px;border-radius:12px;line-height:1.5}
  .omap-sub{padding-left:9px;gap:5px}
  .omap-sub li{font-size:.9rem}
  /* key concepts: a side-swipe row of cards instead of a long stack */
  .concepts{display:flex!important;overflow-x:auto;gap:10px;margin:0 -12px;padding:2px 12px 10px;scroll-snap-type:x mandatory;scroll-padding:0 12px;-webkit-overflow-scrolling:touch;scrollbar-width:none}
  .concepts::-webkit-scrollbar{display:none}
  .concepts>.concept{flex:0 0 84%;padding:12px;scroll-snap-align:start}
  .m-swipe{display:block;margin:-2px 0 8px;font-size:.8rem;font-weight:600;color:var(--muted)}
  .m-dots{display:flex;justify-content:center;gap:5px;margin:-2px 0 10px}
  .m-dots i{width:6px;height:6px;border-radius:50%;background:color-mix(in srgb,var(--sc,var(--brand)) 25%,var(--line));transition:width .2s,background .2s}
  .m-dots i.on{width:16px;border-radius:3px;background:var(--sc,var(--brand))}
  .card .row{gap:8px}

  /* subjects: every subject as a tile, two to a row; tapping one opens its chapter list (mobile.js) */
  .subjects{display:grid!important;grid-template-columns:1fr 1fr;gap:10px;padding:2px 0 4px}
  .subjects .tile{display:flex;flex-direction:column;align-items:flex-start;justify-content:flex-start;gap:8px;min-height:112px;padding:14px 12px 12px;border-radius:16px;text-align:left;border-top:4px solid var(--sc)}
  .subjects .tile:last-child:nth-child(odd){grid-column:1/-1;min-height:0}
  .subjects .tile .ico{width:40px;height:40px;margin:0;border-radius:12px}
  .subjects .tile .ico svg{width:22px;height:22px}
  .subjects .tile b{white-space:normal;font-size:.95rem;line-height:1.25;margin:0}
  .subjects .tile small{display:block;margin-top:auto;font-size:.78rem}
  body.m-pick .subjects .tile.on{box-shadow:none;background:var(--card);border-color:var(--line);border-top-color:var(--sc)}
  body.m-pick .subjects .tile.on::after{display:none}

  /* subject tiles -> chapter list -> chapter: only the step in use shows */
  body.m-pick #main,body.m-list #main{display:none}
  body.m-pick .side #chapters,body.m-pick .side label[for="search"],body.m-pick .side #search,body.m-pick .side .m-ch-toggle{display:none!important}
  body.m-list .side>.seg,body.m-chap .side>.seg,body.m-list .side>h3.cap,body.m-chap .side>h3.cap,body.m-list #subjects,body.m-chap #subjects{display:none!important}
  body.m-list .side .m-ch-toggle{display:none!important}
  .m-subbar{display:none}
  body.m-list .m-subbar,body.m-chap .m-subbar{display:flex;align-items:center;gap:10px;margin:0 0 12px}
  .m-back{flex:none;padding:8px 12px;font-size:.86rem;font-weight:700;border-radius:999px}
  .m-subname{display:flex;align-items:center;gap:8px;min-width:0}
  .m-subname .ico{flex:none;display:grid;place-items:center;width:32px;height:32px;border-radius:10px;color:var(--sc);background:color-mix(in srgb,var(--sc) 14%,var(--card))}
  .m-subname .ico svg{width:18px;height:18px}
  .m-subname b{display:block;font-size:.95rem;line-height:1.2;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .m-subname small{display:block;font-size:.75rem;color:var(--muted)}

  /* chapter list: only the open chapter shows until "All chapters" is tapped */
  .m-ch-toggle{display:block;width:100%;margin-top:6px;padding:8px 12px;font-size:.88rem;font-weight:700}
  .side:not(.m-chopen) #chapters>li[data-i]:not(.active),.side:not(.m-chopen) #chapters>li.mt-part,.side:not(.m-chopen) #search{display:none}

  /* chapter map: the extra points under a topic fold away; tap to open */
  .m-fold-btn{display:flex;width:max-content;align-items:center;gap:4px;margin-top:6px;padding:3px 10px;font-size:.78rem;font-weight:700;border-radius:999px;color:var(--sc,var(--brand));background:color-mix(in srgb,var(--sc,var(--brand)) 10%,var(--card));border:1px solid color-mix(in srgb,var(--sc,var(--brand)) 30%,var(--line))}
  /* chapter map as tap-to-open topics: only the titles show until a topic is tapped */
  .m-acc-all{display:block;margin:-4px 0 8px auto;padding:4px 12px;font-size:.8rem;font-weight:700;border-radius:999px}
  .omap>li.m-acc{padding:0;overflow:hidden}
  .omap>li.m-acc>b{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:11px 12px;cursor:pointer;-webkit-tap-highlight-color:transparent}
  .omap>li.m-acc>b::after{content:"";flex:none;width:7px;height:7px;margin:-3px 4px 0 0;border-right:2px solid currentColor;border-bottom:2px solid currentColor;transform:rotate(45deg);transition:transform .2s}
  .omap>li.m-acc.m-open>b::after{transform:rotate(-135deg);margin-top:3px}
  .omap>li.m-acc:not(.m-open)>:not(b){display:none}
  .omap>li.m-acc.m-open>span{display:block;padding:0 12px 10px}
  .omap>li.m-acc.m-open>.omap-sub{margin:0 12px 12px}
  .hx-w.m-fold:not(.m-open)>.hx-model.hx-open{display:none}
  .hx-w>.m-fold-btn{margin:8px 0 0}

  /* pop-ups: almost full width, less padding */
  dialog{width:calc(100% - 12px)!important;max-width:none!important;padding:16px 14px!important;max-height:calc(100dvh - 24px)}
  #conceptDlg h2{font-size:1.25rem;line-height:1.25}
  .c-head{gap:8px}

  /* tables in pop-ups and pages: each row becomes a small card instead of a squeezed table */
  table.ctbl,table.ctbl tbody,table.ctbl tr,table.ctbl td{display:block;width:100%}
  table.ctbl thead{display:none}
  table.ctbl tr{margin:0 0 8px;padding:8px 10px;border:1px solid var(--line);border-radius:12px;background:var(--card)}
  table.ctbl td{min-width:0;padding:2px 0;border:0;background:none!important}
  table.ctbl td:first-child{font-weight:700;color:var(--sc,var(--brand));padding-bottom:4px}
  table.ctbl td[data-label]:not(:first-child)::before{content:attr(data-label) ": ";font-weight:600;color:var(--muted)}
  .ctbl-wrap,div:has(>table.ctbl){overflow:visible;border:0;background:none}

  /* Ask StudyRaah button: a slim pill with the mascot and its name, so students can tell what it is */
  body .sbq-fab.sbq-fab{width:auto;height:44px;padding:0 13px 0 4px;gap:7px;justify-content:flex-start;border-radius:999px;right:12px;bottom:12px;overflow:visible;font-size:.8rem}
  body .sbq-fab.sbq-fab .sbq-fab-txt{display:inline;white-space:nowrap}
  body .sbq-fab.sbq-fab .mood-fab{width:36px;height:36px;margin:0}
  body.sb-guest .sbq-fab::after{position:absolute;top:-6px;right:-8px;margin:0;padding:1px 5px;font-size:.58rem}
  footer{padding-bottom:70px}

  /* anything scrolled into view is not hidden under the header */
  #main,.card,.quiz,h2,h3{scroll-margin-top:calc(var(--top-h,110px) + 12px)}
}
@media (max-width:380px){
  .top-actions .tab,#auth{padding:6px 9px;font-size:.84rem}
}

/* Phones and tablets: the same look without the effects that make weak phones repaint all the time. The hero colours stop drifting
   and its two soft lights stay still (a plain soft gradient, no blur), the page background scrolls with the page, and full-screen blur is off.
   Computers keep every effect. */
@media (max-width:820px),(hover:none){
  body{background-attachment:scroll}
  .hero{animation:none;background-position:0% 50%}
  .hero::before,.hero::after{animation:none;filter:none}
  .hero::before{background:radial-gradient(closest-side,rgba(255,182,39,.28),transparent)}
  .hero::after{background:radial-gradient(closest-side,rgba(60,207,194,.35),transparent)}
  .banner .ico,dialog::backdrop,.welcome{-webkit-backdrop-filter:none;backdrop-filter:none}
}
