/* 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{display:none}
@media (max-width:640px){
  /* header: one compact row + the feature row; it slides away while reading and comes back when scrolling up */
  .top{padding:6px 10px;gap:6px;transition:transform .25s ease,box-shadow .3s}
  .top.m-hide{transform:translateY(-105%)}
  .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: one scrolling row of small chips instead of big tiles */
  .subjects{display:flex!important;grid-template-columns:none;overflow-x:auto;gap:8px;padding:2px 2px 6px;scroll-snap-type:x proximity;-webkit-overflow-scrolling:touch;scrollbar-width:none}
  .subjects::-webkit-scrollbar{display:none}
  .subjects .tile{flex:0 0 auto;display:flex;align-items:center;gap:8px;padding:7px 12px 7px 7px;min-height:0;height:auto;border-radius:999px;scroll-snap-align:start;text-align:left}
  .subjects .tile .ico{width:28px;height:28px;margin:0;border-radius:50%}
  .subjects .tile .ico svg{width:16px;height:16px}
  .subjects .tile b{white-space:nowrap;font-size:.86rem;margin:0}
  .subjects .tile small,.subjects .tile::after{display:none}

  /* 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 small round button so it does not cover text */
  .sbq-fab{padding:0;width:48px;height:48px;justify-content:center;border-radius:50%;right:12px;bottom:12px}
  .sbq-fab .sbq-fab-txt{display:none}
  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:12px}
}
@media (max-width:380px){
  .top-actions .tab,#auth{padding:6px 9px;font-size:.84rem}
}
