/* Cross-page responsive polish — keeps Arabic glyphs and controls inside every viewport. */
:root{--safe-inline:max(18px,env(safe-area-inset-left,0px),env(safe-area-inset-right,0px))}
html,body{max-width:100%}
img,video,svg,canvas{max-width:100%}
h1,h2,h3,.brand strong,.games-brand strong,.event-brand strong,.lab-brand strong,.portal-brand strong{overflow-wrap:anywhere}

/* The school remains immersive without consuming the entire first desktop fold. */
@media(min-width:761px){
  .classroom-site .school-stage{height:clamp(390px,min(64svh,50vw),700px)}
  .classroom-site .classroom-library{padding-block:72px}
  .lesson-library{position:static}
  #lesson-list{max-height:none;overflow:visible}
}

@media(max-width:760px){
  body{overflow-x:clip}
  .site-header,.games-mast,.mast,.portal-header{padding-inline:var(--safe-inline)}

  /* Shared Arabic brand treatment. */
  :is(.brand,.games-brand,.event-brand,.lab-brand,.portal-brand,.story-brand){min-width:0;max-width:100%}
  :is(.brand,.games-brand,.event-brand,.lab-brand,.portal-brand,.story-brand) strong,
  :is(.brand,.games-brand,.event-brand,.lab-brand,.portal-brand,.story-brand)>span:last-child{
    min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis
  }

  /* Home and school. */
  .classroom-site .site-header{width:100%;gap:7px}
  .classroom-site .brand{max-width:calc(100% - 98px)}
  .classroom-site .brand strong{font-size:.84rem}
  .classroom-site .school-stage{height:clamp(300px,min(58svh,78vw),480px)}
  .classroom-site .content-section{padding:48px var(--safe-inline)}
  .classroom-site :is(.section-heading h2,.learning-spaces h2,.about-copy h2){
    max-width:100%;padding-inline:.1em;font-size:clamp(2.05rem,10.8vw,2.75rem);line-height:1.25
  }
  .classroom-site .library-heading{align-items:start;gap:16px}
  .classroom-site .classroom-outline{min-height:44px;display:inline-flex;align-items:center}

  /* Lesson laboratory. */
  .mast{display:grid;grid-template-columns:minmax(0,1fr) auto;min-height:66px;gap:10px;flex-wrap:nowrap}
  .mast .lab-brand{max-width:100%}
  .mast .lab-brand strong{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  #projector{margin:0;min-height:44px;white-space:nowrap}
  .lab-layout{width:100%;padding:18px var(--safe-inline) 38px}
  .lesson-heading h1{max-width:100%;padding-inline:.1em;font-size:clamp(2.15rem,11.5vw,2.85rem);line-height:1.35}
  .lesson-library{width:100%;max-width:100%}
  .library-filters :is(select,input),#library-details summary,.lesson-choice{min-height:46px}
  .discovery-meter{width:100%;overflow:visible}
  .discovery-meter ol{grid-template-columns:repeat(5,minmax(0,1fr))}
  .discovery-meter li{font-size:.7rem;min-width:0;overflow-wrap:anywhere}
  .live-tools button,.word-lab-actions button{min-height:46px}
  .lab-footer{padding-inline:var(--safe-inline)}

  /* Games: keep profile access visible and make the hero fit Arabic headings. */
  .games-mast{height:auto;min-height:68px;gap:10px}
  .games-brand{max-width:calc(100% - 128px)}
  .games-mast nav{display:flex;align-items:center;gap:.6rem;flex:none}
  .games-mast nav a{display:none!important}
  .games-mast nav a:first-child,.games-mast nav #game-profile{display:inline-flex!important;min-height:44px;align-items:center}
  .games-mast nav a:first-child{display:none!important}
  .games-mast nav #game-profile{max-width:112px;padding:.45rem .6rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .games-hero{width:100%;padding:3rem var(--safe-inline);overflow:hidden}
  .games-hero .hero-copy{width:100%;padding-inline:.1em}
  .hero-copy h1{max-width:100%;font-size:clamp(2.45rem,12.5vw,3.15rem);line-height:1.08;letter-spacing:0}
  .hero-intro{font-size:1rem;line-height:1.85}
  .game-account,.game-setup,.game-deck{width:100%;max-width:100%;padding-inline:var(--safe-inline)}
  .game-account{margin-inline:0}
  .game-setup h2{font-size:clamp(1.9rem,9vw,2.5rem);line-height:1.25;padding-inline:.08em}
  .game-filters label{font-size:.875rem}
  .game-filters select{min-height:48px;font-size:1rem}
  .game-account a,.game-card button,.arena-action{min-height:46px}
  .games-note{margin-inline:var(--safe-inline);max-width:calc(100% - 2 * var(--safe-inline))}

  /* Events and competitions. */
  .event-header-inner,.event-main,.event-footer>div{width:100%;padding-inline:var(--safe-inline)}
  .event-header-inner{gap:10px}
  .event-brand{max-width:100%}
  .event-brand strong{font-size:.92rem}
  .event-header nav{min-width:0;gap:clamp(.65rem,4vw,1rem);font-size:.88rem}
  .occasion-hero{width:100%;max-width:100%;margin-inline:0;padding:1.45rem var(--safe-inline) 2.1rem}
  .occasion-hero-copy{width:100%;padding-inline:.08em}
  .occasion-hero h1{width:100%;max-width:100%;padding-inline:.06em;font-size:clamp(2.2rem,11.5vw,3rem);line-height:1.12;letter-spacing:0;text-wrap:balance}
  .occasion-hero h1 em{margin-inline-start:.25rem}
  .occasion-hero-copy>p:not(.occasion-eyebrow){font-size:1rem;line-height:1.8}
  .occasion-stats{grid-template-columns:repeat(3,minmax(0,1fr));gap:.4rem}
  .occasion-stats span{min-width:0;padding:.55rem .25rem}
  .occasion-orbit{width:min(54vw,210px)}
  .occasion-section-title h2{padding-inline:.08em;line-height:1.25}
  .occasion-filters button{min-height:44px}

  /* Public library. */
  .portal-header{height:auto;min-height:72px;position:relative;flex-wrap:wrap;gap:10px}
  .portal-brand{max-width:100%}
  .portal-brand strong{font-size:1.05rem;line-height:1.45}
  .portal-header .header-links{margin-inline-start:auto;gap:14px;font-size:.875rem}
  .portal-header .header-links a{min-height:44px;display:inline-flex;align-items:center}
  .library-page{width:100%;max-width:100%;padding:28px var(--safe-inline) 52px}
  .library-page .page-heading h1{max-width:100%;padding-inline:.1em;font-size:clamp(2.15rem,11vw,2.75rem);line-height:1.3}
  .studio-toolbar{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));align-items:end;width:100%}
  .studio-toolbar label{width:100%;min-width:0;font-size:.875rem}
  .studio-toolbar label:last-child{grid-column:1/-1}
  .studio-toolbar :is(input,select){min-height:48px;font-size:1rem}
  .library-kind{width:100%;min-width:0}
  .library-kind>header{flex-wrap:wrap;align-items:center}
  .studio-resources{grid-template-columns:repeat(2,minmax(0,1fr))}
  .studio-resource{min-width:0;width:100%;padding:14px;font-size:1rem}
  .studio-resource :is(h3,p,small){max-width:100%;overflow-wrap:anywhere}
  .studio-resource .button,.button.secondary.small{min-height:44px;padding:.65rem .8rem;font-size:.875rem}

  /* Teacher login: compact mobile flow without the large empty middle. */
  .login-layout{width:100%;overflow-x:clip}
  .login-side{width:100%;min-height:auto;padding:18px var(--safe-inline) 28px}
  .login-nav{width:100%;min-width:0;gap:8px;font-size:.875rem}
  .login-card{width:100%;max-width:100%;margin:32px auto;padding:20px 0 24px}
  .login-card h2{max-width:100%;padding-inline:.08em;font-size:clamp(2rem,10.5vw,2.45rem);line-height:1.35}
  .login-intro{font-size:1rem}
  .login-side :is(input,.primary-action){min-height:50px}
  .login-side label{font-size:.875rem}
  .login-footer{margin-top:24px;font-size:.75rem}
  .teacher-story{width:100%;padding-inline:var(--safe-inline)}
  .teacher-story .story-copy h1{padding-inline:.08em;font-size:clamp(2.15rem,11vw,2.65rem);line-height:1.3}
}

@media(max-width:480px){
  .library-filters{grid-template-columns:minmax(0,1fr)}
  .library-filters .search-label{grid-column:auto}
  .studio-toolbar{grid-template-columns:minmax(0,1fr)}
  .studio-toolbar label:last-child{grid-column:auto}
  .studio-resources{grid-template-columns:minmax(0,1fr)}
  .portal-header .header-links{width:100%;margin:0;justify-content:center;border-top:1px solid #dedecb;padding-top:4px}
  .event-header-inner{justify-content:center}
  .event-brand{width:100%;justify-content:center}
  .event-header nav{width:100%;justify-content:center}
  .occasion-stats{grid-template-columns:repeat(3,minmax(0,1fr))}
}

@media(max-width:360px){
  :root{--safe-inline:14px}
  .games-brand>span,.event-brand>span,.portal-brand .brand-symbol{width:36px;height:38px}
  .games-mast nav #game-profile{max-width:100px;font-size:.72rem}
  .occasion-stats small{font-size:.7rem}
  .discovery-meter li{font-size:.62rem}
}
